branch: elpa/bind-map
commit d47be94d236c819b5ca47d66551d23a0ee17ac33
Author: justbur <[email protected]>
Commit: justbur <[email protected]>
Don't try to bind keys that are nil or ""
---
bind-map.el | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/bind-map.el b/bind-map.el
index 66f91a2013..77bf7a0a5d 100644
--- a/bind-map.el
+++ b/bind-map.el
@@ -153,6 +153,14 @@ when the major mode is an element of the cdr. See
(add-hook 'change-major-mode-after-body-hook
'bind-map-change-major-mode-after-body-hook)
+(defun bind-map-kbd-keys (keys)
+ "Apply `kbd' to KEYS filtering out nil and empty strings."
+ (let (res)
+ (dolist (key keys (nreverse res))
+ (when (and (stringp key)
+ (not (string= "" key)))
+ (push (kbd key) res)))))
+
;;;###autoload
(defmacro bind-map (map &rest args)
"Bind keymap MAP in multiple locations.
@@ -284,23 +292,23 @@ mode maps. Set up by bind-map.el." map))
(if (or minor-modes major-modes)
;; only bind keys in root-map
- `((dolist (key (list ,@keys))
- (define-key ,root-map (kbd key) ',prefix-cmd))
- (dolist (key (list ,@evil-keys))
+ `((dolist (key (bind-map-kbd-keys (list ,@keys)))
+ (define-key ,root-map key ',prefix-cmd))
+ (dolist (key (bind-map-kbd-keys (list ,@evil-keys)))
(dolist (state ',evil-states)
(define-key (evil-get-auxiliary-keymap ,root-map state t)
- (kbd key) ',prefix-cmd))))
+ key ',prefix-cmd))))
;; bind in global maps and possibly root-map
- `((dolist (key (list ,@keys))
+ `((dolist (key (bind-map-kbd-keys (list ,@keys)))
(when ,override-minor-modes
- (define-key ,root-map (kbd key) ',prefix-cmd))
- (global-set-key (kbd key) ',prefix-cmd))
- (dolist (key (list ,@evil-keys))
+ (define-key ,root-map key ',prefix-cmd))
+ (global-set-key key ',prefix-cmd))
+ (dolist (key (bind-map-kbd-keys (list ,@evil-keys)))
(dolist (state ',evil-states)
(when ,override-minor-modes
- (push (list ',override-mode state (kbd key) ',prefix-cmd)
+ (push (list ',override-mode state key ',prefix-cmd)
bind-map-evil-local-bindings))
- (evil-global-set-key state (kbd key) ',prefix-cmd)))))
+ (evil-global-set-key state key ',prefix-cmd)))))
(when evil-keys `((evil-normalize-keymaps))))))
(put 'bind-map 'lisp-indent-function 'defun)