How do I jump to function definition?

I wonder if there is a built-in capability or maybe some editor binding where I can just point at a function name and jump to its definition (and then go back where I was before)?

If you’re using emacs, you can create a TAGS file by etags -l prolog *.pl and then jump to a definition using M-. (xref-find-definitions). There’s probably something similar for vim, using ctags.

1 Like

Thanks, Peter, good to know. I am currently using more VSCode, but I am familiar with emacs as well.
I thought if I might miss something built-in the native SWI environment.

There is also a cross-referencer: https://www.swi-prolog.org/pldoc/man?section=xref

Also, if you use the built-in Prolog editor, I think that M-. will jump to the definition (others will need to confirm this; I use emacs). https://www.swi-prolog.org/PceEmacs.txt

1 Like

My LSP implementation also provides jump-to-definition functionality. I’m not sure if it works with VSCode, although it should (I’ve only tested with Emacs & Vim).

1 Like

@jamesnvc - I tried setting up lsp-mode (M-x package-install lsp-mode) but it fails with https://stable.melpa.org/packages/dash-functional-2.16.0.el: Not found … is there a work-around?
(GNU Emacs 28.0.50)

A lot of highlighted fragments allow for right-click to get a menu. Among these are files, modules, predicate heads and goals. The menu provides a lot of stuff, including going to the definition. Emacs M-. works as well. For best experience make sure the program you are editing is loaded. If you continuously need to restart your program during debugging because for some reason it produces side effects that are not easily undone, I usually have one window with the program loaded running the editor and another for running the program.

Strange, I haven’t seen that before; I usually install packages with straight.el. Sounds like the version of dash on MELPA is lagging or something…maybe try doing a manual list-packages to force a refresh? I’m not super-plugged in to the elisp side of lsp-mode, I’ve only been working on the language server side.