]> git.notmuchmail.org Git - notmuch/blobdiff - contrib/notmuch-pick/notmuch-pick.el
contrib: pick: slightly tweak running search and pick from pick buffer
[notmuch] / contrib / notmuch-pick / notmuch-pick.el
index cf026af3b23d0d5783b60199c28fa9b77b13bc74..374cdfc83f4c525c9eec039c8bf79e6b958cca1a 100644 (file)
     (define-key map "q" 'notmuch-pick-quit)
     (define-key map "x" 'notmuch-pick-quit)
     (define-key map "?" 'notmuch-help)
-    (define-key map "a" 'notmuch-pick-archive-message)
+    (define-key map "a" 'notmuch-pick-archive-message-then-next)
     (define-key map "=" 'notmuch-pick-refresh-view)
-    (define-key map "s" 'notmuch-search)
-    (define-key map "z" 'notmuch-pick)
+    (define-key map "s" 'notmuch-pick-to-search)
+    (define-key map "z" 'notmuch-pick-to-pick)
     (define-key map "m" 'notmuch-pick-new-mail)
     (define-key map "f" 'notmuch-pick-forward-message)
     (define-key map "r" 'notmuch-pick-reply-sender)
@@ -289,6 +289,25 @@ Does NOT change the database."
   (interactive)
   (notmuch-pick-tag "-"))
 
+;; The next two functions close the message window before searching or
+;; picking but they do so after the user has entered the query (in
+;; case the user was basing the query on something in the message
+;; window).
+
+(defun notmuch-pick-to-search ()
+  "Run \"notmuch search\" with the given `query' and display results."
+  (interactive)
+  (let ((query (notmuch-read-query "Notmuch search: ")))
+    (notmuch-pick-close-message-window)
+    (notmuch-search query)))
+
+(defun notmuch-pick-to-pick ()
+  "Run a query and display results in experimental notmuch-pick mode"
+  (interactive)
+  (let ((query (notmuch-read-query "Notmuch pick: ")))
+    (notmuch-pick-close-message-window)
+    (notmuch-pick query)))
+
 ;; This function should be in notmuch-hello.el but we are trying to
 ;; minimise impact on the rest of the codebase.
 (defun notmuch-pick-from-hello (&optional search)
@@ -337,8 +356,10 @@ Does NOT change the database."
       (setq notmuch-pick-message-window
            (split-window-vertically (/ (window-height) 4)))
       (with-selected-window notmuch-pick-message-window
-       (setq current-prefix-arg '(4))
-       (setq buffer (notmuch-show id nil nil nil)))
+       ;; Since we are only displaying one message do not indent.
+       (let ((notmuch-show-indent-messages-width 0))
+         (setq current-prefix-arg '(4))
+         (setq buffer (notmuch-show id nil nil nil))))
       (notmuch-pick-tag-update-display (list "-unread"))
       (setq notmuch-pick-message-buffer buffer))))
 
@@ -393,10 +414,23 @@ Does NOT change the database."
       (kill-buffer notmuch-pick-message-buffer))
     t))
 
-(defun notmuch-pick-archive-message ()
+(defun notmuch-pick-archive-message (&optional unarchive)
+  "Archive the current message.
+
+Archive the current message by applying the tag changes in
+`notmuch-archive-tags' to it (remove the \"inbox\" tag by
+default). If a prefix argument is given, the message will be
+\"unarchived\", i.e. the tag changes in `notmuch-archive-tags'
+will be reversed."
+  (interactive "P")
+  (when notmuch-archive-tags
+    (apply 'notmuch-pick-tag
+          (notmuch-tag-change-list notmuch-archive-tags unarchive))))
+
+(defun notmuch-pick-archive-message-then-next (&optional unarchive)
   "Archive the current message and move to next matching message."
-  (interactive)
-  (notmuch-pick-tag "-inbox")
+  (interactive "P")
+  (notmuch-pick-archive-message unarchive)
   (notmuch-pick-next-matching-message))
 
 (defun notmuch-pick-next-message ()