helpful

a fork of Wilfred's helpful
git clone https://git.trogloxene.org/helpful.git
Log | Files | Refs | README

commit 1a3779f25a70d368d0b22c9218d7b4189867909d
parent d4b316d0af522098d97128fcc4ea9f79d64eb339
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Mon, 18 Jun 2018 23:27:17 +0100

Handle references to non-existent keymaps in docstrings

Fixes #110.

Diffstat:
MCHANGELOG.md | 2++
Mhelpful.el | 11++++++++---
Mtest/unit-test.el | 6+++++-
3 files changed, 15 insertions(+), 4 deletions(-)

diff --git 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 diff --git a/helpful.el b/helpful.el @@ -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 @@ -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."