noctuid / evil-guide

Draft of a guide for using emacs with evil
GNU General Public License v3.0
1.26k stars 61 forks source link

SPC cannot be used as leader key in startup *message* buffer #11

Closed BooAA closed 6 years ago

BooAA commented 6 years ago

In order to make SPC as my leader key globally, I used the method you provided,

(defvar my-intercept-mode-map (make-sparse-keymap)
  "High precedence keymap.")

(define-minor-mode my-intercept-mode
  "Global minor mode for higher precedence evil keybindings."
  :global t)

(my-intercept-mode)

(dolist (state '(normal visual insert))
  (evil-make-intercept-map
   ;; NOTE: This requires an evil version from 2018-03-20 or later
   (evil-get-auxiliary-keymap my-intercept-mode-map state t t)
   state))

(evil-define-key 'normal my-intercept-mode-map
  (kbd "SPC") my-cmd-map) ;; this is the only place I modified

Everything works well, the only exception is the message buffer shown when emacs startup.(at other times, message buffer works fine, and the startup scratch buffer works fine too)

I have checked the enable mode list by C-h m, my-intercept-mode has been activated correctly, but SPC doesn't bind to my-cmd-map but evil-forward-char.

If I press C-z twice to activate normal-mode again, then it can work properly, which is very strange.

noctuid commented 6 years ago

Try running (evil-normalize-keymaps) right after binding SPC.

BooAA commented 6 years ago

If you mean adding (evil-normallize-keymaps) right after evil-define-key , I have tried, but it doesn't work.

noctuid commented 6 years ago

Run it in the message buffer manually and see if that fixes it. If it does you can do that in your init with something like with-current-buffer.

BooAA commented 6 years ago

Great! That fixes the problem.

Out of curiosity, can you tell me why only the startup message buffer have this issue? It's so strange that a minor mode has been activated but it's keymap doesn't. I want to understand this.

BTW, do you recommend using evil-escape to escape everything? Another question, I started using evil-collection yesterday, do you think using the evil-collection-setup-minibuffer feature will be a better choice than using hydra in minibuffer?( personally I use ivy with hydra-ivy, I'm wondering whether using evil-collection for minibuffer can give me more consistency.

noctuid commented 6 years ago

It's probably because the message buffer exists even before evil loads. Evil's keymaps aren't really comparable to normal minor mode keymaps.

Edit: To better clarify, the message buffer existing so early may have something to do with it, but this is an issue in general. it's not just a matter of evil-mode being active. Evil's auxiliary maps are actually made in the regular minor and major mode keymaps; they just have no meaning normally and are handled specially by evil.

I don't recommend using evil-escape at all unless you don't have a good key available for escape. I'm guessing that evil-escape has the same issues as key-chord (i.e. that it will accidentally trigger if there is input lag/slow down and that you can only use it in Emacs). I think it's much better to use a dedicated thumbkey (or capslock). For example, I have right alt bound to my altgr layer when held and to escape when immediately released.

Since most evil keybindings aren't usable in the minibuffer, I think that hydra-ivy is fine/preferable. You can try both out and see which you like better. I don't use a modal minibuffer that often and generally prefer using modifiers in the minibuffers personally.