diff options
| author | Wilfred Hughes <me@wilfred.me.uk> | 2018-06-18 23:27:17 +0100 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2018-06-18 23:27:17 +0100 |
| commit | 1a3779f25a70d368d0b22c9218d7b4189867909d (patch) | |
| tree | 2a3ed319b04dd3a2a1be4b9e36ebf4d400044906 | |
| parent | d4b316d0af522098d97128fcc4ea9f79d64eb339 (diff) | |
Handle references to non-existent keymaps in docstrings
Fixes #110.
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | helpful.el | 11 | ||||
| -rw-r--r-- | test/unit-test.el | 6 |
3 files changed, 15 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3911d21..e8376ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ Fixed a crash when minor modes had invalid keymaps. Fixed an issue with `helpful-variable` where the user was pointlessly prompted about file variables. +Fixed a crash when a docstring referenced a non-existent keymap. + # v0.10 When visiting a reference, the occurrences of the symbol are @@ -805,12 +805,17 @@ unescaping too." (rx "\\{" (group (+ (not (in "}")))) "}")) (let* ((symbol-with-parens (match-string 0)) (symbol-name (match-string 1)) - (keymap (symbol-value (intern symbol-name)))) + (keymap + ;; Gracefully handle variables not being defined. + (ignore-errors + (symbol-value (intern symbol-name))))) ;; Remove the original string. (delete-region (point) (+ (point) (length symbol-with-parens))) - (insert - (helpful--format-keymap keymap)))) + (if keymap + (insert (helpful--format-keymap keymap)) + (insert (format "Keymap %s is not currently defined." + symbol-name))))) ((looking-at ;; Text of the form \\[foo-command] (rx "\\[" (group (+ (not (in "]")))) "]")) diff --git a/test/unit-test.el b/test/unit-test.el index 95539be..c1c1cfd 100644 --- a/test/unit-test.el +++ b/test/unit-test.el @@ -210,7 +210,11 @@ symbol (not a form)." ;; Propertize mode maps. (-let [formatted (helpful--format-docstring "`\\{python-mode-map}'")] (should - (s-contains-p "run-python" formatted)))) + (s-contains-p "run-python" formatted))) + ;; Handle non-existent mode maps gracefully. + (-let [formatted (helpful--format-docstring "`\\{no-such-mode-map}'")] + (should + (s-contains-p "not currently defined" formatted)))) (ert-deftest helpful--format-docstring--info () "Ensure we propertize references to the info manual." |
