3

I use evil-mode and evil-leader, and I have the <SPC>s keybinding to save the buffer. But when I edit a src code block in org-mode (with C-'), I want <SPC>s to run org-edit-src-save instead of save-buffer. Some things I tried:

;; I think this one has no effect because `set-key-for-mode`
;; probably only works with major-modes.
(evil-leader/set-key-for-mode 'org-src-mode "s" 'org-edit-src-save)


;; This one works, but makes the binding global.
(defun my/org-src-conf () 
 (make-local-variable 'evil-leader--default-map)
 (make-local-variable 'evil-leader--mode-maps)
 (evil-leader/set-key "s" 'org-edit-src-save))

(add-hook 'org-src-mode-hook 'my/org-src-conf)

How can I achieve this local binding for evil-leader?

  • Is there any specific reason you're using evil-leader instead of the keymap support Emacs comes with? – wasamasa Aug 14 '15 at 14:04
  • None other than evil-leader seems the right way to do it. Also, I didn't just use the evil-define-key because I want to learn how to actually achieve this. I'm trying to understand emacs better. – Jesse Aug 14 '15 at 14:14
2

org-src-mode is a minor mode and evil-leader doesn't support these last time I checked. evil-leader/set-key-for-mode is for major modes. In org-src-mode the major mode is tied to the language of the source that you are editing.

The most natural way to accomplish what you want is to use evil-define-minor-mode-key with the following.

(evil-define-minor-mode-key 'normal 'org-src-mode " s" 'org-edit-src-exit)

You can use evil-define-key too, but it does not always activate the key bindings for keys in maps connected to minor modes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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