Re: SVG attachment crashes emacs
[notmuch-archives.git] / e0 / 30a189665cd887cbf06a20a705c03c40d58c91
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 132B1431FAE\r
6         for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:21 -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 AXkZLTqCf9ZS for <notmuch@notmuchmail.org>;\r
16         Sat, 21 Jul 2012 10:37:19 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
18         [18.9.25.14])\r
19         by olra.theworths.org (Postfix) with ESMTP id B4051431FAF\r
20         for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:19 -0700 (PDT)\r
21 X-AuditID: 1209190e-b7fb56d0000008b2-3b-500ae8ce825d\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id EA.13.02226.EC8EA005; Sat, 21 Jul 2012 13:37:18 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q6LHbHRx018463; \r
27         Sat, 21 Jul 2012 13:37:17 -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 q6LHbFJu008016\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Sat, 21 Jul 2012 13:37:16 -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 1SsdcB-0001Zl-Ba; Sat, 21 Jul 2012 13:37:15 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v4 4/8] emacs: Use result text properties for search result\r
41         iteration\r
42 Date: Sat, 21 Jul 2012 13:37:08 -0400\r
43 Message-Id: <1342892232-5659-5-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.10\r
45 In-Reply-To: <1342892232-5659-1-git-send-email-amdragon@mit.edu>\r
46 References: <1341354059-29396-1-git-send-email-amdragon@mit.edu>\r
47         <1342892232-5659-1-git-send-email-amdragon@mit.edu>\r
48 X-Brightmail-Tracker:\r
49  H4sIAAAAAAAAA+NgFjrMIsWRmVeSWpSXmKPExsUixCmqrXvuBVeAQdsrUYs9+7wsVs/lsbh+\r
50         cyazA7PH3dNcHjtn3WX3eLbqFnMAcxSXTUpqTmZZapG+XQJXxutPK5gK9mtU/F+9m7mB8aZC\r
51         FyMnh4SAiUT71FVsELaYxIV764FsLg4hgX2MEkuu3WSHcDYwSrSs+c0IUiUk8IhJ4vvjCojE\r
52         XEaJjp417CAJNgENiW37l4MViQhIS+y8O5sVxGYWSJP43v4WKM7BISwQKnH7lTtImEVAVeL1\r
53         6YVg5bwC9hKHnj1kh7hCXuLp/T6wizgFHCQenT3AArG3TGJxx2HGCYz8CxgZVjHKpuRW6eYm\r
54         ZuYUpybrFicn5uWlFuka6+VmluilppRuYgSHlSTfDsavB5UOMQpwMCrx8HrM4gwQYk0sK67M\r
55         PcQoycGkJMrbd58rQIgvKT+lMiOxOCO+qDQntfgQowQHs5II76bTQDnelMTKqtSifJiUNAeL\r
56         kjjvlZSb/kIC6YklqdmpqQWpRTBZGQ4OJQled2D8CAkWpaanVqRl5pQgpJk4OEGG8wANDwap\r
57         4S0uSMwtzkyHyJ9iVJQS57UDSQiAJDJK8+B6YXH/ilEc6BVh3m/Pgap4gCkDrvsV0GAmoMHS\r
58         WWCDSxIRUlINjAs/KgsKzuVtrnockMPhEcJT+1Sv9YfB4hu7Wo6xX/irpuTKmmeuqh/ee6ov\r
59         XsRUQjr//1vb/JWTg1zZppw/er3647amczpSN3mzVafH/4qQ2nbYZW6sQFPob40X5a7vN3+f\r
60         1rr+xhGD54eNTqfWR34Rrj0aXeookaJhOsPkzel3EtLB93wPKLEUZyQaajEXFScCABHskUvW        AgAA\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.13\r
63 Precedence: list\r
64 List-Id: "Use and development of the notmuch mail system."\r
65         <notmuch.notmuchmail.org>\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
69 List-Post: <mailto:notmuch@notmuchmail.org>\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
73 X-List-Received-Date: Sat, 21 Jul 2012 17:37:21 -0000\r
74 \r
75 This simplifies the traversal of regions of results and eliminates the\r
76 need for save-excursions (which tend to get in the way of maintaining\r
77 point when we make changes to the buffer).  It also fixes some strange\r
78 corner cases in the old line-based code where results that bordered\r
79 the region but were not included in it could be affected by region\r
80 commands.  Coincidentally, this also essentially enables multi-line\r
81 search result formats; the only remaining non-multi-line-capable\r
82 functions are notmuch-search-{next,previous}-thread, which are only\r
83 used for interactive navigation.\r
84 ---\r
85  emacs/notmuch.el |   78 ++++++++++++++++++++++++++++++++++--------------------\r
86  1 file changed, 50 insertions(+), 28 deletions(-)\r
87 \r
88 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
89 index 6995482..f79d004 100644\r
90 --- a/emacs/notmuch.el\r
91 +++ b/emacs/notmuch.el\r
92 @@ -69,7 +69,13 @@\r
93         date, count, authors, subject, tags\r
94  For example:\r
95         (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)\r
96 -                                            \(\"subject\" . \"%s\"\)\)\)"\r
97 +                                            \(\"subject\" . \"%s\"\)\)\)\r
98 +Line breaks are permitted in format strings (though this is\r
99 +currently experimental).  Note that a line break at the end of an\r
100 +\"authors\" field will get elided if the authors list is long;\r
101 +place it instead at the beginning of the following field.  To\r
102 +enter a line break when setting this variable with setq, use \\n.\r
103 +To enter a line break in customize, press \\[quoted-insert] C-j."\r
104    :type '(alist :key-type (string) :value-type (string))\r
105    :group 'notmuch-search)\r
106  \r
107 @@ -427,17 +433,40 @@ returns nil"\r
108      (next-single-property-change (or pos (point)) 'notmuch-search-result\r
109                                  nil (point-max))))\r
110  \r
111 +(defun notmuch-search-foreach-result (beg end function)\r
112 +  "Invoke FUNCTION for each result between BEG and END.\r
113 +\r
114 +FUNCTION should take one argument.  It will be applied to the\r
115 +character position of the beginning of each result that overlaps\r
116 +the region between points BEG and END.  As a special case, if (=\r
117 +BEG END), FUNCTION will be applied to the result containing point\r
118 +BEG."\r
119 +\r
120 +  (lexical-let ((pos (notmuch-search-result-beginning beg))\r
121 +               ;; End must be a marker in case function changes the\r
122 +               ;; text.\r
123 +               (end (copy-marker end))\r
124 +               ;; Make sure we examine at least one result, even if\r
125 +               ;; (= beg end).\r
126 +               (first t))\r
127 +    ;; We have to be careful if the region extends beyond the results.\r
128 +    ;; In this case, pos could be null or there could be no result at\r
129 +    ;; pos.\r
130 +    (while (and pos (or (< pos end) first))\r
131 +      (when (notmuch-search-get-result pos)\r
132 +       (funcall function pos))\r
133 +      (setq pos (notmuch-search-result-end pos)\r
134 +           first nil))))\r
135 +;; Unindent the function argument of notmuch-search-foreach-result so\r
136 +;; the indentation of callers doesn't get out of hand.\r
137 +(put 'notmuch-search-foreach-result 'lisp-indent-function 2)\r
138 +\r
139  (defun notmuch-search-properties-in-region (property beg end)\r
140 -  (save-excursion\r
141 -    (let ((output nil)\r
142 -         (last-line (line-number-at-pos end))\r
143 -         (max-line (- (line-number-at-pos (point-max)) 2)))\r
144 -      (goto-char beg)\r
145 -      (beginning-of-line)\r
146 -      (while (<= (line-number-at-pos) (min last-line max-line))\r
147 -       (setq output (cons (get-text-property (point) property) output))\r
148 -       (forward-line 1))\r
149 -      output)))\r
150 +  (let (output)\r
151 +    (notmuch-search-foreach-result beg end\r
152 +      (lambda (pos)\r
153 +       (push (get-text-property pos property) output)))\r
154 +    output))\r
155  \r
156  (defun notmuch-search-find-thread-id ()\r
157    "Return the thread for the current thread"\r
158 @@ -517,28 +546,21 @@ and will also appear in a buffer named \"*Notmuch errors*\"."\r
159    (plist-get (notmuch-search-get-result pos) :tags))\r
160  \r
161  (defun notmuch-search-get-tags-region (beg end)\r
162 -  (save-excursion\r
163 -    (let ((output nil)\r
164 -         (last-line (line-number-at-pos end))\r
165 -         (max-line (- (line-number-at-pos (point-max)) 2)))\r
166 -      (goto-char beg)\r
167 -      (while (<= (line-number-at-pos) (min last-line max-line))\r
168 -       (setq output (append output (notmuch-search-get-tags)))\r
169 -       (forward-line 1))\r
170 -      output)))\r
171 +  (let (output)\r
172 +    (notmuch-search-foreach-result beg end\r
173 +      (lambda (pos)\r
174 +       (setq output (append output (notmuch-search-get-tags pos)))))\r
175 +    output))\r
176  \r
177  (defun notmuch-search-tag-region (beg end &optional tag-changes)\r
178    "Change tags for threads in the given region."\r
179    (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))\r
180      (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))\r
181 -    (save-excursion\r
182 -      (let ((last-line (line-number-at-pos end))\r
183 -           (max-line (- (line-number-at-pos (point-max)) 2)))\r
184 -       (goto-char beg)\r
185 -       (while (<= (line-number-at-pos) (min last-line max-line))\r
186 -         (notmuch-search-set-tags\r
187 -          (notmuch-update-tags (notmuch-search-get-tags) tag-changes))\r
188 -         (forward-line))))))\r
189 +    (notmuch-search-foreach-result beg end\r
190 +      (lambda (pos)\r
191 +       (notmuch-search-set-tags\r
192 +        (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
193 +        pos)))))\r
194  \r
195  (defun notmuch-search-tag (&optional tag-changes)\r
196    "Change tags for the currently selected thread or region.\r
197 -- \r
198 1.7.10\r
199 \r