notmuch search and tags
[notmuch-archives.git] / 35 / 926c40e336764c26071111db9f75dad5b9557f
1 Return-Path: <dmitry.kurochkin@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 03D76414B8A\r
6         for <notmuch@notmuchmail.org>; Tue, 24 Jan 2012 17:12:24 -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.799\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
14 Received: from olra.theworths.org ([127.0.0.1])\r
15         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
16         with ESMTP id AqrkxgHxCQAG for <notmuch@notmuchmail.org>;\r
17         Tue, 24 Jan 2012 17:12:20 -0800 (PST)\r
18 Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com\r
19         [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id C4F03431FB6\r
22         for <notmuch@notmuchmail.org>; Tue, 24 Jan 2012 17:12:16 -0800 (PST)\r
23 Received: by mail-bk0-f53.google.com with SMTP id zt19so2972694bkb.26\r
24         for <notmuch@notmuchmail.org>; Tue, 24 Jan 2012 17:12:16 -0800 (PST)\r
25 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
26         h=from:to:subject:date:message-id:x-mailer:in-reply-to:references;\r
27         bh=sIzGTj7/8JHWss2TuNUdl0yjjHRfVZFwgC1J2dn/Z0Q=;\r
28         b=BZW32socSm/eptZU4AJBfr/jLo5+UPc9cfCfJ7n/G+HXVvnE13jyFdbqCfsFg32RFk\r
29         +CwMV+xB+EurFjjySWM4hNQ9hI2zUaRI9b8Il/2LoDx1mJBsnvsGaJNkaNrbfjiDUPmt\r
30         TzcV6/cIdmu59/KRj6BFtc8U94X9/rAJTBjAA=\r
31 Received: by 10.205.128.140 with SMTP id he12mr6236151bkc.76.1327453936444;\r
32         Tue, 24 Jan 2012 17:12:16 -0800 (PST)\r
33 Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id\r
34         fg16sm40124369bkb.16.2012.01.24.17.12.15\r
35         (version=TLSv1/SSLv3 cipher=OTHER);\r
36         Tue, 24 Jan 2012 17:12:15 -0800 (PST)\r
37 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH v4 2/3] emacs: use a single history for all searches\r
40 Date: Wed, 25 Jan 2012 05:10:53 +0400\r
41 Message-Id: <1327453854-29908-3-git-send-email-dmitry.kurochkin@gmail.com>\r
42 X-Mailer: git-send-email 1.7.8.3\r
43 In-Reply-To: <1327453854-29908-1-git-send-email-dmitry.kurochkin@gmail.com>\r
44 References: <1327362537-9607-1-git-send-email-dmitry.kurochkin@gmail.com>\r
45         <1327453854-29908-1-git-send-email-dmitry.kurochkin@gmail.com>\r
46 X-BeenThere: notmuch@notmuchmail.org\r
47 X-Mailman-Version: 2.1.13\r
48 Precedence: list\r
49 List-Id: "Use and development of the notmuch mail system."\r
50         <notmuch.notmuchmail.org>\r
51 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
52         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
53 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
54 List-Post: <mailto:notmuch@notmuchmail.org>\r
55 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
56 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
58 X-List-Received-Date: Wed, 25 Jan 2012 01:12:24 -0000\r
59 \r
60 There are two ways to do search in Emacs UI: search widget in\r
61 notmuch-hello buffer and `notmuch-search' function bound to "s".\r
62 Before the change, these search mechanisms used different history\r
63 lists.  The patch makes notmuch-hello search use the same history list\r
64 as `notmuch-search' function.\r
65 ---\r
66  emacs/notmuch-hello.el |   47 +++++++++++++++++++----------------------------\r
67  emacs/notmuch-lib.el   |    3 +++\r
68  emacs/notmuch.el       |   16 ++++++++++------\r
69  3 files changed, 32 insertions(+), 34 deletions(-)\r
70 \r
71 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
72 index d88a870..6970bc3 100644\r
73 --- a/emacs/notmuch-hello.el\r
74 +++ b/emacs/notmuch-hello.el\r
75 @@ -29,8 +29,8 @@\r
76  (declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))\r
77  (declare-function notmuch-poll "notmuch" ())\r
78  \r
79 -(defcustom notmuch-recent-searches-max 10\r
80 -  "The number of recent searches to store and display."\r
81 +(defcustom notmuch-hello-recent-searches-max 10\r
82 +  "The number of recent searches to display."\r
83    :type 'integer\r
84    :group 'notmuch-hello)\r
85  \r
86 @@ -154,16 +154,6 @@ International Bureau of Weights and Measures."\r
87  (defvar notmuch-hello-url "http://notmuchmail.org"\r
88    "The `notmuch' web site.")\r
89  \r
90 -(defvar notmuch-hello-recent-searches nil)\r
91 -\r
92 -(defun notmuch-hello-remember-search (search)\r
93 -  (setq notmuch-hello-recent-searches\r
94 -       (delete search notmuch-hello-recent-searches))\r
95 -  (push search notmuch-hello-recent-searches)\r
96 -  (if (> (length notmuch-hello-recent-searches)\r
97 -        notmuch-recent-searches-max)\r
98 -      (setq notmuch-hello-recent-searches (butlast notmuch-hello-recent-searches))))\r
99 -\r
100  (defun notmuch-hello-nice-number (n)\r
101    (let (result)\r
102      (while (> n 0)\r
103 @@ -183,9 +173,12 @@ International Bureau of Weights and Measures."\r
104      search))\r
105  \r
106  (defun notmuch-hello-search (search)\r
107 -  (let ((search (notmuch-hello-trim search)))\r
108 -    (notmuch-hello-remember-search search)\r
109 -    (notmuch-search search notmuch-search-oldest-first nil nil #'notmuch-hello-search-continuation)))\r
110 +  (unless (null search)\r
111 +    (setq search (notmuch-hello-trim search))\r
112 +    (let ((history-delete-duplicates t))\r
113 +      (add-to-history 'notmuch-search-history search)))\r
114 +  (notmuch-search search notmuch-search-oldest-first nil nil\r
115 +                 #'notmuch-hello-search-continuation))\r
116  \r
117  (defun notmuch-hello-add-saved-search (widget)\r
118    (interactive)\r
119 @@ -464,7 +457,7 @@ Complete list of currently available key bindings:\r
120  \r
121      (let ((found-target-pos nil)\r
122           (final-target-pos nil)\r
123 -         (search-bar-pos))\r
124 +         (default-pos))\r
125        (let* ((saved-alist\r
126               ;; Filter out empty saved searches if required.\r
127               (if notmuch-show-empty-saved-searches\r
128 @@ -496,7 +489,7 @@ Complete list of currently available key bindings:\r
129             (indent-rigidly start (point) notmuch-hello-indent)))\r
130  \r
131         (widget-insert "\nSearch: ")\r
132 -       (setq search-bar-pos (point-marker))\r
133 +       (setq default-pos (point-marker))\r
134         (widget-create 'editable-field\r
135                        ;; Leave some space at the start and end of the\r
136                        ;; search boxes.\r
137 @@ -513,18 +506,18 @@ Complete list of currently available key bindings:\r
138         (put-text-property (1- (point)) (point) 'invisible t)\r
139         (widget-insert "\n")\r
140  \r
141 -       (when notmuch-hello-recent-searches\r
142 +       (when notmuch-search-history\r
143           (widget-insert "\nRecent searches: ")\r
144           (widget-create 'push-button\r
145                          :notify (lambda (&rest ignore)\r
146 -                                  (setq notmuch-hello-recent-searches nil)\r
147 +                                  (setq notmuch-search-history nil)\r
148                                    (notmuch-hello-update))\r
149                          "clear")\r
150           (widget-insert "\n\n")\r
151 -         (let ((start (point))\r
152 -               (nth 0))\r
153 -           (mapc (lambda (search)\r
154 -                   (let ((widget-symbol (intern (format "notmuch-hello-search-%d" nth))))\r
155 +         (let ((start (point)))\r
156 +           (loop for i from 1 to notmuch-hello-recent-searches-max\r
157 +                 for search in notmuch-search-history do\r
158 +                   (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))\r
159                       (set widget-symbol\r
160                            (widget-create 'editable-field\r
161                                           ;; Don't let the search boxes be\r
162 @@ -551,9 +544,7 @@ Complete list of currently available key bindings:\r
163                                                (notmuch-hello-add-saved-search widget))\r
164                                      :notmuch-saved-search-widget widget-symbol\r
165                                      "save"))\r
166 -                   (widget-insert "\n")\r
167 -                   (setq nth (1+ nth)))\r
168 -                 notmuch-hello-recent-searches)\r
169 +                   (widget-insert "\n"))\r
170             (indent-rigidly start (point) notmuch-hello-indent)))\r
171  \r
172         (when alltags-alist\r
173 @@ -582,7 +573,7 @@ Complete list of currently available key bindings:\r
174        (let ((start (point)))\r
175         (widget-insert "\n\n")\r
176         (widget-insert "Type a search query and hit RET to view matching threads.\n")\r
177 -       (when notmuch-hello-recent-searches\r
178 +       (when notmuch-search-history\r
179           (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")\r
180           (widget-insert "Save recent searches with the `save' button.\n"))\r
181         (when notmuch-saved-searches\r
182 @@ -600,7 +591,7 @@ Complete list of currently available key bindings:\r
183           (widget-forward 1)))\r
184  \r
185        (unless (widget-at)\r
186 -       (goto-char search-bar-pos))))\r
187 +       (goto-char default-pos))))\r
188  \r
189    (run-hooks 'notmuch-hello-refresh-hook))\r
190  \r
191 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
192 index 241fe8c..c906ca7 100644\r
193 --- a/emacs/notmuch-lib.el\r
194 +++ b/emacs/notmuch-lib.el\r
195 @@ -69,6 +69,9 @@\r
196  \r
197  ;;\r
198  \r
199 +(defvar notmuch-search-history nil\r
200 +  "Variable to store notmuch searches history.")\r
201 +\r
202  (defcustom notmuch-saved-searches nil\r
203    "A list of saved searches to display."\r
204    :type '(alist :key-type string :value-type string)\r
205 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
206 index 6b2c252..b8b875b 100644\r
207 --- a/emacs/notmuch.el\r
208 +++ b/emacs/notmuch.el\r
209 @@ -925,21 +925,25 @@ PROMPT is the string to prompt with."\r
210                (t (list string)))))))\r
211        ;; this was simpler than convincing completing-read to accept spaces:\r
212        (define-key keymap (kbd "<tab>") 'minibuffer-complete)\r
213 -      (read-from-minibuffer prompt nil keymap nil\r
214 -                           'notmuch-query-history nil nil))))\r
215 +      (let ((history-delete-duplicates t))\r
216 +       (read-from-minibuffer prompt nil keymap nil\r
217 +                             'notmuch-search-history nil nil)))))\r
218  \r
219  ;;;###autoload\r
220 -(defun notmuch-search (query &optional oldest-first target-thread target-line continuation)\r
221 -  "Run \"notmuch search\" with the given query string and display results.\r
222 +(defun notmuch-search (&optional query oldest-first target-thread target-line continuation)\r
223 +  "Run \"notmuch search\" with the given `query' and display results.\r
224  \r
225 -The optional parameters are used as follows:\r
226 +If `query' is nil, it is read interactively from the minibuffer.\r
227 +Other optional parameters are used as follows:\r
228  \r
229    oldest-first: A Boolean controlling the sort order of returned threads\r
230    target-thread: A thread ID (with the thread: prefix) that will be made\r
231                   current if it appears in the search results.\r
232    target-line: The line number to move to if the target thread does not\r
233                 appear in the search results."\r
234 -  (interactive (list (notmuch-read-query "Notmuch search: ")))\r
235 +  (interactive)\r
236 +  (if (null query)\r
237 +      (setq query (notmuch-read-query "Notmuch search: ")))\r
238    (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))\r
239      (switch-to-buffer buffer)\r
240      (notmuch-search-mode)\r
241 -- \r
242 1.7.8.3\r
243 \r