helpful

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

commit beb7bec0d9628942452c5f769aee60c0cc988a0b
parent f248ebc7335efa05d190f07a3e65087bc6c4b0e7
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sat, 26 Aug 2017 12:24:47 +0100

Only propertize links to bound variables/functions

Diffstat:
Mhelpful.el | 10+++++++---
Mtest/unit-test.el | 13+++++++++++++
2 files changed, 20 insertions(+), 3 deletions(-)

diff --git 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 @@ -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."))))