helpful

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

commit 9778c0d988d1b7dcc48e7b22b53d80be53451ff5
parent 3698c95359fa45b38f65f08bfa350996f1e91af8
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sat, 16 Dec 2017 12:30:32 +0000

Propertize references to Info nodes

Closes #32

Diffstat:
MCHANGELOG.md | 2+-
MREADME.md | 3++-
Mhelpful.el | 28++++++++++++++++++++++++++++
3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -1,6 +1,6 @@ # v0.5 -No changes yet. +Ensure docstring references to Info nodes are converted to buttons. # v0.4 diff --git a/README.md b/README.md @@ -60,7 +60,8 @@ Helpful will show you where a function is being called! Docstrings in helpful: * Highlight the summary (the first sentence) -* Include cross-references +* Include cross-references to other functions/variables +* Linkify references to Info nodes * Hide superfluous punctuation ![screenshot](screenshots/helpful_view_in_manual.png) diff --git a/helpful.el b/helpful.el @@ -348,6 +348,16 @@ or disable if already enabled." (let ((sym (button-get button 'symbol))) (helpful-symbol sym))) +(define-button-type 'helpful-info-button + 'action #'helpful--info + 'info-node nil + 'follow-link t + 'help-echo "View this Info node") + +(defun helpful--info (button) + "Describe the symbol that this BUTTON represents." + (info (button-get button 'info-node))) + (defun helpful--split-first-line (docstring) "If the first line is a standalone sentence, ensure we have a blank line afterwards." @@ -382,12 +392,30 @@ blank line afterwards." docstring t t)) +(defun helpful--propertize-info (docstring) + "Convert info references in docstrings to buttons." + (replace-regexp-in-string + ;; Replace all text of the form `foo'. + (rx "Info node `" (group (+ (not (in "'")))) "'") + (lambda (it) + ;; info-node has the form "(cl)Loop Facility". + (let ((info-node (match-string 1 it))) + (concat + "Info node " + (make-text-button + info-node nil + :type 'helpful-info-button + 'info-node info-node)))) + 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." (-> docstring (helpful--split-first-line) + (helpful--propertize-info) (helpful--propertize-symbols) (s-trim)))