diff options
| author | Sean Allred <code@seanallred.com> | 2018-01-19 20:16:42 -0600 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2018-04-07 11:20:23 +0100 |
| commit | 5b487625d04bdbbf63b5bd12368f926ad446d4e9 (patch) | |
| tree | 60c9c57621c1456bb56fdbf6b4a7e27b87312feb /helpful.el | |
| parent | f2d6751c48d8318f93124e380f0beba5a1c802cb (diff) | |
Linkify URLs in documentation strings
URLs written as
URL `some-url'
is transformed into a button
URL some-url
with `some-url' being the button. The URL "some-url" is passed to
`browse-url' as the action (i.e., `(browse-url "some-url")').
The positioning of `helpful--propertize-links' inside
`helpful--format-docstring' is of some importance; the call to
`helpful--propertize-quoted' presently catches `some-url' as a symbol
and deals with it as such. We need to look for URLs before symbols.
Diffstat (limited to 'helpful.el')
| -rw-r--r-- | helpful.el | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -834,10 +834,33 @@ unescaping too." (helpful--format-command-keys) (helpful--split-first-line) (helpful--propertize-info) + (helpful--propertize-links) (helpful--propertize-keywords) (helpful--propertize-quoted) (s-trim))) +(define-button-type 'helpful-link-button + 'action #'helpful--follow-link + 'follow-link t + 'help-echo "Follow this link") + +(defun helpful--propertize-links (docstring) + "Convert URL links in docstrings to buttons." + (replace-regexp-in-string + (rx "URL `" (group (*? any)) "'") + (lambda (match) + (let ((url (match-string 1 match))) + (concat "URL " + (helpful--button + url + 'helpful-link-button + 'url url)))) + docstring)) + +(defun helpful--follow-link (button) + "Follow the URL specified by BUTTON." + (browse-url (button-get button 'url))) + (defconst helpful--highlighting-funcs '(ert--activate-font-lock-keywords highlight-quoted-mode |
