--- /dev/null
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1A5B5431FC3\r
+ for <notmuch@notmuchmail.org>; Mon, 4 Aug 2014 18:45:38 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id jb0gjxB9W6zX for <notmuch@notmuchmail.org>;\r
+ Mon, 4 Aug 2014 18:45:30 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
+ [18.7.68.37])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id BE719431FBC\r
+ for <notmuch@notmuchmail.org>; Mon, 4 Aug 2014 18:45:29 -0700 (PDT)\r
+X-AuditID: 12074425-f79766d000006da8-df-53e037399fd3\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 6F.BA.28072.93730E35; Mon, 4 Aug 2014 21:45:29 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s751jQAU005688; \r
+ Mon, 4 Aug 2014 21:45:26 -0400\r
+Received: from drake.dyndns.org\r
+ (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [216.15.114.40]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s751jOL3005237\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Mon, 4 Aug 2014 21:45:25 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1XEToa-0004b8-Ie; Mon, 04 Aug 2014 21:45:24 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 1/2] emacs: Introduce notmuch-jump: shortcut keys to saved\r
+ searches\r
+Date: Mon, 4 Aug 2014 21:45:20 -0400\r
+Message-Id: <1407203121-17640-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.0.0\r
+In-Reply-To: <20140805014403.GX13893@mit.edu>\r
+References: <20140805014403.GX13893@mit.edu>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFlrAKsWRmVeSWpSXmKPExsUixG6nomtp/iDYoHkSu8WN1m5Gi313tjBZ\r
+ rJ7LY3H95kxmBxaPXc//MnnsnHWX3ePZqlvMHlsOvWcOYInisklJzcksSy3St0vgynhzW7rg\r
+ SUDFp433mBoYVzp0MXJySAiYSBw7coQRwhaTuHBvPVsXIxeHkMBsJolFnQvYIZwNjBKz3x5l\r
+ hHBuM0lMvX8GypnLKPF142V2kH42AQ2JbfuXg80SEZCW2Hl3NiuIzSyQJbHh5UFmEFtYIExi\r
+ 76ypLF2MHBwsAqoS0xZJgYR5BRwklp5sZIU4Q06i4cYnNpASTgFdicZFgSBhIQEdiVntEBN5\r
+ BQQlTs58AjaFWUBdYv08IYhF8hLNW2czT2AUmoWkahZC1SwkVQsYmVcxyqbkVunmJmbmFKcm\r
+ 6xYnJ+blpRbpWujlZpbopaaUbmIEB76L6g7GCYeUDjEKcDAq8fAKqN0PFmJNLCuuzD3EKMnB\r
+ pCTKG6r3IFiILyk/pTIjsTgjvqg0J7X4EKMEB7OSCG++IFCONyWxsiq1KB8mJc3BoiTO+9ba\r
+ KlhIID2xJDU7NbUgtQgmK8PBoSTBO88MqFGwKDU9tSItM6cEIc3EwQkynAdo+G6QGt7igsTc\r
+ 4sx0iPwpRl2OruvH2piEWPLy81KlxHkzTYGKBECKMkrz4ObAEtYrRnGgt4R5m0BG8QCTHdyk\r
+ V0BLmICWmOncB1lSkoiQkmpgjNO1Fn0SEm40w6MutfSIX2KUS3Dc6aD6XRcnrDY0m8ypkzhX\r
+ 8NjUQrvKM6Gr+XkOyrQaK1xSkrMsLNon1/J31VvlrnqrnTa7jpoKX/8/cfPStL/Jj7l0o0VY\r
+ 7m9mb6z+lqt81ObJwjYbU+3M6W6ZixSWfPjWepapLGztw2UWZYIl8zZPPb1WiaU4I9FQi7mo\r
+ OBEAqFpy2DMDAAA=\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 05 Aug 2014 01:45:38 -0000\r
+\r
+This introduces notmuch-jump, which is like a user-friendly,\r
+user-configurable global prefix map for saved searches. This provides\r
+a non-modal and much faster way to access saved searches than\r
+notmuch-hello.\r
+\r
+A user configures shortcut keys in notmuch-saved-searches, which are\r
+immediately accessible from anywhere in Notmuch under the "j" key (for\r
+"jump"). When the user hits "j", the minibuffer immediately shows a\r
+helpful table of bindings reminiscent of a completions buffer.\r
+\r
+This code is a combination of work from myself (originally,\r
+"notmuch-go"), David Edmondson, and modifications from Mark Walters.\r
+---\r
+ emacs/Makefile.local | 3 +-\r
+ emacs/notmuch-hello.el | 2 +\r
+ emacs/notmuch-jump.el | 173 +++++++++++++++++++++++++++++++++++++++++++++++++\r
+ emacs/notmuch-lib.el | 13 ++++\r
+ 4 files changed, 190 insertions(+), 1 deletion(-)\r
+ create mode 100644 emacs/notmuch-jump.el\r
+\r
+diff --git a/emacs/Makefile.local b/emacs/Makefile.local\r
+index c0d6b19..1109cfa 100644\r
+--- a/emacs/Makefile.local\r
++++ b/emacs/Makefile.local\r
+@@ -18,7 +18,8 @@ emacs_sources := \\r
+ $(dir)/notmuch-tag.el \\r
+ $(dir)/coolj.el \\r
+ $(dir)/notmuch-print.el \\r
+- $(dir)/notmuch-version.el\r
++ $(dir)/notmuch-version.el \\r
++ $(dir)/notmuch-jump.el \\r
+ \r
+ $(dir)/notmuch-version.el: $(dir)/Makefile.local version.stamp\r
+ $(dir)/notmuch-version.el: $(srcdir)/$(dir)/notmuch-version.el.tmpl\r
+diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el\r
+index 3de5238..061b27d 100644\r
+--- a/emacs/notmuch-hello.el\r
++++ b/emacs/notmuch-hello.el\r
+@@ -85,6 +85,7 @@ (define-widget 'notmuch-saved-search-plist 'list\r
+ (group :format "%v" :inline t (const :format " Query: " :query) (string :format "%v")))\r
+ (checklist :inline t\r
+ :format "%v"\r
++ (group :format "%v" :inline t (const :format "Shortcut key: " :key) (key-sequence :format "%v"))\r
+ (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))\r
+ (group :format "%v" :inline t (const :format "" :sort-order)\r
+ (choice :tag " Sort Order"\r
+@@ -101,6 +102,7 @@ (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")\r
+ \r
+ :name Name of the search (required).\r
+ :query Search to run (required).\r
++ :key Optional shortcut key for `notmuch-jump-search'.\r
+ :count-query Optional extra query to generate the count\r
+ shown. If not present then the :query property\r
+ is used.\r
+diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el\r
+new file mode 100644\r
+index 0000000..05bbce5\r
+--- /dev/null\r
++++ b/emacs/notmuch-jump.el\r
+@@ -0,0 +1,173 @@\r
++;; notmuch-jump.el --- User-friendly shortcut keys\r
++;;\r
++;; Copyright © Austin Clements\r
++;;\r
++;; This file is part of Notmuch.\r
++;;\r
++;; Notmuch is free software: you can redistribute it and/or modify it\r
++;; under the terms of the GNU General Public License as published by\r
++;; the Free Software Foundation, either version 3 of the License, or\r
++;; (at your option) any later version.\r
++;;\r
++;; Notmuch is distributed in the hope that it will be useful, but\r
++;; WITHOUT ANY WARRANTY; without even the implied warranty of\r
++;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
++;; General Public License for more details.\r
++;;\r
++;; You should have received a copy of the GNU General Public License\r
++;; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.\r
++;;\r
++;; Authors: Austin Clements <aclements@csail.mit.edu>\r
++;; David Edmondson <dme@dme.org>\r
++\r
++(eval-when-compile (require 'cl))\r
++\r
++(require 'notmuch-lib)\r
++(require 'notmuch-hello)\r
++\r
++;;;###autoload\r
++(defun notmuch-jump-search ()\r
++ "Jump to a saved search by shortcut key.\r
++\r
++This prompts for and performs a saved search using the shortcut\r
++keys configured in the :key property of `notmuch-saved-searches'.\r
++Typically these shortcuts are a single key long, so this is a\r
++fast way to jump to a saved search from anywhere in Notmuch."\r
++ (interactive)\r
++\r
++ ;; Build the action map\r
++ (let (action-map)\r
++ (dolist (saved-search notmuch-saved-searches)\r
++ (let* ((saved-search (notmuch-hello-saved-search-to-plist saved-search))\r
++ (key (plist-get saved-search :key)))\r
++ (when key\r
++ (let ((name (plist-get saved-search :name))\r
++ (query (plist-get saved-search :query))\r
++ (oldest-first\r
++ (case (plist-get saved-search :sort-order)\r
++ (newest-first nil)\r
++ (oldest-first t)\r
++ (otherwise (default-value notmuch-search-oldest-first)))))\r
++ (push (list key name\r
++ `(lambda () (notmuch-search ',query ',oldest-first)))\r
++ action-map)))))\r
++ (setq action-map (nreverse action-map))\r
++\r
++ (if action-map\r
++ (notmuch-jump action-map "Search: ")\r
++ (error "To use notmuch-jump, please customize shortcut keys in notmuch-saved-searches."))))\r
++\r
++(defvar notmuch-jump--action nil)\r
++\r
++(defun notmuch-jump (action-map prompt)\r
++ "Interactively prompt for one of the keys in ACTION-MAP.\r
++\r
++Displays a summary of all bindings in ACTION-MAP in the\r
++minibuffer, reads a key from the minibuffer, and performs the\r
++corresponding action. The prompt can be canceled with C-g or\r
++RET. PROMPT must be a string to use for the prompt. PROMPT\r
++should include a space at the end.\r
++\r
++ACTION-MAP must be a list of triples of the form\r
++ (KEY LABEL ACTION)\r
++where KEY is a key binding, LABEL is a string label to display in\r
++the buffer, and ACTION is a nullary function to call. LABEL may\r
++be null, in which case the action will still be bound, but will\r
++not appear in the pop-up buffer.\r
++"\r
++\r
++ (let* ((items (notmuch-jump--format-actions action-map))\r
++ ;; Format the table of bindings and the full prompt\r
++ (table\r
++ (with-temp-buffer\r
++ (notmuch-jump--insert-items (window-body-width) items)\r
++ (buffer-string)))\r
++ (full-prompt\r
++ (concat table "\n\n"\r
++ (propertize prompt 'face 'minibuffer-prompt)))\r
++ ;; By default, the minibuffer applies the minibuffer face to\r
++ ;; the entire prompt. However, we want to clearly\r
++ ;; distinguish bindings (which we put in the prompt face\r
++ ;; ourselves) from their labels, so disable the minibuffer's\r
++ ;; own re-face-ing.\r
++ (minibuffer-prompt-properties\r
++ (notmuch-plist-delete\r
++ (copy-sequence minibuffer-prompt-properties)\r
++ 'face))\r
++ ;; Build the keymap with our bindings\r
++ (minibuffer-map (notmuch-jump--make-keymap action-map))\r
++ ;; The bindings save the the action in notmuch-jump--action\r
++ (notmuch-jump--action nil))\r
++ ;; Read the action\r
++ (read-from-minibuffer full-prompt nil minibuffer-map)\r
++\r
++ ;; If we got an action, do it\r
++ (when notmuch-jump--action\r
++ (funcall notmuch-jump--action))))\r
++\r
++(defun notmuch-jump--format-actions (action-map)\r
++ "Format the actions in ACTION-MAP.\r
++\r
++Returns a list of strings, one for each item with a label in\r
++ACTION-MAP. These strings can be inserted into a tabular\r
++buffer."\r
++\r
++ ;; Compute the maximum key description width\r
++ (let ((key-width 1))\r
++ (dolist (entry action-map)\r
++ (setq key-width\r
++ (max key-width\r
++ (string-width (format-kbd-macro (first entry))))))\r
++ ;; Format each action\r
++ (mapcar (lambda (entry)\r
++ (let ((key (format-kbd-macro (first entry)))\r
++ (desc (second entry)))\r
++ (concat\r
++ (propertize key 'face 'minibuffer-prompt)\r
++ (make-string (- key-width (length key)) ? )\r
++ " " desc)))\r
++ action-map)))\r
++\r
++(defun notmuch-jump--insert-items (width items)\r
++ "Make a table of ITEMS up to WIDTH wide in the current buffer."\r
++ (let* ((nitems (length items))\r
++ (col-width (+ 3 (apply #'max (mapcar #'string-width items))))\r
++ (ncols (if (> (* col-width nitems) width)\r
++ (max 1 (/ width col-width))\r
++ ;; Items fit on one line. Space them out\r
++ (setq col-width (/ width nitems))\r
++ (length items))))\r
++ (while items\r
++ (dotimes (col ncols)\r
++ (when items\r
++ (let ((item (pop items)))\r
++ (insert item)\r
++ (when (and items (< col (- ncols 1)))\r
++ (insert (make-string (- col-width (string-width item)) ? ))))))\r
++ (when items\r
++ (insert "\n")))))\r
++\r
++(defvar notmuch-jump-minibuffer-map\r
++ (let ((map (make-sparse-keymap)))\r
++ (set-keymap-parent map minibuffer-local-map)\r
++ ;; Make this like a special-mode keymap, with no self-insert-command\r
++ (suppress-keymap map)\r
++ map)\r
++ "Base keymap for notmuch-jump's minibuffer keymap.")\r
++\r
++(defun notmuch-jump--make-keymap (action-map)\r
++ "Translate ACTION-MAP into a minibuffer keymap."\r
++ (let ((map (make-sparse-keymap)))\r
++ (set-keymap-parent map notmuch-jump-minibuffer-map)\r
++ (dolist (action action-map)\r
++ (define-key map (first action)\r
++ `(lambda () (interactive)\r
++ (setq notmuch-jump--action ',(third action))\r
++ (exit-minibuffer))))\r
++ map))\r
++\r
++(unless (fboundp 'window-body-width)\r
++ ;; Compatibility for Emacs pre-24\r
++ (defun window-body-width (&optional window)\r
++ (let ((edges (window-inside-edges window)))\r
++ (- (caddr edges) (car edges)))))\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index c06baac..19269e3 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -25,6 +25,9 @@\r
+ (require 'mm-decode)\r
+ (require 'cl)\r
+ \r
++(autoload 'notmuch-jump-search "notmuch-jump"\r
++ "Jump to a saved search by shortcut key." t)\r
++\r
+ (defgroup notmuch nil\r
+ "Notmuch mail reader for Emacs."\r
+ :group 'mail)\r
+@@ -138,6 +141,7 @@ (defvar notmuch-common-keymap\r
+ (define-key map "m" 'notmuch-mua-new-mail)\r
+ (define-key map "=" 'notmuch-refresh-this-buffer)\r
+ (define-key map "G" 'notmuch-poll-and-refresh-this-buffer)\r
++ (define-key map "j" 'notmuch-jump-search)\r
+ map)\r
+ "Keymap shared by all notmuch modes.")\r
+ \r
+@@ -472,6 +476,15 @@ (defun notmuch-remove-if-not (predicate list)\r
+ (setq list (cdr list)))\r
+ (nreverse out)))\r
+ \r
++(defun notmuch-plist-delete (plist property)\r
++ (let* ((xplist (cons nil plist))\r
++ (pred xplist))\r
++ (while (cdr pred)\r
++ (when (eq (cadr pred) property)\r
++ (setcdr pred (cdddr pred)))\r
++ (setq pred (cddr pred)))\r
++ (cdr xplist)))\r
++\r
+ (defun notmuch-split-content-type (content-type)\r
+ "Split content/type into 'content' and 'type'"\r
+ (split-string content-type "/"))\r
+-- \r
+2.0.0\r
+\r