Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 21 / 894e5e60aded9e7ec3559467d9c0d587cb1118
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 2887F429E28\r
6         for <notmuch@notmuchmail.org>; Thu, 17 Nov 2011 12:07:49 -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 7k2UcLXcnR1X for <notmuch@notmuchmail.org>;\r
16         Thu, 17 Nov 2011 12:07:48 -0800 (PST)\r
17 Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
18         [209.85.214.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 DA5F1429E26\r
21         for <notmuch@notmuchmail.org>; Thu, 17 Nov 2011 12:07:47 -0800 (PST)\r
22 Received: by bkaq10 with SMTP id q10so2676332bka.26\r
23         for <notmuch@notmuchmail.org>; Thu, 17 Nov 2011 12:07:45 -0800 (PST)\r
24 Received: by 10.204.152.134 with SMTP id g6mr112920bkw.44.1321560464917;\r
25         Thu, 17 Nov 2011 12:07:44 -0800 (PST)\r
26 Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi.\r
27         [80.220.92.23])\r
28         by mx.google.com with ESMTPS id y17sm3031597faa.22.2011.11.17.12.07.40\r
29         (version=SSLv3 cipher=OTHER); Thu, 17 Nov 2011 12:07:42 -0800 (PST)\r
30 From: Jani Nikula <jani@nikula.org>\r
31 To: notmuch@notmuchmail.org\r
32 Subject: [DRAFT PATCH] emacs: support limiting the number of results shown in\r
33         search results\r
34 Date: Thu, 17 Nov 2011 22:07:38 +0200\r
35 Message-Id: <1321560458-32010-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: Thu, 17 Nov 2011 20:07:49 -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 Note: This is not intended for inclusion yet. It works, but I'd like to try\r
63 to simplify things a bit (in this patch and otherwise) by keeping the\r
64 relevant variables buffer local over notmuch-search-refresh-view. This\r
65 would mean not killing the search buffer in between.\r
66 \r
67 I just wanted to share the work-in-progress, rebased against the current\r
68 master and the merged lib/cli dependencies. The previous versions of the\r
69 emacs part is at:\r
70 id:"0b937eb1103dbb24142a783eff599a7cb08f195e.1320093940.git.jani@nikula.org"\r
71 ---\r
72  emacs/notmuch-hello.el |   18 +++++++++++--\r
73  emacs/notmuch.el       |   62 +++++++++++++++++++++++++++++++++++++++--------\r
74  2 files changed, 66 insertions(+), 14 deletions(-)\r
75 \r
76 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
77 index 1a76c30..0e165e7 100644\r
78 --- a/emacs/notmuch-hello.el\r
79 +++ b/emacs/notmuch-hello.el\r
80 @@ -26,7 +26,7 @@\r
81  (require 'notmuch-lib)\r
82  (require 'notmuch-mua)\r
83  \r
84 -(declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))\r
85 +(declare-function notmuch-search "notmuch" (query &optional oldest-first limit target-thread target-line continuation))\r
86  (declare-function notmuch-poll "notmuch" ())\r
87  \r
88  (defvar notmuch-hello-search-bar-marker nil\r
89 @@ -37,6 +37,18 @@\r
90    :type 'integer\r
91    :group 'notmuch)\r
92  \r
93 +(defcustom notmuch-search-limit nil\r
94 +  "The maximum number of results to show in search results.\r
95 +\r
96 +This variables controls the maximum number of results to\r
97 +initially show in search results. If nil, the number of results\r
98 +is not limited. If non-nil, the search results will contain push\r
99 +buttons to double the number (can be repeated) or show unlimited\r
100 +number of results."\r
101 +  :type '(choice (const :tag "Unlimited" nil)\r
102 +                (integer :tag "Limit"))\r
103 +  :group 'notmuch)\r
104 +\r
105  (defcustom notmuch-show-empty-saved-searches nil\r
106    "Should saved searches with no messages be listed?"\r
107    :type 'boolean\r
108 @@ -151,7 +163,7 @@ Typically \",\" in the US and UK and \".\" in Europe."\r
109  (defun notmuch-hello-search (search)\r
110    (let ((search (notmuch-hello-trim search)))\r
111      (notmuch-hello-remember-search search)\r
112 -    (notmuch-search search notmuch-search-oldest-first nil nil #'notmuch-hello-search-continuation)))\r
113 +    (notmuch-search search notmuch-search-oldest-first notmuch-search-limit nil nil #'notmuch-hello-search-continuation)))\r
114  \r
115  (defun notmuch-hello-add-saved-search (widget)\r
116    (interactive)\r
117 @@ -200,7 +212,7 @@ diagonal."\r
118  (defun notmuch-hello-widget-search (widget &rest ignore)\r
119    (notmuch-search (widget-get widget\r
120                               :notmuch-search-terms)\r
121 -                 notmuch-search-oldest-first\r
122 +                 notmuch-search-oldest-first notmuch-search-limit\r
123                   nil nil #'notmuch-hello-search-continuation))\r
124  \r
125  (defun notmuch-saved-search-count (search)\r
126 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
127 index c1827cc..a644cef 100644\r
128 --- a/emacs/notmuch.el\r
129 +++ b/emacs/notmuch.el\r
130 @@ -196,6 +196,7 @@ For a mouse binding, return nil."\r
131  \r
132  (defvar notmuch-search-mode-map\r
133    (let ((map (make-sparse-keymap)))\r
134 +    (set-keymap-parent map widget-keymap)\r
135      (define-key map "?" 'notmuch-help)\r
136      (define-key map "q" 'notmuch-search-quit)\r
137      (define-key map "x" 'notmuch-search-quit)\r
138 @@ -241,6 +242,7 @@ For a mouse binding, return nil."\r
139  (defvar notmuch-search-target-thread)\r
140  (defvar notmuch-search-target-line)\r
141  (defvar notmuch-search-continuation)\r
142 +(defvar notmuch-search-limit)\r
143  \r
144  (defvar notmuch-search-disjunctive-regexp      "\\<[oO][rR]\\>")\r
145  \r
146 @@ -375,6 +377,7 @@ Complete list of currently available key bindings:\r
147    (make-local-variable 'notmuch-search-oldest-first)\r
148    (make-local-variable 'notmuch-search-target-thread)\r
149    (make-local-variable 'notmuch-search-target-line)\r
150 +  (make-local-variable 'notmuch-search-limit)\r
151    (set (make-local-variable 'notmuch-search-continuation) nil)\r
152    (set (make-local-variable 'scroll-preserve-screen-position) t)\r
153    (add-to-invisibility-spec (cons 'ellipsis t))\r
154 @@ -631,6 +634,11 @@ This function advances the next thread when finished."\r
155                         (insert "End of search results.")\r
156                         (if (not (= exit-status 0))\r
157                             (insert (format " (process returned %d)" exit-status)))\r
158 +                       (if (and notmuch-search-limit\r
159 +                                (< 0 notmuch-search-limit)\r
160 +                                (< notmuch-search-limit\r
161 +                                   (count-lines (point-min) (point-max))))\r
162 +                           (notmuch-search-setup-buttons))\r
163                         (insert "\n")\r
164                         (if (and atbob\r
165                                  (not (string= notmuch-search-target-thread "found")))\r
166 @@ -906,7 +914,7 @@ PROMPT is the string to prompt with."\r
167                             'notmuch-query-history nil nil))))\r
168  \r
169  ;;;###autoload\r
170 -(defun notmuch-search (query &optional oldest-first target-thread target-line continuation)\r
171 +(defun notmuch-search (query &optional oldest-first limit target-thread target-line continuation)\r
172    "Run \"notmuch search\" with the given query string and display results.\r
173  \r
174  The optional parameters are used as follows:\r
175 @@ -922,6 +930,7 @@ The optional parameters are used as follows:\r
176      (notmuch-search-mode)\r
177      (set 'notmuch-search-query-string query)\r
178      (set 'notmuch-search-oldest-first oldest-first)\r
179 +    (set 'notmuch-search-limit limit)\r
180      (set 'notmuch-search-target-thread target-thread)\r
181      (set 'notmuch-search-target-line target-line)\r
182      (set 'notmuch-search-continuation continuation)\r
183 @@ -933,13 +942,19 @@ The optional parameters are used as follows:\r
184        (erase-buffer)\r
185        (goto-char (point-min))\r
186        (save-excursion\r
187 -       (let ((proc (start-process\r
188 -                    "notmuch-search" buffer\r
189 -                    notmuch-command "search"\r
190 -                    (if oldest-first\r
191 -                        "--sort=oldest-first"\r
192 -                      "--sort=newest-first")\r
193 -                    query)))\r
194 +       (let* ((args (append\r
195 +                     (if oldest-first\r
196 +                         (list "--sort=oldest-first")\r
197 +                       (list "--sort=newest-first"))\r
198 +                     (if (and limit (< 0 limit))\r
199 +                         (if oldest-first\r
200 +                             (list (format "--offset=-%d" limit))\r
201 +                           (list (format "--limit=%d" limit))))\r
202 +                     (list query)))\r
203 +              (proc (apply 'start-process\r
204 +                           "notmuch-search" buffer\r
205 +                           notmuch-command "search"\r
206 +                           args)))\r
207           (set-process-sentinel proc 'notmuch-search-process-sentinel)\r
208           (set-process-filter proc 'notmuch-search-process-filter)\r
209           (set-process-query-on-exit-flag proc nil))))\r
210 @@ -956,13 +971,38 @@ same relative position within the new buffer."\r
211    (interactive)\r
212    (let ((target-line (line-number-at-pos))\r
213         (oldest-first notmuch-search-oldest-first)\r
214 +       (limit notmuch-search-limit)\r
215         (target-thread (notmuch-search-find-thread-id))\r
216         (query notmuch-search-query-string)\r
217         (continuation notmuch-search-continuation))\r
218      (notmuch-kill-this-buffer)\r
219 -    (notmuch-search query oldest-first target-thread target-line continuation)\r
220 +    (notmuch-search query oldest-first limit target-thread target-line continuation)\r
221      (goto-char (point-min))))\r
222  \r
223 +(defun notmuch-search-double-results (&rest ignore)\r
224 +  (if notmuch-search-limit\r
225 +      (setq notmuch-search-limit (* 2 notmuch-search-limit)))\r
226 +  (notmuch-search-refresh-view))\r
227 +\r
228 +(defun notmuch-search-unlimited-results (&rest ignore)\r
229 +  (setq notmuch-search-limit nil)\r
230 +  (notmuch-search-refresh-view))\r
231 +\r
232 +(defun notmuch-search-setup-buttons ()\r
233 +  (widget-insert "    ")\r
234 +  (widget-create 'push-button\r
235 +                :keymap widget-keymap\r
236 +                :notify 'notmuch-search-double-results\r
237 +                :help-echo "Double the number of results shown"\r
238 +                "Show 2X results")\r
239 +  (widget-insert "    ")\r
240 +  (widget-create 'push-button\r
241 +                :keymap widget-keymap\r
242 +                :notify 'notmuch-search-unlimited-results\r
243 +                :help-echo "Show all search results"\r
244 +                "Show unlimited results")\r
245 +  (widget-setup))\r
246 +\r
247  (defcustom notmuch-poll-script ""\r
248    "An external script to incorporate new mail into the notmuch database.\r
249  \r
250 @@ -1021,7 +1061,7 @@ current search results AND the additional query string provided."\r
251                          query)))\r
252      (notmuch-search (if (string= notmuch-search-query-string "*")\r
253                         grouped-query\r
254 -                     (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first)))\r
255 +                     (concat notmuch-search-query-string " and " grouped-query)) notmuch-search-oldest-first notmuch-search-limit)))\r
256  \r
257  (defun notmuch-search-filter-by-tag (tag)\r
258    "Filter the current search results based on a single tag.\r
259 @@ -1030,7 +1070,7 @@ Runs a new search matching only messages that match both the\r
260  current search results AND that are tagged with the given tag."\r
261    (interactive\r
262     (list (notmuch-select-tag-with-completion "Filter by tag: ")))\r
263 -  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))\r
264 +  (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first notmuch-search-limit))\r
265  \r
266  ;;;###autoload\r
267  (defun notmuch ()\r
268 -- \r
269 1.7.5.4\r
270 \r