jacktasia / dumb-jump

an Emacs "jump to definition" package for 50+ languages
GNU General Public License v3.0
1.58k stars 151 forks source link

dumb-jump-go still very useful #378

Open DavidVujic opened 3 years ago

DavidVujic commented 3 years ago

I very much like the new way of navigating with M-. and via xref. When in clojure-mode the cider-find-var command will be used, if I have understood it correctly.

I think the now deprecated dumb-jump-go (C-M-g) is still very useful:

Would it be a good idea to not deprecate that feature?

phikal commented 3 years ago

Could you explain what dumb-jump-go is better at in the examples you gave, that the xref iterface isn't?

DavidVujic commented 3 years ago

Here's an example - xref doesn't seem to find ClojureScript re-agent events or subscriptions. Here, I first use C-. with no findings and then C-M-g (dumb-jump-go) with a popup.

The behavior is slightly different when connected to a Cider session or not. However, dumb-jump-go will in both cases present a search result. In both cases, xref doesn't find anything. I have verified this on a Linux machine running Emacs 25, and on a Mac running emacs 26. Maybe there is a configuration I should add for xref?

with-cider

phikal commented 3 years ago

From what I see, xref doesn't seem to be using the dumb-jump backend (the miniprompt says "Visit tags table"), so it might be that xref-backend-functions has just changed. What does M-: xref-backend-functions RET say?

DavidVujic commented 3 years ago
(defvar xref-backend-functions nil
  "Special hook to find the xref backend for the current context.
Each function on this hook is called in turn with no arguments,
and should return either nil to mean that it is not applicable,
or an xref backend, which is a value to be used to dispatch the
generic functions.")

;; We make the etags backend the default for now, until something
;; better comes along.  Use APPEND so that any `add-hook' calls made
;; before this package is loaded put new items before this one.
(add-hook 'xref-backend-functions #'etags--xref-backend t)
DavidVujic commented 3 years ago

Oh! I realize I might have messed up my configuration. Accdentally put the

;; jump to definition
(dumb-jump-mode)
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)

after a provide statement.

phikal commented 3 years ago

Sorry, I didn't mean the definition, that should be the same for everyone by default. I wanted to know what the buffer-local vaue was. The point is that if the value is (etags--xref-backend), then xref isn't using dumb-jump, but that can be changed, which should do everything that dumb-jump-go does in your situation.

Alternativly, you could also use something like

(defun local/dumb-jump (arg)
  (interactive (let ((xref-backend-functions '(dumb-jump-xref-activate)))
         (list (xref--read-identifier "Find definitions of: "))))
  (let ((xref-backend-functions '(dumb-jump-xref-activate)))
    (xref-find-definitions arg)))

to test if the xref backend dumb-jump is properly working.

DavidVujic commented 3 years ago

Thanks! I'll try that!

This is what is printed when I type "xref-backend-functions"

Skärmavbild 2020-11-16 kl  21 48 50
DavidVujic commented 3 years ago

I tried with adding the local/dumb-jump function to my config, but got this message. Maybe I misunderstood how to use it? (I'm an Emacs noob).

Screenshot from 2020-11-17 17 48 17

DavidVujic commented 3 years ago

M-. works fine (after I fixed the typo in my config) when browsing code. But when I activate Cider the command is not finding anything (the same behaviour as the previous gif in this thread). Could it be that a different command is activated? I think I have read somewhere that the cider-find-var is used - and the re-agent events/subs aren't really vars.

phikal commented 3 years ago

Looks like it, but that doesn't explain the behaviour from the gif.

And the bug with "xref-backend-identifier-completion-table" was fixed in #374 mentioned here again.

andreyorst commented 3 years ago

FYI I've opened the issue at CIDER bug tracker asking not to rebing M-. keybinding, and use xref backend feature instead: https://github.com/clojure-emacs/cider/issues/2987

Until then it seems that the only way to solve it for CIDER is to advice it's jumping functions to use xref, but the case with M-, is a bit harder to advice as it seems