From beb7bec0d9628942452c5f769aee60c0cc988a0b Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Sat, 26 Aug 2017 12:24:47 +0100 Subject: Only propertize links to bound variables/functions --- helpful.el | 10 +++++++--- test/unit-test.el | 13 +++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/helpful.el b/helpful.el index da1f332..643dc6b 100644 --- a/helpful.el +++ b/helpful.el @@ -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.")))) -- cgit v1.0