Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 46 / e3464a4307f05ef41fab368bd0dae4b8be1d8a
1 Return-Path: <m.walters@qmul.ac.uk>\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 674D3431FBD\r
6         for <notmuch@notmuchmail.org>; Sun, 15 Jul 2012 09:27:26 -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: -1.098\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
12         tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
13         NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id 0CY2ZGFC5ioU for <notmuch@notmuchmail.org>;\r
17         Sun, 15 Jul 2012 09:27:25 -0700 (PDT)\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id 529F6431FBC\r
22         for <notmuch@notmuchmail.org>; Sun, 15 Jul 2012 09:27:25 -0700 (PDT)\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
24         by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
25         (envelope-from <m.walters@qmul.ac.uk>)\r
26         id 1SqRfE-0006Au-0G; Sun, 15 Jul 2012 17:27:20 +0100\r
27 Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
28         helo=localhost)\r
29         by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
30         (envelope-from <m.walters@qmul.ac.uk>)\r
31         id 1SqRfD-0005Qe-I0; Sun, 15 Jul 2012 17:27:19 +0100\r
32 From: Mark Walters <markwalters1009@gmail.com>\r
33 To: Austin Clements <amdragon@MIT.EDU>, notmuch@notmuchmail.org\r
34 Subject: Re: [PATCH v3 0/8] emacs: JSON-based search cleanups\r
35 In-Reply-To: <1342306940-7499-1-git-send-email-amdragon@mit.edu>\r
36 References: <1342140319-19859-1-git-send-email-amdragon@mit.edu>\r
37         <1342306940-7499-1-git-send-email-amdragon@mit.edu>\r
38 User-Agent: Notmuch/0.13.2+90~g84fa1ef (http://notmuchmail.org) Emacs/23.4.1\r
39         (x86_64-pc-linux-gnu)\r
40 Date: Sun, 15 Jul 2012 17:27:17 +0100\r
41 Message-ID: <87a9z1at22.fsf@qmul.ac.uk>\r
42 MIME-Version: 1.0\r
43 Content-Type: text/plain; charset=us-ascii\r
44 X-Sender-Host-Address: 94.192.233.223\r
45 X-QM-SPAM-Info: Sender has good ham record.  :)\r
46 X-QM-Body-MD5: 61aa3a54130196eb864a56ca4ab759c4 (of first 20000 bytes)\r
47 X-SpamAssassin-Score: -1.8\r
48 X-SpamAssassin-SpamBar: -\r
49 X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
50         determine if it is\r
51         spam. We require at least 5.0 points to mark a message as spam.\r
52         This message scored -1.8 points.\r
53         Summary of the scoring: \r
54         * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
55         *      medium trust\r
56         *      [138.37.6.40 listed in list.dnswl.org]\r
57         * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
58         provider *      (markwalters1009[at]gmail.com)\r
59         * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
60         *      domain\r
61         *  0.5 AWL AWL: From: address is in the auto white-list\r
62 X-QM-Scan-Virus: ClamAV says the message is clean\r
63 X-BeenThere: notmuch@notmuchmail.org\r
64 X-Mailman-Version: 2.1.13\r
65 Precedence: list\r
66 List-Id: "Use and development of the notmuch mail system."\r
67         <notmuch.notmuchmail.org>\r
68 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
69         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
70 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
71 List-Post: <mailto:notmuch@notmuchmail.org>\r
72 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
73 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
74         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
75 X-List-Received-Date: Sun, 15 Jul 2012 16:27:26 -0000\r
76 \r
77 \r
78 On Sun, 15 Jul 2012, Austin Clements <amdragon@MIT.EDU> wrote:\r
79 > This version swaps out the notmuch-search-do-results macro for a\r
80 > higher-order function, notmuch-search-foreach-result.  This requires\r
81 > less squiting to understand and clearly distinguishes the arguments\r
82 > passed in to the function from the arguments passed to the callback.\r
83 > This version also updates the docstring for\r
84 > notmuch-search-result-format to mention that multi-line result formats\r
85 > work and how to enter them, and it adds a NEWS patch.\r
86 \r
87 Hello\r
88 \r
89 I am afraid I have found a minor (but reproducible) bug in the line\r
90 re-drawing even with single line results. Find a search result with a\r
91 partially elided author field and put the cursor after the ellipsis in\r
92 that line. Then update the tags. The result gets redrawn with ellipsis\r
93 written out in full. Re-redrawing with the cursor after the author field\r
94 redraws the line with the keeping the ellipsis written out in full,\r
95 whereas re-redrawing the line with cursor before the author field gets\r
96 it written with the correct ellipsis.\r
97 \r
98 Best wishes\r
99 \r
100 Mark\r
101 >\r
102 > Diff from v2:\r
103 >\r
104 > diff --git a/NEWS b/NEWS\r
105 > index a1a6e93..7b33f0d 100644\r
106 > --- a/NEWS\r
107 > +++ b/NEWS\r
108 > @@ -17,6 +17,20 @@ Maildir tag synchronization\r
109 >  Emacs Interface\r
110 >  ---------------\r
111 >  \r
112 > +Search results now get re-colored when tags are updated\r
113 > +\r
114 > +The formatting of tags in search results can now be customized\r
115 > +\r
116 > +  Previously, attempting to change the format of tags in\r
117 > +  `notmuch-search-result-format` would usually break tagging from\r
118 > +  search-mode.  We no longer make assumptions about the format.\r
119 > +\r
120 > +Multi-line search result formats are now supported\r
121 > +\r
122 > +  It is now possible to embed newlines in\r
123 > +  `notmuch-search-result-format` to make individual search results\r
124 > +  span multiple lines.\r
125 > +\r
126 >  Search now uses the JSON format internally\r
127 >  \r
128 >    This should address problems with unusual characters in authors and\r
129 > diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
130 > index 7302fa7..ec760dc 100644\r
131 > --- a/emacs/notmuch.el\r
132 > +++ b/emacs/notmuch.el\r
133 > @@ -69,7 +69,13 @@\r
134 >       date, count, authors, subject, tags\r
135 >  For example:\r
136 >       (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)\r
137 > -                                          \(\"subject\" . \"%s\"\)\)\)"\r
138 > +                                          \(\"subject\" . \"%s\"\)\)\)\r
139 > +Line breaks are permitted in format strings.  Note that a line\r
140 > +break at the end of an \"authors\" field will get elided if the\r
141 > +authors list is long; place it instead at the beginning of the\r
142 > +following field.  To enter a line break when setting this\r
143 > +variable with setq, use \\n.  To enter a line break in customize,\r
144 > +press \\[quoted-insert] C-j."\r
145 >    :type '(alist :key-type (string) :value-type (string))\r
146 >    :group 'notmuch-search)\r
147 >  \r
148 > @@ -433,32 +439,39 @@ returns nil"\r
149 >      (next-single-property-change (or pos (point)) 'notmuch-search-result\r
150 >                                nil (point-max))))\r
151 >  \r
152 > -(defmacro notmuch-search-do-results (beg end pos-sym &rest body)\r
153 > -  "Invoke BODY for each result between BEG and END.\r
154 > -\r
155 > -POS-SYM will be bound to the point at the beginning of the\r
156 > -current result."\r
157 > -  (declare (indent 3))\r
158 > -  (let ((end-sym (make-symbol "end"))\r
159 > -     (first-sym (make-symbol "first")))\r
160 > -    `(let ((,pos-sym (notmuch-search-result-beginning ,beg))\r
161 > -        ;; End must be a marker in case body changes the text\r
162 > -        (,end-sym (copy-marker ,end))\r
163 > -        ;; Make sure we examine one result, even if (= beg end)\r
164 > -        (,first-sym t))\r
165 > -       ;; We have to be careful if the region extends beyond the\r
166 > -       ;; results.  In this case, pos could be null or there could be\r
167 > -       ;; no result at pos.\r
168 > -       (while (and ,pos-sym (or (< ,pos-sym ,end-sym) ,first-sym))\r
169 > -      (when (notmuch-search-get-result ,pos-sym)\r
170 > -        ,@body)\r
171 > -      (setq ,pos-sym (notmuch-search-result-end ,pos-sym)\r
172 > -            ,first-sym nil)))))\r
173 > +(defun notmuch-search-foreach-result (beg end function)\r
174 > +  "Invoke FUNCTION for each result between BEG and END.\r
175 > +\r
176 > +FUNCTION should take one argument.  It will be applied to the\r
177 > +character position of the beginning of each result that overlaps\r
178 > +the region between points BEG and END.  As a special case, if (=\r
179 > +BEG END), FUNCTION will be applied to the result containing point\r
180 > +BEG."\r
181 > +\r
182 > +  (lexical-let ((pos (notmuch-search-result-beginning beg))\r
183 > +             ;; End must be a marker in case function changes the\r
184 > +             ;; text.\r
185 > +             (end (copy-marker end))\r
186 > +             ;; Make sure we examine at least one result, even if\r
187 > +             ;; (= beg end).\r
188 > +             (first t))\r
189 > +    ;; We have to be careful if the region extends beyond the results.\r
190 > +    ;; In this case, pos could be null or there could be no result at\r
191 > +    ;; pos.\r
192 > +    (while (and pos (or (< pos end) first))\r
193 > +      (when (notmuch-search-get-result pos)\r
194 > +     (funcall function pos))\r
195 > +      (setq pos (notmuch-search-result-end pos)\r
196 > +         first nil))))\r
197 > +;; Unindent the function argument of notmuch-search-foreach-result so\r
198 > +;; the indentation of callers doesn't get out of hand.\r
199 > +(put 'notmuch-search-foreach-result 'lisp-indent-function 2)\r
200 >  \r
201 >  (defun notmuch-search-properties-in-region (property beg end)\r
202 >    (let (output)\r
203 > -    (notmuch-search-do-results beg end pos\r
204 > -      (push (plist-get (notmuch-search-get-result pos) property) output))\r
205 > +    (notmuch-search-foreach-result beg end\r
206 > +      (lambda (pos)\r
207 > +     (push (plist-get (notmuch-search-get-result pos) property) output)))\r
208 >      output))\r
209 >  \r
210 >  (defun notmuch-search-find-thread-id ()\r
211 > @@ -542,18 +555,20 @@ and will also appear in a buffer named \"*Notmuch errors*\"."\r
212 >  \r
213 >  (defun notmuch-search-get-tags-region (beg end)\r
214 >    (let (output)\r
215 > -    (notmuch-search-do-results beg end pos\r
216 > -      (setq output (append output (notmuch-search-get-tags pos))))\r
217 > +    (notmuch-search-foreach-result beg end\r
218 > +      (lambda (pos)\r
219 > +     (setq output (append output (notmuch-search-get-tags pos)))))\r
220 >      output))\r
221 >  \r
222 >  (defun notmuch-search-tag-region (beg end &optional tag-changes)\r
223 >    "Change tags for threads in the given region."\r
224 >    (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))\r
225 >      (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))\r
226 > -    (notmuch-search-do-results beg end pos\r
227 > -      (notmuch-search-set-tags\r
228 > -       (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
229 > -       pos))))\r
230 > +    (notmuch-search-foreach-result beg end\r
231 > +      (lambda (pos)\r
232 > +     (notmuch-search-set-tags\r
233 > +      (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
234 > +      pos)))))\r
235 >  \r
236 >  (defun notmuch-search-tag (&optional tag-changes)\r
237 >    "Change tags for the currently selected thread or region.\r