X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;ds=sidebyside;f=emacs%2Fnotmuch-jump.el;h=1cdf5b5090d7cb594f29338e3eb98cb56f64ceb1;hb=c6f43306ccb35a5e885b186fbf87394d2f036813;hp=506ae2c8e399785c9f56169a1f16589c5d3ad807;hpb=391d9f94204234d6ef3dd701d69bfdf92dbad8f0;p=notmuch
diff --git a/emacs/notmuch-jump.el b/emacs/notmuch-jump.el
index 506ae2c8..1cdf5b50 100644
--- a/emacs/notmuch-jump.el
+++ b/emacs/notmuch-jump.el
@@ -1,4 +1,4 @@
-;; notmuch-jump.el --- User-friendly shortcut keys
+;;; notmuch-jump.el --- User-friendly shortcut keys
;;
;; Copyright © Austin Clements
;;
@@ -15,11 +15,13 @@
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
-;; along with Notmuch. If not, see .
+;; along with Notmuch. If not, see .
;;
;; Authors: Austin Clements
;; David Edmondson
+;;; Code:
+
(eval-when-compile (require 'cl))
(require 'notmuch-lib)
@@ -54,9 +56,13 @@ fast way to jump to a saved search from anywhere in Notmuch."
(oldest-first t)
(otherwise (default-value 'notmuch-search-oldest-first)))))
(push (list key name
- (if (eq (plist-get saved-search :search-type) 'tree)
- `(lambda () (notmuch-tree ',query))
- `(lambda () (notmuch-search ',query ',oldest-first))))
+ (cond
+ ((eq (plist-get saved-search :search-type) 'tree)
+ `(lambda () (notmuch-tree ',query)))
+ ((eq (plist-get saved-search :search-type) 'unthreaded)
+ `(lambda () (notmuch-unthreaded ',query)))
+ (t
+ `(lambda () (notmuch-search ',query ',oldest-first)))))
action-map)))))
(setq action-map (nreverse action-map))
@@ -102,7 +108,7 @@ not appear in the pop-up buffer.
(copy-sequence minibuffer-prompt-properties)
'face))
;; Build the keymap with our bindings
- (minibuffer-map (notmuch-jump--make-keymap action-map))
+ (minibuffer-map (notmuch-jump--make-keymap action-map prompt))
;; The bindings save the the action in notmuch-jump--action
(notmuch-jump--action nil))
;; Read the action
@@ -159,20 +165,51 @@ buffer."
(set-keymap-parent map minibuffer-local-map)
;; Make this like a special-mode keymap, with no self-insert-command
(suppress-keymap map)
+ (define-key map (kbd "DEL") 'exit-minibuffer)
map)
"Base keymap for notmuch-jump's minibuffer keymap.")
-(defun notmuch-jump--make-keymap (action-map)
+(defun notmuch-jump--make-keymap (action-map prompt)
"Translate ACTION-MAP into a minibuffer keymap."
(let ((map (make-sparse-keymap)))
(set-keymap-parent map notmuch-jump-minibuffer-map)
(dolist (action action-map)
- (define-key map (first action)
- `(lambda () (interactive)
- (setq notmuch-jump--action ',(third action))
- (exit-minibuffer))))
+ (if (= (length (first action)) 1)
+ (define-key map (first action)
+ `(lambda () (interactive)
+ (setq notmuch-jump--action ',(third action))
+ (exit-minibuffer)))))
+ ;; By doing this in two passes (and checking if we already have a
+ ;; binding) we avoid problems if the user specifies a binding which
+ ;; is a prefix of another binding.
+ (dolist (action action-map)
+ (if (> (length (first action)) 1)
+ (let* ((key (elt (first action) 0))
+ (keystr (string key))
+ (new-prompt (concat prompt (format-kbd-macro keystr) " "))
+ (action-submap nil))
+ (unless (lookup-key map keystr)
+ (dolist (act action-map)
+ (when (= key (elt (first act) 0))
+ (push (list (substring (first act) 1)
+ (second act)
+ (third act))
+ action-submap)))
+ ;; We deal with backspace specially
+ (push (list (kbd "DEL")
+ "Backup"
+ (apply-partially #'notmuch-jump action-map prompt))
+ action-submap)
+ (setq action-submap (nreverse action-submap))
+ (define-key map keystr
+ `(lambda () (interactive)
+ (setq notmuch-jump--action
+ ',(apply-partially #'notmuch-jump action-submap new-prompt))
+ (exit-minibuffer)))))))
map))
;;
(provide 'notmuch-jump)
+
+;;; notmuch-jump.el ends here