diff options
| author | Wilfred Hughes <me@wilfred.me.uk> | 2019-04-07 21:43:02 +0100 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2019-04-07 21:43:51 +0100 |
| commit | 67b7592f970776776d243cacf7363eb93bc28ebc (patch) | |
| tree | 21c8d6fd25441074e96a64db753d0b0869ee4e45 | |
| parent | 0a83a7b028881a7a463ba5dfc7646ca98afc48c7 (diff) | |
Render keyboard maros in keymap pretty view
Fixes #202
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | helpful.el | 21 | ||||
| -rw-r--r-- | 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. @@ -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)) |
