diff options
| author | Wilfred Hughes <me@wilfred.me.uk> | 2017-08-26 12:24:47 +0100 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2017-08-26 12:24:47 +0100 |
| commit | beb7bec0d9628942452c5f769aee60c0cc988a0b (patch) | |
| tree | f2fecab7e6e52bfce81c8a894041f8c9544af872 | |
| parent | f248ebc7335efa05d190f07a3e65087bc6c4b0e7 (diff) | |
Only propertize links to bound variables/functions
| -rw-r--r-- | helpful.el | 10 | ||||
| -rw-r--r-- | test/unit-test.el | 13 |
2 files changed, 20 insertions, 3 deletions
@@ -222,9 +222,13 @@ blank line afterwards." (replace-regexp-in-string (rx "`" symbol-start (+? anything) symbol-end "'") (lambda (it) - (let ((sym-name - (s-chop-prefix "`" (s-chop-suffix "'" it)))) - (helpful--describe-button (read sym-name)))) + (let* ((sym-name + (s-chop-prefix "`" (s-chop-suffix "'" it))) + (sym (intern sym-name))) + (if (or (boundp sym) (fboundp sym)) + (helpful--describe-button (read sym-name)) + (propertize sym-name + 'face 'font-lock-constant-face)))) (helpful--split-first-line docstring) t t)) diff --git a/test/unit-test.el b/test/unit-test.el index ccc35fd..46bad32 100644 --- a/test/unit-test.el +++ b/test/unit-test.el @@ -80,3 +80,16 @@ (equal (helpful--format-reference '(advice-add 'bar) 1 123 "/foo/bar.el") "(advice-add 'bar ...) ; 1 reference"))) + +(ert-deftest helpful--format-docstring () + "Ensure we create links in docstrings." + ;; If it's bound, we should link it. + (let* ((formatted (helpful--format-docstring "foo `message'.")) + (m-position (s-index-of "m" formatted))) + (should (get-text-property m-position 'button formatted))) + ;; If it's not bound, we should not. + (let* ((formatted (helpful--format-docstring "foo `messagexxx'.")) + (m-position (s-index-of "m" formatted))) + (should (not (get-text-property m-position 'button formatted))) + ;; But we should always remove the backticks. + (should (equal formatted "foo messagexxx.")))) |
