1 Return-Path: <m.walters@qmul.ac.uk>
\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 980BE431FBD
\r
6 for <notmuch@notmuchmail.org>; Tue, 15 Jul 2014 00:03:27 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0.502 tagged_above=-999 required=5
\r
12 tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,
\r
13 NML_ADSP_CUSTOM_MED=1.2, 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 vVwmGS1Nycrv for <notmuch@notmuchmail.org>;
\r
17 Tue, 15 Jul 2014 00:03:19 -0700 (PDT)
\r
18 Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])
\r
19 (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id C3C36431FBC
\r
22 for <notmuch@notmuchmail.org>; Tue, 15 Jul 2014 00:03:18 -0700 (PDT)
\r
23 Received: from smtp.qmul.ac.uk ([138.37.6.40])
\r
24 by mail2.qmul.ac.uk with esmtp (Exim 4.71)
\r
25 (envelope-from <m.walters@qmul.ac.uk>)
\r
26 id 1X6wlE-0002Z1-Gh; Tue, 15 Jul 2014 08:03:13 +0100
\r
27 Received: from [194.42.225.51] (helo=localhost)
\r
28 by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)
\r
29 (envelope-from <m.walters@qmul.ac.uk>)
\r
30 id 1X6wlE-0003gN-1L; Tue, 15 Jul 2014 08:02:48 +0100
\r
31 From: Mark Walters <markwalters1009@gmail.com>
\r
32 To: Austin Clements <amdragon@MIT.EDU>
\r
33 Subject: Re: [PATCH 1/2] emacs: Introduce notmuch-jump: shortcut keys to saved
\r
35 In-Reply-To: <20140715034645.GE4660@mit.edu>
\r
36 References: <1405353735-26244-1-git-send-email-amdragon@mit.edu>
\r
37 <1405353735-26244-2-git-send-email-amdragon@mit.edu>
\r
38 <87egxnd4aq.fsf@qmul.ac.uk> <20140715034645.GE4660@mit.edu>
\r
39 User-Agent: Notmuch/0.15.2+615~g78e3a93 (http://notmuchmail.org) Emacs/23.4.1
\r
40 (x86_64-pc-linux-gnu)
\r
41 Date: Tue, 15 Jul 2014 08:02:28 +0100
\r
42 Message-ID: <8738e3xfy3.fsf@qmul.ac.uk>
\r
44 Content-Type: text/plain; charset=utf-8
\r
45 Content-Transfer-Encoding: quoted-printable
\r
46 X-Sender-Host-Address: 194.42.225.51
\r
47 X-QM-Geographic: According to ripencc,
\r
48 this message was delivered by a machine in Britain (UK) (GB).
\r
49 X-QM-SPAM-Info: Sender has good ham record. :)
\r
50 X-QM-Body-MD5: e85281fccc416b0614b5a4f6626b5d86 (of first 20000 bytes)
\r
51 X-SpamAssassin-Score: 0.0
\r
52 X-SpamAssassin-SpamBar: /
\r
53 X-SpamAssassin-Report: The QM spam filters have analysed this message to
\r
55 spam. We require at least 5.0 points to mark a message as spam.
\r
56 This message scored 0.0 points. Summary of the scoring:
\r
57 * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail
\r
58 provider * (markwalters1009[at]gmail.com)
\r
59 * -0.0 AWL AWL: From: address is in the auto white-list
\r
60 X-QM-Scan-Virus: ClamAV says the message is clean
\r
61 Cc: notmuch@notmuchmail.org
\r
62 X-BeenThere: notmuch@notmuchmail.org
\r
63 X-Mailman-Version: 2.1.13
\r
65 List-Id: "Use and development of the notmuch mail system."
\r
66 <notmuch.notmuchmail.org>
\r
67 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
68 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
69 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
70 List-Post: <mailto:notmuch@notmuchmail.org>
\r
71 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
72 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
73 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
74 X-List-Received-Date: Tue, 15 Jul 2014 07:03:27 -0000
\r
76 On Tue, 15 Jul 2014, Austin Clements <amdragon@MIT.EDU> wrote:
\r
77 > Quoth Mark Walters on Jul 14 at 10:22 pm:
\r
79 >> On Mon, 14 Jul 2014, Austin Clements <amdragon@MIT.EDU> wrote:
\r
80 >> > This introduces notmuch-jump, which is like a user-friendly,
\r
81 >> > user-configurable global prefix map for saved searches. This provides
\r
82 >> > a non-modal and much faster way to access saved searches than
\r
85 >> > A user configures shortcut keys in notmuch-saved-searches, which are
\r
86 >> > immediately accessible from anywhere in Notmuch under the "j" key (for
\r
87 >> > "jump"). When the user hits "j", the minibuffer immediately shows a
\r
88 >> > helpful table of bindings reminiscent of a completions buffer.
\r
90 >> I am basically happy with this: the only downside compared to dme's
\r
91 >> patch is that this is quite substantially bigger. However, since this is
\r
92 >> all in it's own file that is not really a problem.
\r
94 >> I have a few comments below. In all cases I am happy to go with the
\r
95 >> current code if you think it's better than my suggestion.
\r
97 >> > This code is a combination of work from myself (originally,
\r
98 >> > "notmuch-go"), David Edmondson, and modifications from Mark Walters.
\r
100 >> > emacs/Makefile.local | 3 +-
\r
101 >> > emacs/notmuch-hello.el | 2 +
\r
102 >> > emacs/notmuch-jump.el | 189 ++++++++++++++++++++++++++++++++++++++++=
\r
104 >> > emacs/notmuch-lib.el | 3 +
\r
105 >> > 4 files changed, 196 insertions(+), 1 deletion(-)
\r
106 >> > create mode 100644 emacs/notmuch-jump.el
\r
108 >> > diff --git a/emacs/Makefile.local b/emacs/Makefile.local
\r
109 >> > index c0d6b19..1109cfa 100644
\r
110 >> > --- a/emacs/Makefile.local
\r
111 >> > +++ b/emacs/Makefile.local
\r
112 >> > @@ -18,7 +18,8 @@ emacs_sources :=3D \
\r
113 >> > $(dir)/notmuch-tag.el \
\r
114 >> > $(dir)/coolj.el \
\r
115 >> > $(dir)/notmuch-print.el \
\r
116 >> > - $(dir)/notmuch-version.el
\r
117 >> > + $(dir)/notmuch-version.el \
\r
118 >> > + $(dir)/notmuch-jump.el \
\r
120 >> > $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
\r
121 >> > $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl
\r
122 >> > diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
\r
123 >> > index 3de5238..061b27d 100644
\r
124 >> > --- a/emacs/notmuch-hello.el
\r
125 >> > +++ b/emacs/notmuch-hello.el
\r
126 >> > @@ -85,6 +85,7 @@ (define-widget 'notmuch-saved-search-plist 'list
\r
127 >> > (group :format "%v" :inline t (const :format " Query: " :query) (s=
\r
128 tring :format "%v")))
\r
129 >> > (checklist :inline t
\r
131 >> > + (group :format "%v" :inline t (const :format "Shortcut key: " =
\r
132 :key) (key-sequence :format "%v"))
\r
133 >> > (group :format "%v" :inline t (const :format "Count-Query: " :=
\r
134 count-query) (string :format "%v"))
\r
135 >> > (group :format "%v" :inline t (const :format "" :sort-order)
\r
136 >> > (choice :tag " Sort Order"
\r
137 >> > @@ -101,6 +102,7 @@ (defcustom notmuch-saved-searches '((:name "inbox"=
\r
138 :query "tag:inbox")
\r
140 >> > :name Name of the search (required).
\r
141 >> > :query Search to run (required).
\r
142 >> > + :key Optional shortcut key for `notmuch-jump-search'.
\r
143 >> > :count-query Optional extra query to generate the count
\r
144 >> > shown. If not present then the :query property
\r
146 >> > diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
\r
147 >> > new file mode 100644
\r
148 >> > index 0000000..cb1ae10
\r
150 >> > +++ b/emacs/notmuch-jump.el
\r
151 >> > @@ -0,0 +1,189 @@
\r
152 >> > +;; notmuch-jump.el --- User-friendly shortcut keys
\r
154 >> > +;; Copyright =C2=A9 Austin Clements
\r
156 >> > +;; This file is part of Notmuch.
\r
158 >> > +;; Notmuch is free software: you can redistribute it and/or modify it
\r
159 >> > +;; under the terms of the GNU General Public License as published by
\r
160 >> > +;; the Free Software Foundation, either version 3 of the License, or
\r
161 >> > +;; (at your option) any later version.
\r
163 >> > +;; Notmuch is distributed in the hope that it will be useful, but
\r
164 >> > +;; WITHOUT ANY WARRANTY; without even the implied warranty of
\r
165 >> > +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
166 >> > +;; General Public License for more details.
\r
168 >> > +;; You should have received a copy of the GNU General Public License
\r
169 >> > +;; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.
\r
171 >> > +;; Authors: Austin Clements <aclements@csail.mit.edu>
\r
172 >> > +;; David Edmondson <dme@dme.org>
\r
174 >> > +(eval-when-compile (require 'cl))
\r
176 >> > +(require 'notmuch-hello)
\r
178 >> > +;;;###autoload
\r
179 >> > +(defun notmuch-jump-search ()
\r
180 >> > + "Jump to a saved search by shortcut key.
\r
182 >> > +This prompts for and performs a saved search using the shortcut
\r
183 >> > +keys configured in the :key property of `notmuch-saved-searches'.
\r
184 >> > +Typically these shortcuts are a single key long, so this is a
\r
185 >> > +fast way to jump to a saved search from anywhere in Notmuch."
\r
186 >> > + (interactive)
\r
188 >> > + ;; Build the action map
\r
189 >> > + (let (action-map)
\r
190 >> > + (dolist (saved-search notmuch-saved-searches)
\r
191 >> > + (let* ((saved-search (notmuch-hello-saved-search-to-plist saved=
\r
193 >> > + (key (plist-get saved-search :key)))
\r
195 >> > + (let ((name (plist-get saved-search :name))
\r
196 >> > + (query (plist-get saved-search :query))
\r
197 >> > + (oldest-first
\r
198 >> > + (case (plist-get saved-search :sort-order)
\r
200 >> I would probably not do the saved-search-to-plist bit and just use
\r
201 >> notmuch-saved-search-get each time.
\r
203 > What's the downside of notmuch-hello-saved-search-to-plist? Using
\r
204 > notmuch-saved-search-get everywhere is more verbose.
\r
206 The only downside is that I sort of intended
\r
207 notmuch-hello-saved-search-to-list to be a private function (I am not
\r
208 sure why I gave notmuch-hello--saved-searches-to-plist the double dash
\r
209 bit not this). But I am definitely happy with it as is: I wasn't sure
\r
210 whether to make any comment when first reviewing.
\r
212 >> > + (newest-first nil)
\r
213 >> > + (oldest-first t)
\r
214 >> > + (otherwise (default-value notmuch-search-oldest-first)))))
\r
215 >> > + (push (list key name
\r
216 >> > + `(lambda () (notmuch-search ',query ',oldest-first)))
\r
217 >> > + action-map)))))
\r
218 >> > + (setq action-map (nreverse action-map))
\r
220 >> > + (if action-map
\r
221 >> > + (notmuch-jump action-map "Search ")
\r
222 >> > + (error "No shortcut keys for saved searches. Please customize =
\r
223 notmuch-saved-searches."))))
\r
225 >> I would slightly rephrase the error: something more like "... To use
\r
226 >> notmuch-jump please customize notmuch-saved-searches." So that the user
\r
227 >> who doesn't want to use notmuch-jump doesn't think they are at fault.
\r
231 >> > +(defvar notmuch-jump--action nil)
\r
233 >> > +(defun notmuch-jump (action-map prompt)
\r
234 >> > + "Interactively prompt for one of the keys in ACTION-MAP.
\r
236 >> > +Displays a pop-up temporary buffer with a summary of all bindings
\r
237 >> > +in ACTION-MAP, reads a key from the minibuffer, and performs the
\r
238 >> > +corresponding action. The prompt can be canceled with C-g.
\r
240 >> Maybe say the prompt can be canceled with RET too?
\r
242 > Done. I also fixed the docstring's mention of a pop-up temporary
\r
243 > buffer, since that's not how the code works any more.
\r
245 >> > +PROMPT must be a string to use for the prompt if this command was
\r
246 >> > +not invoked directly by a key binding (e.g., it was invoked
\r
247 >> > +through M-x). PROMPT should include a space at the end.
\r
249 >> I find the "j-" prompt a bit weird and would prefer something more like
\r
250 >> "Jump to search: " to be used however the user enters the function.
\r
252 > The intent was to make it act like a prefix keymap. For example, if
\r
253 > you hit "C-x", Emacs will show "C-x-" in the minibuffer until you hit
\r
254 > the next key. OTOH, Emacs isn't exactly a paragon of usability, so
\r
255 > you're probably right and this should just use the provided prompt
\r
256 > string regardless.
\r
258 >> > +ACTION-MAP must be a list of triples of the form
\r
259 >> > + (KEY LABEL ACTION)
\r
260 >> > +where KEY is a key binding, LABEL is a string label to display in
\r
261 >> > +the buffer, and ACTION is a nullary function to call. LABEL may
\r
262 >> > +be null, in which case the action will still be bound, but will
\r
263 >> > +not appear in the pop-up buffer.
\r
266 >> > + (let* ((items (notmuch-jump--format-actions action-map))
\r
267 >> > + ;; Format the table of bindings and the full prompt
\r
269 >> > + (with-temp-buffer
\r
270 >> > + (notmuch-jump--insert-items (window-body-width) items)
\r
271 >> > + (buffer-string)))
\r
272 >> > + (prompt-text
\r
273 >> > + (if (eq this-original-command this-command)
\r
274 >> > + ;; Make it look like we're just part of any regular
\r
275 >> > + ;; submap prompt (like C-x, C-c, etc.)
\r
276 >> > + (concat (format-kbd-macro (this-command-keys)) "-")
\r
277 >> > + ;; We were invoked through something like M-x
\r
279 >> > + (full-prompt
\r
280 >> > + (concat table "\n\n"
\r
281 >> > + (propertize prompt-text 'face 'minibuffer-prompt)))
\r
282 >> > + ;; By default, the minibuffer applies the minibuffer face to
\r
283 >> > + ;; the entire prompt. However, we want to clearly
\r
284 >> > + ;; distinguish bindings (which we put in the prompt face
\r
285 >> > + ;; ourselves) from their labels, so disable the minibuffer's
\r
286 >> > + ;; own re-face-ing.
\r
287 >> > + (minibuffer-prompt-properties
\r
288 >> > + (notmuch-jump--plist-delete
\r
289 >> > + (copy-sequence minibuffer-prompt-properties)
\r
291 >> > + ;; Build the keymap with our bindings
\r
292 >> > + (minibuffer-map (notmuch-jump--make-keymap action-map))
\r
293 >> > + ;; The bindings save the the action in notmuch-jump--action
\r
294 >> > + (notmuch-jump--action nil))
\r
295 >> > + ;; Read the action
\r
296 >> > + (read-from-minibuffer full-prompt nil minibuffer-map)
\r
298 >> > + ;; If we got an action, do it
\r
299 >> > + (when notmuch-jump--action
\r
300 >> > + (funcall notmuch-jump--action))))
\r
302 >> > +(defun notmuch-jump--format-actions (action-map)
\r
303 >> > + "Format the actions in ACTION-MAP.
\r
305 >> > +Returns a list of strings, one for each item with a label in
\r
306 >> > +ACTION-MAP. These strings can be inserted into a tabular
\r
309 >> > + ;; Compute the maximum key description width
\r
310 >> > + (let ((key-width 1))
\r
311 >> > + (dolist (action action-map)
\r
313 >> The name "action" is slightly unfortunate when you use ACTION as the
\r
314 >> third item of each element of action-map when describing it
\r
315 >> above. However, no better name springs to mind. (Maybe "triple"?)
\r
317 > Good catch. Changed to "entry" (for an entry in the action map).
\r
319 >> > + (setq key-width
\r
320 >> > + (max key-width
\r
321 >> > + (string-width (format-kbd-macro (first action))))))
\r
322 >> > + ;; Format each action
\r
323 >> > + (mapcar (lambda (action)
\r
324 >> > + (let ((key (format-kbd-macro (first action)))
\r
325 >> > + (desc (second action)))
\r
327 >> > + (propertize key 'face 'minibuffer-prompt)
\r
328 >> > + (make-string (- key-width (length key)) ? )
\r
330 >> > + action-map)))
\r
332 >> > +(defun notmuch-jump--insert-items (width items)
\r
333 >> > + "Make a table of ITEMS up to WIDTH wide in the current buffer."
\r
334 >> > + (let* ((nitems (length items))
\r
335 >> > + (col-width (+ 3 (apply #'max (mapcar #'string-width items))))
\r
336 >> > + (ncols (if (> (* col-width nitems) width)
\r
337 >> > + (max 1 (/ width col-width))
\r
338 >> > + ;; Items fit on one line. Space them out
\r
339 >> > + (setq col-width (/ width nitems))
\r
340 >> > + (length items))))
\r
341 >> > + (while items
\r
342 >> > + (dotimes (col ncols)
\r
344 >> > + (let ((item (pop items)))
\r
345 >> > + (insert item)
\r
346 >> > + (when (and items (< col (- ncols 1)))
\r
347 >> > + (insert (make-string (- col-width (string-width item)) ? ))))))
\r
349 >> > + (insert "\n")))))
\r
351 >> > +(defvar notmuch-jump-minibuffer-map
\r
352 >> > + (let ((map (make-sparse-keymap)))
\r
353 >> > + (set-keymap-parent map minibuffer-local-map)
\r
354 >> > + ;; Make this like a special-mode keymap, with no self-insert-comm=
\r
356 >> > + (suppress-keymap map)
\r
358 >> > + "Base keymap for notmuch-jump's minibuffer keymap.")
\r
360 >> > +(defun notmuch-jump--make-keymap (action-map)
\r
361 >> > + "Translate ACTION-MAP into a minibuffer keymap."
\r
362 >> > + (let ((map (make-sparse-keymap)))
\r
363 >> > + (set-keymap-parent map notmuch-jump-minibuffer-map)
\r
364 >> > + (dolist (action action-map)
\r
365 >> > + (define-key map (first action)
\r
366 >> > + `(lambda () (interactive)
\r
367 >> > + (setq notmuch-jump--action ',(third action))
\r
368 >> > + (exit-minibuffer))))
\r
371 >> > +(defun notmuch-jump--plist-delete (plist property)
\r
372 >> > + (let* ((xplist (cons nil plist))
\r
373 >> > + (pred xplist))
\r
374 >> > + (while (cdr pred)
\r
375 >> > + (when (eq (cadr pred) property)
\r
376 >> > + (setcdr pred (cdddr pred)))
\r
377 >> > + (setq pred (cddr pred)))
\r
378 >> > + (cdr xplist)))
\r
380 >> > +(unless (fboundp 'window-body-width)
\r
381 >> > + ;; Compatibility for Emacs pre-24
\r
382 >> > + (defun window-body-width (&optional window)
\r
383 >> > + (let ((edges (window-inside-edges window)))
\r
384 >> > + (- (caddr edges) (car edges)))))
\r
385 >> > diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
\r
386 >> > index 2941da3..135422d 100644
\r
387 >> > --- a/emacs/notmuch-lib.el
\r
388 >> > +++ b/emacs/notmuch-lib.el
\r
389 >> > @@ -130,9 +130,12 @@ (defvar notmuch-common-keymap
\r
390 >> > (define-key map "m" 'notmuch-mua-new-mail)
\r
391 >> > (define-key map "=3D" 'notmuch-refresh-this-buffer)
\r
392 >> > (define-key map "G" 'notmuch-poll-and-refresh-this-buffer)
\r
393 >> > + (define-key map "j" 'notmuch-jump-search)
\r
395 >> > "Keymap shared by all notmuch modes.")
\r
397 >> > +(autoload 'notmuch-jump-search "notmuch-jump" "Jump to a saved search=
\r
398 by shortcut key." t)
\r
400 >> We don't normally seem to use autoload but instead use
\r
401 >> declare-function. It might be worth being consistent (I am not very sure
\r
402 >> of the pros and cons of autoload). May also be worth having it with the
\r
403 >> other declare-functions to keep it clear how things are loaded.
\r
405 > I used autoload because it won't bother even reading
\r
406 > notmuch-jump.el(c) until the user hits "j" for the first time (and,
\r
407 > hence, won't load it at all if they don't use jump). This is easy
\r
408 > with notmuch-jump because it's self-contained and has a single clear
\r
409 > entry-point and no customizable variables.
\r
411 > declare-function, on the other hand, still requires you to load the
\r
412 > source containing the function (either eagerly, which is what notmuch
\r
413 > usually does, or with an autoload).
\r
415 > I think we should do *more* autoloading, though maybe it's not
\r
416 > practical for the bulk of notmuch-emacs.
\r
418 > I'm happy to move the autoload call to somewhere else, though
\r
419 > notmuch-lib doesn't actually have any declare-functions (since it's
\r
420 > sort of a root of the dependency tree). I could put it right below
\r
421 > the requires, since that's where we usually put declare-functions.
\r
423 I think having the autoload at the top sounds good. With the changes
\r
424 you suggest it gets my +1.
\r
438 >> > ;; By default clicking on a button does not select the window
\r
439 >> > ;; containing the button (as opposed to clicking on a widget which
\r
440 >> > ;; does). This means that the button action is then executed in the
\r