From: Austin Clements <amdragon@MIT.EDU>
To: notmuch@notmuchmail.org
Cc: sascha-ml-reply-to-2012-4@silbe.org
Subject: [PATCH v2 2/3] emacs: Improve the regexp used to match id:'s in messages
Date: Sat, 10 Nov 2012 23:46:14 -0500 [thread overview]
Message-ID: <1352609175-12790-3-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1352609175-12790-1-git-send-email-amdragon@mit.edu>
This regexp agrees with Xapian query syntax much more closely, though
we specifically disallow various cases that would be confusing in the
context of an email body (e.g., punctuation at the end of an id: link
is not considered part of the id: link because it's probably part of
the surrounding text).
In particular, this handles id: links that are not surrounded by
quotes much better, which stash is much more likely to generate now
that we don't quote id's that don't need to be quoted. It also
handles quoted id: links better.
We update the buttonization test to reflect the new pattern.
---
emacs/notmuch-show.el | 20 +++++++++++++++++++-
test/emacs-show | 20 ++++++++++----------
2 files changed, 29 insertions(+), 11 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index d061367..49961fb 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -996,6 +996,24 @@ message at DEPTH in the current thread."
"Insert the forest of threads FOREST."
(mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))
+(defvar notmuch-id-regexp
+ (concat
+ ;; Match the id: prefix only if it begins a word (to disallow, for
+ ;; example, matching cid:).
+ "\\<id:\\("
+ ;; If the term starts with a ", then parse Xapian's quoted boolean
+ ;; term syntax, which allows for anything as long as embedded
+ ;; double quotes escaped by doubling them. We also disallow
+ ;; newlines (which Xapian allows) to prevent runaway terms.
+ "\"\\([^\"\n]\\|\"\"\\)*\""
+ ;; Otherwise, parse Xapian's unquoted syntax, which goes up to the
+ ;; next space or ). We disallow [.,;] as the last character
+ ;; because these are probably part of the surrounding text, and not
+ ;; part of the id. This doesn't match single character ids; meh.
+ "\\|[^\"[:space:])][^[:space:])]*[^])[:space:].,:;?!]"
+ "\\)")
+ "The regexp used to match id: links in messages.")
+
(defun notmuch-show-buttonise-links (start end)
"Buttonise URLs and mail addresses between START and END.
@@ -1004,7 +1022,7 @@ a corresponding notmuch search."
(goto-address-fontify-region start end)
(save-excursion
(goto-char start)
- (while (re-search-forward "id:\\(\"?\\)[^[:space:]\"]+\\1" end t)
+ (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)
diff --git a/test/emacs-show b/test/emacs-show
index 9712633..8944e73 100755
--- a/test/emacs-show
+++ b/test/emacs-show
@@ -136,23 +136,23 @@ To: Notmuch Test Suite <test_suite@notmuchmail.org>
Date: Fri, 05 Jan 2001 15:43:57 +0000
<<id:abc>>
-<<id:abc.def.>> <<id:abc,def,>> <<id:abc;def;>> <<id:abc:def:>>
-<<id:foo@bar.?baz?>> <<id:foo@bar!.baz!>>
-(<<id:foo@bar.baz)>> [<<id:foo@bar.baz]>>
-<<id:foo@bar.baz...>>
+<<id:abc.def>>. <<id:abc,def>>, <<id:abc;def>>; <<id:abc:def>>:
+<<id:foo@bar.?baz>>? <<id:foo@bar!.baz>>!
+(<<id:foo@bar.baz>>) [<<id:foo@bar.baz>>]
+<<id:foo@bar.baz>>...
<<id:2+2=5>>
<<id:=_-:/.[]@$%+>>
-<<id:abc)def>>
-<<id:ab>>"c def
+<<id:abc>>)def
+<<id:ab"c>> def
<<id:"abc">>def
-<<id:"ab">>"c"def
-id:"ab c"def
+<<id:"ab""c">>def
+<<id:"ab c">>def
<<id:"abc">>.def
id:"abc
"
-<<id:)>>
+id:)
id:
-c<<id:xxx>>
+cid:xxx
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 ` Austin Clements [this message]
2012-11-11 4:46 ` [PATCH v2 3/3] emacs: Buttonize mid: links Austin Clements
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-3-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).