aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Drozd <nicholasdrozd@gmail.com>2018-07-07 19:46:21 -0500
committerNick Drozd <nicholasdrozd@gmail.com>2018-07-16 09:33:45 -0500
commit166c669a1d8058e5ea299720e4345f81cf54eaae (patch)
tree6822b02453d81bdc89d90812f3eb669528fa66ae
parent1a320c996cf648cb2ec58020f0180078b15b5763 (diff)
Look up global-keycodes just once
Looking up the global keycodes is expensive, so don't do it in a loop.
-rw-r--r--helpful.el11
1 files changed, 6 insertions, 5 deletions
diff --git a/helpful.el b/helpful.el
index ff62ac2..7225e7b 100644
--- a/helpful.el
+++ b/helpful.el
@@ -1216,7 +1216,7 @@ buffer."
(push sym keymaps))))
keymaps))
-(defun helpful--key-sequences (command-sym keymap)
+(defun helpful--key-sequences (command-sym keymap global-keycodes)
"Return all the key sequences of COMMAND-SYM in KEYMAP."
(let* ((keycodes
;; Look up this command in the keymap, its parent and the
@@ -1232,8 +1232,7 @@ buffer."
;; Look up this command in the global map.
(global-keycodes
(unless (eq keymap global-map)
- (where-is-internal
- command-sym (list global-map) nil t))))
+ global-keycodes)))
(->> keycodes
;; Ignore keybindings from the parent or global map.
(--remove (or (-contains-p global-keycodes it)
@@ -1255,11 +1254,13 @@ from parent keymaps.
same bindings as `global-map'."
(let* ((keymap-syms (helpful--all-keymap-syms))
(keymap-sym-vals (-map #'symbol-value keymap-syms))
+ (global-keycodes (where-is-internal
+ command-sym (list global-map) nil t))
matching-keymaps)
;; Look for this command in all keymaps bound to variables.
(-map
(-lambda ((keymap-sym . keymap))
- (let ((key-sequences (helpful--key-sequences command-sym keymap)))
+ (let ((key-sequences (helpful--key-sequences command-sym keymap global-keycodes)))
(when (and key-sequences (not (eq keymap-sym 'widget-global-map)))
(push (cons (symbol-name keymap-sym) key-sequences)
matching-keymaps))))
@@ -1272,7 +1273,7 @@ same bindings as `global-map'."
;; Only consider this keymap if we didn't find it bound to a variable.
(when (and (keymapp keymap)
(not (memq keymap keymap-sym-vals)))
- (let ((key-sequences (helpful--key-sequences command-sym keymap)))
+ (let ((key-sequences (helpful--key-sequences command-sym keymap global-keycodes)))
(when key-sequences
(push (cons (format "minor-mode-map-alist (%s)" minor-mode)
key-sequences)