aboutsummaryrefslogtreecommitdiff
path: root/helpful.el
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2018-07-28 14:30:46 +0100
committerWilfred Hughes <me@wilfred.me.uk>2018-07-28 14:30:46 +0100
commita7260fb844924481abf01ac5796354ced084c1f8 (patch)
tree9f3a2525ee30935529491fa4673b2ac8cea22130 /helpful.el
parent0eac5f08ea471010902e84501b2b5d0c62762195 (diff)
Show keybindings for command aliases too
Fixes #143
Diffstat (limited to 'helpful.el')
-rw-r--r--helpful.el28
1 files changed, 27 insertions, 1 deletions
diff --git a/helpful.el b/helpful.el
index 7daa98f..0b67081 100644
--- a/helpful.el
+++ b/helpful.el
@@ -1315,11 +1315,37 @@ same bindings as `global-map'."
matching-keymaps))
+(defun helpful--merge-alists (l1 l2)
+ "Given two alists mapping symbols to lists, return a single
+alist with the lists concatenated."
+ (let* ((l1-keys (-map #'-first-item l1))
+ (l2-keys (-map #'-first-item l2))
+ (l2-extra-keys (-difference l2-keys l1-keys))
+ (l2-extra-values
+ (--map (assoc it l2) l2-extra-keys))
+ (l1-with-values
+ (-map (-lambda ((key . values))
+ (cons key (append values
+ (cdr (assoc key l2)))))
+ l1)))
+ (append l1-with-values l2-extra-values)))
+
+(defun helpful--keymaps-containing-aliases (command-sym)
+ "Return a list of pairs mapping keymap symbols to the
+keybindings for COMMAND-SYM in each keymap.
+
+Includes keybindings for aliases, unlike
+`helpful--keymaps-containing'."
+ (let* ((aliases (helpful--aliases 'helpful--dummy-command t))
+ (syms (cons command-sym aliases))
+ (syms-keymaps (-map #'helpful--keymaps-containing syms)))
+ (-reduce #'helpful--merge-alists syms-keymaps)))
+
(defun helpful--format-keys (command-sym)
"Describe all the keys that call COMMAND-SYM."
(let (mode-lines
global-lines)
- (--each (helpful--keymaps-containing command-sym)
+ (--each (helpful--keymaps-containing-aliases command-sym)
(-let [(map . keys) it]
(dolist (key keys)
(push