helpful

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

commit fe126eac03e510a47a12dc468f0be70d024e130e
parent 64dee8141ccb47494dc469153ff6447ade948646
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sat,  7 Apr 2018 11:50:45 +0100

Also linkify bare URLs

Diffstat:
MCHANGELOG.md | 2+-
Mhelpful.el | 21+++++++++++++++++++++
Mtest/unit-test.el | 25+++++++++++++++++++++++--
3 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -1,6 +1,6 @@ # v0.10 -No changes yet. +URLs in docstrings are now converted to buttons. # v0.9 diff --git 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))) diff --git a/test/unit-test.el b/test/unit-test.el @@ -230,8 +230,7 @@ symbol (not a form)." (get-text-property paren-position 'button formatted)))) (ert-deftest helpful--format-docstring--url () - "Ensure we propertize URLs." - ;; This is the typical format. + "Ensure we propertize URLs with backticks." (let* ((formatted (helpful--format-docstring "URL `http://example.com'")) (url-position (s-index-of "h" formatted))) (should @@ -239,6 +238,28 @@ symbol (not a form)." (should (get-text-property url-position 'button formatted)))) +(ert-deftest helpful--format-docstring--bare-url () + "Ensure we propertize URLs without backticks." + (let* ((formatted (helpful--format-docstring "http://example.com\nbar")) + (url-position (s-index-of "h" formatted))) + (should + (string-equal formatted "http://example.com\nbar")) + (should + (get-text-property url-position 'button formatted)) + (should + (equal + (get-text-property url-position 'url formatted) + "http://example.com"))) + ;; Don't consider trailing punctuation to be part of the URL. + (let* ((formatted (helpful--format-docstring "See http://example.com.")) + (url-position (s-index-of "h" formatted))) + (should + (string-equal formatted "See http://example.com.")) + (should + (equal + (get-text-property url-position 'url formatted) + "http://example.com")))) + (ert-deftest helpful--definition-c-vars () "Handle definitions of variables in C source code." (let* ((emacs-src-path (f-join default-directory "emacs-25.3" "src")))