[PATCH 4/4] Update NEWS for user.other_name
[notmuch-archives.git] / a1 / e4e86e698eb50329ee636ab1607f11da7c0382
1 Return-Path: <sojkam1@fel.cvut.cz>\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 710AB431FD0\r
6         for <notmuch@notmuchmail.org>; Mon,  4 Jul 2011 17:00:39 -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\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         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 Gm7RL7BT9NFI for <notmuch@notmuchmail.org>;\r
16         Mon,  4 Jul 2011 17:00:37 -0700 (PDT)\r
17 Received: from max.feld.cvut.cz (max.feld.cvut.cz [147.32.192.36])\r
18         by olra.theworths.org (Postfix) with ESMTP id 71654431FB6\r
19         for <notmuch@notmuchmail.org>; Mon,  4 Jul 2011 17:00:37 -0700 (PDT)\r
20 Received: from localhost (unknown [192.168.200.4])\r
21         by max.feld.cvut.cz (Postfix) with ESMTP id 529C919F334D;\r
22         Tue,  5 Jul 2011 02:00:36 +0200 (CEST)\r
23 X-Virus-Scanned: IMAP AMAVIS\r
24 Received: from max.feld.cvut.cz ([192.168.200.1])\r
25         by localhost (styx.feld.cvut.cz [192.168.200.4]) (amavisd-new,\r
26         port 10044)\r
27         with ESMTP id kIQmzjAmglgB; Tue,  5 Jul 2011 02:00:34 +0200 (CEST)\r
28 Received: from imap.feld.cvut.cz (imap.feld.cvut.cz [147.32.192.34])\r
29         by max.feld.cvut.cz (Postfix) with ESMTP id BB72619F3349;\r
30         Tue,  5 Jul 2011 02:00:34 +0200 (CEST)\r
31 Received: from steelpick.2x.cz (cable-86-56-4-108.cust.telecolumbus.net\r
32         [86.56.4.108]) (Authenticated sender: sojkam1)\r
33         by imap.feld.cvut.cz (Postfix) with ESMTPSA id 85A9615C028;\r
34         Tue,  5 Jul 2011 02:00:34 +0200 (CEST)\r
35 Received: from wsh by steelpick.2x.cz with local (Exim 4.76)\r
36         (envelope-from <sojkam1@fel.cvut.cz>)\r
37         id 1Qdt45-0003f5-SD; Tue, 05 Jul 2011 02:00:33 +0200\r
38 From: Michal Sojka <sojkam1@fel.cvut.cz>\r
39 To: Daniel Schoepe <daniel.schoepe@googlemail.com>, notmuch@notmuchmail.org\r
40 Subject: Re: [PATCH 0/2] emacs: User-defined sections in notmuch-hello\r
41 In-Reply-To: <1309379221-5617-1-git-send-email-daniel.schoepe@googlemail.com>\r
42 References: <1309379221-5617-1-git-send-email-daniel.schoepe@googlemail.com>\r
43 User-Agent: Notmuch/0.5-320-g02ea1cf (http://notmuchmail.org) Emacs/23.3.1\r
44         (x86_64-pc-linux-gnu)\r
45 Date: Tue, 05 Jul 2011 02:00:33 +0200\r
46 Message-ID: <87wrfxk34u.fsf@steelpick.2x.cz>\r
47 MIME-Version: 1.0\r
48 Content-Type: text/plain; charset=us-ascii\r
49 X-BeenThere: notmuch@notmuchmail.org\r
50 X-Mailman-Version: 2.1.13\r
51 Precedence: list\r
52 List-Id: "Use and development of the notmuch mail system."\r
53         <notmuch.notmuchmail.org>\r
54 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
55         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
56 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
57 List-Post: <mailto:notmuch@notmuchmail.org>\r
58 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
59 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
60         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
61 X-List-Received-Date: Tue, 05 Jul 2011 00:00:39 -0000\r
62 \r
63 On Wed, 29 Jun 2011, Daniel Schoepe wrote:\r
64 > Unfortunately the customize-interface for more customized entries in\r
65 > notmuch-hello-sections looks a bit weird, but I couldn't figure out how\r
66 > to get rid of the empty lines produced by generating the lambda expression\r
67 > needed.\r
68 \r
69 Hi Daniel,\r
70 \r
71 this looks really great and it comes at the right time for me. I can use\r
72 it for creating a custom section "What's in your inbox" - a\r
73 functionality which I previously implemented in my personal branch [*]\r
74 but I was unable to rebase it on the current HEAD. Basically, it took\r
75 all saved searches and tag searches, filtered them with tag:inbox and\r
76 displayed the buttons for those searches.\r
77 \r
78 With your patch it is "quite easy" to implement such a functionality.\r
79 There are a few problems, though.\r
80 \r
81 First, the customization interface for the custom sections (not the\r
82 predefined ones) is very confusing. I was not able to use it at all.\r
83 Instead I hacked the source code (see below) to add my section to the\r
84 notmuch-hello-sections list.\r
85 \r
86 Second, when I tried to understand your patch, I found some names of\r
87 functions and variables quite confusing. In the patch below, I tried to\r
88 give them a better names and I also updated the documentation. Feel free\r
89 to use my changes for your later patch submission.\r
90 \r
91 And last but not least, you allow quite wild modifications of tag\r
92 searches (e.g. in notmuch-hello-generate-tag-alist), but is might be\r
93 also useful to use such modifications for other searches. For example, I\r
94 want to modify the saved searches in a similar way.\r
95  \r
96 > To avoid unnecessary complexity in the code this patch removes\r
97 > aligning all the tag entries in different sections (e.g. saved\r
98 > searches and all tags) the same way. So if someone really thinks this\r
99 > was an important features, please yell loudly.\r
100 \r
101 I do not miss this at all.\r
102 \r
103 And here are my changes to your patch, which you might use as a\r
104 suggestions for a next version of your patch. As I wrote above, it\r
105 renames some functions and variables to more understandable names,\r
106 updates documentation and adds a custom section for my personal use (I\r
107 can live with this custom section in my .emacs if others do not like\r
108 it).\r
109 \r
110 Cheers,\r
111 -Michal\r
112 \r
113 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
114 index e4c9307..226024c 100644\r
115 --- a/emacs/notmuch-hello.el\r
116 +++ b/emacs/notmuch-hello.el\r
117 @@ -124,6 +124,7 @@ Typically \",\" in the US and UK and \".\" in Europe."\r
118  \r
119  (defcustom notmuch-hello-sections\r
120    (list #'notmuch-hello-insert-header\r
121 +       #'notmuch-hello-insert-inbox\r
122         #'notmuch-hello-insert-saved-searches\r
123         #'notmuch-hello-insert-search\r
124         #'notmuch-hello-insert-recent-searches\r
125 @@ -205,8 +206,8 @@ in the order they appear in this list."\r
126      (message "Saved '%s' as '%s'." search name)\r
127      (notmuch-hello-update)))\r
128  \r
129 -(defun notmuch-hello-longest-label (tag-alist)\r
130 -  (or (loop for elem in tag-alist\r
131 +(defun notmuch-hello-longest-label (searches-alist)\r
132 +  (or (loop for elem in searches-alist\r
133             maximize (length (car elem)))\r
134        0))\r
135  \r
136 @@ -270,11 +271,18 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
137                                    (* tags-per-line (+ 9 1))))\r
138                            tags-per-line))))\r
139  \r
140 -(defun notmuch-hello-query-entries (tag-alist &optional hide-empty)\r
141 -  "Compute list of counts and queries for TAG-ALIST.\r
142 +(defun notmuch-hello-query-counts (query-alist &optional hide-empty)\r
143 +  "Compute list of counts of matched messages from QUERY-ALIST.\r
144  \r
145 -If HIDE-EMPTY is non-nil, entries with no matching messages will be\r
146 -removed from the result."\r
147 +QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)\r
148 +or (NAME QUERY COUNT-QUERY). If the latter form is used,\r
149 +COUNT-QUERY specifies an alternate query to be used to generate\r
150 +the count for the associated query.\r
151 +\r
152 +The result is the list of elements of the form (NAME QUERY COUNT).\r
153 +\r
154 +If HIDE-EMPTY is non-nil, searches with no matching messages\r
155 +(COUNT equal to zero) will be removed from the result."\r
156    (notmuch-remove-if-not\r
157     #'identity\r
158     (mapcar\r
159 @@ -289,21 +297,21 @@ removed from the result."\r
160                                  (cdr query-and-count)))))\r
161         (and (or (not hide-empty) (> message-count 0))\r
162            (list name (car query-and-count) message-count))))\r
163 -    tag-alist)))\r
164 +    query-alist)))\r
165  \r
166 -(defun notmuch-hello-insert-tags (entries)\r
167 -  "Insert query items from ENTRIES.\r
168 +(defun notmuch-hello-insert-buttons (searches)\r
169 +  "Insert buttons for SEARCHES.\r
170  \r
171 -ENTRIES must be a list containing lists of the form (NAME QUERY COUNT), where\r
172 +SEARCHES must be a list containing lists of the form (NAME QUERY COUNT), where\r
173  QUERY is the query to start when the button for the corresponding entry is\r
174  activated. COUNT should be the number of messages matching the query.\r
175 -Such a list can be computed with `notmuch-hello-query-entries'."\r
176 -  (let* ((widest (notmuch-hello-longest-label entries))\r
177 +Such a list can be computed with `notmuch-hello-query-counts'."\r
178 +  (let* ((widest (notmuch-hello-longest-label searches))\r
179          (tags-and-width (notmuch-hello-tags-per-line widest))\r
180          (tags-per-line (car tags-and-width))\r
181          (widest (cdr tags-and-width))\r
182          (count 0)\r
183 -        (reordered-list (notmuch-hello-reflect entries tags-per-line))\r
184 +        (reordered-list (notmuch-hello-reflect searches tags-per-line))\r
185          ;; Hack the display of the buttons used.\r
186          (widget-push-button-prefix "")\r
187          (widget-push-button-suffix "")\r
188 @@ -337,7 +345,7 @@ Such a list can be computed with `notmuch-hello-query-entries'."\r
189             (setq count (1+ count))\r
190             (if (eq (% count tags-per-line) 0)\r
191                 (widget-insert "\n")))\r
192 -         entries)\r
193 +         searches)\r
194  \r
195      ;; If the last line was not full (and hence did not include a\r
196      ;; carriage return), insert one now.\r
197 @@ -398,26 +406,36 @@ Complete list of currently available key bindings:\r
198    ;;(setq buffer-read-only t)\r
199    )\r
200  \r
201 -(defun notmuch-hello-make-query (tag make-query)\r
202 +(defun notmuch-hello-make-tag-query (tag filter)\r
203 +  "Constructs a query to search all messages tagged by TAG and\r
204 +matching FILTER.\r
205 +\r
206 +If FILTER is a string, it is directly used in the returned query.\r
207 +\r
208 +If FILTER is a function, it is called with TAG as a parameter and\r
209 +the string it returns is used as the filter.\r
210 +\r
211 +Finally, if FILTER is `t' it is ignored.\r
212 +"\r
213    (cond\r
214 -   ((functionp make-query)\r
215 -    (let ((result (funcall make-query tag)))\r
216 +   ((functionp filter)\r
217 +    (let ((result (funcall filter tag)))\r
218        (and result (concat "tag:" tag " and (" result ")"))))\r
219 -   ((stringp make-query)\r
220 -    (concat "tag:" tag " and (" make-query ")"))\r
221 +   ((stringp filter)\r
222 +    (concat "tag:" tag " and (" filter ")"))\r
223     (t (concat "tag:" tag))))\r
224  \r
225 -(defun notmuch-hello-generate-tag-alist (&optional hide-tags make-query make-count)\r
226 +(defun notmuch-hello-generate-tag-alist (&optional hide-tags filter-query filter-count)\r
227    "Return an alist from tags to queries to display in the all-tags section."\r
228    (notmuch-remove-if-not\r
229     #'identity\r
230     (mapcar (lambda (tag)\r
231 -            (let ((query (notmuch-hello-make-query tag make-query)))\r
232 +            (let ((query (notmuch-hello-make-tag-query tag filter-query)))\r
233                (when query\r
234 -                (if make-count\r
235 -                    (list tag (notmuch-hello-make-query tag make-query)\r
236 -                          (notmuch-hello-make-query tag make-count))\r
237 -                  (cons tag (notmuch-hello-make-query tag make-query))))))\r
238 +                (if filter-count\r
239 +                    (list tag (notmuch-hello-make-tag-query tag filter-query)\r
240 +                          (notmuch-hello-make-tag-query tag filter-count))\r
241 +                  (cons tag (notmuch-hello-make-tag-query tag filter-query))))))\r
242            (notmuch-remove-if-not\r
243             (lambda (tag)\r
244               (not (member tag hide-tags)))\r
245 @@ -462,11 +480,11 @@ Complete list of currently available key bindings:\r
246  \r
247  (defun notmuch-hello-insert-saved-searches ()\r
248    "Insert the saved-searches section."\r
249 -  (let ((entries (notmuch-hello-query-entries\r
250 +  (let ((searches (notmuch-hello-query-counts\r
251                   notmuch-saved-searches\r
252                   (not notmuch-show-empty-saved-searches)))\r
253         found-target-pos final-target-pos)\r
254 -    (when entries\r
255 +    (when searches\r
256        (widget-insert "\nSaved searches: ")\r
257        (widget-create 'push-button\r
258                      :notify (lambda (&rest ignore)\r
259 @@ -476,7 +494,7 @@ Complete list of currently available key bindings:\r
260        (setq final-target-pos (point-marker))\r
261        (let ((start (point)))\r
262         (setq found-target-pos\r
263 -             (notmuch-hello-insert-tags entries))\r
264 +             (notmuch-hello-insert-buttons searches))\r
265         (if found-target-pos\r
266             (setq final-target-pos found-target-pos))\r
267         (indent-rigidly start (point) notmuch-hello-indent)\r
268 @@ -539,19 +557,19 @@ Complete list of currently available key bindings:\r
269             notmuch-hello-recent-searches)\r
270        (indent-rigidly start (point) notmuch-hello-indent))))\r
271  \r
272 -(defun notmuch-hello-insert-query-list (title query-alist &rest options)\r
273 -  "Insert a section with TITLE showing tags from QUERY-ALIST.\r
274 -\r
275 -Supports the following entries in OPTIONS as a plist:\r
276 -:initially-hidden - if non-nil, section will be hidden on startup\r
277 -:hide-empty-tags - hide entries with no matching messages\r
278 -:hide-if-empty - hide if no entries would be shown\r
279 -   (only makes sense with :hide-empty-tags)\r
280 +(defun notmuch-hello-insert-searches (title query-alist &rest options)\r
281 +  "Insert a section with TITLE showing a list of buttons made from QUERY-ALIST.\r
282  \r
283  QUERY-ALIST must be a list containing elements of the form (NAME . QUERY)\r
284  or (NAME QUERY COUNT-QUERY). If the latter form is used,\r
285  COUNT-QUERY specifies an alternate query to be used to generate\r
286 -the count for the associated tag."\r
287 +the count for the associated tag.\r
288 +\r
289 +Supports the following entries in OPTIONS as a plist:\r
290 +:initially-hidden - if non-nil, section will be hidden on startup\r
291 +:hide-empty-searches - hide buttons with no matching messages\r
292 +:hide-if-empty - hide if no buttons would be shown\r
293 +   (only makes sense with :hide-empty-searches)"\r
294    (widget-insert title)\r
295    (if (and notmuch-hello-first-run (plist-get options :initially-hidden))\r
296        (add-to-list 'notmuch-hello-hidden-sections title))\r
297 @@ -572,21 +590,21 @@ the count for the associated tag."\r
298                      "hide"))\r
299      (widget-insert "\n")\r
300      (let (target-pos\r
301 -         (entries (notmuch-hello-query-entries\r
302 -                   query-alist (plist-get options :hide-empty-tags))))\r
303 +         (searches (notmuch-hello-query-counts\r
304 +                   query-alist (plist-get options :hide-empty-searches))))\r
305        (when (and (not is-hidden)\r
306                (or (not (plist-get options :hide-if-empty))\r
307 -                 entries))\r
308 +                 searches))\r
309         (widget-insert "\n")\r
310         (setq target-pos\r
311 -             (notmuch-hello-insert-tags entries))\r
312 +             (notmuch-hello=-insert-buttons searches))\r
313         (indent-rigidly start (point) notmuch-hello-indent)\r
314         target-pos))))\r
315  \r
316  (defun notmuch-hello-insert-tags-section (&rest options)\r
317    "Insert a section displaying all tags and message counts for each.\r
318  \r
319 -Allowed options are those accepted by `notmuch-hello-insert-query-list' and the\r
320 +Allowed options are those accepted by `notmuch-hello-insert-searches' and the\r
321  following:\r
322  \r
323  :title - Title for this section, defaults to \"All tags: \"\r
324 @@ -596,7 +614,7 @@ following:\r
325  :make-count - Seperate query to generate the count that should be displayed for each\r
326      tag. Accepts the same values as :make-query\r
327  :hide-tags - List of tags that should be excluded."\r
328 -  (apply 'notmuch-hello-insert-query-list\r
329 +  (apply 'notmuch-hello-insert-searches\r
330          (or (plist-get options :title) "All tags: ")\r
331          (notmuch-hello-generate-tag-alist\r
332           (plist-get options :hide-tags)\r
333 @@ -604,6 +622,15 @@ following:\r
334           (plist-get options :make-count))\r
335          options))\r
336  \r
337 +(defun notmuch-hello-insert-inbox ()\r
338 +  (notmuch-hello-insert-searches "What's in your inbox: "\r
339 +                                (mapcar (lambda (elem)\r
340 +                                          (cons (car elem) (concat "tag:inbox and (" (cdr elem) ")")))\r
341 +                                        (append\r
342 +                                         (notmuch-saved-searches)\r
343 +                                         (notmuch-hello-generate-tag-alist)))\r
344 +                                :hide-empty-searches t))\r
345 +\r
346  (defun notmuch-hello-insert-alltags ()\r
347    "Insert a section displaying all tags and associated message counts"\r
348    (notmuch-hello-insert-tags-section :initially-hidden\r
349 -- \r
350 1.7.5.4\r
351 \r
352 \r
353 \r
354 Footnotes:\r
355 \r
356 [*] id:"1275633449-17134-1-git-send-email-sojkam1@fel.cvut.cz"\r