From 67b7592f970776776d243cacf7363eb93bc28ebc Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sun, 7 Apr 2019 21:43:02 +0100 Subject: Render keyboard maros in keymap pretty view Fixes #202 --- CHANGELOG.md | 2 ++ helpful.el | 21 ++++++++++++++------- test/helpful-unit-test.el | 11 +++++++++++ 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) - "#") + (cond + ((symbolp it) + (helpful--button + (symbol-name it) + 'helpful-describe-button + 'symbol it)) + ((or (stringp it) (vectorp it)) + "Keyboard Macro") + (t + "#")) 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)) -- cgit v1.0