commit 67b7592f970776776d243cacf7363eb93bc28ebc
parent 0a83a7b028881a7a463ba5dfc7646ca98afc48c7
Author: Wilfred Hughes <me@wilfred.me.uk>
Date: Sun, 7 Apr 2019 21:43:02 +0100
Render keyboard maros in keymap pretty view
Fixes #202
Diffstat:
3 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -9,6 +9,8 @@ are now rendered as hooks.
String literals are now rendered correctly in docstrings. Previously
command substitution applied inside literals.
+Fixed a crash on keyboard macros in keymaps.
+
# v0.16
Improved wording when looking at aliases.
diff --git a/helpful.el b/helpful.el
@@ -840,7 +840,10 @@ vector suitable for `key-description', and COMMAND is a smbol."
;; so this is a command we can call.
((or
(symbolp keymap)
- (functionp keymap))
+ (functionp keymap)
+ ;; Strings or vectors mean a keyboard macro.
+ (stringp keymap)
+ (vectorp keymap))
`(([] ,keymap)))
((stringp (car keymap))
(helpful--keymap-keys (cdr keymap)))
@@ -917,12 +920,16 @@ vector suitable for `key-description', and COMMAND is a smbol."
keys-and-commands))
(formatted-commands
(--map
- (if (symbolp it)
- (helpful--button
- (symbol-name it)
- 'helpful-describe-button
- 'symbol it)
- "#<anonymous-function>")
+ (cond
+ ((symbolp it)
+ (helpful--button
+ (symbol-name it)
+ 'helpful-describe-button
+ 'symbol it))
+ ((or (stringp it) (vectorp it))
+ "Keyboard Macro")
+ (t
+ "#<anonymous-function>"))
commands))
;; Build lines for display.
(lines
diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el
@@ -620,6 +620,17 @@ associated a lambda with a keybinding."
;; Don't crash on anonymous functions in a keymap.
(helpful--keymap-keys keymap)))
+(ert-deftest helpful--format-keymap--keyboard-macros ()
+ (let* ((keymap (make-keymap)))
+ ;; A keyboard macro can be a string or a vector.
+ (define-key keymap "a" "ABC")
+ (define-key keymap "b" [TAB])
+
+ (should
+ (equal
+ (helpful--format-keymap keymap)
+ "a Keyboard Macro\nb Keyboard Macro"))))
+
(defun helpful--dummy-command ()
(interactive))