Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 2c / ee6ad5e4956a5c901469a4c651f9ee8ce36e2b
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id C658C431FC3\r
6         for <notmuch@notmuchmail.org>; Tue, 30 Oct 2012 19:29:42 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id qLaMTQ5aNXbI for <notmuch@notmuchmail.org>;\r
16         Tue, 30 Oct 2012 19:29:41 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
18         [18.9.25.13])\r
19         by olra.theworths.org (Postfix) with ESMTP id 1ECB3431FC4\r
20         for <notmuch@notmuchmail.org>; Tue, 30 Oct 2012 19:29:37 -0700 (PDT)\r
21 X-AuditID: 1209190d-b7f906d0000008de-a9-50908d101f56\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 6B.FE.02270.01D80905; Tue, 30 Oct 2012 22:29:36 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q9V2TZD0000788; \r
27         Tue, 30 Oct 2012 22:29:35 -0400\r
28 Received: from drake.dyndns.org\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q9V2TUNu027171\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Tue, 30 Oct 2012 22:29:35 -0400 (EDT)\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
36         (envelope-from <amdragon@mit.edu>)\r
37         id 1TTO3X-00021Q-TD; Tue, 30 Oct 2012 22:29:23 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 2/2] emacs: Improve the regexp used to match id:'s in messages\r
41 Date: Tue, 30 Oct 2012 22:29:21 -0400\r
42 Message-Id: <1351650561-7331-3-git-send-email-amdragon@mit.edu>\r
43 X-Mailer: git-send-email 1.7.10\r
44 In-Reply-To: <1351650561-7331-1-git-send-email-amdragon@mit.edu>\r
45 References: <1351650561-7331-1-git-send-email-amdragon@mit.edu>\r
46 X-Brightmail-Tracker:\r
47  H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixG6nrivQOyHAYNlTNYum6c4W12/OZHZg\r
48         8rh1/zW7x7NVt5gDmKK4bFJSczLLUov07RK4Mi4tPcVUMEGy4v2+s0wNjEtFuhg5OSQETCQ2\r
49         fr/OCmGLSVy4t56ti5GLQ0hgH6PE4WMt7BDOBkaJP5PfQjmPmCTmzv/ICOHMZZR4svELG0g/\r
50         m4CGxLb9yxlBbBEBaYmdd2cDzeXgYBYwl7jZEgcSFhbwk1gy9y0TiM0ioCqxtPU1C4jNK2Av\r
51         0XtpKtQZ8hJP7/eBjeQUcJB4unUtI8gYIaCa2y8lJjDyL2BkWMUom5JbpZubmJlTnJqsW5yc\r
52         mJeXWqRrpJebWaKXmlK6iREURpySvDsY3x1UOsQowMGoxMOr8b0/QIg1say4MvcQoyQHk5Io\r
53         b1HXhAAhvqT8lMqMxOKM+KLSnNTiQ4wSHMxKIrwXM4ByvCmJlVWpRfkwKWkOFiVx3ispN/2F\r
54         BNITS1KzU1MLUotgsjIcHEoSvJo9QI2CRanpqRVpmTklCGkmDk6Q4TxAw6NAaniLCxJzizPT\r
55         IfKnGBWlxHnfdAMlBEASGaV5cL2wOH/FKA70ijCvC0g7DzBFwHW/AhrMBDRYh68XZHBJIkJK\r
56         qoFxyZLZckbJV8QXRN5ae+Z8xJXzZ1TV3nVfTP4o3Lg32ZrDt9ik1f61bce0y2KWJ3cwLy2s\r
57         Mt/fdE2+ZiIvx+ejze/eiN+QZr43m6P4z2yxCTeVvF6FPDld/uM1T3m6aqrDvgDbXKMJk7x4\r
58         Du2Ve3fslA1XtfeeRzKVf//vs80X/rE3/K3avhg2JZbijERDLeai4kQAlo70BM4CAAA=\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.13\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63         <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Wed, 31 Oct 2012 02:29:43 -0000\r
72 \r
73 This regexp agrees with Xapian query syntax much more closely, though\r
74 we specifically disallow various cases that would be confusing in the\r
75 context of an email body (e.g., punctuation at the end of an id: link\r
76 is not considered part of the id: link because it's probably part of\r
77 the surrounding text).\r
78 \r
79 In particular, this handles id: links that are not surrounded by\r
80 quotes much better, which stash is much more likely to generate now\r
81 that we don't quote id's that don't need to be quoted.  It also\r
82 handles quoted id: links better.\r
83 \r
84 We update the buttonization test to reflect the new pattern.\r
85 ---\r
86  emacs/notmuch-show.el |   20 +++++++++++++++++++-\r
87  test/emacs-show       |   14 +++++++-------\r
88  2 files changed, 26 insertions(+), 8 deletions(-)\r
89 \r
90 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
91 index f273eb4..e96e099 100644\r
92 --- a/emacs/notmuch-show.el\r
93 +++ b/emacs/notmuch-show.el\r
94 @@ -991,6 +991,24 @@ message at DEPTH in the current thread."\r
95    "Insert the forest of threads FOREST."\r
96    (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))\r
97  \r
98 +(defvar notmuch-id-regexp\r
99 +  (concat\r
100 +   ;; Match the id: prefix only if it begins a word (to disallow, for\r
101 +   ;; example, matching cid:).\r
102 +   "\\<id:\\("\r
103 +   ;; If the term starts with a ", then parse Xapian's quoted boolean\r
104 +   ;; term syntax, which allows for anything as long as embedded\r
105 +   ;; double quotes escaped by doubling them.  We also disallow\r
106 +   ;; newlines (which Xapian allows) to prevent runaway terms.\r
107 +   "\"\\([^\"\n]\\|\"\"\\)*\""\r
108 +   ;; Otherwise, parse Xapian's unquoted syntax, which goes up to the\r
109 +   ;; next space or ).  We disallow [.,;] as the last character\r
110 +   ;; because these are probably part of the surrounding text, and not\r
111 +   ;; part of the id.  This doesn't match single character ids; meh.\r
112 +   "\\|[^\"[:space:])][^[:space:])]*[^[:space:]).,;]"\r
113 +   "\\)")\r
114 +  "The regexp used to match id: links in messages.")\r
115 +\r
116  (defun notmuch-show-buttonise-links (start end)\r
117    "Buttonise URLs and mail addresses between START and END.\r
118  \r
119 @@ -999,7 +1017,7 @@ a corresponding notmuch search."\r
120    (goto-address-fontify-region start end)\r
121    (save-excursion\r
122      (goto-char start)\r
123 -    (while (re-search-forward "id:\\(\"?\\)[^[:space:]\"]+\\1" end t)\r
124 +    (while (re-search-forward notmuch-id-regexp end t)\r
125        ;; remove the overlay created by goto-address-mode\r
126        (remove-overlays (match-beginning 0) (match-end 0) 'goto-address t)\r
127        (make-text-button (match-beginning 0) (match-end 0)\r
128 diff --git a/test/emacs-show b/test/emacs-show\r
129 index c4f3cf4..e16483c 100755\r
130 --- a/test/emacs-show\r
131 +++ b/test/emacs-show\r
132 @@ -131,18 +131,18 @@ To: Notmuch Test Suite <test_suite@notmuchmail.org>\r
133  Date: Fri, 05 Jan 2001 15:43:57 +0000\r
134  \r
135  <<id:abc>>\r
136 -<<id:abc.def.>> <<id:abc,def,>> <<id:abc;def;>>\r
137 -<<id:abc)def>>\r
138 -<<id:ab>>"c def\r
139 +<<id:abc.def>>. <<id:abc,def>>, <<id:abc;def>>;\r
140 +<<id:abc>>)def\r
141 +<<id:ab"c>> def\r
142  <<id:"abc">>def\r
143 -<<id:"ab">>"c"def\r
144 -id:"ab c"def\r
145 +<<id:"ab""c">>def\r
146 +<<id:"ab c">>def\r
147  <<id:"abc">>.def\r
148  id:"abc\r
149  "\r
150 -<<id:)>>\r
151 +id:)\r
152  id:\r
153 -c<<id:xxx>>\r
154 +cid:xxx\r
155  EOF\r
156  test_expect_equal_file OUTPUT EXPECTED\r
157  \r
158 -- \r
159 1.7.10\r
160 \r