Open mnewt opened 4 years ago
You can probably define something like this that uses the other- type functions.
(defvar smart-jump-xref-fallback
'(
:jump-fn xref-find-definitions
:pop-fn xref-pop-marker-stack
:refs-fn xref-find-references
:should-jump t
:heuristic error
:async nil
:order 1000
)
"Xref fallback to use when no other :jump-fn mechanism succeeded.")
I'm not sure how it'd be done generically though (or even feasible).
How about this? It works for me.
(defun smart-jump-go-other-window (&optional smart-list continue)
"Show the function/variable declartion for thing at point in another window.
SMART-LIST will be set (or nil) if this is a continuation of a
previous jump.
CONTINUE will be non nil if this is a continuation of a previous jump."
(interactive)
(let ((old (current-buffer)))
(smart-jump-go smart-list continue)
(let ((new (current-buffer)))
;; If old and new are the same then `xref' has popped up another window
;; listing multiple definitions and we bail.
(unless (eq new old)
(switch-to-buffer old)
(switch-to-buffer-other-window new)))))
Only caveat is if xref finds multiple definitions then xref opens another window midway through the process and there doesn't seem to be a good way to react to that so the command just gives up. A way around that would be to use a lower level xref function to actually get a list of references like this (using use-package
as an example that returns multiple references)
(funcall (xref--create-fetcher 'use-package 'definitions 'use-package))
And then use completing-read
to prompt the user rather than the popup window
That would require re-plumbing the xref-find-definitions fallback but shouldn't be too terrible to implement.
Are you interested in a PR along those lines? Or have other suggestions?
What's the best way to implement a version of
smart-jump-go
that pops open in a new/other window, likexref-find-definitions-other-window
? Should:before-jump-fn
be used, or wouldsmart-jump-run
need to be modified?Thanks!