aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2019-04-07 21:43:02 +0100
committerWilfred Hughes <me@wilfred.me.uk>2019-04-07 21:43:51 +0100
commit67b7592f970776776d243cacf7363eb93bc28ebc (patch)
tree21c8d6fd25441074e96a64db753d0b0869ee4e45
parent0a83a7b028881a7a463ba5dfc7646ca98afc48c7 (diff)
Render keyboard maros in keymap pretty view
Fixes #202
-rw-r--r--CHANGELOG.md2
-rw-r--r--helpful.el21
-rw-r--r--test/helpful-unit-test.el11
3 files changed, 27 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 26236f5..1501875 100644
--- 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
index 4aac2aa..a88031a 100644
--- 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
index d4fd835..01e8067 100644
--- 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))