Re: [PATCH v4 13/16] add indexopts to notmuch python bindings.
[notmuch-archives.git] / 3f / 4dff3c01677a1ce2cb936d5c1376744dc9cd8f
1 Return-Path: <jani@nikula.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 610E1431FBC\r
6         for <notmuch@notmuchmail.org>; Fri, 27 Jan 2012 11:35:10 -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.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 KZGBpkgrRpv3 for <notmuch@notmuchmail.org>;\r
16         Fri, 27 Jan 2012 11:35:08 -0800 (PST)\r
17 Received: from mail-lpp01m010-f53.google.com (mail-lpp01m010-f53.google.com\r
18         [209.85.215.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id BAE62431FAE\r
21         for <notmuch@notmuchmail.org>; Fri, 27 Jan 2012 11:35:07 -0800 (PST)\r
22 Received: by lahd3 with SMTP id d3so1401443lah.26\r
23         for <notmuch@notmuchmail.org>; Fri, 27 Jan 2012 11:35:04 -0800 (PST)\r
24 Received: by 10.112.23.229 with SMTP id p5mr2089168lbf.21.1327692904776;\r
25         Fri, 27 Jan 2012 11:35:04 -0800 (PST)\r
26 Received: from localhost (dsl-hkibrasgw4-fe50f800-253.dhcp.inet.fi.\r
27         [84.248.80.253])\r
28         by mx.google.com with ESMTPS id w8sm6611795lbm.8.2012.01.27.11.35.01\r
29         (version=SSLv3 cipher=OTHER); Fri, 27 Jan 2012 11:35:03 -0800 (PST)\r
30 From: Jani Nikula <jani@nikula.org>\r
31 To: notmuch@notmuchmail.org\r
32 Subject: [PATCH] emacs: support limiting the number of results shown in search\r
33         results\r
34 Date: Fri, 27 Jan 2012 21:35:00 +0200\r
35 Message-Id: <1327692900-22926-1-git-send-email-jani@nikula.org>\r
36 X-Mailer: git-send-email 1.7.5.4\r
37 X-BeenThere: notmuch@notmuchmail.org\r
38 X-Mailman-Version: 2.1.13\r
39 Precedence: list\r
40 List-Id: "Use and development of the notmuch mail system."\r
41         <notmuch.notmuchmail.org>\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
43         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
45 List-Post: <mailto:notmuch@notmuchmail.org>\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
48         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
49 X-List-Received-Date: Fri, 27 Jan 2012 19:35:10 -0000\r
50 \r
51 Add support for limiting the maximum number of results initially displayed\r
52 in search results. When enabled, the search results will contain push\r
53 buttons to double the number of results displayed or to show unlimited\r
54 results.\r
55 \r
56 The approach is inspired by vc-print-log in Emacs vc.el.\r
57 \r
58 Signed-off-by: Jani Nikula <jani@nikula.org>\r
59 \r
60 ---\r
61 \r
62 Rebased since id:"1321560458-32010-1-git-send-email-jani@nikula.org",\r
63 and added option to limit results to window height. Limiting does not\r
64 work through the 's' key binding in search view, and some of the\r
65 issues reported by Austin in id:"20111104205415.GJ22935@mit.edu" and\r
66 Aneesh in id:"87hb1gu643.fsf@linux.vnet.ibm.com" are unfortunately\r
67 still there.\r
68 \r
69 If anyone wants to pick this up from here, I'd be delighted. I use\r
70 this, but don't have the time to polish. This is just to share the\r
71 rebased patch as Aneesh was asking for it on IRC.\r
72 ---\r
73  emacs/notmuch-hello.el |   21 +++++++++++++--\r
74  emacs/notmuch.el       |   64 +++++++++++++++++++++++++++++++++++++++--------\r
75  2 files changed, 71 insertions(+), 14 deletions(-)\r
76 \r
77 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
78 index d17a30f..9ed68e2 100644\r
79 --- a/emacs/notmuch-hello.el\r
80 +++ b/emacs/notmuch-hello.el\r
81 @@ -26,7 +26,7 @@\r
82  (require 'notmuch-lib)\r
83  (require 'notmuch-mua)\r
84  \r
85 -(declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))\r
86 +(declare-function notmuch-search "notmuch" (query &optional oldest-first limit target-thread target-line continuation))\r
87  (declare-function notmuch-poll "notmuch" ())\r
88  \r
89  (defcustom notmuch-hello-recent-searches-max 10\r
90 @@ -34,6 +34,21 @@\r
91    :type 'integer\r
92    :group 'notmuch-hello)\r
93  \r
94 +(defcustom notmuch-search-limit nil\r
95 +  "The maximum number of results to show in search results.\r
96 +\r
97 +This variables controls the maximum number of results to\r
98 +initially show in search results. Set to 0 to limit to window\r
99 +height. The search results will contain push buttons to double\r
100 +the number (can be repeated) or show unlimited number of results.\r
101 +\r
102 +If set to nil, the number of results is not limited."\r
103 +  :type '(choice (const :tag "Unlimited" nil)\r
104 +                (const :tag "Window height" 0)\r
105 +                (integer :tag "Limit"))\r
106 +  :group 'notmuch-search\r
107 +  :group 'notmuch)\r
108 +\r
109  (defcustom notmuch-show-empty-saved-searches nil\r
110    "Should saved searches with no messages be listed?"\r
111    :type 'boolean\r
112 @@ -178,7 +193,7 @@ International Bureau of Weights and Measures."\r
113      (setq search (notmuch-hello-trim search))\r
114      (let ((history-delete-duplicates t))\r
115        (add-to-history 'notmuch-search-history search)))\r
116 -  (notmuch-search search notmuch-search-oldest-first nil nil\r
117 +  (notmuch-search search notmuch-search-oldest-first notmuch-search-limit nil nil\r
118                   #'notmuch-hello-search-continuation))\r
119  \r
120  (defun notmuch-hello-add-saved-search (widget)\r
121 @@ -228,7 +243,7 @@ diagonal."\r
122  (defun notmuch-hello-widget-search (widget &rest ignore)\r
123    (notmuch-search (widget-get widget\r
124                               :notmuch-search-terms)\r
125 -                 notmuch-search-oldest-first\r
126 +                 notmuch-search-oldest-first notmuch-search-limit\r
127                   nil nil #'notmuch-hello-search-continuation))\r
128  \r
129  (defun notmuch-saved-search-count (search)\r
130 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
131 index 72f78ed..b3fef88 100644\r
132 --- a/emacs/notmuch.el\r
133 +++ b/emacs/notmuch.el\r
134 @@ -231,6 +231,7 @@ For a mouse binding, return nil."\r
135  \r
136  (defvar notmuch-search-mode-map\r
137    (let ((map (make-sparse-keymap)))\r
138 +    (set-keymap-parent map widget-keymap)\r
139      (define-key map "?" 'notmuch-help)\r
140      (define-key map "q" 'notmuch-search-quit)\r
141      (define-key map "x" 'notmuch-search-quit)\r
142 @@ -277,6 +278,7 @@ For a mouse binding, return nil."\r
143  (defvar notmuch-search-target-thread)\r
144  (defvar notmuch-search-target-line)\r
145  (defvar notmuch-search-continuation)\r
146 +(defvar notmuch-search-limit)\r
147  \r
148  (defvar notmuch-search-disjunctive-regexp      "\\<[oO][rR]\\>")\r
149  \r
150 @@ -418,6 +420,7 @@ Complete list of currently available key bindings:\r
151    (make-local-variable 'notmuch-search-oldest-first)\r
152    (make-local-variable 'notmuch-search-target-thread)\r
153    (make-local-variable 'notmuch-search-target-line)\r
154 +  (make-local-variable 'notmuch-search-limit)\r
155    (set (make-local-variable 'notmuch-search-continuation) nil)\r
156    (set (make-local-variable 'scroll-preserve-screen-position) t)\r
157    (add-to-invisibility-spec (cons 'ellipsis t))\r
158 @@ -680,6 +683,11 @@ This function advances the next thread when finished."\r
159                         (insert "End of search results.")\r
160                         (unless (= exit-status 0)\r
161                           (insert (format " (process returned %d)" exit-status)))\r
162 +                       (if (and notmuch-search-limit\r
163 +                                (< 0 notmuch-search-limit)\r
164 +                                (< notmuch-search-limit\r
165 +                                   (count-lines (point-min) (point-max))))\r
166 +                           (notmuch-search-setup-buttons))\r
167                         (insert "\n")\r
168                         (if (and atbob\r
169                                  (not (string= notmuch-search-target-thread "found")))\r
170 @@ -957,7 +965,7 @@ PROMPT is the string to prompt with."\r
171                               'notmuch-search-history nil nil)))))\r
172  \r
173  ;;;###autoload\r
174 -(defun notmuch-search (&optional query oldest-first target-thread target-line continuation)\r
175 +(defun notmuch-search (&optional query oldest-first limit target-thread target-line continuation)\r
176    "Run \"notmuch search\" with the given `query' and display results.\r
177  \r
178  If `query' is nil, it is read interactively from the minibuffer.\r
179 @@ -978,6 +986,9 @@ Other optional parameters are used as follows:\r
180      (set 'buffer-undo-list t)\r
181      (set 'notmuch-search-query-string query)\r
182      (set 'notmuch-search-oldest-first oldest-first)\r
183 +    (if (and limit (= limit 0))\r
184 +       (setq limit (- (window-body-height) 1)))\r
185 +    (set 'notmuch-search-limit limit)\r
186      (set 'notmuch-search-target-thread target-thread)\r
187      (set 'notmuch-search-target-line target-line)\r
188      (set 'notmuch-search-continuation continuation)\r
189 @@ -989,13 +1000,19 @@ Other optional parameters are used as follows:\r
190        (erase-buffer)\r
191        (goto-char (point-min))\r
192        (save-excursion\r
193 -       (let ((proc (start-process\r
194 -                    "notmuch-search" buffer\r
195 -                    notmuch-command "search"\r
196 -                    (if oldest-first\r
197 -                        "--sort=oldest-first"\r
198 -                      "--sort=newest-first")\r
199 -                    query)))\r
200 +       (let* ((args (append\r
201 +                     (if oldest-first\r
202 +                         (list "--sort=oldest-first")\r
203 +                       (list "--sort=newest-first"))\r
204 +                     (if (and limit (< 0 limit))\r
205 +                         (if oldest-first\r
206 +                             (list (format "--offset=-%d" limit))\r
207 +                           (list (format "--limit=%d" limit))))\r
208 +                     (list query)))\r
209 +              (proc (apply 'start-process\r
210 +                           "notmuch-search" buffer\r
211 +                           notmuch-command "search"\r
212 +                           args)))\r
213           (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
214           (set-process-filter proc 'notmuch-search-process-filter)\r
215           (set-process-query-on-exit-flag proc nil))))\r
216 @@ -1012,13 +1029,38 @@ same relative position within the new buffer."\r
217    (interactive)\r
218    (let ((target-line (line-number-at-pos))\r
219         (oldest-first notmuch-search-oldest-first)\r
220 +       (limit notmuch-search-limit)\r
221         (target-thread (notmuch-search-find-thread-id))\r
222         (query notmuch-search-query-string)\r
223         (continuation notmuch-search-continuation))\r
224      (notmuch-kill-this-buffer)\r
225 -    (notmuch-search query oldest-first target-thread target-line continuation)\r
226 +    (notmuch-search query oldest-first limit target-thread target-line continuation)\r
227      (goto-char (point-min))))\r
228  \r
229 +(defun notmuch-search-double-results (&rest ignore)\r
230 +  (if notmuch-search-limit\r
231 +      (setq notmuch-search-limit (* 2 notmuch-search-limit)))\r
232 +  (notmuch-search-refresh-view))\r
233 +\r
234 +(defun notmuch-search-unlimited-results (&rest ignore)\r
235 +  (setq notmuch-search-limit nil)\r
236 +  (notmuch-search-refresh-view))\r
237 +\r
238 +(defun notmuch-search-setup-buttons ()\r
239 +  (widget-insert "    ")\r
240 +  (widget-create 'push-button\r
241 +                :keymap widget-keymap\r
242 +                :notify 'notmuch-search-double-results\r
243 +                :help-echo "Double the number of results shown"\r
244 +                "Show 2X results")\r
245 +  (widget-insert "    ")\r
246 +  (widget-create 'push-button\r
247 +                :keymap widget-keymap\r
248 +                :notify 'notmuch-search-unlimited-results\r
249 +                :help-echo "Show all search results"\r
250 +                "Show unlimited results")\r
251 +  (widget-setup))\r
252 +\r
253  (defcustom notmuch-poll-script nil\r
254    "An external script to incorporate new mail into the notmuch database.\r
255  \r
256 @@ -1092,7 +1134,7 @@ current search results AND the additional query string provided."\r
257                          query)))\r
258      (notmuch-search (if (string= notmuch-search-query-string "*")\r
259                         grouped-query\r
260 -                     (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first)))\r
261 +                     (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first notmuch-search-limit)))\r
262  \r
263  (defun notmuch-search-filter-by-tag (tag)\r
264    "Filter the current search results based on a single tag.\r
265 @@ -1101,7 +1143,7 @@ Runs a new search matching only messages that match both the\r
266  current search results AND that are tagged with the given tag."\r
267    (interactive\r
268     (list (notmuch-select-tag-with-completion "Filter by tag: ")))\r
269 -  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))\r
270 +  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first notmuch-search-limit))\r
271  \r
272  ;;;###autoload\r
273  (defun notmuch ()\r
274 -- \r
275 1.7.5.4\r
276 \r