Re: Flat search and threaded views
[notmuch-archives.git] / cf / 1b69f8afc42b151a75cb0c904aabba9338629d
1 Return-Path: <markwalters1009@gmail.com>\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 212C9431FC7\r
6         for <notmuch@notmuchmail.org>; Mon, 12 May 2014 08:20:12 -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.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id 8yFOV68n9+Qm for <notmuch@notmuchmail.org>;\r
18         Mon, 12 May 2014 08:20:04 -0700 (PDT)\r
19 Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com\r
20         [209.85.212.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id C1564431FC2\r
23         for <notmuch@notmuchmail.org>; Mon, 12 May 2014 08:20:03 -0700 (PDT)\r
24 Received: by mail-wi0-f174.google.com with SMTP id r20so4675740wiv.13\r
25         for <notmuch@notmuchmail.org>; Mon, 12 May 2014 08:20:02 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:subject:in-reply-to:references:user-agent:date:message-id\r
28         :mime-version:content-type;\r
29         bh=pH/7PJmg15Y0qTNgcT9K1L+wfwcZljTuiyBU+1duR7w=;\r
30         b=OyeoRB6Ibxcei6qPncM6mCMnjpkCZtwgHcOhSAkINVBxJy45JAJb/L3Nll6M+wFpRn\r
31         /Z4k23buXc6Q6avdqjXJTYcr3znJzF+bPGbVIuDA+lhxJtq5xBbGRczGlq88yDaKYoR0\r
32         zSCzP+3hoIzxzITqcH2s4ejiuxrWaVQT9g1ZZSsFvwpmlct2vX89LoFc1e0WKT3NcXtL\r
33         kNdxlJUvMPjFyWhvLjWVrToLJmU/Pm0aBIth/rKhEyEv1RrEbr7IrYm9v1TvnZeKkcZ0\r
34         JarmQAcn+6ZFtLUHJXARTsGdZOuaWxdLhxc0Kajz61ByVtQoUtXaJb051+YEMeMuV5X3\r
35         DHwA==\r
36 X-Received: by 10.194.92.7 with SMTP id ci7mr22184509wjb.7.1399908002480;\r
37         Mon, 12 May 2014 08:20:02 -0700 (PDT)\r
38 Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
39         by mx.google.com with ESMTPSA id dg7sm18329407wjc.4.2014.05.12.08.20.01\r
40         for <multiple recipients>\r
41         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
42         Mon, 12 May 2014 08:20:01 -0700 (PDT)\r
43 From: Mark Walters <markwalters1009@gmail.com>\r
44 To: David Edmondson <dme@dme.org>, notmuch@notmuchmail.org\r
45 Subject: Re: [PATCH 2/7] emacs: hello: allow saved search display functions\r
46 In-Reply-To: <cuniopb6qma.fsf@hotblack-desiato.hh.sledj.net>\r
47 References: <1399797282-20389-1-git-send-email-markwalters1009@gmail.com>\r
48         <1399797282-20389-3-git-send-email-markwalters1009@gmail.com>\r
49         <cuniopb6qma.fsf@hotblack-desiato.hh.sledj.net>\r
50 User-Agent: Notmuch/0.15.2+615~g78e3a93 (http://notmuchmail.org) Emacs/23.4.1\r
51         (x86_64-pc-linux-gnu)\r
52 Date: Mon, 12 May 2014 16:20:00 +0100\r
53 Message-ID: <871tvzkorj.fsf@qmul.ac.uk>\r
54 MIME-Version: 1.0\r
55 Content-Type: text/plain; charset=us-ascii\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: Mon, 12 May 2014 15:20:12 -0000\r
69 \r
70 On Mon, 12 May 2014, David Edmondson <dme@dme.org> wrote:\r
71 > On Sun, May 11 2014, Mark Walters wrote:\r
72 >> Extend the saved search plist to include a :display-function property\r
73 >> that can customise the display of the saved search. It can change the\r
74 >> count string displayed and the name string. Thus the user can\r
75 >> customise so that a particular search:\r
76 >>\r
77 >> does not show a count (and is thus hello is faster), shows a thread\r
78 >> count, show a combined message/thread count, changes colour of the\r
79 >> search button based on new messages arriving etc.\r
80 >>\r
81 >> The display function should use (&rest args) to take a keyword list of\r
82 >> arguments. The advantage of this is that it is easy to add extra\r
83 >> arguments in a backwards compatible way (existing user scripts will\r
84 >> still work).\r
85 >>\r
86 >> If a user uses this it will not take advantage of the batch counting\r
87 >> currently done so will make things slower over remote links (except in\r
88 >> cases where no query is done!).\r
89 >>\r
90 >> It also deletes the :count-query option from the customise for saved\r
91 >> searches as this method is much more general. The code still supports\r
92 >> the :count-query option though (just the defcustom does not).\r
93 >> ---\r
94 >>  emacs/notmuch-hello.el |   47 +++++++++++++++++++++++++++++++----------------\r
95 >>  1 file changed, 31 insertions(+), 16 deletions(-)\r
96 >>\r
97 >> diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
98 >> index 0a7004c..7075860 100644\r
99 >> --- a/emacs/notmuch-hello.el\r
100 >> +++ b/emacs/notmuch-hello.el\r
101 >> @@ -85,12 +85,13 @@ (define-widget 'notmuch-saved-search-plist 'list\r
102 >>              (group :format "%v" :inline t (const :format "  Query: " :query) (string :format "%v")))\r
103 >>        (checklist :inline t\r
104 >>                   :format "%v"\r
105 >> -                 (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))\r
106 >>                   (group :format "%v" :inline t (const :format "" :sort-order)\r
107 >>                          (choice :tag " Sort Order"\r
108 >>                                  (const :tag "Default" nil)\r
109 >>                                  (const :tag "Oldest-first" oldest-first)\r
110 >> -                                (const :tag "Newest-first" newest-first))))))\r
111 >> +                                (const :tag "Newest-first" newest-first)))\r
112 >> +                 (group :format "%v" :inline t (const :format "Display-function: " :display-function) (function :format "%v")))))\r
113 >> +\r
114 >>  \r
115 >>  (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")\r
116 >>                                  (:name "unread" :query "tag:unread"))\r
117 >> @@ -101,12 +102,19 @@ (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")\r
118 >>  \r
119 >>    :name            Name of the search (required).\r
120 >>    :query           Search to run (required).\r
121 >> -  :count-query     Optional extra query to generate the count\r
122 >> -                   shown. If not present then the :query property\r
123 >> -                   is used.\r
124 >>    :sort-order      Specify the sort order to be used for the search.\r
125 >>                     Possible values are 'oldest-first 'newest-first or\r
126 >>                     nil. Nil means use the default sort order.\r
127 >> +  :display-function Optional function to generate the count and\r
128 >> +                   name to be displayed. The function takes a\r
129 >> +                   keyword list of arguments (it should use\r
130 >> +                   &rest). Keywords include :current for the\r
131 >> +                   current saved search plist and :options. If\r
132 >> +                   this function is not set then the default\r
133 >> +                   display of message count and name is used. The\r
134 >> +                   function should return an updated saved search\r
135 >> +                   plist including :name and :count as the name\r
136 >> +                   and count-string to be displayed.\r
137 >>  \r
138 >>  Other accepted forms are a cons cell of the form (NAME . QUERY)\r
139 >>  or a list of the form (NAME QUERY COUNT-QUERY)."\r
140 >> @@ -507,15 +515,16 @@ (defun notmuch-hello-query-counts (query-list &rest options)\r
141 >>  `notmuch-hello-insert-searches'."\r
142 >>    (with-temp-buffer\r
143 >>      (dolist (elem query-list nil)\r
144 >> -      (let ((count-query (or (notmuch-saved-search-get elem :count-query)\r
145 >> -                         (notmuch-saved-search-get elem :query))))\r
146 >> -    (insert\r
147 >> -     (replace-regexp-in-string\r
148 >> -      "\n" " "\r
149 >> -      (notmuch-hello-filtered-query count-query\r
150 >> -                                    (or (plist-get options :filter-count)\r
151 >> -                                        (plist-get options :filter))))\r
152 >> -      "\n")))\r
153 >> +      (unless (notmuch-saved-search-get elem :display-function)\r
154 >> +    (let ((count-query (or (notmuch-saved-search-get elem :count-query)\r
155 >> +                           (notmuch-saved-search-get elem :query))))\r
156 >> +      (insert\r
157 >> +       (replace-regexp-in-string\r
158 >> +        "\n" " "\r
159 >> +        (notmuch-hello-filtered-query count-query\r
160 >> +                                      (or (plist-get options :filter-count)\r
161 >> +                                          (plist-get options :filter))))\r
162 >> +       "\n"))))\r
163 >>  \r
164 >>      (unless (= (call-process-region (point-min) (point-max) notmuch-command\r
165 >>                                  t t nil "count" "--batch") 0)\r
166 >> @@ -530,8 +539,14 @@ (defun notmuch-hello-query-counts (query-list &rest options)\r
167 >>       #'identity\r
168 >>       (mapcar\r
169 >>        (lambda (elem)\r
170 >> -    (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem)))\r
171 >> -      (notmuch-hello-batch-message-count elem-plist options)))\r
172 >> +    (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem))\r
173 >> +           (display-function (plist-get elem-plist :display-function))\r
174 >> +           (result (if display-function\r
175 >> +                        (funcall display-function\r
176 >> +                                 :current elem-plist\r
177 >> +                                 :option options)\r
178 >> +                      (notmuch-hello-batch-message-count elem-plist\r
179 >>                        options))))\r
180 >\r
181 > If `notmuch-hello-batch-message-count' were re-written to operate as a\r
182 > display-function, this could be replaced with something like:\r
183 >\r
184 >       (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem))\r
185 >              (result (funcall (or (plist-get elem-plist :display-function)\r
186 >                                   #'notmuch-hello-batch-message-count)\r
187 >                               :current elem-plist\r
188 >                               :option options))\r
189 >\r
190 \r
191 The reason I didn't do this is that things would break if a user\r
192 manually configured display function to be\r
193 #'notmuch-hello-batch-message-count as the query would not have been\r
194 batched. Thus my version made the distinction fundamental. But perhaps\r
195 the batch queuing code could queue the query if either there is no\r
196 display function or the display-function is\r
197 notmuch-hello-batch-message-count, but that seems a bit gross. \r
198 \r
199 I also played with calling each display function in the batch phase too\r
200 and then they could queue any message counts they wanted. But I thought\r
201 that might be too complex. OTOH being able to do display\r
202 match/match-and-unread might be nice and could be batched with the\r
203 correct infrastructure.\r
204 \r
205 Any thoughts?\r
206 \r
207 Best wishes\r
208 \r
209 Mark\r
210 \r
211 \r
212 \r
213 \r
214 \r
215 >> +      result))\r
216 >>        query-list))))\r
217 >>  \r
218 >>  (defun notmuch-hello-insert-buttons (searches)\r
219 >> -- \r
220 >> 1.7.10.4\r
221 >>\r
222 >> _______________________________________________\r
223 >> notmuch mailing list\r
224 >> notmuch@notmuchmail.org\r
225 >> http://notmuchmail.org/mailman/listinfo/notmuch\r