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 9BB6F431FCB
\r
6 for <notmuch@notmuchmail.org>; Tue, 6 May 2014 11:49:04 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 WY57ThTyvg-a for <notmuch@notmuchmail.org>;
\r
18 Tue, 6 May 2014 11:48:59 -0700 (PDT)
\r
19 Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com
\r
20 [74.125.82.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client
\r
21 certificate requested) by olra.theworths.org (Postfix) with ESMTPS id
\r
22 CDA7F431FAF for <notmuch@notmuchmail.org>; Tue, 6 May 2014 11:48:58 -0700
\r
24 Received: by mail-wg0-f48.google.com with SMTP id b13so4155629wgh.7
\r
25 for <notmuch@notmuchmail.org>; Tue, 06 May 2014 11:48:57 -0700 (PDT)
\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
27 h=from:to:cc:subject:date:message-id;
\r
28 bh=S4DaxMJsAHRZFxMNDcN2p0yA5tG7SB5T2WHOo2Yu5Gc=;
\r
29 b=0R39i5hIRqQiS5bNbjIVjiczXNNmDogrAqgqFUCzYPbtkiP9PqE52BQitAm+0ZEIYH
\r
30 m2UIQErteKdtSdUayoXgkgjV614z0tYLUWj1jhV8b1csixGMn8slt3oz+Mc/8uQyrfHV
\r
31 vZgeyaY4kK5N9uH0z32AzW9OFWPKBuh0vFvDzoM0vVW5Qh6EeKp+wqeUlcXyNH/sOBXR
\r
32 Yxv/hxqZo+4gyF/zu9r32Ga3joNsfD8b3a1N7rmJW51wR+ScwvHtVkyOo5DK36t+mKY9
\r
33 AbT0F5lhPtCoioOv7ARjCZgRuxgHT3KdMbRwXujtcZdS8Nclc4H3EFpVwV91Sc8Pif/i
\r
35 X-Received: by 10.180.104.5 with SMTP id ga5mr3704357wib.47.1399402137279;
\r
36 Tue, 06 May 2014 11:48:57 -0700 (PDT)
\r
37 Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])
\r
38 by mx.google.com with ESMTPSA id dn1sm26381493wid.6.2014.05.06.11.48.55
\r
39 for <multiple recipients>
\r
40 (version=TLSv1.2 cipher=RC4-SHA bits=128/128);
\r
41 Tue, 06 May 2014 11:48:56 -0700 (PDT)
\r
42 From: Mark Walters <markwalters1009@gmail.com>
\r
43 To: notmuch@notmuchmail.org
\r
44 Subject: [PATCH] emacs: hello: allow arbitrary lisp for generating the count.
\r
45 Date: Tue, 6 May 2014 19:48:52 +0100
\r
46 Message-Id: <1399402132-1030-1-git-send-email-markwalters1009@gmail.com>
\r
47 X-Mailer: git-send-email 1.7.10.4
\r
48 X-BeenThere: notmuch@notmuchmail.org
\r
49 X-Mailman-Version: 2.1.13
\r
51 List-Id: "Use and development of the notmuch mail system."
\r
52 <notmuch.notmuchmail.org>
\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
56 List-Post: <mailto:notmuch@notmuchmail.org>
\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
60 X-List-Received-Date: Tue, 06 May 2014 18:49:04 -0000
\r
62 This allows a function to be given for the count-query of a saved
\r
63 search. The function will be called with the query plist as an
\r
64 argument to generate the count shown and should return either a string
\r
65 or a number to be displayed as the count.
\r
67 If this option is a function then its query will not be part of the
\r
68 normal bacth query used so it may make notmuch-hello slower to display.
\r
70 There was some discussion on irc today about notmuch hello being slow
\r
71 (because it can make a lot of queries). This extends the new
\r
72 saved-searches :count-query option to allow aribtrary lisp functions.
\r
74 Thus a user could configure some searches to be (lambda (elem) "--")
\r
75 so that these searches do not have a count executed and just display
\r
76 "--". Alternatively (and at the risk of some slow down) they could
\r
77 configure them to be my-notmuch-count where
\r
79 (defun my-notmuch-count (elem)
\r
81 (notmuch-hello-nice-number
\r
84 (process-lines notmuch-command "count" "--output=messages"
\r
85 (plist-get elem :query)))))
\r
87 (notmuch-hello-nice-number
\r
90 (process-lines notmuch-command "count" "--output=threads"
\r
91 (plist-get elem :query)))))))
\r
93 which would display messages/threads for that particular query.
\r
95 Maybe the interface is too complicated but I can actually imagine
\r
96 using this (possibly even both of the above for different of my saved
\r
105 emacs/notmuch-hello.el | 41 ++++++++++++++++++++++++++---------------
\r
106 1 file changed, 26 insertions(+), 15 deletions(-)
\r
108 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
\r
109 index 3de5238..877c84f 100644
\r
110 --- a/emacs/notmuch-hello.el
\r
111 +++ b/emacs/notmuch-hello.el
\r
112 @@ -85,7 +85,7 @@ (define-widget 'notmuch-saved-search-plist 'list
\r
113 (group :format "%v" :inline t (const :format " Query: " :query) (string :format "%v")))
\r
114 (checklist :inline t
\r
116 - (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))
\r
117 + (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (sexp :format "%v"))
\r
118 (group :format "%v" :inline t (const :format "" :sort-order)
\r
119 (choice :tag " Sort Order"
\r
120 (const :tag "Default" nil)
\r
121 @@ -101,9 +101,12 @@ (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")
\r
123 :name Name of the search (required).
\r
124 :query Search to run (required).
\r
125 - :count-query Optional extra query to generate the count
\r
126 - shown. If not present then the :query property
\r
128 + :count-query Optional extra lisp to generate the count
\r
129 + shown. If it is a string then it is a query
\r
130 + string for generating the count. If it is a
\r
131 + function then the function is called with the
\r
132 + query plist as a parameter. If it is nil or not
\r
133 + present then the :query property is used.
\r
134 :sort-order Specify the sort order to be used for the search.
\r
135 Possible values are 'oldest-first 'newest-first or
\r
136 nil. Nil means use the default sort order.
\r
137 @@ -493,13 +496,14 @@ (defun notmuch-hello-query-counts (query-list &rest options)
\r
138 (dolist (elem query-list nil)
\r
139 (let ((count-query (or (notmuch-saved-search-get elem :count-query)
\r
140 (notmuch-saved-search-get elem :query))))
\r
142 - (replace-regexp-in-string
\r
144 - (notmuch-hello-filtered-query count-query
\r
145 - (or (plist-get options :filter-count)
\r
146 - (plist-get options :filter))))
\r
148 + (unless (functionp count-query)
\r
150 + (replace-regexp-in-string
\r
152 + (notmuch-hello-filtered-query count-query
\r
153 + (or (plist-get options :filter-count)
\r
154 + (plist-get options :filter))))
\r
157 (unless (= (call-process-region (point-min) (point-max) notmuch-command
\r
158 t t nil "count" "--batch") 0)
\r
159 @@ -515,12 +519,17 @@ (defun notmuch-hello-query-counts (query-list &rest options)
\r
162 (let* ((elem-plist (notmuch-hello-saved-search-to-plist elem))
\r
163 + (count-query (plist-get elem-plist :count-query))
\r
164 (search-query (plist-get elem-plist :query))
\r
165 (filtered-query (notmuch-hello-filtered-query
\r
166 search-query (plist-get options :filter)))
\r
167 - (message-count (prog1 (read (current-buffer))
\r
168 - (forward-line 1))))
\r
169 - (when (and filtered-query (or (plist-get options :show-empty-searches) (> message-count 0)))
\r
170 + (message-count (if (functionp count-query)
\r
171 + (funcall count-query elem-plist)
\r
172 + (prog1 (read (current-buffer))
\r
173 + (forward-line 1)))))
\r
174 + (when (and filtered-query (or (plist-get options :show-empty-searches)
\r
175 + (not (integerp message-count))
\r
176 + (> message-count 0)))
\r
177 (setq elem-plist (plist-put elem-plist :query filtered-query))
\r
178 (plist-put elem-plist :count message-count))))
\r
180 @@ -559,7 +568,9 @@ (defun notmuch-hello-insert-buttons (searches)
\r
181 (otherwise notmuch-search-oldest-first)))
\r
182 (msg-count (plist-get elem :count)))
\r
183 (widget-insert (format "%8s "
\r
184 - (notmuch-hello-nice-number msg-count)))
\r
185 + (if (stringp msg-count)
\r
187 + (notmuch-hello-nice-number msg-count))))
\r
188 (widget-create 'push-button
\r
189 :notify #'notmuch-hello-widget-search
\r
190 :notmuch-search-terms query
\r