[PATCH v3 4/7] Add internal functions to search for alternate doc types
[notmuch-archives.git] / 93 / 338c4f6054fe02c397d86776ff4edd3bea9f41
1 Return-Path: <amdragon@mit.edu>\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 11F3B429E25\r
6         for <notmuch@notmuchmail.org>; Fri,  4 Nov 2011 13:52:08 -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.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 uaciEQQd4sKb for <notmuch@notmuchmail.org>;\r
16         Fri,  4 Nov 2011 13:52:07 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
18         [18.9.25.14])\r
19         by olra.theworths.org (Postfix) with ESMTP id C2932431FB6\r
20         for <notmuch@notmuchmail.org>; Fri,  4 Nov 2011 13:52:06 -0700 (PDT)\r
21 X-AuditID: 1209190e-b7f4a6d0000008e5-02-4eb45075c7e7\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 59.AB.02277.57054BE4; Fri,  4 Nov 2011 16:52:05 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id pA4Kq5Ue027178; \r
27         Fri, 4 Nov 2011 16:52:05 -0400\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pA4Kq3Ya013551\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Fri, 4 Nov 2011 16:52:04 -0400 (EDT)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1RMQmF-0003Z4-HE; Fri, 04 Nov 2011 16:54:15 -0400\r
37 Date: Fri, 4 Nov 2011 16:54:15 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Jani Nikula <jani@nikula.org>\r
40 Subject: Re: [RFC PATCH v2 3/3] emacs: support limiting the number of\r
41         results shown in search results\r
42 Message-ID: <20111104205415.GJ22935@mit.edu>\r
43 References: <cover.1320093940.git.jani@nikula.org>\r
44         <0b937eb1103dbb24142a783eff599a7cb08f195e.1320093940.git.jani@nikula.org>\r
45 MIME-Version: 1.0\r
46 Content-Type: text/plain; charset=us-ascii\r
47 Content-Disposition: inline\r
48 In-Reply-To:\r
49  <0b937eb1103dbb24142a783eff599a7cb08f195e.1320093940.git.jani@nikula.org>\r
50 User-Agent: Mutt/1.5.20 (2009-06-14)\r
51 X-Brightmail-Tracker:\r
52  H4sIAAAAAAAAA+NgFuplleLIzCtJLcpLzFFi42IR4hTV1i0N2OJnsPaQtUXTdGeL6zdnMjsw\r
53         edy6/5rd49mqW8wBTFFcNimpOZllqUX6dglcGX1bZzMWNAdVnJj6iKWB8bxjFyMnh4SAicTN\r
54         F0sZIWwxiQv31rN1MXJxCAnsY5RYdLmNBcJZzyhxcd8MdgjnBJPEntsLoDJLGCV2nNnNCtLP\r
55         IqAiMaevjRnEZhPQkNi2fznYXBEBRYnNJ/eD2cwC0hLffjczgdjCAukSq/ZMA6rn4OAV0JHY\r
56         1iEMYgoJ1EmsuwY2hVdAUOLkzCcsEJ1aEjf+vWQCKQGZsvwfB0iYUyBM4t7eLrCBokAHXNvf\r
57         zjaBUWgWku5ZSLpnIXQvYGRexSibklulm5uYmVOcmqxbnJyYl5dapGusl5tZopeaUrqJERzS\r
58         knw7GL8eVDrEKMDBqMTDu4Jzi58Qa2JZcWXuIUZJDiYlUd5LfkAhvqT8lMqMxOKM+KLSnNTi\r
59         Q4wSHMxKIrxxjEA53pTEyqrUonyYlDQHi5I47+odDn5CAumJJanZqakFqUUwWRkODiUJXj9/\r
60         oEbBotT01Iq0zJwShDQTByfIcB6g4fEgi3mLCxJzizPTIfKnGHU5zv+9dIpRiCUvPy9VSpx3\r
61         CsggAZCijNI8uDmwVPSKURzoLWHeNpAqHmAag5v0CmgJE9ASn42bQJaUJCKkpBoYk66stDrO\r
62         5K7DFzNXaElb/Ja1DF2ql7LfVi3anPX+ZP/xr4Vp37I2Hpi+84Owh+tUBcEWsX9ttoFGz0oU\r
63         ncRZJvf8Plz80HCp7SPlfEa5A3tTPobv8mviTOs9ma57dFtyKcvObTa1s9tfbqxtVzL6vD74\r
64         7MH3orK2Mw6vCXnnuKH668WL4YtfK7EUZyQaajEXFScCAASO6AogAwAA\r
65 Cc: notmuch@notmuchmail.org\r
66 X-BeenThere: notmuch@notmuchmail.org\r
67 X-Mailman-Version: 2.1.13\r
68 Precedence: list\r
69 List-Id: "Use and development of the notmuch mail system."\r
70         <notmuch.notmuchmail.org>\r
71 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
73 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
74 List-Post: <mailto:notmuch@notmuchmail.org>\r
75 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
76 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
77         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
78 X-List-Received-Date: Fri, 04 Nov 2011 20:52:08 -0000\r
79 \r
80 Quoth Jani Nikula on Oct 31 at 11:18 pm:\r
81 > Add support for limiting the maximum number of results initially displayed\r
82 > in search results. When enabled, the search results will contain push\r
83 > buttons to double the number of results displayed or to show unlimited\r
84 > results.\r
85\r
86 > The approach is inspired by vc-print-log in Emacs vc.el.\r
87\r
88 > Signed-off-by: Jani Nikula <jani@nikula.org>\r
89 > ---\r
90 >  emacs/notmuch-hello.el |   17 ++++++++++++--\r
91 >  emacs/notmuch.el       |   53 +++++++++++++++++++++++++++++++++++++++++++----\r
92 >  2 files changed, 62 insertions(+), 8 deletions(-)\r
93\r
94 > diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
95 > index 65fde75..4ba13e3 100644\r
96 > --- a/emacs/notmuch-hello.el\r
97 > +++ b/emacs/notmuch-hello.el\r
98 > @@ -26,7 +26,7 @@\r
99 >  (require 'notmuch-lib)\r
100 >  (require 'notmuch-mua)\r
101 >  \r
102 > -(declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))\r
103 > +(declare-function notmuch-search "notmuch" (query &optional oldest-first maxitems target-thread target-line continuation))\r
104 >  (declare-function notmuch-poll "notmuch" ())\r
105 >  \r
106 >  (defvar notmuch-hello-search-bar-marker nil\r
107 > @@ -37,6 +37,17 @@\r
108 >    :type 'integer\r
109 >    :group 'notmuch)\r
110 >  \r
111 > +(defcustom notmuch-search-maxitems 0\r
112 > +  "The maximum number of results to show in search results.\r
113 > +\r
114 > +This variables controls the maximum number of results to\r
115 > +initially show in search results. Set to 0 to not limit the\r
116 > +number of results. If non-zero, the search results will contain\r
117 > +push buttons to double the number (can be repeated) or show\r
118 > +unlimited number of results."\r
119 > +  :type 'integer\r
120 > +  :group 'notmuch)\r
121 > +\r
122 \r
123 It would be more lispy to use nil to indicate no limit, rather than 0.\r
124 The type could be something like\r
125   (choice (const   :tag "Unlimited" nil)\r
126           (integer :tag "Limit"))\r
127 \r
128 >  (defcustom notmuch-show-empty-saved-searches nil\r
129 >    "Should saved searches with no messages be listed?"\r
130 >    :type 'boolean\r
131 > @@ -151,7 +162,7 @@ Typically \",\" in the US and UK and \".\" in Europe."\r
132 >  (defun notmuch-hello-search (search)\r
133 >    (let ((search (notmuch-hello-trim search)))\r
134 >      (notmuch-hello-remember-search search)\r
135 > -    (notmuch-search search notmuch-search-oldest-first nil nil #'notmuch-hello-search-continuation)))\r
136 > +    (notmuch-search search notmuch-search-oldest-first notmuch-search-maxitems nil nil #'notmuch-hello-search-continuation)))\r
137 \r
138 It might make more sense of notmuch-search to use the value of\r
139 notmuch-search-maxitems directly, rather than feeding it in\r
140 everywhere, especially since it's buffer-local.  If there's really a\r
141 place that needs to override it, it would be easy to let-bind the\r
142 variable there.\r
143 \r
144 >  \r
145 >  (defun notmuch-hello-add-saved-search (widget)\r
146 >    (interactive)\r
147 > @@ -200,7 +211,7 @@ diagonal."\r
148 >  (defun notmuch-hello-widget-search (widget &rest ignore)\r
149 >    (notmuch-search (widget-get widget\r
150 >                             :notmuch-search-terms)\r
151 > -               notmuch-search-oldest-first\r
152 > +               notmuch-search-oldest-first notmuch-search-maxitems\r
153 >                 nil nil #'notmuch-hello-search-continuation))\r
154 >  \r
155 >  (defun notmuch-saved-search-count (search)\r
156 > diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
157 > index f11ec24..741ebe1 100644\r
158 > --- a/emacs/notmuch.el\r
159 > +++ b/emacs/notmuch.el\r
160 > @@ -193,6 +193,7 @@ For a mouse binding, return nil."\r
161 >  \r
162 >  (defvar notmuch-search-mode-map\r
163 >    (let ((map (make-sparse-keymap)))\r
164 > +    (set-keymap-parent map widget-keymap)\r
165 >      (define-key map "?" 'notmuch-help)\r
166 >      (define-key map "q" 'notmuch-search-quit)\r
167 >      (define-key map "x" 'notmuch-search-quit)\r
168 > @@ -217,7 +218,13 @@ For a mouse binding, return nil."\r
169 >      (define-key map "a" 'notmuch-search-archive-thread)\r
170 >      (define-key map "-" 'notmuch-search-remove-tag)\r
171 >      (define-key map "+" 'notmuch-search-add-tag)\r
172 > -    (define-key map (kbd "RET") 'notmuch-search-show-thread)\r
173 > +    ; Some hackery to allow RET both on buttons and messages. There's probably a\r
174 > +    ; better way to do this...\r
175 > +    (define-key map (kbd "RET") '(lambda (pos)\r
176 > +                                (interactive "@d")\r
177 > +                                (if (get-char-property pos 'button)\r
178 > +                                    (widget-button-press pos)\r
179 > +                                  (notmuch-search-show-thread))))\r
180 \r
181 Huh.  I thought widgets automatically had local keymaps, but maybe\r
182 that's only buttons (insert-button type buttons, that is).  A local\r
183 keymap is probably the right way to do this regardless.  Or use\r
184 buttons instead of widgets.\r
185 \r
186 >      (define-key map (kbd "M-RET") 'notmuch-search-show-thread-crypto-switch)\r
187 >      map)\r
188 >    "Keymap for \"notmuch search\" buffers.")\r
189 > @@ -239,6 +246,7 @@ For a mouse binding, return nil."\r
190 >  (defvar notmuch-search-target-thread)\r
191 >  (defvar notmuch-search-target-line)\r
192 >  (defvar notmuch-search-continuation)\r
193 > +(defvar notmuch-search-maxitems)\r
194 >  \r
195 >  (defvar notmuch-search-disjunctive-regexp      "\\<[oO][rR]\\>")\r
196 >  \r
197 > @@ -373,6 +381,7 @@ Complete list of currently available key bindings:\r
198 >    (make-local-variable 'notmuch-search-oldest-first)\r
199 >    (make-local-variable 'notmuch-search-target-thread)\r
200 >    (make-local-variable 'notmuch-search-target-line)\r
201 > +  (make-local-variable 'notmuch-search-maxitems)\r
202 >    (set (make-local-variable 'notmuch-search-continuation) nil)\r
203 >    (set (make-local-variable 'scroll-preserve-screen-position) t)\r
204 >    (add-to-invisibility-spec 'notmuch-search)\r
205 > @@ -633,6 +642,11 @@ This function advances the next thread when finished."\r
206 >                       (insert "End of search results.")\r
207 >                       (if (not (= exit-status 0))\r
208 >                           (insert (format " (process returned %d)" exit-status)))\r
209 > +                     (if (and notmuch-search-maxitems\r
210 > +                              (< 0 notmuch-search-maxitems)\r
211 > +                              (< notmuch-search-maxitems\r
212 > +                                 (count-lines (point-min) (point-max))))\r
213 > +                         (notmuch-search-setup-buttons))\r
214 >                       (insert "\n")\r
215 >                       (if (and atbob\r
216 >                                (not (string= notmuch-search-target-thread "found")))\r
217 > @@ -883,7 +897,7 @@ characters as well as `_.+-'.\r
218 >         )))\r
219 >  \r
220 >  ;;;###autoload\r
221 > -(defun notmuch-search (query &optional oldest-first target-thread target-line continuation)\r
222 > +(defun notmuch-search (query &optional oldest-first maxitems target-thread target-line continuation)\r
223 >    "Run \"notmuch search\" with the given query string and display results.\r
224 >  \r
225 >  The optional parameters are used as follows:\r
226 > @@ -899,6 +913,7 @@ The optional parameters are used as follows:\r
227 >      (notmuch-search-mode)\r
228 >      (set 'notmuch-search-query-string query)\r
229 >      (set 'notmuch-search-oldest-first oldest-first)\r
230 > +    (set 'notmuch-search-maxitems maxitems)\r
231 >      (set 'notmuch-search-target-thread target-thread)\r
232 >      (set 'notmuch-search-target-line target-line)\r
233 >      (set 'notmuch-search-continuation continuation)\r
234 > @@ -916,6 +931,11 @@ The optional parameters are used as follows:\r
235 >                    (if oldest-first\r
236 >                        "--sort=oldest-first"\r
237 >                      "--sort=newest-first")\r
238 > +                  (if (and maxitems (< 0 maxitems))\r
239 > +                      (if oldest-first\r
240 > +                          (format "--first=-%d" maxitems)\r
241 > +                        (format "--maxitems=%d" maxitems))\r
242 > +                    "")\r
243 >                    query)))\r
244 >         (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
245 >         (set-process-filter proc 'notmuch-search-process-filter))))\r
246 > @@ -932,13 +952,36 @@ same relative position within the new buffer."\r
247 >    (interactive)\r
248 >    (let ((target-line (line-number-at-pos))\r
249 >       (oldest-first notmuch-search-oldest-first)\r
250 > +     (maxitems notmuch-search-maxitems)\r
251 >       (target-thread (notmuch-search-find-thread-id))\r
252 >       (query notmuch-search-query-string)\r
253 >       (continuation notmuch-search-continuation))\r
254 >      (notmuch-kill-this-buffer)\r
255 > -    (notmuch-search query oldest-first target-thread target-line continuation)\r
256 > +    (notmuch-search query oldest-first maxitems target-thread target-line continuation)\r
257 >      (goto-char (point-min))))\r
258 >  \r
259 > +(defun notmuch-search-double-results (&rest ignore)\r
260 > +  (if notmuch-search-maxitems\r
261 > +      (set 'notmuch-search-maxitems (* 2 notmuch-search-maxitems)))\r
262 > +  (notmuch-search-refresh-view))\r
263 > +\r
264 > +(defun notmuch-search-unlimited-results (&rest ignore)\r
265 > +  (set 'notmuch-search-maxitems nil)\r
266 > +  (notmuch-search-refresh-view))\r
267 \r
268 I would recommend setq instead of set, except in the weird local\r
269 places where `set' is clearly the prevailing style.\r
270 \r
271 > +\r
272 > +(defun notmuch-search-setup-buttons ()\r
273 > +  (widget-insert "    ")\r
274 > +  (widget-create 'push-button\r
275 > +              :notify 'notmuch-search-double-results\r
276 > +              :help-echo "Double the number of results shown"\r
277 > +              "Show 2X results")\r
278 > +  (widget-insert "    ")\r
279 > +  (widget-create 'push-button\r
280 > +              :notify 'notmuch-search-unlimited-results\r
281 > +              :help-echo "Show all search results"\r
282 > +              "Show unlimited results")\r
283 > +  (widget-setup))\r
284 > +\r
285 \r
286 If you're limiting from the bottom, would it make more sense for these\r
287 widgets to be placed at the top of the buffer, since that's the\r
288 direction they'll expand the results?\r
289 \r
290 >  (defcustom notmuch-poll-script ""\r
291 >    "An external script to incorporate new mail into the notmuch database.\r
292 >  \r
293 > @@ -997,7 +1040,7 @@ current search results AND the additional query string provided."\r
294 >                        query)))\r
295 >      (notmuch-search (if (string= notmuch-search-query-string "*")\r
296 >                       grouped-query\r
297 > -                   (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first)))\r
298 > +                   (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first notmuch-search-maxitems)))\r
299 >  \r
300 >  (defun notmuch-search-filter-by-tag (tag)\r
301 >    "Filter the current search results based on a single tag.\r
302 > @@ -1006,7 +1049,7 @@ Runs a new search matching only messages that match both the\r
303 >  current search results AND that are tagged with the given tag."\r
304 >    (interactive\r
305 >     (list (notmuch-select-tag-with-completion "Filter by tag: ")))\r
306 > -  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))\r
307 > +  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first notmuch-search-maxitems))\r
308 >  \r
309 >  ;;;###autoload\r
310 >  (defun notmuch ()\r
311 \r
312 -- \r
313 Austin Clements                                      MIT/'06/PhD/CSAIL\r
314 amdragon@mit.edu                           http://web.mit.edu/amdragon\r
315        Somewhere in the dream we call reality you will find me,\r
316               searching for the reality we call dreams.\r