markasoftware · 2022-12-22 21:56
Imenu seems to be smarter than dumb-jump but much easier to get working than a full LSP server for languages I don't use very often. Is there any way to get xref jump to definition working with imenu as a backend so I can just use M-. instead of having to manually search the imenu?
_viz_ · 2022-12-23 04:37
I tried to do that once and failed to achieve a satisfactory experience since the imenu item could be named anything (i.e., not just the symbol. for an example, look at the imenu items in a python buffer). In any case, my attempts are posted as patches to bug#28407 [1]. If it still has weird bugs and edge cases, then I might have fixed it in my local copy which I can share if you want.
My intent was to use imenu backend with another xref backend, but the experience might be really dodgy. Etags in particular prompts you for the TAGS file which I _tried_ to work around.
1. https://debbugs.gnu.org/cgi/bugreport.cgi?bug=28407
oantolin · 2022-12-23 17:13
I have a cheap way to do this involving [Embark](https://github.com/oantolin/embark) and [Consult](https://github.com/minad/consult): use consult-imenu as an embark action on an identifier. (You need consult-imenu here because it flattens the imenu hierarchy). Say you bind `embark-act` to `C-.`, then you can put point on an identifier and type `C-. C i` and embark will run `consult-imenu` for you, type the identifier at the minibuffer prompt automatically, *and* if there is a single matching item, press `RET` for you too. (If more than one item matches, then you must select among them and press `RET`.) You need a completion style that will match substrings for this to work. The built-in `substring` would work, but obviously I recommend [Orderless](https://github.com/oantolin/orderless):P.
I use this sometimes even when `xref-find-definitions` would work: when I'm working on one of my Emacs Lisp packages I'm usually *running* the version installed in `~/.emacs.d/elpa` but *working* on the source code somewhere else, so then I don't actually want to go to the place the identifier was defined (in `~/.emacs.d/elpa`) but to the place in the current file that has a definition for it.
eleven_cupfuls · 2022-12-25 02:06
dumb-jump uses regexes to find things. Most likely, the imenu indexer for the languages you're interested is also regex-based (see `imenu-generic-expression`). So one thing that might be worth exploring is transferring the imenu _regexes_ to dumb-jump's configuration for those languages.