3

I'm using Spacemacs. I noticed that in help-mode, q quits, which is exactly what I want. However, in certain other modes, customize-mode, for example, q is bound to evil-record-macro. (I set it to start in normal state rather than in emacs state because I like the vim navigation keybindings.) I tried (evil-define-key 'normal custom-mode-map "q" nil), but it didn't rebind.

How can I modify the keybinding so that q quits as expected?

2 Answers 2

2

Customize appears to be autoloaded, so Emacs won't know about custom-mode-map until after you run customize. The following should rebind q to run test in normal state:

(defun test ()
  (interactive)
  (message "testing"))

(eval-after-load "custom"
  '(evil-define-key 'normal custom-mode-map "q" #'test))
3
  • Rebinding to 'Custom-buffer-done works; rebinding to nil doesn't.
    – Alex R
    Apr 16, 2015 at 22:41
  • The reason for this is simple, evil-define-key adds an auxiliary keymap which is put on top of, say, evil-normal-state-map. If you bind a command with it, Emacs will notice this and return that command when pressing q, if you bind nothing however, Emacs will assume the map shall be disregarded and use the keybinding of the underlying map.
    – wasamasa
    Nov 13, 2015 at 18:26
  • As a workaround, look up what q is bound to in Emacs state, then bind that command with evil-define-key. Also, it's not necessary to wrap it into eval-after-load as it is doing something very similiar on its own...
    – wasamasa
    Nov 13, 2015 at 18:27
0

Customize the mode to use motion state instead of normal state to keep motion keybindings while leaving out q for quitting:

(evil-set-initial-state 'Custom-mode 'motion)
2
  • Clever. Doesn't this break down if I want to go into insert state and then press escape?
    – Alex R
    Nov 13, 2015 at 17:57
  • Motion state is about moving, not editing text. i isn't bound there. You could still use M-x evil-insert-state, but that would exit to normal state, yes.
    – wasamasa
    Nov 13, 2015 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.