Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add smart-jump-go-other-window #26

Open
mnewt opened this issue Jun 13, 2020 · 2 comments
Open

Add smart-jump-go-other-window #26

mnewt opened this issue Jun 13, 2020 · 2 comments

Comments

@mnewt
Copy link

mnewt commented Jun 13, 2020

What's the best way to implement a version of smart-jump-go that pops open in a new/other window, like xref-find-definitions-other-window? Should :before-jump-fn be used, or would smart-jump-run need to be modified?

Thanks!

@jojojames
Copy link
Owner

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).

@mnewt
Copy link
Author

mnewt commented Aug 6, 2020

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants