aboutsummaryrefslogtreecommitdiff
path: root/evil-core.el
diff options
context:
space:
mode:
authorjustbur <justin@burkett.cc>2016-05-19 10:27:40 -0400
committerjustbur <justin@burkett.cc>2016-05-19 10:27:40 -0400
commit7f5b651154d6878420b1960f8ca4bb58ed85f6eb (patch)
tree360af92ed0cbb2976820a660ed1324de31c43ab1 /evil-core.el
parent2711d45326ec9cb508329ab9b6b1bfadda54aaaa (diff)
evil-core.el: Allow list of states in evil-define-key
Support a common pattern of putting the same binding in multiple states and avoid difficulties with using evil-define-key inside of a dolist loop due to it being a macro.
Diffstat (limited to 'evil-core.el')
-rw-r--r--evil-core.el26
1 files changed, 18 insertions, 8 deletions
diff --git a/evil-core.el b/evil-core.el
index 9dbdd24..d438b84 100644
--- a/evil-core.el
+++ b/evil-core.el
@@ -944,8 +944,9 @@ A return value of t means all states."
(defmacro evil-define-key (state keymap key def &rest bindings)
"Create a STATE binding from KEY to DEF for KEYMAP.
STATE is one of `normal', `insert', `visual', `replace',
-`operator', `motion' and `emacs'. The remaining arguments
-are like those of `define-key'. For example:
+`operator', `motion', `emacs', or a list of one or more of
+these. The remaining arguments are like those of
+`define-key'. For example:
(evil-define-key 'normal foo-map \"a\" 'bar)
@@ -964,16 +965,25 @@ to `after-load-functions', delaying execution as necessary."
`(and (boundp ',keymap) (keymapp ,keymap))
`(keymapp ,keymap))
'(let* ((state ,state) (keymap ,keymap) (key ,key) (def ,def)
- (bindings (list ,@bindings)) aux)
- (if state
- (setq aux (evil-get-auxiliary-keymap keymap state t))
- (setq aux keymap))
+ (bindings (list ,@bindings)) aux-maps)
+ (cond ((listp state)
+ (setq aux-maps (mapcar
+ (lambda (st)
+ (evil-get-auxiliary-keymap keymap st t))
+ state)))
+ (state
+ (setq aux-maps
+ (list (evil-get-auxiliary-keymap keymap state t))))
+ (t
+ (setq aux-maps (list keymap))))
(while key
- (define-key aux key def)
+ (dolist (map aux-maps)
+ (define-key map key def))
(setq key (pop bindings)
def (pop bindings)))
;; ensure the prompt string comes first
- (evil-set-keymap-prompt aux (keymap-prompt aux)))
+ (dolist (map aux-maps)
+ (evil-set-keymap-prompt map (keymap-prompt map))))
'after-load-functions t nil
(format "evil-define-key-in-%s"
',(if (symbolp keymap) keymap 'keymap))))