[PATCH] make http links into buttons

Subject: [PATCH] make http links into buttons

Date: Fri, 23 Aug 2013 07:51:35 +0100

To: notmuch@notmuchmail.org

Cc:

From: Mark Walters


This patch replaces the use of goto-address-fontify-region with our
own code doing roughly the same thing. The advantage is that we
control how the resulting buttons work. In particular RET on link
activates the button (in my case opening it in an external browser)
and TAB stops at these links.


It finds the urls using the goto-address variable for the regexp so it
should make exactly the same links.

Caveats and queries:

1) the buttons used now are text buttons rather than overlay "things":
this seems to mean some things like fonts get overridden by
notmuch-wash (observable in cited regions for example).

2) Email links are also activatable by RET but there are quite a lot
of them (eg all addresses in headers) so I make these buttons
skippable. Possibly they should not be changed as pressing RET in a
show body (to collapse the message) is relatively common so
accidentally composing a mail may be irritating.

3) the test for id buttonization in emacs-show fails because some
links become buttons. I don't think it is worth updating this
until/unless we have some consensus on how this should all work.

What do people think?

Best wishes

Mark

 
---
 emacs/notmuch-show.el |   27 ++++++++++++++++++++++++---
 1 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 82b70ba..8aa56e0 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1080,8 +1080,31 @@ See RFC 2392.")
 
 This also turns id:\"<message id>\"-parts and mid: links into
 buttons for a corresponding notmuch search."
-  (goto-address-fontify-region start end)
   (save-excursion
+    ;; Do urls
+    (goto-char start)
+    (while (re-search-forward goto-address-url-regexp end t)
+      (make-text-button (match-beginning 0) (match-end 0)
+			:type 'notmuch-button-type
+			'action #'goto-address-at-point
+			'follow-link t
+			'help-echo "Mouse-1, RET: open this link in browser"
+			'face goto-address-url-face
+			'priority 10
+			'mouse-face goto-address-url-mouse-face))
+    ;; do email addresses
+    (goto-char start)
+    (while (re-search-forward goto-address-mail-regexp end t)
+      (make-text-button (match-beginning 0) (match-end 0)
+			:type 'notmuch-button-type
+			'action #'goto-address-at-point
+			'follow-link t
+			'help-echo "Mouse-1, RET: mail this address"
+			'face goto-address-mail-face
+			'priority 10
+			'skip t ;; don't make tab stop at all email addresses in headers etc
+			'mouse-face goto-address-mail-mouse-face))
+    ;; Do id: and mid: links
     (let (links)
       (goto-char start)
       (while (re-search-forward notmuch-id-regexp end t)
@@ -1096,8 +1119,6 @@ buttons for a corresponding notmuch search."
 	  (push (list (match-beginning 0) (match-end 0)
 		      (notmuch-id-to-query mid)) links)))
       (dolist (link links)
-	;; Remove the overlay created by goto-address-mode
-	(remove-overlays (first link) (second link) 'goto-address t)
 	(make-text-button (first link) (second link)
 			  :type 'notmuch-button-type
 			  'action `(lambda (arg)
-- 
1.7.9.1


Thread: