1 Return-Path: <amdragon@mit.edu>
\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 2062C431FC4
\r
6 for <notmuch@notmuchmail.org>; Mon, 14 Jul 2014 20:46:59 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 Bk-mPmHeZqu4 for <notmuch@notmuchmail.org>;
\r
16 Mon, 14 Jul 2014 20:46:50 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (dmz-mailsec-scanner-2.mit.edu
\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 34598431FBC
\r
22 for <notmuch@notmuchmail.org>; Mon, 14 Jul 2014 20:46:50 -0700 (PDT)
\r
23 X-AuditID: 1209190d-f79c06d000002f07-43-53c4a429729b
\r
24 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])
\r
25 (using TLS with cipher AES256-SHA (256/256 bits))
\r
26 (Client did not present a certificate)
\r
27 by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP
\r
28 id 13.B9.12039.924A4C35; Mon, 14 Jul 2014 23:46:49 -0400 (EDT)
\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])
\r
30 by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s6F3klvJ004257;
\r
31 Mon, 14 Jul 2014 23:46:48 -0400
\r
32 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])
\r
33 (authenticated bits=0)
\r
34 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
35 by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s6F3kjEY026768
\r
36 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT);
\r
37 Mon, 14 Jul 2014 23:46:46 -0400
\r
38 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.80)
\r
39 (envelope-from <amdragon@mit.edu>)
\r
40 id 1X6thV-0005Vg-4p; Mon, 14 Jul 2014 23:46:45 -0400
\r
41 Date: Mon, 14 Jul 2014 23:46:45 -0400
\r
42 From: Austin Clements <amdragon@MIT.EDU>
\r
43 To: Mark Walters <markwalters1009@gmail.com>
\r
44 Subject: Re: [PATCH 1/2] emacs: Introduce notmuch-jump: shortcut keys to
\r
46 Message-ID: <20140715034645.GE4660@mit.edu>
\r
47 References: <1405353735-26244-1-git-send-email-amdragon@mit.edu>
\r
48 <1405353735-26244-2-git-send-email-amdragon@mit.edu>
\r
49 <87egxnd4aq.fsf@qmul.ac.uk>
\r
51 Content-Type: text/plain; charset=iso-8859-1
\r
52 Content-Disposition: inline
\r
53 Content-Transfer-Encoding: 8bit
\r
54 In-Reply-To: <87egxnd4aq.fsf@qmul.ac.uk>
\r
55 User-Agent: Mutt/1.5.21 (2010-09-15)
\r
56 X-Brightmail-Tracker:
\r
57 H4sIAAAAAAAAA+NgFtrFKsWRmVeSWpSXmKPExsUixCmqrau55EiwwctfChY3WrsZLfbd2cJk
\r
58 sXouj8X1mzOZHVg8dj3/y+Sxc9Zddo9nq24xe2w59J45gCWKyyYlNSezLLVI3y6BK+PV7aCC
\r
59 5qKK1w0LmRsYV0V0MXJySAiYSBw/1MUMYYtJXLi3nq2LkYtDSGA2k8T+f5fYQBJCAhsZJX7/
\r
60 4YRInGaSOPRkPyOEs4RR4mDPBLB2FgFVifvbnzCC2GwCGhLb9i8Hs0UEdCRuH1rADmIzC1hL
\r
61 vFv1DywuLBAp8fn1VVYQm1dAW2L3rrlQq6cySpz8u5YNIiEocXLmExaIZh2JnVvvAMU5gGxp
\r
62 ieX/OCDC8hLNW2eD3cAJtPdN41Ow+aICKhJTTm5jm8AoPAvJpFlIJs1CmDQLyaQFjCyrGGVT
\r
63 cqt0cxMzc4pTk3WLkxPz8lKLdI30cjNL9FJTSjcxgqNFkncH47uDSocYBTgYlXh4T3w6HCzE
\r
64 mlhWXJl7iFGSg0lJlLdg6pFgIb6k/JTKjMTijPii0pzU4kOMEhzMSiK8HouBcrwpiZVVqUX5
\r
65 MClpDhYlcd631lbBQgLpiSWp2ampBalFMFkZDg4lCV5VkEbBotT01Iq0zJwShDQTByfIcB6g
\r
66 4dPBhhcXJOYWZ6ZD5E8x6nJ0XT/WxiTEkpeflyolzvt1EVCRAEhRRmke3BxYknvFKA70ljBv
\r
67 BMgoHmCChJv0CmgJE9CS8prDIEtKEhFSUg2MZeeObpp8bFf/7FuuD0+LbI2xubnLjWcfU3f7
\r
68 lY/7Hk5ddKx0/7/vMY/8a6JeLBTr4FxvJWB8P5XHT0lrwuzvjIE10SyK0fw/3E0n1Wd/Xv7T
\r
69 +32ETELVvQZ3jmzuVcdrLu6dFLXyz9Xl1k/ymblrFkhIOrg9VPi999r1Z34zhB7LrPJ7zBUv
\r
70 qsRSnJFoqMVcVJwIADugN4dNAwAA
\r
71 Cc: notmuch@notmuchmail.org
\r
72 X-BeenThere: notmuch@notmuchmail.org
\r
73 X-Mailman-Version: 2.1.13
\r
75 List-Id: "Use and development of the notmuch mail system."
\r
76 <notmuch.notmuchmail.org>
\r
77 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
78 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
79 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
80 List-Post: <mailto:notmuch@notmuchmail.org>
\r
81 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
82 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
83 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
84 X-List-Received-Date: Tue, 15 Jul 2014 03:46:59 -0000
\r
86 Quoth Mark Walters on Jul 14 at 10:22 pm:
\r
88 > On Mon, 14 Jul 2014, Austin Clements <amdragon@MIT.EDU> wrote:
\r
89 > > This introduces notmuch-jump, which is like a user-friendly,
\r
90 > > user-configurable global prefix map for saved searches. This provides
\r
91 > > a non-modal and much faster way to access saved searches than
\r
94 > > A user configures shortcut keys in notmuch-saved-searches, which are
\r
95 > > immediately accessible from anywhere in Notmuch under the "j" key (for
\r
96 > > "jump"). When the user hits "j", the minibuffer immediately shows a
\r
97 > > helpful table of bindings reminiscent of a completions buffer.
\r
99 > I am basically happy with this: the only downside compared to dme's
\r
100 > patch is that this is quite substantially bigger. However, since this is
\r
101 > all in it's own file that is not really a problem.
\r
103 > I have a few comments below. In all cases I am happy to go with the
\r
104 > current code if you think it's better than my suggestion.
\r
106 > > This code is a combination of work from myself (originally,
\r
107 > > "notmuch-go"), David Edmondson, and modifications from Mark Walters.
\r
109 > > emacs/Makefile.local | 3 +-
\r
110 > > emacs/notmuch-hello.el | 2 +
\r
111 > > emacs/notmuch-jump.el | 189 +++++++++++++++++++++++++++++++++++++++++++++++++
\r
112 > > emacs/notmuch-lib.el | 3 +
\r
113 > > 4 files changed, 196 insertions(+), 1 deletion(-)
\r
114 > > create mode 100644 emacs/notmuch-jump.el
\r
116 > > diff --git a/emacs/Makefile.local b/emacs/Makefile.local
\r
117 > > index c0d6b19..1109cfa 100644
\r
118 > > --- a/emacs/Makefile.local
\r
119 > > +++ b/emacs/Makefile.local
\r
120 > > @@ -18,7 +18,8 @@ emacs_sources := \
\r
121 > > $(dir)/notmuch-tag.el \
\r
122 > > $(dir)/coolj.el \
\r
123 > > $(dir)/notmuch-print.el \
\r
124 > > - $(dir)/notmuch-version.el
\r
125 > > + $(dir)/notmuch-version.el \
\r
126 > > + $(dir)/notmuch-jump.el \
\r
128 > > $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp
\r
129 > > $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl
\r
130 > > diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
\r
131 > > index 3de5238..061b27d 100644
\r
132 > > --- a/emacs/notmuch-hello.el
\r
133 > > +++ b/emacs/notmuch-hello.el
\r
134 > > @@ -85,6 +85,7 @@ (define-widget 'notmuch-saved-search-plist 'list
\r
135 > > (group :format "%v" :inline t (const :format " Query: " :query) (string :format "%v")))
\r
136 > > (checklist :inline t
\r
138 > > + (group :format "%v" :inline t (const :format "Shortcut key: " :key) (key-sequence :format "%v"))
\r
139 > > (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))
\r
140 > > (group :format "%v" :inline t (const :format "" :sort-order)
\r
141 > > (choice :tag " Sort Order"
\r
142 > > @@ -101,6 +102,7 @@ (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")
\r
144 > > :name Name of the search (required).
\r
145 > > :query Search to run (required).
\r
146 > > + :key Optional shortcut key for `notmuch-jump-search'.
\r
147 > > :count-query Optional extra query to generate the count
\r
148 > > shown. If not present then the :query property
\r
150 > > diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
\r
151 > > new file mode 100644
\r
152 > > index 0000000..cb1ae10
\r
154 > > +++ b/emacs/notmuch-jump.el
\r
155 > > @@ -0,0 +1,189 @@
\r
156 > > +;; notmuch-jump.el --- User-friendly shortcut keys
\r
158 > > +;; Copyright © Austin Clements
\r
160 > > +;; This file is part of Notmuch.
\r
162 > > +;; Notmuch is free software: you can redistribute it and/or modify it
\r
163 > > +;; under the terms of the GNU General Public License as published by
\r
164 > > +;; the Free Software Foundation, either version 3 of the License, or
\r
165 > > +;; (at your option) any later version.
\r
167 > > +;; Notmuch is distributed in the hope that it will be useful, but
\r
168 > > +;; WITHOUT ANY WARRANTY; without even the implied warranty of
\r
169 > > +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
170 > > +;; General Public License for more details.
\r
172 > > +;; You should have received a copy of the GNU General Public License
\r
173 > > +;; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.
\r
175 > > +;; Authors: Austin Clements <aclements@csail.mit.edu>
\r
176 > > +;; David Edmondson <dme@dme.org>
\r
178 > > +(eval-when-compile (require 'cl))
\r
180 > > +(require 'notmuch-hello)
\r
182 > > +;;;###autoload
\r
183 > > +(defun notmuch-jump-search ()
\r
184 > > + "Jump to a saved search by shortcut key.
\r
186 > > +This prompts for and performs a saved search using the shortcut
\r
187 > > +keys configured in the :key property of `notmuch-saved-searches'.
\r
188 > > +Typically these shortcuts are a single key long, so this is a
\r
189 > > +fast way to jump to a saved search from anywhere in Notmuch."
\r
190 > > + (interactive)
\r
192 > > + ;; Build the action map
\r
193 > > + (let (action-map)
\r
194 > > + (dolist (saved-search notmuch-saved-searches)
\r
195 > > + (let* ((saved-search (notmuch-hello-saved-search-to-plist saved-search))
\r
196 > > + (key (plist-get saved-search :key)))
\r
198 > > + (let ((name (plist-get saved-search :name))
\r
199 > > + (query (plist-get saved-search :query))
\r
200 > > + (oldest-first
\r
201 > > + (case (plist-get saved-search :sort-order)
\r
203 > I would probably not do the saved-search-to-plist bit and just use
\r
204 > notmuch-saved-search-get each time.
\r
206 What's the downside of notmuch-hello-saved-search-to-plist? Using
\r
207 notmuch-saved-search-get everywhere is more verbose.
\r
209 > > + (newest-first nil)
\r
210 > > + (oldest-first t)
\r
211 > > + (otherwise (default-value notmuch-search-oldest-first)))))
\r
212 > > + (push (list key name
\r
213 > > + `(lambda () (notmuch-search ',query ',oldest-first)))
\r
214 > > + action-map)))))
\r
215 > > + (setq action-map (nreverse action-map))
\r
217 > > + (if action-map
\r
218 > > + (notmuch-jump action-map "Search ")
\r
219 > > + (error "No shortcut keys for saved searches. Please customize notmuch-saved-searches."))))
\r
221 > I would slightly rephrase the error: something more like "... To use
\r
222 > notmuch-jump please customize notmuch-saved-searches." So that the user
\r
223 > who doesn't want to use notmuch-jump doesn't think they are at fault.
\r
227 > > +(defvar notmuch-jump--action nil)
\r
229 > > +(defun notmuch-jump (action-map prompt)
\r
230 > > + "Interactively prompt for one of the keys in ACTION-MAP.
\r
232 > > +Displays a pop-up temporary buffer with a summary of all bindings
\r
233 > > +in ACTION-MAP, reads a key from the minibuffer, and performs the
\r
234 > > +corresponding action. The prompt can be canceled with C-g.
\r
236 > Maybe say the prompt can be canceled with RET too?
\r
238 Done. I also fixed the docstring's mention of a pop-up temporary
\r
239 buffer, since that's not how the code works any more.
\r
241 > > +PROMPT must be a string to use for the prompt if this command was
\r
242 > > +not invoked directly by a key binding (e.g., it was invoked
\r
243 > > +through M-x). PROMPT should include a space at the end.
\r
245 > I find the "j-" prompt a bit weird and would prefer something more like
\r
246 > "Jump to search: " to be used however the user enters the function.
\r
248 The intent was to make it act like a prefix keymap. For example, if
\r
249 you hit "C-x", Emacs will show "C-x-" in the minibuffer until you hit
\r
250 the next key. OTOH, Emacs isn't exactly a paragon of usability, so
\r
251 you're probably right and this should just use the provided prompt
\r
254 > > +ACTION-MAP must be a list of triples of the form
\r
255 > > + (KEY LABEL ACTION)
\r
256 > > +where KEY is a key binding, LABEL is a string label to display in
\r
257 > > +the buffer, and ACTION is a nullary function to call. LABEL may
\r
258 > > +be null, in which case the action will still be bound, but will
\r
259 > > +not appear in the pop-up buffer.
\r
262 > > + (let* ((items (notmuch-jump--format-actions action-map))
\r
263 > > + ;; Format the table of bindings and the full prompt
\r
265 > > + (with-temp-buffer
\r
266 > > + (notmuch-jump--insert-items (window-body-width) items)
\r
267 > > + (buffer-string)))
\r
269 > > + (if (eq this-original-command this-command)
\r
270 > > + ;; Make it look like we're just part of any regular
\r
271 > > + ;; submap prompt (like C-x, C-c, etc.)
\r
272 > > + (concat (format-kbd-macro (this-command-keys)) "-")
\r
273 > > + ;; We were invoked through something like M-x
\r
276 > > + (concat table "\n\n"
\r
277 > > + (propertize prompt-text 'face 'minibuffer-prompt)))
\r
278 > > + ;; By default, the minibuffer applies the minibuffer face to
\r
279 > > + ;; the entire prompt. However, we want to clearly
\r
280 > > + ;; distinguish bindings (which we put in the prompt face
\r
281 > > + ;; ourselves) from their labels, so disable the minibuffer's
\r
282 > > + ;; own re-face-ing.
\r
283 > > + (minibuffer-prompt-properties
\r
284 > > + (notmuch-jump--plist-delete
\r
285 > > + (copy-sequence minibuffer-prompt-properties)
\r
287 > > + ;; Build the keymap with our bindings
\r
288 > > + (minibuffer-map (notmuch-jump--make-keymap action-map))
\r
289 > > + ;; The bindings save the the action in notmuch-jump--action
\r
290 > > + (notmuch-jump--action nil))
\r
291 > > + ;; Read the action
\r
292 > > + (read-from-minibuffer full-prompt nil minibuffer-map)
\r
294 > > + ;; If we got an action, do it
\r
295 > > + (when notmuch-jump--action
\r
296 > > + (funcall notmuch-jump--action))))
\r
298 > > +(defun notmuch-jump--format-actions (action-map)
\r
299 > > + "Format the actions in ACTION-MAP.
\r
301 > > +Returns a list of strings, one for each item with a label in
\r
302 > > +ACTION-MAP. These strings can be inserted into a tabular
\r
305 > > + ;; Compute the maximum key description width
\r
306 > > + (let ((key-width 1))
\r
307 > > + (dolist (action action-map)
\r
309 > The name "action" is slightly unfortunate when you use ACTION as the
\r
310 > third item of each element of action-map when describing it
\r
311 > above. However, no better name springs to mind. (Maybe "triple"?)
\r
313 Good catch. Changed to "entry" (for an entry in the action map).
\r
315 > > + (setq key-width
\r
316 > > + (max key-width
\r
317 > > + (string-width (format-kbd-macro (first action))))))
\r
318 > > + ;; Format each action
\r
319 > > + (mapcar (lambda (action)
\r
320 > > + (let ((key (format-kbd-macro (first action)))
\r
321 > > + (desc (second action)))
\r
323 > > + (propertize key 'face 'minibuffer-prompt)
\r
324 > > + (make-string (- key-width (length key)) ? )
\r
326 > > + action-map)))
\r
328 > > +(defun notmuch-jump--insert-items (width items)
\r
329 > > + "Make a table of ITEMS up to WIDTH wide in the current buffer."
\r
330 > > + (let* ((nitems (length items))
\r
331 > > + (col-width (+ 3 (apply #'max (mapcar #'string-width items))))
\r
332 > > + (ncols (if (> (* col-width nitems) width)
\r
333 > > + (max 1 (/ width col-width))
\r
334 > > + ;; Items fit on one line. Space them out
\r
335 > > + (setq col-width (/ width nitems))
\r
336 > > + (length items))))
\r
338 > > + (dotimes (col ncols)
\r
340 > > + (let ((item (pop items)))
\r
341 > > + (insert item)
\r
342 > > + (when (and items (< col (- ncols 1)))
\r
343 > > + (insert (make-string (- col-width (string-width item)) ? ))))))
\r
345 > > + (insert "\n")))))
\r
347 > > +(defvar notmuch-jump-minibuffer-map
\r
348 > > + (let ((map (make-sparse-keymap)))
\r
349 > > + (set-keymap-parent map minibuffer-local-map)
\r
350 > > + ;; Make this like a special-mode keymap, with no self-insert-command
\r
351 > > + (suppress-keymap map)
\r
353 > > + "Base keymap for notmuch-jump's minibuffer keymap.")
\r
355 > > +(defun notmuch-jump--make-keymap (action-map)
\r
356 > > + "Translate ACTION-MAP into a minibuffer keymap."
\r
357 > > + (let ((map (make-sparse-keymap)))
\r
358 > > + (set-keymap-parent map notmuch-jump-minibuffer-map)
\r
359 > > + (dolist (action action-map)
\r
360 > > + (define-key map (first action)
\r
361 > > + `(lambda () (interactive)
\r
362 > > + (setq notmuch-jump--action ',(third action))
\r
363 > > + (exit-minibuffer))))
\r
366 > > +(defun notmuch-jump--plist-delete (plist property)
\r
367 > > + (let* ((xplist (cons nil plist))
\r
368 > > + (pred xplist))
\r
369 > > + (while (cdr pred)
\r
370 > > + (when (eq (cadr pred) property)
\r
371 > > + (setcdr pred (cdddr pred)))
\r
372 > > + (setq pred (cddr pred)))
\r
373 > > + (cdr xplist)))
\r
375 > > +(unless (fboundp 'window-body-width)
\r
376 > > + ;; Compatibility for Emacs pre-24
\r
377 > > + (defun window-body-width (&optional window)
\r
378 > > + (let ((edges (window-inside-edges window)))
\r
379 > > + (- (caddr edges) (car edges)))))
\r
380 > > diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
\r
381 > > index 2941da3..135422d 100644
\r
382 > > --- a/emacs/notmuch-lib.el
\r
383 > > +++ b/emacs/notmuch-lib.el
\r
384 > > @@ -130,9 +130,12 @@ (defvar notmuch-common-keymap
\r
385 > > (define-key map "m" 'notmuch-mua-new-mail)
\r
386 > > (define-key map "=" 'notmuch-refresh-this-buffer)
\r
387 > > (define-key map "G" 'notmuch-poll-and-refresh-this-buffer)
\r
388 > > + (define-key map "j" 'notmuch-jump-search)
\r
390 > > "Keymap shared by all notmuch modes.")
\r
392 > > +(autoload 'notmuch-jump-search "notmuch-jump" "Jump to a saved search by shortcut key." t)
\r
394 > We don't normally seem to use autoload but instead use
\r
395 > declare-function. It might be worth being consistent (I am not very sure
\r
396 > of the pros and cons of autoload). May also be worth having it with the
\r
397 > other declare-functions to keep it clear how things are loaded.
\r
399 I used autoload because it won't bother even reading
\r
400 notmuch-jump.el(c) until the user hits "j" for the first time (and,
\r
401 hence, won't load it at all if they don't use jump). This is easy
\r
402 with notmuch-jump because it's self-contained and has a single clear
\r
403 entry-point and no customizable variables.
\r
405 declare-function, on the other hand, still requires you to load the
\r
406 source containing the function (either eagerly, which is what notmuch
\r
407 usually does, or with an autoload).
\r
409 I think we should do *more* autoloading, though maybe it's not
\r
410 practical for the bulk of notmuch-emacs.
\r
412 I'm happy to move the autoload call to somewhere else, though
\r
413 notmuch-lib doesn't actually have any declare-functions (since it's
\r
414 sort of a root of the dependency tree). I could put it right below
\r
415 the requires, since that's where we usually put declare-functions.
\r
423 > > ;; By default clicking on a button does not select the window
\r
424 > > ;; containing the button (as opposed to clicking on a widget which
\r
425 > > ;; does). This means that the button action is then executed in the
\r