[PATCH 4/4] Update NEWS for user.other_name
[notmuch-archives.git] / 4f / f5cbf90ed6e5b0eae8e6b8623d7f9bd2bdb05c
1 Return-Path: <dme@dme.org>\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 D7A20431FC3\r
6         for <notmuch@notmuchmail.org>; Tue, 25 Nov 2014 01:07:07 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.699\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7, UNPARSEABLE_RELAY=0.001]\r
13         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 Pv2Yf5HeDRTb for <notmuch@notmuchmail.org>;\r
17         Tue, 25 Nov 2014 01:07:00 -0800 (PST)\r
18 Received: from mail-wg0-f50.google.com (mail-wg0-f50.google.com\r
19  [74.125.82.50])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
20  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
21  1316F431FAF    for <notmuch@notmuchmail.org>; Tue, 25 Nov 2014 01:07:00 -0800\r
22  (PST)\r
23 Received: by mail-wg0-f50.google.com with SMTP id k14so228219wgh.23\r
24         for <notmuch@notmuchmail.org>; Tue, 25 Nov 2014 01:06:59 -0800 (PST)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26         d=1e100.net; s=20130820;\r
27         h=x-gm-message-state:user-agent:from:to:subject:date:message-id;\r
28         bh=qNqAimSRgAqUvWo9JF+eLK4arCODnursqIvPaWAs0Rc=;\r
29         b=f1aP94TylBERCxZo3X69WSnqxT+he1v69y9lJtjXKSrcNawt0cSltkdV6x9xHZTsYb\r
30         qkeGq0UAYSqhgQTGUCXIC0Z1z6xQCWHZ/72yGuFwl/Dg+aI49m6YhLaM+7HqVeJqzDaw\r
31         D5XF+BVpamaZvFDndBmr3w4dvHehAbHfCo3Nc5HpV30rzCP/7jRlSHolqwu3vw3nK8pi\r
32         Lh/yKjbcaqwOoi+OqO2KzYx0pIYs+F1xc11ZR2BwBwZZi3vZD1mkcYwPn3broEfTHRv0\r
33         qF/468AbothFn5PO+BGi/OxN1tR3w9npVF205H/uGxXXYqGnlx3bz8qzbbeRVGDhUGsT\r
34         7/Yw==\r
35 X-Gm-Message-State:\r
36  ALoCoQlPWy1vcm8NEQ9LcepslS0y/vlKKaGrBWsVbKwNHOt9IYSkAZO2bNXlXKC9HS9Pj6pZAXpb\r
37 X-Received: by 10.180.92.129 with SMTP id cm1mr6687547wib.33.1416906418764;\r
38         Tue, 25 Nov 2014 01:06:58 -0800 (PST)\r
39 Received: from disaster-area.hh.sledj.net\r
40         ([2a01:348:1a2:1:ea39:35ff:fe2c:a227])\r
41         by mx.google.com with ESMTPSA id s9sm1913937wiz.12.2014.11.25.01.06.57\r
42         for <notmuch@notmuchmail.org>\r
43         (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
44         Tue, 25 Nov 2014 01:06:58 -0800 (PST)\r
45 Received: from localhost (30000@localhost [local]);\r
46         by localhost (OpenSMTPD) with ESMTPA id af847ce3;\r
47         for <notmuch@notmuchmail.org>; Tue, 25 Nov 2014 09:06:56 +0000 (UTC)\r
48 User-Agent: OpenSMTPD enqueuer (Demoostik)\r
49 From: David Edmondson <dme@dme.org>\r
50 To: notmuch@notmuchmail.org\r
51 Subject: [RFC][PATCH v2] emacs: Replace `notmuch-search-result-format'\r
52         evaluation.\r
53 Date: Tue, 25 Nov 2014 09:06:56 +0000\r
54 Message-Id: <1416906416-3952-1-git-send-email-dme@dme.org>\r
55 X-Mailer: git-send-email 2.1.3\r
56 X-BeenThere: notmuch@notmuchmail.org\r
57 X-Mailman-Version: 2.1.13\r
58 Precedence: list\r
59 List-Id: "Use and development of the notmuch mail system."\r
60         <notmuch.notmuchmail.org>\r
61 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
63 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
64 List-Post: <mailto:notmuch@notmuchmail.org>\r
65 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
66 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
68 X-List-Received-Date: Tue, 25 Nov 2014 09:07:08 -0000\r
69 \r
70 Alternative implementation of code that interprets\r
71 `notmuch-search-result-format' to insert the results of a search.\r
72 ---\r
73 \r
74 Added some more documentation, as per bremner.\r
75 \r
76  emacs/notmuch.el | 300 +++++++++++++++++++++++++++++++++----------------------\r
77  1 file changed, 178 insertions(+), 122 deletions(-)\r
78 \r
79 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
80 index 218486a..eb79a29 100644\r
81 --- a/emacs/notmuch.el\r
82 +++ b/emacs/notmuch.el\r
83 @@ -66,23 +66,103 @@\r
84      "Placeholder variable when notmuch-version.el[c] is not available."))\r
85  \r
86  (defcustom notmuch-search-result-format\r
87 -  `(("date" . "%12s ")\r
88 -    ("count" . "%-7s ")\r
89 -    ("authors" . "%-20s ")\r
90 -    ("subject" . "%s ")\r
91 -    ("tags" . "(%s)"))\r
92 -  "Search result formatting. Supported fields are:\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 -Line breaks are permitted in format strings (though this is\r
98 -currently experimental).  Note that a line break at the end of an\r
99 -\"authors\" field will get elided if the authors list is long;\r
100 -place it instead at the beginning of the following field.  To\r
101 -enter a line break when setting this variable with setq, use \\n.\r
102 -To enter a line break in customize, press \\[quoted-insert] C-j."\r
103 -  :type '(alist :key-type (string) :value-type (string))\r
104 +  '((:width -12 :date_relative) " "\r
105 +    (:width -7 (:concat "[" :matched "/" :total "]")) " "\r
106 +    ;; This splitting will not be necessary once\r
107 +    ;; id:1414172643-28270-1-git-send-email-dme@dme.org is integrated.\r
108 +    (:width 40 (:eval (let* ((split-authors (split-string\r
109 +                                            (plist-get notmuch-thread :authors)\r
110 +                                            "|" t split-string-default-separators))\r
111 +                            ;; There will always be matched authors.\r
112 +                            (matched-authors (car split-authors))\r
113 +                            ;; There may not be non-matched authors.\r
114 +                            (non-matched-authors (mapconcat #'identity (cdr split-authors) " ")))\r
115 +                       (notmuch-search-format-authors matched-authors non-matched-authors)))) " "\r
116 +    :subject " "\r
117 +    "(" (:eval (notmuch-tag-format-tags (plist-get notmuch-thread :tags)\r
118 +                                       (plist-get notmuch-thread :orig-tags)))\r
119 +    ")" "\n")\r
120 +\r
121 +  "Template for displaying search results.\r
122 +\r
123 +The value is a list of items to insert in the search\r
124 +results. Individual items should be in one of the following\r
125 +forms:\r
126 +\r
127 +A string that is inserted directly (e.g. \" \").\r
128 +\r
129 +A number that is inserted directly (e.g. 5).\r
130 +\r
131 +A list that is recursively evaluated (e.g. `(:concat FORM1\r
132 + FORM2)').\r
133 +\r
134 +A function that is evaluated with a single argument, the current\r
135 + thread.\r
136 +\r
137 +A symbol corresponding to an attribute of the\r
138 + thread. Currently available attributes include:\r
139 +\r
140 + :date_relative -- a user-readable rendering of the Date: header\r
141 + of the first matching message in the thread, as a string.\r
142 +\r
143 + :timestamp -- the number of seconds since the Epoch, 1970-01-01\r
144 + 00:00:00 +0000 (UTC), corresponding to the Date: header of the\r
145 + first matching message in the thread.\r
146 +\r
147 + :subject -- the subject of the first matching message in the\r
148 + thread as a string.\r
149 +\r
150 + :authors -- a comma separated string containing a list of the\r
151 + authors of messages in the thread. If there are non-matching\r
152 + authors (i.e. the thread contains messages which did not match\r
153 + the search terms and those messages have authors who are not\r
154 + also authors of messages that did match the search terms) then\r
155 + the matching and non-matching authors are separated by a `|'\r
156 + symbol in the results in place of a comma.\r
157 +\r
158 + :matched -- the number of messages that matched search terms in\r
159 + the thread (a number).\r
160 +\r
161 + :total -- the total number of messages in the thread (i.e. the\r
162 + count of both matching and non-matching messages).\r
163 +\r
164 + :tags -- a list of tags associated with messages in the\r
165 + thread. Each tag is included as a distinct string.\r
166 +\r
167 + :orig-tags -- a list of tags that were associated with messages\r
168 + in the thread when the search originally took place.\r
169 +\r
170 + :query -- a list with two elements. The first element is a query\r
171 + string that will return all of the matching messages in the\r
172 + current thread. The second element is a query string that will\r
173 + return all of the non-matching messages in the current thread.\r
174 +\r
175 + :thread -- the thread id of the matching thread, as a string.\r
176 +\r
177 + For a full list of the attributes available, see the source code\r
178 + for notmuch itself.\r
179 +\r
180 +A directive that describes how to evaluate the remainder of the\r
181 + list. The following directives are available:\r
182 +\r
183 + `:concat FORM...' -- evaluate each element of FORM and return\r
184 + the concatenated results.\r
185 +\r
186 + `:width WIDTH FORM' -- evaluate FORM and return the result\r
187 + truncated to WIDTH characters. The result will be padded with\r
188 + spaces to WIDTH characters, with padding at on the left if the\r
189 + WIDTH is negative.\r
190 +\r
191 + `:tag TAG FORM' -- if the thread has the tag TAG, insert the\r
192 + result of evaluating FORM.\r
193 +\r
194 + `:eval COMPLEX-FORM' -- evaluate COMPLEX-FORM as emacs lisp and\r
195 + evaluate the result.\r
196 +\r
197 +During the evaluation of `notmuch-search-result-format', the\r
198 +symbol `notmuch-thread' is bound to the current thread (a\r
199 +property list), which can then be used in `:eval' forms."\r
200 +  :type 'list\r
201    :group 'notmuch-search)\r
202  \r
203  ;; The name of this variable `notmuch-init-file' is consistent with the\r
204 @@ -672,109 +752,84 @@ foreground and blue background."\r
205         ;; Reverse the list so earlier entries take precedence\r
206         (reverse notmuch-search-line-faces)))\r
207  \r
208 -(defun notmuch-search-author-propertize (authors)\r
209 -  "Split `authors' into matching and non-matching authors and\r
210 -propertize appropriately. If no boundary between authors and\r
211 -non-authors is found, assume that all of the authors match."\r
212 -  (if (string-match "\\(.*\\)|\\(.*\\)" authors)\r
213 -      (concat (propertize (concat (match-string 1 authors) ",")\r
214 -                         'face 'notmuch-search-matching-authors)\r
215 -             (propertize (match-string 2 authors)\r
216 -                         'face 'notmuch-search-non-matching-authors))\r
217 -    (propertize authors 'face 'notmuch-search-matching-authors)))\r
218 -\r
219 -(defun notmuch-search-insert-authors (format-string authors)\r
220 -  ;; Save the match data to avoid interfering with\r
221 -  ;; `notmuch-search-process-filter'.\r
222 -  (save-match-data\r
223 -    (let* ((formatted-authors (format format-string authors))\r
224 -          (formatted-sample (format format-string ""))\r
225 -          (visible-string formatted-authors)\r
226 -          (invisible-string "")\r
227 -          (padding ""))\r
228 -\r
229 -      ;; Truncate the author string to fit the specification.\r
230 -      (if (> (length formatted-authors)\r
231 -            (length formatted-sample))\r
232 -         (let ((visible-length (- (length formatted-sample)\r
233 -                                  (length "... "))))\r
234 -           ;; Truncate the visible string according to the width of\r
235 -           ;; the display string.\r
236 -           (setq visible-string (substring formatted-authors 0 visible-length)\r
237 -                 invisible-string (substring formatted-authors visible-length))\r
238 -           ;; If possible, truncate the visible string at a natural\r
239 -           ;; break (comma or pipe), as incremental search doesn't\r
240 -           ;; match across the visible/invisible border.\r
241 -           (when (string-match "\\(.*\\)\\([,|] \\)\\([^,|]*\\)" visible-string)\r
242 -             ;; Second clause is destructive on `visible-string', so\r
243 -             ;; order is important.\r
244 -             (setq invisible-string (concat (match-string 3 visible-string)\r
245 -                                            invisible-string)\r
246 -                   visible-string (concat (match-string 1 visible-string)\r
247 -                                          (match-string 2 visible-string))))\r
248 -           ;; `visible-string' may be shorter than the space allowed\r
249 -           ;; by `format-string'. If so we must insert some padding\r
250 -           ;; after `invisible-string'.\r
251 -           (setq padding (make-string (- (length formatted-sample)\r
252 -                                         (length visible-string)\r
253 -                                         (length "..."))\r
254 -                                      ? ))))\r
255 -\r
256 -      ;; Use different faces to show matching and non-matching authors.\r
257 -      (if (string-match "\\(.*\\)|\\(.*\\)" visible-string)\r
258 -         ;; The visible string contains both matching and\r
259 -         ;; non-matching authors.\r
260 -         (setq visible-string (notmuch-search-author-propertize visible-string)\r
261 -               ;; The invisible string must contain only non-matching\r
262 -               ;; authors, as the visible-string contains both.\r
263 -               invisible-string (propertize invisible-string\r
264 -                                            'face 'notmuch-search-non-matching-authors))\r
265 -       ;; The visible string contains only matching authors.\r
266 -       (setq visible-string (propertize visible-string\r
267 -                                        'face 'notmuch-search-matching-authors)\r
268 -             ;; The invisible string may contain both matching and\r
269 -             ;; non-matching authors.\r
270 -             invisible-string (notmuch-search-author-propertize invisible-string)))\r
271 -\r
272 -      ;; If there is any invisible text, add it as a tooltip to the\r
273 -      ;; visible text.\r
274 -      (when (not (string= invisible-string ""))\r
275 -       (setq visible-string (propertize visible-string 'help-echo (concat "..." invisible-string))))\r
276 -\r
277 -      ;; Insert the visible and, if present, invisible author strings.\r
278 -      (insert visible-string)\r
279 -      (when (not (string= invisible-string ""))\r
280 -       (let ((start (point))\r
281 -             overlay)\r
282 -         (insert invisible-string)\r
283 -         (setq overlay (make-overlay start (point)))\r
284 -         (overlay-put overlay 'invisible 'ellipsis)\r
285 -         (overlay-put overlay 'isearch-open-invisible #'delete-overlay)))\r
286 -      (insert padding))))\r
287 -\r
288 -(defun notmuch-search-insert-field (field format-string result)\r
289 +(defun notmuch-search-format-authors (matched non-matched)\r
290 +  (if (string-equal "" non-matched)\r
291 +      (propertize matched 'face 'notmuch-search-matching-authors)\r
292 +    (concat (propertize (concat matched ", ")\r
293 +                       'face 'notmuch-search-matching-authors)\r
294 +           (propertize non-matched\r
295 +                       'face 'notmuch-search-non-matching-authors))))\r
296 +\r
297 +(defun notmuch-search-make-width (width string)\r
298 +  (let ((neg (< 0 width))\r
299 +       (width (abs width))\r
300 +       (orig-len (length string)))\r
301 +\r
302 +    (if (< width orig-len)\r
303 +       ;; A sub-set of the string will be visible.\r
304 +       (let* ((ellipsis "...")\r
305 +              (visible-len (- width (length ellipsis)))\r
306 +              (visible-string (substring string 0 visible-len))\r
307 +              (invisible-string (substring string visible-len)))\r
308 +\r
309 +         (concat (propertize (concat visible-string\r
310 +                                     ;; The ellipsis should share the\r
311 +                                     ;; face of the preceding\r
312 +                                     ;; character.\r
313 +                                     (propertize ellipsis 'face\r
314 +                                                 (get-text-property visible-len 'face string)))\r
315 +                             'help-echo (concat ellipsis invisible-string))))\r
316 +\r
317 +      ;; All of the string is visible - pad it.\r
318 +      (concat (if neg string)\r
319 +             (make-string (- width orig-len) ? )\r
320 +             (if neg "" string)))))\r
321 +\r
322 +(defun notmuch-search-elem-repr (elem thread)\r
323    (cond\r
324 -   ((string-equal field "date")\r
325 -    (insert (propertize (format format-string (plist-get result :date_relative))\r
326 -                       'face 'notmuch-search-date)))\r
327 -   ((string-equal field "count")\r
328 -    (insert (propertize (format format-string\r
329 -                               (format "[%s/%s]" (plist-get result :matched)\r
330 -                                       (plist-get result :total)))\r
331 -                       'face 'notmuch-search-count)))\r
332 -   ((string-equal field "subject")\r
333 -    (insert (propertize (format format-string\r
334 -                               (notmuch-sanitize (plist-get result :subject)))\r
335 -                       'face 'notmuch-search-subject)))\r
336 -\r
337 -   ((string-equal field "authors")\r
338 -    (notmuch-search-insert-authors\r
339 -     format-string (notmuch-sanitize (plist-get result :authors))))\r
340 -\r
341 -   ((string-equal field "tags")\r
342 -    (let ((tags (plist-get result :tags))\r
343 -         (orig-tags (plist-get result :orig-tags)))\r
344 -      (insert (format format-string (notmuch-tag-format-tags tags orig-tags)))))))\r
345 +   ((not elem)\r
346 +    "")\r
347 +   \r
348 +   ((numberp elem)\r
349 +    (format "%d" elem))\r
350 +\r
351 +   ((stringp elem)\r
352 +    elem)\r
353 +\r
354 +   ((functionp elem)\r
355 +    (funcall elem thread))\r
356 +\r
357 +   ((listp elem)\r
358 +    (let ((op (car elem))\r
359 +         (rest (cdr elem)))\r
360 +      (case op\r
361 +       (:concat\r
362 +        (mapconcat (lambda (inner-elem)\r
363 +                     (notmuch-search-elem-repr inner-elem thread))\r
364 +                   rest ""))\r
365 +\r
366 +       (:width\r
367 +        (notmuch-search-make-width (car rest)\r
368 +                                   (notmuch-search-elem-repr (cadr rest) thread)))\r
369 +\r
370 +       (:tag\r
371 +        (when (member (car rest) (plist-get thread :tags))\r
372 +          (notmuch-search-elem-repr (cadr rest) thread)))\r
373 +\r
374 +       (:eval\r
375 +        (notmuch-search-elem-repr (apply #'eval rest) thread))\r
376 +\r
377 +       (otherwise\r
378 +        (mapconcat\r
379 +         (lambda (inner-elem) (notmuch-search-elem-repr inner-elem thread))\r
380 +         elem "")))))\r
381 +\r
382 +   (t\r
383 +    (let ((val (plist-get thread elem)))\r
384 +      (if val\r
385 +         (notmuch-search-elem-repr val thread)\r
386 +       (message "Unknown message attribute in `notmuch-search-elem-repr': %s" elem)\r
387 +       "")))))\r
388  \r
389  (defun notmuch-search-show-result (result pos)\r
390    "Insert RESULT at POS."\r
391 @@ -782,9 +837,10 @@ non-authors is found, assume that all of the authors match."\r
392    (unless (= (plist-get result :matched) 0)\r
393      (save-excursion\r
394        (goto-char pos)\r
395 -      (dolist (spec notmuch-search-result-format)\r
396 -       (notmuch-search-insert-field (car spec) (cdr spec) result))\r
397 -      (insert "\n")\r
398 +       ;; `notmuch-thread' is a well known symbol for functions to\r
399 +       ;; use during evaluation of `notmuch-search-result-format'.\r
400 +      (insert (let ((notmuch-thread result))\r
401 +               (notmuch-search-elem-repr notmuch-search-result-format notmuch-thread)))\r
402        (notmuch-search-color-line pos (point) (plist-get result :tags))\r
403        (put-text-property pos (point) 'notmuch-search-result result))))\r
404  \r
405 -- \r
406 2.1.3\r
407 \r