commit 7d5538941d7da79dd85af64b90a24e93d6518bb3 parent 8c2a65e65bb1bf6251d9405d72c3d82936aca45a Author: Wilfred Hughes <me@wilfred.me.uk> Date: Sat, 16 Dec 2017 12:03:12 +0000 Factoring out a helpful--propertize-symbols worker function Diffstat:
| M | helpful.el | | | 41 | +++++++++++++++++++++++++---------------- |
1 file changed, 25 insertions(+), 16 deletions(-)
diff --git a/helpful.el b/helpful.el @@ -367,26 +367,35 @@ blank line afterwards." (-cons* first-line "" (cdr lines))) docstring))) +(defun helpful--propertize-symbols (docstring) + "Convert symbol references in docstrings to buttons." + (replace-regexp-in-string + ;; Replace all text of the form `foo'. + (rx "`" symbol-start (+? anything) symbol-end "'") + (lambda (it) + (let* ((sym-name + (s-chop-prefix "`" (s-chop-suffix "'" it))) + (sym (intern sym-name))) + ;; Only create a link if this is a symbol that is bound as a + ;; variable or callable. + (if (or (boundp sym) (fboundp sym)) + (make-text-button + sym-name nil + :type 'helpful-describe-button + 'symbol sym) + (propertize sym-name + 'face 'font-lock-constant-face)))) + docstring + t t)) + ;; TODO: fix upstream Emacs bug that means `-map' is not highlighted ;; in the docstring for `--map'. (defun helpful--format-docstring (docstring) "Replace cross-references with links in DOCSTRING." - (s-trim - (replace-regexp-in-string - (rx "`" symbol-start (+? anything) symbol-end "'") - (lambda (it) - (let* ((sym-name - (s-chop-prefix "`" (s-chop-suffix "'" it))) - (sym (intern sym-name))) - (if (or (boundp sym) (fboundp sym)) - (make-text-button - sym-name nil - :type 'helpful-describe-button - 'symbol sym) - (propertize sym-name - 'face 'font-lock-constant-face)))) - (helpful--split-first-line docstring) - t t))) + (-> docstring + (helpful--split-first-line) + (helpful--propertize-symbols) + (s-trim))) (defconst helpful--highlighting-funcs '(ert--activate-font-lock-keywords