helpful

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

commit 0eac5f08ea471010902e84501b2b5d0c62762195
parent e8db0f37db655565e4325d8fbb5b4524413f3877
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sat, 28 Jul 2018 13:40:40 +0100

Merge pull request #137 from nickdrozd/key-sequences

Improve helpful--key-sequence performance
Diffstat:
Mhelpful.el | 15++++++++-------
Mtest/unit-test.el | 10+++++++++-
2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/helpful.el b/helpful.el @@ -1248,7 +1248,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 @@ -1264,12 +1264,11 @@ 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 (-contains-p parent-keycodes it)) - (--remove (-contains-p global-keycodes it)) + (--remove (or (-contains-p global-keycodes it) + (-contains-p parent-keycodes it))) ;; Convert raw keycode vectors into human-readable strings. (-map #'key-description)))) @@ -1287,11 +1286,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)))) @@ -1304,7 +1305,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) diff --git a/test/unit-test.el b/test/unit-test.el @@ -543,7 +543,15 @@ associated a lambda with a keybinding." 2)) ;; Undo keybinding. - (global-set-key (kbd "C-c M-S-c") nil)) + (global-set-key (kbd "C-c M-S-c") nil) + + ;; Check for ido command remapping. + (ido-mode 1) + (should + (equal + (helpful--keymaps-containing 'ido-find-file) + '(("minor-mode-map-alist (ido-mode)" "<open>" "C-x C-f")))) + (ido-mode 0)) (ert-deftest helpful--source () (-let* (((buf pos opened) (helpful--definition #'helpful--source t))