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

Refactor jump to definition #6815

Closed
wants to merge 1 commit into from
Closed

Conversation

TheBB
Copy link
Collaborator

@TheBB TheBB commented Aug 13, 2016

According to discussion with @syl20bnr.

This commit defines:

  • spacemacs-default-jump-handlers: a list of functions that can jump to
    definition in ALL modes.
  • spacemacs-jump-handlers-MODE: a list of functions that can jump to
    definition in MODE.
  • spacemacs-jump-handlers: a buffer-local list of functions that can
    jump to definition. This is made up of the values of the two previous
    variables whenever a given major mode is activated.
  • spacemacs/jump-to-definition: a function that tries each function in
    spacemacs-jump-handlers in order, and stops when one of them takes us
    somewhere new.
  • spacemacs|define-jump-handlers: a macro that
    • defines spacemacs-jump-handlers-MODE, possibly filled with initial
      functions
    • defines a function that is added to the hook of the given MODE
    • binds “SPC m g g” of that MODE to spacemacs/jump-to-definition

This is an attempt to harmonize all the different approaches to jumping.
Specifically,

  • Existing intelligent jump packages that work for only a single mode
    should go to the beginning of spacemacs-jump-handlers-MODE. E.g.
    anaconda for python, ensime for scala, etc.
  • Packages like gtags that work for several modes (but potentially not
    all) and which is dumber than the intelligent jumpers should go the
    the END of spacemacs-jump-handlers-MODE.
  • Packages like dumb-jump that work for all modes should go to
    spacemacs-default-jump-handlers.

In all cases the order of the jump handlers in each list should be from
most to least intelligent.

Fixes #6619, and to some degree supersedes #6164 (CC @axyz re: dumb-jump)

@TheBB
Copy link
Collaborator Author

TheBB commented Aug 13, 2016

Note, with this is it potentially possible to make gtags work automatically in all modes that use spacemacs|define-jump-handlers without listing the package everywhere. I haven't done that here.

@ksjogo
Copy link
Contributor

ksjogo commented Aug 13, 2016

Another option would be to use the new xref functions from 25 and create xref backends for the jumpers.
This route would introduce less spacemacs specific functionality and let emacs do the picking of the backends.
Based on the xref backends we could introduce just one common frontend in spacemacs e.g. one helm/ivy.

@TheBB
Copy link
Collaborator Author

TheBB commented Aug 13, 2016

That looks promising, but we can't drop support for 24 for a good while yet. I assume we will also need to wait for upstream jumpers to integrate with xref.

(add-hook 'spacemacs-jump-handlers-c++-mode 'ycmd-goto)
(add-hook 'spacemacs-jump-handlers-c-mode 'ycmd-goto)
(dolist (mode '(c++-mode c-mode))
(spacemacs/set-leader-keys-for-major-mode 'c++-mode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not be a dolist, or should it be mode instead of 'c++-mode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be a dolist, I just messed up the mode.

@TheBB
Copy link
Collaborator Author

TheBB commented Aug 17, 2016

I have been using this for a few days now and I'm quite happy with it. If there are no complaints I might just merge it soon.

@TheBB TheBB force-pushed the smart-jump branch 8 times, most recently from ef70502 to 39ba4cf Compare August 21, 2016 15:51
This commit defines:

- spacemacs-default-jump-handlers: a list of functions that can jump to
  definition in ALL modes.

- spacemacs-jump-handlers-MODE: a list of functions that can jump to
  definition in MODE.

- spacemacs-jump-handlers: a buffer-local list of functions that can
  jump to definition. This is made up of the values of the two previous
  variables whenever a given major mode is activated.

- spacemacs/jump-to-definition: a function that tries each function in
  spacemacs-jump-handlers in order, and stops when one of them takes us
  somewhere new.

- spacemacs|define-jump-handlers: a macro that
  * defines spacemacs-jump-handlers-MODE, possibly filled with initial
    functions
  * defines a function that is added to the hook of the given MODE
  * binds “SPC m g g” of that MODE to spacemacs/jump-to-definition

This is an attempt to harmonize all the different approaches to jumping.
Specifically,

- Existing intelligent jump packages that work for only a single mode
  should go to the beginning of spacemacs-jump-handlers-MODE. E.g.
  anaconda for python, ensime for scala, etc.

- Packages like gtags that work for several modes (but potentially not
  all) and which is dumber than the intelligent jumpers should go the
  the END of spacemacs-jump-handlers-MODE.

- Packages like dumb-jump that work for all modes should go to
  spacemacs-default-jump-handlers.

In all cases the order of the jump handlers in each list should be from
most to least intelligent.

Fixes syl20bnr#6619
@TheBB
Copy link
Collaborator Author

TheBB commented Aug 22, 2016

Merged.

@TheBB TheBB closed this Aug 22, 2016
@TheBB TheBB deleted the smart-jump branch August 22, 2016 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants