Re: Emacs: Notmuch logo is not displayed when using ELPA package
[notmuch-archives.git] / ba / fe1b46b56c36b9698d420c2d82a54f5135e22f
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 5A34D431FD0\r
6         for <notmuch@notmuchmail.org>; Sat, 24 Dec 2011 20:15:44 -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 JUJTB9AWfiXu for <notmuch@notmuchmail.org>;\r
17         Sat, 24 Dec 2011 20:15:43 -0800 (PST)\r
18 Received: from mail-ww0-f41.google.com (mail-ww0-f41.google.com\r
19  [74.125.82.41])        (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
20  certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
21  0C1D8431FB6    for <notmuch@notmuchmail.org>; Sat, 24 Dec 2011 20:15:42 -0800\r
22  (PST)\r
23 Received: by wgbdt12 with SMTP id dt12so13853151wgb.2\r
24         for <notmuch@notmuchmail.org>; Sat, 24 Dec 2011 20:15:41 -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;\r
27         bh=VL7Hio/hj4qJxsagobWOhX44OFZvli/fB/OimXpjcIo=;\r
28         b=WU4t5QhWvAXI1v1Jg9D67ZDIwuPuXN6aVjR+2fjl43IWlw5Tk+Fa4Goet+/q+GYmKh\r
29         u7VRpIqNn7lIeJXQDYai8aNbZMSNj8Eh5+B9NaUKY5Zi+/bL9SEXDTGRF3eXMlyTgInF\r
30         Jl/5x/vslN8AasY222ZIhSqW8wl9wEctEvaGY=\r
31 Received: by 10.216.139.153 with SMTP id c25mr16806285wej.25.1324786541657;\r
32         Sat, 24 Dec 2011 20:15:41 -0800 (PST)\r
33 Received: from localhost ([91.144.186.21])\r
34         by mx.google.com with ESMTPS id z5sm45488534wix.5.2011.12.24.20.15.40\r
35         (version=TLSv1/SSLv3 cipher=OTHER);\r
36         Sat, 24 Dec 2011 20:15:41 -0800 (PST)\r
37 From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
38 To: notmuch@notmuchmail.org\r
39 Subject: [PATCH 1/4] emacs: unify search mechanisms\r
40 Date: Sun, 25 Dec 2011 08:14:52 +0400\r
41 Message-Id: <1324786495-14221-1-git-send-email-dmitry.kurochkin@gmail.com>\r
42 X-Mailer: git-send-email 1.7.7.3\r
43 X-BeenThere: notmuch@notmuchmail.org\r
44 X-Mailman-Version: 2.1.13\r
45 Precedence: list\r
46 List-Id: "Use and development of the notmuch mail system."\r
47         <notmuch.notmuchmail.org>\r
48 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
50 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
51 List-Post: <mailto:notmuch@notmuchmail.org>\r
52 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
53 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
55 X-List-Received-Date: Sun, 25 Dec 2011 04:15:44 -0000\r
56 \r
57 Before the change, there were two ways to do search in Emacs UI:\r
58 search widget in notmuch-hello buffer and `notmuch-search'\r
59 function bound to "s".  Internally, notmuch-hello search widget\r
60 uses `notmuch-search' function.  But it uses widget field input\r
61 instead of minibuffer.  Such duplication is a major issue for\r
62 notmuch-hello usability: search interface is inconsistent and\r
63 lacks features that are available in minibuffer (e.g. history and\r
64 auto completion).  Some of these features may be relatively easy\r
65 to implement for notmuch-hello search, others would be much more\r
66 tricky.  So to avoid duplication, make UI more consistent, bring\r
67 notmuch-hello search to feature parity with the minibuffer\r
68 search, the patch replaces notmuch-hello search widget and with a\r
69 button that works the same way as "s" key binding.\r
70 ---\r
71  emacs/notmuch-hello.el |   84 +++++++++++++++---------------------------------\r
72  emacs/notmuch-lib.el   |    9 +++++\r
73  emacs/notmuch.el       |   20 ++++++-----\r
74  3 files changed, 46 insertions(+), 67 deletions(-)\r
75 \r
76 diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
77 index 333d4c1..eb08a09 100644\r
78 --- a/emacs/notmuch-hello.el\r
79 +++ b/emacs/notmuch-hello.el\r
80 @@ -29,11 +29,8 @@\r
81  (declare-function notmuch-search "notmuch" (query &optional oldest-first target-thread target-line continuation))\r
82  (declare-function notmuch-poll "notmuch" ())\r
83  \r
84 -(defvar notmuch-hello-search-bar-marker nil\r
85 -  "The position of the search bar within the notmuch-hello buffer.")\r
86 -\r
87 -(defcustom notmuch-recent-searches-max 10\r
88 -  "The number of recent searches to store and display."\r
89 +(defcustom notmuch-hello-recent-searches-max 10\r
90 +  "The number of recent searches to display."\r
91    :type 'integer\r
92    :group 'notmuch)\r
93  \r
94 @@ -154,16 +151,6 @@ International Bureau of Weights and Measures."\r
95  (defvar notmuch-hello-url "http://notmuchmail.org"\r
96    "The `notmuch' web site.")\r
97  \r
98 -(defvar notmuch-hello-recent-searches nil)\r
99 -\r
100 -(defun notmuch-hello-remember-search (search)\r
101 -  (setq notmuch-hello-recent-searches\r
102 -       (delete search notmuch-hello-recent-searches))\r
103 -  (push search notmuch-hello-recent-searches)\r
104 -  (if (> (length notmuch-hello-recent-searches)\r
105 -        notmuch-recent-searches-max)\r
106 -      (setq notmuch-hello-recent-searches (butlast notmuch-hello-recent-searches))))\r
107 -\r
108  (defun notmuch-hello-nice-number (n)\r
109    (let (result)\r
110      (while (> n 0)\r
111 @@ -176,16 +163,10 @@ International Bureau of Weights and Measures."\r
112               (format "%s%03d" notmuch-hello-thousands-separator elem))\r
113              (cdr result)))))\r
114  \r
115 -(defun notmuch-hello-trim (search)\r
116 -  "Trim whitespace."\r
117 -  (if (string-match "^[[:space:]]*\\(.*[^[:space:]]\\)[[:space:]]*$" search)\r
118 -      (match-string 1 search)\r
119 -    search))\r
120 -\r
121 -(defun notmuch-hello-search (search)\r
122 -  (let ((search (notmuch-hello-trim search)))\r
123 -    (notmuch-hello-remember-search search)\r
124 -    (notmuch-search search notmuch-search-oldest-first nil nil #'notmuch-hello-search-continuation)))\r
125 +(defun notmuch-hello-search (&optional search)\r
126 +  (interactive)\r
127 +  (notmuch-search search notmuch-search-oldest-first nil nil\r
128 +                 #'notmuch-hello-search-continuation))\r
129  \r
130  (defun notmuch-hello-add-saved-search (widget)\r
131    (interactive)\r
132 @@ -319,11 +300,6 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
133         (widget-insert "\n"))\r
134      found-target-pos))\r
135  \r
136 -(defun notmuch-hello-goto-search ()\r
137 -  "Put point inside the `search' widget."\r
138 -  (interactive)\r
139 -  (goto-char notmuch-hello-search-bar-marker))\r
140 -\r
141  (defimage notmuch-hello-logo ((:type png :file "notmuch-logo.png")))\r
142  \r
143  (defun notmuch-hello-search-continuation()\r
144 @@ -353,7 +329,7 @@ should be. Returns a cons cell `(tags-per-line width)'."\r
145      (define-key map "G" 'notmuch-hello-poll-and-update)\r
146      (define-key map (kbd "<C-tab>") 'widget-backward)\r
147      (define-key map "m" 'notmuch-mua-new-mail)\r
148 -    (define-key map "s" 'notmuch-hello-goto-search)\r
149 +    (define-key map "s" 'notmuch-hello-search)\r
150      map)\r
151    "Keymap for \"notmuch hello\" buffers.")\r
152  (fset 'notmuch-hello-mode-map notmuch-hello-mode-map)\r
153 @@ -466,7 +442,8 @@ Complete list of currently available key bindings:\r
154        (widget-insert " messages.\n"))\r
155  \r
156      (let ((found-target-pos nil)\r
157 -         (final-target-pos nil))\r
158 +         (final-target-pos nil)\r
159 +         (default-pos))\r
160        (let* ((saved-alist\r
161               ;; Filter out empty saved searches if required.\r
162               (if notmuch-show-empty-saved-searches\r
163 @@ -497,33 +474,26 @@ Complete list of currently available key bindings:\r
164                 (setq final-target-pos found-target-pos))\r
165             (indent-rigidly start (point) notmuch-hello-indent)))\r
166  \r
167 -       (widget-insert "\nSearch: ")\r
168 -       (setq notmuch-hello-search-bar-marker (point-marker))\r
169 -       (widget-create 'editable-field\r
170 -                      ;; Leave some space at the start and end of the\r
171 -                      ;; search boxes.\r
172 -                      :size (max 8 (- (window-width) notmuch-hello-indent\r
173 -                                      (length "Search: ")))\r
174 -                      :action (lambda (widget &rest ignore)\r
175 -                                (notmuch-hello-search (widget-value widget))))\r
176 -       ;; add an invisible space to make `widget-end-of-line' ignore\r
177 -       ;; trailine spaces in the search widget field\r
178 -       (widget-insert " ")\r
179 -       (put-text-property (1- (point)) (point) 'invisible t)\r
180 +       (widget-insert "\n")\r
181 +       (setq default-pos (point-marker))\r
182 +       (widget-create 'push-button\r
183 +                      :notify (lambda (&rest ignore)\r
184 +                                (notmuch-hello-search))\r
185 +                      " Search! ")\r
186         (widget-insert "\n")\r
187  \r
188 -       (when notmuch-hello-recent-searches\r
189 +       (when notmuch-search-history\r
190           (widget-insert "\nRecent searches: ")\r
191           (widget-create 'push-button\r
192                          :notify (lambda (&rest ignore)\r
193 -                                  (setq notmuch-hello-recent-searches nil)\r
194 +                                  (setq notmuch-search-history nil)\r
195                                    (notmuch-hello-update))\r
196                          "clear")\r
197           (widget-insert "\n\n")\r
198 -         (let ((start (point))\r
199 -               (nth 0))\r
200 -           (mapc (lambda (search)\r
201 -                   (let ((widget-symbol (intern (format "notmuch-hello-search-%d" nth))))\r
202 +         (let ((start (point)))\r
203 +           (loop for i from 1 to notmuch-hello-recent-searches-max\r
204 +                 for search in notmuch-search-history do\r
205 +                   (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i))))\r
206                       (set widget-symbol\r
207                            (widget-create 'editable-field\r
208                                           ;; Don't let the search boxes be\r
209 @@ -550,9 +520,7 @@ Complete list of currently available key bindings:\r
210                                                (notmuch-hello-add-saved-search widget))\r
211                                      :notmuch-saved-search-widget widget-symbol\r
212                                      "save"))\r
213 -                   (widget-insert "\n")\r
214 -                   (setq nth (1+ nth)))\r
215 -                 notmuch-hello-recent-searches)\r
216 +                   (widget-insert "\n"))\r
217             (indent-rigidly start (point) notmuch-hello-indent)))\r
218  \r
219         (when alltags-alist\r
220 @@ -580,14 +548,14 @@ Complete list of currently available key bindings:\r
221  \r
222        (let ((start (point)))\r
223         (widget-insert "\n\n")\r
224 -       (widget-insert "Type a search query and hit RET to view matching threads.\n")\r
225 -       (when notmuch-hello-recent-searches\r
226 +       (widget-insert "Use the `search' button or hit `s' to enter search query.\n")\r
227 +       (when notmuch-search-history\r
228           (widget-insert "Hit RET to re-submit a previous search. Edit it first if you like.\n")\r
229           (widget-insert "Save recent searches with the `save' button.\n"))\r
230         (when notmuch-saved-searches\r
231           (widget-insert "Edit saved searches with the `edit' button.\n"))\r
232         (widget-insert "Hit RET or click on a saved search or tag name to view matching threads.\n")\r
233 -       (widget-insert "`=' refreshes this screen. `s' jumps to the search box. `q' to quit.\n")\r
234 +       (widget-insert "`=' refreshes this screen. `s' to search messages. `q' to quit.\n")\r
235         (let ((fill-column (- (window-width) notmuch-hello-indent)))\r
236           (center-region start (point))))\r
237  \r
238 @@ -599,7 +567,7 @@ Complete list of currently available key bindings:\r
239           (widget-forward 1)))\r
240  \r
241        (unless (widget-at)\r
242 -       (notmuch-hello-goto-search))))\r
243 +       (goto-char default-pos))))\r
244  \r
245    (run-hooks 'notmuch-hello-refresh-hook))\r
246  \r
247 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
248 index 0f856bf..a2cb6f2 100644\r
249 --- a/emacs/notmuch-lib.el\r
250 +++ b/emacs/notmuch-lib.el\r
251 @@ -35,6 +35,9 @@\r
252  \r
253  ;;\r
254  \r
255 +(defvar notmuch-search-history nil\r
256 +  "Variable to store minibuffer history for notmuch searches.")\r
257 +\r
258  (defcustom notmuch-saved-searches nil\r
259    "A list of saved searches to display."\r
260    :type '(alist :key-type string :value-type string)\r
261 @@ -114,6 +117,12 @@ the user hasn't set this variable with the old or new value."\r
262        (setq list (cdr list)))\r
263      (nreverse out)))\r
264  \r
265 +(defun notmuch-trim (search)\r
266 +  "Trim whitespaces."\r
267 +  (if (string-match "^[[:space:]]*\\(.*[^[:space:]]\\)[[:space:]]*$" search)\r
268 +      (match-string 1 search)\r
269 +    search))\r
270 +\r
271  ; This lets us avoid compiling these replacement functions when emacs\r
272  ; is sufficiently new enough to supply them alone. We do the macro\r
273  ; treatment rather than just wrapping our defun calls in a when form\r
274 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
275 index fde2377..938a149 100644\r
276 --- a/emacs/notmuch.el\r
277 +++ b/emacs/notmuch.el\r
278 @@ -72,9 +72,6 @@ For example:\r
279    :type '(alist :key-type (string) :value-type (string))\r
280    :group 'notmuch)\r
281  \r
282 -(defvar notmuch-query-history nil\r
283 -  "Variable to store minibuffer history for notmuch queries")\r
284 -\r
285  (defun notmuch-select-tag-with-completion (prompt &rest search-terms)\r
286    (let ((tag-list\r
287          (with-output-to-string\r
288 @@ -902,21 +899,26 @@ PROMPT is the string to prompt with."\r
289                (t (list string)))))))\r
290        ;; this was simpler than convincing completing-read to accept spaces:\r
291        (define-key keymap (kbd "<tab>") 'minibuffer-complete)\r
292 -      (read-from-minibuffer prompt nil keymap nil\r
293 -                           'notmuch-query-history nil nil))))\r
294 +      (let ((history-delete-duplicates t))\r
295 +       (read-from-minibuffer prompt nil keymap nil\r
296 +                             'notmuch-search-history nil nil)))))\r
297  \r
298  ;;;###autoload\r
299 -(defun notmuch-search (query &optional oldest-first target-thread target-line continuation)\r
300 -  "Run \"notmuch search\" with the given query string and display results.\r
301 +(defun notmuch-search (&optional query oldest-first target-thread target-line continuation)\r
302 +  "Run \"notmuch search\" with the given `query' and display results.\r
303  \r
304 -The optional parameters are used as follows:\r
305 +If `query' is nil, it is read interactively from the minibuffer.\r
306 +Other optional parameters are used as follows:\r
307  \r
308    oldest-first: A Boolean controlling the sort order of returned threads\r
309    target-thread: A thread ID (with the thread: prefix) that will be made\r
310                   current if it appears in the search results.\r
311    target-line: The line number to move to if the target thread does not\r
312                 appear in the search results."\r
313 -  (interactive (list (notmuch-read-query "Notmuch search: ")))\r
314 +  (interactive)\r
315 +  (if (null query)\r
316 +      (setq query (notmuch-read-query "Notmuch search: ")))\r
317 +  (setq query (notmuch-trim query))\r
318    (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))\r
319      (switch-to-buffer buffer)\r
320      (notmuch-search-mode)\r
321 -- \r
322 1.7.7.3\r
323 \r