[PATCH v2] emacs: Add support for saved search accelerators

David Edmondson dme at dme.org
Wed May 7 04:21:34 PDT 2014


Extended the saved search definition to allow the inclusion of an
accelerator key for the search. Bind 'j' in the common mode map as a
leader for such accelerator keys.
---
 emacs/notmuch-hello.el |  5 ++++-
 emacs/notmuch-lib.el   | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 3de5238..64d5aa1 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -85,6 +85,7 @@ searches so they still work in customize."
 		(group :format "%v" :inline t (const :format "  Query: " :query) (string :format "%v")))
 	  (checklist :inline t
 		     :format "%v"
+		     (group :format "%v" :inline t (const :format "    Key: " :key) (key-sequence :format "%v"))
 		     (group :format "%v" :inline t (const :format "Count-Query: " :count-query) (string :format "%v"))
 		     (group :format "%v" :inline t (const :format "" :sort-order)
 			    (choice :tag " Sort Order"
@@ -101,6 +102,7 @@ a plist. Supported properties are
 
   :name            Name of the search (required).
   :query           Search to run (required).
+  :key             Optional accelerator key.
   :count-query     Optional extra query to generate the count
                    shown. If not present then the :query property
                    is used.
@@ -551,7 +553,8 @@ with `notmuch-hello-query-counts'."
 	    (when elem
 	      (if (> column-indent 0)
 		  (widget-insert (make-string column-indent ? )))
-	      (let* ((name (plist-get elem :name))
+	      (let* ((key (plist-get elem :key))
+		     (name (plist-get elem :name))
 		     (query (plist-get elem :query))
 		     (oldest-first (case (plist-get elem :sort-order)
 				     (newest-first nil)
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 2941da3..f8c5f96 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -25,6 +25,10 @@
 (require 'mm-decode)
 (require 'cl)
 
+(declare-function notmuch-search "notmuch" (&optional query oldest-first target-thread target-line continuation))
+(declare-function notmuch-saved-search-get "notmuch-hello" (saved-search field))
+(defvar notmuch-saved-searches) ;; In `notmuch-hello.el'.
+
 (defvar notmuch-command "notmuch"
   "Command to run the notmuch binary.")
 
@@ -130,6 +134,7 @@ For example, if you wanted to remove an \"inbox\" tag and add an
     (define-key map "m" 'notmuch-mua-new-mail)
     (define-key map "=" 'notmuch-refresh-this-buffer)
     (define-key map "G" 'notmuch-poll-and-refresh-this-buffer)
+    (define-key map "j" 'notmuch-jump)
     map)
   "Keymap shared by all notmuch modes.")
 
@@ -845,6 +850,47 @@ status."
 (defvar notmuch-show-process-crypto nil)
 (make-variable-buffer-local 'notmuch-show-process-crypto)
 
+;; Jump key support:
+
+(defvar notmuch-jump-search nil)
+(defun notmuch-jump-map ()
+  (let ((map (make-sparse-keymap))
+	help)
+    (set-keymap-parent map minibuffer-local-map)
+    (suppress-keymap map)
+    (dolist (saved-search notmuch-saved-searches)
+      (let ((key (notmuch-saved-search-get saved-search :key)))
+	(when key
+	  (define-key map key `(lambda ()
+				 (interactive)
+				 (setq notmuch-jump-search ',saved-search)
+				 (exit-minibuffer)))
+	  (push (format "%s: %s"
+			(propertize key 'face 'minibuffer-prompt)
+			(notmuch-saved-search-get saved-search :name))
+		help))))
+    ;; Hitting ? displays a quick hint of the accelerators.
+    (define-key map "?" `(lambda ()
+			   (interactive)
+			   (message "%s"
+				    (mapconcat #'identity
+					       ;; Reverse the list so
+					       ;; that elements appear
+					       ;; in the same order as
+					       ;; `notmuch-saved-searches'.
+					       (reverse ',help)
+					       " "))))
+    map))
+
+(defun notmuch-jump ()
+  "Read a saved search accelerator key and perform the search."
+  (interactive)
+  (setq notmuch-jump-search nil)
+  (read-from-minibuffer "Jump to saved search: " nil (notmuch-jump-map))
+  (when notmuch-jump-search
+    (notmuch-search (notmuch-saved-search-get notmuch-jump-search :query)
+		    (notmuch-saved-search-get notmuch-jump-search :oldest-first))))
+
 (provide 'notmuch-lib)
 
 ;; Local Variables:
-- 
2.0.0.rc0



More information about the notmuch mailing list