commit bd2a1f5bb52d8e2d2b3dc30ed8a66c9250ebafab
parent 397185d21d0ecbb36fa7b13c77eb23d31c110df3
Author: Wilfred Hughes <me@wilfred.me.uk>
Date: Thu, 7 Jun 2018 23:25:29 +0100
Handle non-keymaps in minor-mode-map-alist robustly
Fixes #114
Diffstat:
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -3,6 +3,8 @@
Fixed an issue where Helpful didn't find keybindings if the command
was only referenced in `minor-mode-map-alist`.
+Fixed a crash when minor modes had invalid keymaps.
+
# v0.10
When visiting a reference, the occurrences of the symbol are
diff --git a/helpful.el b/helpful.el
@@ -1188,12 +1188,14 @@ same bindings as `global-map'."
(-map
(-lambda ((minor-mode . keymap))
;; Only consider this keymap if we didn't find it bound to a variable.
- (unless (memq keymap keymap-sym-vals)
+ (when (and (keymapp keymap)
+ (not (memq keymap keymap-sym-vals)))
(let ((key-sequences (helpful--key-sequences command-sym keymap)))
(when key-sequences
(push (cons (format "minor-mode-map-alist (%s)" minor-mode)
key-sequences)
matching-keymaps)))))
+ ;; TODO: examine `minor-mode-overriding-map-alist' too.
minor-mode-map-alist)
matching-keymaps))
diff --git a/test/unit-test.el b/test/unit-test.el
@@ -485,6 +485,14 @@ associated a lambda with a keybinding."
(should
(helpful--keymaps-containing #'helpful--dummy-command))))
+ ;; Don't crash if there are dodgy values in `minor-mode-map-alist'.
+ (let ((minor-mode-map-alist
+ ;; I'm not convinced this is legal, but
+ ;; pdf-cache-prefetch-minor-mode in pdf-tools has t as a
+ ;; keymap.
+ (cons (cons 'foo-mode t) minor-mode-map-alist)))
+ (helpful--keymaps-containing #'helpful--dummy-command))
+
;; Create a keybinding that is very unlikely to clobber actually
;; defined keybindings in the current emacs instance.
(global-set-key (kbd "C-c M-S-c") #'helpful--dummy-command)