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

let certain minor-mode's key bindings override evil's default key bindings #511

Closed
TheBB opened this issue Apr 8, 2015 · 3 comments
Closed

Comments

@TheBB
Copy link
Member

TheBB commented Apr 8, 2015

Originally reported by: Bin Chen (Bitbucket: redguardtoo, GitHub: redguardtoo)


for example, git-timemachine will use "n", "p", "q" "g" key bindings.

I need a list like evil-set-initial-state, but it's for minor-modes.

for certain minor-modes, I could:

  • use the keybindings defined in major-mode, but let this minor mode take precedence

  • OR, use emacs keybindings if the minor is loaded and restore its original key bindings if the minor-mode is turned off.


@TheBB
Copy link
Member Author

TheBB commented Apr 8, 2015

Original comment by Frank Fischer (Bitbucket: lyro, GitHub: lyro):


You can use evil-make-overriding-map to give some keymap a priority higher than Evil's keymaps:

(evil-make-overriding-map some-key-map 'normal)

gives the keymap some-key-map a higher priority

@TheBB
Copy link
Member Author

TheBB commented Apr 9, 2015

Original comment by Bin Chen (Bitbucket: redguardtoo, GitHub: redguardtoo):


doesn't work, here is my setup. use the dev version of evil:

(eval-after-load 'git-timemachine
'(progn
(defvar git-timemachine-mode-map)
(evil-make-override-map git-timemachine-mode-map 'normal)
))

(require 'evil)

;; enable evil-mode
(evil-mode 1)

@TheBB
Copy link
Member Author

TheBB commented Apr 9, 2015

Original comment by Frank Fischer (Bitbucket: lyro, GitHub: lyro):


Please try

(evil-make-override-map git-timemachine-mode-map 'normal)
(add-hook 'git-timemachine-mode-hook #'evil-normalize-keymaps)

Updating key bindings according to some minor-modes or keymaps is very difficult in Emacs, because there is no reliable way (that I know of) to detect whether some minor mode is activated or some keymap becomes active (there are hooks like change-major-mode-hook but nothing equivalent for minor-modes and keymaps). Usually minor modes define some hook minormodename-mode-hook, but not all minor modes do this. That's why it is so difficult to get the right keymaps into the right places at the right time.

The hook for evil-normalize-keymaps forces an update of all Evil keymaps after git-timemachine has become active.

Note that this gives all bindings of git-timemachine higher priority than any Evil binding (but only in normal state). If this is not what you want you could do the following:

  1. use evil-add-hjkl-bindings or evil-define-key to add give a few Evil bindings highest priority (see evil-integration.el for some examples)
  2. if you need only few bindings from git-timemachine then you can simply replace some Evil bindings by their corresponding git-timemachine bindings in Evil's standard keymaps:
(add-hook 'git-timemachine-hook 
  (lambda ()
    (define-key evil-normal-state-local-map "n" 'git-timemachine-show-next-revision)))

Btw, it might be a good idea to make git-timemachine come up in motion-state instead of normal-state.

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

No branches or pull requests

1 participant