helpful

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

commit 8e5390f0e8983816b938607c9b3a42fd7b868a00
parent 53dd618dc2d5fbd6b6edf72fb29210c8d129728b
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sun,  7 Jan 2018 00:04:26 +0000

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.

Diffstat:
MCHANGELOG.md | 8+++++---
Mhelpful.el | 7+++++--
Mtest/unit-test.el | 12++++++++++++
3 files changed, 22 insertions(+), 5 deletions(-)

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