diff options
| author | Wilfred Hughes <me@wilfred.me.uk> | 2018-01-07 00:04:26 +0000 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2018-01-07 00:10:50 +0000 |
| commit | 8e5390f0e8983816b938607c9b3a42fd7b868a00 (patch) | |
| tree | 85b4a8a74b6fb7b83e30e8d20253f6706848c884 | |
| parent | 53dd618dc2d5fbd6b6edf72fb29210c8d129728b (diff) | |
Stricter regexps for highlighting `foo' in docstrings
Previously, the regexp was greedy, so we would erroneously highlight:
`foo `bar'
as a single symbol. Fixes #87.
| -rw-r--r-- | CHANGELOG.md | 8 | ||||
| -rw-r--r-- | helpful.el | 7 | ||||
| -rw-r--r-- | test/unit-test.el | 12 |
3 files changed, 22 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 94b4aa2..6c4d1b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,15 +2,17 @@ Added imenu support! You can now navigate between headings with imenu. -Helpful now correctly handles \= escapes in docstrings. +Better handling of docstrings: + +* Correctly handle \= escapes +* Quoted keywords are now highlighted +* Correctly highlight docstrings that contain standalone `` ` `` Added disassemble buttons to byte-code functions in symbol properties. Fixed an issue with the prompt when setting variables to symbol values. -Quoted keywords in docstrings are now highlighted. - Smarter handling of keybindings: * Consider all keymaps, not just `foo-mode-map`. @@ -545,7 +545,10 @@ blank line afterwards." (replace-regexp-in-string ;; Replace all text of the form `foo'. (rx "`" - (group ":" symbol-start (+? anything) symbol-end) + (group ":" + symbol-start + (+? (or (syntax word) (syntax symbol))) + symbol-end) "'") (lambda (it) (propertize (match-string 1 it) @@ -557,7 +560,7 @@ blank line afterwards." "Convert symbol references in docstrings to buttons." (replace-regexp-in-string ;; Replace all text of the form `foo'. - (rx "`" symbol-start (+? anything) symbol-end "'") + (rx "`" symbol-start (+? (not (any "`" "'"))) symbol-end "'") (lambda (it) (let* ((sym-name (s-chop-prefix "`" (s-chop-suffix "'" it))) diff --git a/test/unit-test.el b/test/unit-test.el index db75500..2579316 100644 --- a/test/unit-test.el +++ b/test/unit-test.el @@ -27,6 +27,18 @@ (helpful--docstring #'test-foo t) "Docstring here."))) +(ert-deftest helpful--docstring-symbol () + "Correctly handle quotes around symbols." + ;; We should replace quoted symbols with links, so the punctuation + ;; should not be in the output. + (let* ((formatted-docstring (helpful--format-docstring "`message'"))) + (should + (equal formatted-docstring "message"))) + ;; We should handle stray backquotes. + (let* ((formatted-docstring (helpful--format-docstring "`foo `message'"))) + (should + (equal formatted-docstring "`foo message")))) + (ert-deftest helpful--docstring-unescape () "Discard \\=\\= in docstrings." (let* ((docstring (helpful--docstring #'apply t)) |
