Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 40 / ecaa9367e21b740d4d1eb74e6cf6fea794e0b6
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 D7531421197\r
6         for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 11:35:17 -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 lnzkj0apKfcD for <notmuch@notmuchmail.org>;\r
17         Tue, 17 Jan 2012 11:35:15 -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 03EFD42119F\r
22         for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 11:35:09 -0800 (PST)\r
23 Received: by mail-bk0-f53.google.com with SMTP id y12so894828bkt.26\r
24         for <notmuch@notmuchmail.org>; Tue, 17 Jan 2012 11:35:09 -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=WlsuaTE+Jq4Fjr/AhPMrRuKlQiIbevzrXCn4LBWEc/w=;\r
28         b=ccZ9Ta3Z54WyqZot+WOoOZW81BVoOGaYMs4oWuOF/9t4/ANyRe7fv1xTitMlszPDCv\r
29         N7ye/FbGb36/EioCVtZGcquVYdnmi1dG4gF/GKFILgF2UXouy5Y6VVMaC0PzqsE6QpR6\r
30         I0Bovwyn2+7waF1CCbI1MHq+DX4GtaenykwIc=\r
31 Received: by 10.205.26.67 with SMTP id rl3mr7360291bkb.45.1326828908679;\r
32         Tue, 17 Jan 2012 11:35:08 -0800 (PST)\r
33 Received: from localhost ([91.144.186.21])\r
34         by mx.google.com with ESMTPS id d2sm49247764bky.11.2012.01.17.11.35.07\r
35         (version=TLSv1/SSLv3 cipher=OTHER);\r
36         Tue, 17 Jan 2012 11:35:08 -0800 (PST)\r
37 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 2/3] emacs: use a single history for all searches\r
40 Date: Tue, 17 Jan 2012 23:34:09 +0400\r
41 Message-Id: <1326828850-8519-2-git-send-email-dmitry.kurochkin@gmail.com>\r
42 X-Mailer: git-send-email 1.7.8.3\r
43 In-Reply-To: <1326828850-8519-1-git-send-email-dmitry.kurochkin@gmail.com>\r
44 References: <1326828850-8519-1-git-send-email-dmitry.kurochkin@gmail.com>\r
45 X-BeenThere: notmuch@notmuchmail.org\r
46 X-Mailman-Version: 2.1.13\r
47 Precedence: list\r
48 List-Id: "Use and development of the notmuch mail system."\r
49         <notmuch.notmuchmail.org>\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
53 List-Post: <mailto:notmuch@notmuchmail.org>\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
57 X-List-Received-Date: Tue, 17 Jan 2012 19:35:18 -0000\r
58 \r
59 There are two ways to do search in Emacs UI: search widget in\r
60 notmuch-hello buffer and `notmuch-search' function bound to "s".\r
61 Before the change, these search mechanisms used different history\r
62 lists.  The patch makes notmuch-hello search use the same history list\r
63 as `notmuch-search' function.\r
64 ---\r
65  emacs/notmuch-hello.el                             |   49 ++++++--------------\r
66  emacs/notmuch-lib.el                               |    9 ++++\r
67  emacs/notmuch.el                                   |   19 +++++--\r
68  test/emacs.expected-output/notmuch-hello           |    2 +-\r
69  .../notmuch-hello-no-saved-searches                |    2 +-\r
70  .../emacs.expected-output/notmuch-hello-with-empty |    2 +-\r
71  6 files changed, 40 insertions(+), 43 deletions(-)\r
72 \r
73 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
74 index 08fcd22..cb36977 100644\r
75 --- a/emacs/notmuch-hello.el\r
76 +++ b/emacs/notmuch-hello.el\r
77 @@ -29,8 +29,8 @@\r
78  (declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))\r
79  (declare-function notmuch-poll "notmuch" ())\r
80  \r
81 -(defcustom notmuch-recent-searches-max 10\r
82 -  "The number of recent searches to store and display."\r
83 +(defcustom notmuch-hello-recent-searches-max 10\r
84 +  "The number of recent searches to display."\r
85    :type 'integer\r
86    :group 'notmuch)\r
87  \r
88 @@ -151,16 +151,6 @@ International Bureau of Weights and Measures."\r
89  (defvar notmuch-hello-url "http://notmuchmail.org"\r
90    "The `notmuch' web site.")\r
91  \r
92 -(defvar notmuch-hello-recent-searches nil)\r
93 -\r
94 -(defun notmuch-hello-remember-search (search)\r
95 -  (setq notmuch-hello-recent-searches\r
96 -       (delete search notmuch-hello-recent-searches))\r
97 -  (push search notmuch-hello-recent-searches)\r
98 -  (if (> (length notmuch-hello-recent-searches)\r
99 -        notmuch-recent-searches-max)\r
100 -      (setq notmuch-hello-recent-searches (butlast notmuch-hello-recent-searches))))\r
101 -\r
102  (defun notmuch-hello-nice-number (n)\r
103    (let (result)\r
104      (while (> n 0)\r
105 @@ -173,16 +163,9 @@ International Bureau of Weights and Measures."\r
106               (format "%s%03d" notmuch-hello-thousands-separator elem))\r
107              (cdr result)))))\r
108  \r
109 -(defun notmuch-hello-trim (search)\r
110 -  "Trim whitespace."\r
111 -  (if (string-match "^[[:space:]]*\\(.*[^[:space:]]\\)[[:space:]]*$" search)\r
112 -      (match-string 1 search)\r
113 -    search))\r
114 -\r
115  (defun notmuch-hello-search (search)\r
116 -  (let ((search (notmuch-hello-trim search)))\r
117 -    (notmuch-hello-remember-search search)\r
118 -    (notmuch-search search notmuch-search-oldest-first nil nil #'notmuch-hello-search-continuation)))\r
119 +  (notmuch-search search notmuch-search-oldest-first nil nil\r
120 +                 #'notmuch-hello-search-continuation))\r
121  \r
122  (defun notmuch-hello-add-saved-search (widget)\r
123    (interactive)\r
124 @@ -461,7 +444,7 @@ Complete list of currently available key bindings:\r
125  \r
126      (let ((found-target-pos nil)\r
127           (final-target-pos nil)\r
128 -         (search-bar-pos))\r
129 +         (default-pos))\r
130        (let* ((saved-alist\r
131               ;; Filter out empty saved searches if required.\r
132               (if notmuch-show-empty-saved-searches\r
133 @@ -493,7 +476,7 @@ Complete list of currently available key bindings:\r
134             (indent-rigidly start (point) notmuch-hello-indent)))\r
135  \r
136         (widget-insert "\nSearch: ")\r
137 -       (setq search-bar-pos (point-marker))\r
138 +       (setq default-pos (point-marker))\r
139         (widget-create 'editable-field\r
140                        ;; Leave some space at the start and end of the\r
141                        ;; search boxes.\r
142 @@ -507,18 +490,18 @@ Complete list of currently available key bindings:\r
143         (put-text-property (1- (point)) (point) 'invisible t)\r
144         (widget-insert "\n")\r
145  \r
146 -       (when notmuch-hello-recent-searches\r
147 +       (when notmuch-search-history\r
148           (widget-insert "\nRecent searches: ")\r
149           (widget-create 'push-button\r
150                          :notify (lambda (&rest ignore)\r
151 -                                  (setq notmuch-hello-recent-searches nil)\r
152 +                                  (setq notmuch-search-history nil)\r
153                                    (notmuch-hello-update))\r
154                          "clear")\r
155           (widget-insert "\n\n")\r
156 -         (let ((start (point))\r
157 -               (nth 0))\r
158 -           (mapc (lambda (search)\r
159 -                   (let ((widget-symbol (intern (format "notmuch-hello-search-%d" nth))))\r
160 +         (let ((start (point)))\r
161 +           (loop for i from 1 to notmuch-hello-recent-searches-max\r
162 +                 for search in notmuch-search-history do\r
163 +                   (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))\r
164                       (set widget-symbol\r
165                            (widget-create 'editable-field\r
166                                           ;; Don't let the search boxes be\r
167 @@ -545,9 +528,7 @@ Complete list of currently available key bindings:\r
168                                                (notmuch-hello-add-saved-search widget))\r
169                                      :notmuch-saved-search-widget widget-symbol\r
170                                      "save"))\r
171 -                   (widget-insert "\n")\r
172 -                   (setq nth (1+ nth)))\r
173 -                 notmuch-hello-recent-searches)\r
174 +                   (widget-insert "\n"))\r
175             (indent-rigidly start (point) notmuch-hello-indent)))\r
176  \r
177         (when alltags-alist\r
178 @@ -576,7 +557,7 @@ Complete list of currently available key bindings:\r
179        (let ((start (point)))\r
180         (widget-insert "\n\n")\r
181         (widget-insert "Type a search query and hit RET to view matching threads.\n")\r
182 -       (when notmuch-hello-recent-searches\r
183 +       (when notmuch-search-history\r
184           (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")\r
185           (widget-insert "Save recent searches with the `save' button.\n"))\r
186         (when notmuch-saved-searches\r
187 @@ -594,7 +575,7 @@ Complete list of currently available key bindings:\r
188           (widget-forward 1)))\r
189  \r
190        (unless (widget-at)\r
191 -       (goto-char search-bar-pos))))\r
192 +       (goto-char default-pos))))\r
193  \r
194    (run-hooks 'notmuch-hello-refresh-hook))\r
195  \r
196 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
197 index 0f856bf..dfbc2e0 100644\r
198 --- a/emacs/notmuch-lib.el\r
199 +++ b/emacs/notmuch-lib.el\r
200 @@ -35,6 +35,9 @@\r
201  \r
202  ;;\r
203  \r
204 +(defvar notmuch-search-history nil\r
205 +  "Variable to store notmuch searches history.")\r
206 +\r
207  (defcustom notmuch-saved-searches nil\r
208    "A list of saved searches to display."\r
209    :type '(alist :key-type string :value-type string)\r
210 @@ -114,6 +117,12 @@ the user hasn't set this variable with the old or new value."\r
211        (setq list (cdr list)))\r
212      (nreverse out)))\r
213  \r
214 +(defun notmuch-trim (search)\r
215 +  "Trim whitespaces."\r
216 +  (if (string-match "^[[:space:]]*\\(.*[^[:space:]]\\)[[:space:]]*$" search)\r
217 +      (match-string 1 search)\r
218 +    search))\r
219 +\r
220  ; This lets us avoid compiling these replacement functions when emacs\r
221  ; is sufficiently new enough to supply them alone. We do the macro\r
222  ; treatment rather than just wrapping our defun calls in a when form\r
223 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
224 index ef4dcc7..450c0c1 100644\r
225 --- a/emacs/notmuch.el\r
226 +++ b/emacs/notmuch.el\r
227 @@ -916,21 +916,28 @@ PROMPT is the string to prompt with."\r
228                (t (list string)))))))\r
229        ;; this was simpler than convincing completing-read to accept spaces:\r
230        (define-key keymap (kbd "<tab>") 'minibuffer-complete)\r
231 -      (read-from-minibuffer prompt nil keymap nil\r
232 -                           'notmuch-query-history nil nil))))\r
233 +      (let ((history-delete-duplicates t))\r
234 +       (read-from-minibuffer prompt nil keymap nil\r
235 +                             'notmuch-search-history nil nil)))))\r
236  \r
237  ;;;###autoload\r
238 -(defun notmuch-search (query &optional oldest-first target-thread target-line continuation)\r
239 -  "Run \"notmuch search\" with the given query string and display results.\r
240 +(defun notmuch-search (&optional query oldest-first target-thread target-line continuation)\r
241 +  "Run \"notmuch search\" with the given `query' and display results.\r
242  \r
243 -The optional parameters are used as follows:\r
244 +If `query' is nil, it is read interactively from the minibuffer.\r
245 +Other optional parameters are used as follows:\r
246  \r
247    oldest-first: A Boolean controlling the sort order of returned threads\r
248    target-thread: A thread ID (with the thread: prefix) that will be made\r
249                   current if it appears in the search results.\r
250    target-line: The line number to move to if the target thread does not\r
251                 appear in the search results."\r
252 -  (interactive (list (notmuch-read-query "Notmuch search: ")))\r
253 +  (interactive)\r
254 +  (if (null query)\r
255 +      (setq query (notmuch-read-query "Notmuch search: "))\r
256 +    (setq query (notmuch-trim query))\r
257 +    (let ((history-delete-duplicates t))\r
258 +      (add-to-history 'notmuch-search-history query)))\r
259    (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))\r
260      (switch-to-buffer buffer)\r
261      (notmuch-search-mode)\r
262 diff --git a/test/emacs.expected-output/notmuch-hello b/test/emacs.expected-output/notmuch-hello\r
263 index de57de2..da47a6b 100644\r
264 --- a/test/emacs.expected-output/notmuch-hello\r
265 +++ b/test/emacs.expected-output/notmuch-hello\r
266 @@ -11,4 +11,4 @@ Search:\r
267          Type a search query and hit RET to view matching threads.\r
268                 Edit saved searches with the `edit' button.\r
269    Hit RET or click on a saved search or tag name to view matching threads.\r
270 -    `=' refreshes this screen. `s' jumps to the search box. `q' to quit.\r
271 +      `=' refreshes this screen. `s' to search messages. `q' to quit.\r
272 diff --git a/test/emacs.expected-output/notmuch-hello-no-saved-searches b/test/emacs.expected-output/notmuch-hello-no-saved-searches\r
273 index f1fc4d6..202d7d2 100644\r
274 --- a/test/emacs.expected-output/notmuch-hello-no-saved-searches\r
275 +++ b/test/emacs.expected-output/notmuch-hello-no-saved-searches\r
276 @@ -7,4 +7,4 @@ Search:\r
277          Type a search query and hit RET to view matching threads.\r
278                 Edit saved searches with the `edit' button.\r
279    Hit RET or click on a saved search or tag name to view matching threads.\r
280 -    `=' refreshes this screen. `s' jumps to the search box. `q' to quit.\r
281 +      `=' refreshes this screen. `s' to search messages. `q' to quit.\r
282 diff --git a/test/emacs.expected-output/notmuch-hello-with-empty b/test/emacs.expected-output/notmuch-hello-with-empty\r
283 index dd8728b..d810b51 100644\r
284 --- a/test/emacs.expected-output/notmuch-hello-with-empty\r
285 +++ b/test/emacs.expected-output/notmuch-hello-with-empty\r
286 @@ -11,4 +11,4 @@ Search:\r
287          Type a search query and hit RET to view matching threads.\r
288                 Edit saved searches with the `edit' button.\r
289    Hit RET or click on a saved search or tag name to view matching threads.\r
290 -    `=' refreshes this screen. `s' jumps to the search box. `q' to quit.\r
291 +      `=' refreshes this screen. `s' to search messages. `q' to quit.\r
292 -- \r
293 1.7.8.3\r
294 \r