From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Cc: sascha-ml-reply-to-2012-4@silbe.org
Subject: [PATCH v2 3/3] emacs: Buttonize mid: links
Date: Sat, 10 Nov 2012 23:46:15 -0500 [thread overview]
Message-ID: <1352609175-12790-4-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1352609175-12790-1-git-send-email-amdragon@mit.edu>
This adds support for RFC 2392 mid: message ID links.
---
emacs/notmuch-show.el | 45 +++++++++++++++++++++++++++++++++------------
test/emacs-show | 8 +++++++-
2 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 49961fb..5b3e70e 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1014,23 +1014,44 @@ message at DEPTH in the current thread."
"\\)")
"The regexp used to match id: links in messages.")
+(defvar notmuch-mid-regexp
+ ;; goto-address-url-regexp matched cid: links, which have the same
+ ;; grammar as the message ID part of a mid: link. Construct the
+ ;; regexp using the same technique as goto-address-url-regexp.
+ (concat "\\<mid:\\(" thing-at-point-url-path-regexp "\\)")
+ "The regexp used to match mid: links in messages.
+
+See RFC 2392.")
+
(defun notmuch-show-buttonise-links (start end)
"Buttonise URLs and mail addresses between START and END.
-This also turns id:\"<message id>\"-parts into buttons for
-a corresponding notmuch search."
+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
- (goto-char start)
- (while (re-search-forward notmuch-id-regexp end t)
- ;; remove the overlay created by goto-address-mode
- (remove-overlays (match-beginning 0) (match-end 0) 'goto-address t)
- (make-text-button (match-beginning 0) (match-end 0)
- 'action `(lambda (arg)
- (notmuch-show ,(match-string-no-properties 0)))
- 'follow-link t
- 'help-echo "Mouse-1, RET: search for this message"
- 'face goto-address-mail-face))))
+ (let (links)
+ (goto-char start)
+ (while (re-search-forward notmuch-id-regexp end t)
+ (push (list (match-beginning 0) (match-end 0)
+ (match-string-no-properties 0)) links))
+ (goto-char start)
+ (while (re-search-forward notmuch-mid-regexp end t)
+ (let* ((mid-cid (match-string-no-properties 1))
+ (mid (save-match-data
+ (string-match "^[^/]*" mid-cid)
+ (url-unhex-string (match-string 0 mid-cid)))))
+ (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)
+ 'action `(lambda (arg)
+ (notmuch-show ,(third link)))
+ 'follow-link t
+ 'help-echo "Mouse-1, RET: search for this message"
+ 'face goto-address-mail-face)))))
;;;###autoload
(defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name)
diff --git a/test/emacs-show b/test/emacs-show
index 8944e73..91706ea 100755
--- a/test/emacs-show
+++ b/test/emacs-show
@@ -125,7 +125,10 @@ id:\"abc
\"
id:)
id:
-cid:xxx"'
+cid:xxx
+mid:abc mid:abc/def
+mid:abc%20def
+mid:abc. mid:abc, mid:abc;"'
test_emacs '(notmuch-show "id:'$gen_msg_id'")
(notmuch-test-mark-links)
(test-visible-output)'
@@ -153,6 +156,9 @@ id:"abc
id:)
id:
cid:xxx
+<<mid:abc>> <<mid:abc/def>>
+<<mid:abc%20def>>
+<<mid:abc>>. <<mid:abc>>, <<mid:abc>>;
EOF
test_expect_equal_file EXPECTED OUTPUT
--
1.7.10.4
next prev parent reply other threads:[~2012-11-11 4:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-11 4:46 [PATCH v2 0/3] Better id: link buttonization Austin Clements
2012-11-11 4:46 ` [PATCH v2 1/3] test: Test buttonization of id: links Austin Clements
2012-11-11 4:46 ` [PATCH v2 2/3] emacs: Improve the regexp used to match id:'s in messages Austin Clements
2012-11-11 4:46 ` Austin Clements [this message]
2012-11-14 2:38 ` [PATCH v2 0/3] Better id: link buttonization Ethan Glasser-Camp
2012-11-14 8:32 ` Tomi Ollila
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1352609175-12790-4-git-send-email-amdragon@mit.edu \
--to=amdragon@mit.edu \
--cc=notmuch@notmuchmail.org \
--cc=sascha-ml-reply-to-2012-4@silbe.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).