helpful

a fork of Wilfred's helpful
git clone https://git.trogloxene.org/helpful.git
Log | Files | Refs | README

commit 166c669a1d8058e5ea299720e4345f81cf54eaae
parent 1a320c996cf648cb2ec58020f0180078b15b5763
Author: Nick Drozd <nicholasdrozd@gmail.com>
Date:   Sat,  7 Jul 2018 19:46:21 -0500

Look up global-keycodes just once

Looking up the global keycodes is expensive, so don't do it in a loop.

Diffstat:
Mhelpful.el | 11++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)

diff --git 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)