aboutsummaryrefslogtreecommitdiff
path: root/helpful.el
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2018-04-07 11:50:45 +0100
committerWilfred Hughes <me@wilfred.me.uk>2018-04-07 11:51:07 +0100
commitfe126eac03e510a47a12dc468f0be70d024e130e (patch)
treebd2ceca8e4b5fe9753526ed182792b8b9a13ca4d /helpful.el
parent64dee8141ccb47494dc469153ff6447ade948646 (diff)
Also linkify bare URLs
Diffstat (limited to 'helpful.el')
-rw-r--r--helpful.el21
1 files changed, 21 insertions, 0 deletions
diff --git a/helpful.el b/helpful.el
index 2def3e2..2c07900 100644
--- a/helpful.el
+++ b/helpful.el
@@ -835,6 +835,7 @@ unescaping too."
(helpful--split-first-line)
(helpful--propertize-info)
(helpful--propertize-links)
+ (helpful--propertize-bare-links)
(helpful--propertize-keywords)
(helpful--propertize-quoted)
(s-trim)))
@@ -857,6 +858,26 @@ unescaping too."
'url url))))
docstring))
+(defun helpful--propertize-bare-links (docstring)
+ "Convert URL links in docstrings to buttons."
+ (replace-regexp-in-string
+ (rx (group (or string-start space))
+ (group "http" (? "s") "://" (+? (not (any space))))
+ (group (? (any "." ">" ")"))
+ (or space string-end)))
+ (lambda (match)
+ (let ((space-before (match-string 1 match))
+ (url (match-string 2 match))
+ (after (match-string 3 match)))
+ (concat
+ space-before
+ (helpful--button
+ url
+ 'helpful-link-button
+ 'url url)
+ after)))
+ docstring))
+
(defun helpful--follow-link (button)
"Follow the URL specified by BUTTON."
(browse-url (button-get button 'url)))