[PATCH] Add 'd'elete keybinding to search and show views

Dirk Hohndel hohndel at infradead.org
Wed Apr 21 16:16:03 PDT 2010


This is a variation of the 'a'rchive binding - it additionally sets
the "deleted" tag (which notmuchsync uses to trigger pruning of files)

Signed-off-by: Dirk Hohndel <hohndel at infradead.org>
---
 emacs/notmuch-show.el |   26 ++++++++++++++++++++++----
 emacs/notmuch.el      |   10 ++++++++++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 916b39e..45d1abe 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -520,6 +520,7 @@ function is used. "
 	(define-key map "+" 'notmuch-show-add-tag)
 	(define-key map "x" 'notmuch-show-archive-thread-then-exit)
 	(define-key map "a" 'notmuch-show-archive-thread)
+	(define-key map "d" 'notmuch-show-delete-thread)
 	(define-key map "N" 'notmuch-show-next-message)
 	(define-key map "P" 'notmuch-show-previous-message)
 	(define-key map "n" 'notmuch-show-next-open-message)
@@ -910,10 +911,13 @@ to stdout or stderr will appear in the *Messages* buffer."
   (interactive)
   (backward-button 1))
 
-(defun notmuch-show-archive-thread-internal (show-next)
+(defun notmuch-show-archive-or-delete-thread-internal (show-next delete)
   ;; Remove the tag from the current set of messages.
   (goto-char (point-min))
-  (loop do (notmuch-show-remove-tag "inbox")
+  (loop do (progn
+	     (notmuch-show-remove-tag "inbox")
+	     (if delete
+		 (notmuch-show-add-tag "deleted")))
 	until (not (notmuch-show-goto-message-next)))
   ;; Move to the next item in the search results, if any.
   (let ((parent-buffer notmuch-show-parent-buffer))
@@ -925,6 +929,20 @@ to stdout or stderr will appear in the *Messages* buffer."
 	  (if show-next
 	      (notmuch-search-show-thread))))))
 
+(defun notmuch-show-delete-thread ()
+  "Delete each message in thread, then show next thread from search.
+
+Archive each message currently shown by removing the \"inbox\"
+tag from each. Then kill this buffer and show the next thread
+from the search from which this thread was originally shown.
+
+Note: This command is safe from any race condition of new messages
+being delivered to the same thread. It does not archive the
+entire thread, but only the messages shown in the current
+buffer."
+  (interactive)
+  (notmuch-show-archive-or-delete-thread-internal t t))
+
 (defun notmuch-show-archive-thread ()
   "Archive each message in thread, then show next thread from search.
 
@@ -937,12 +955,12 @@ being delivered to the same thread. It does not archive the
 entire thread, but only the messages shown in the current
 buffer."
   (interactive)
-  (notmuch-show-archive-thread-internal t))
+  (notmuch-show-archive-or-delete-thread-internal t nil))
 
 (defun notmuch-show-archive-thread-then-exit ()
   "Archive each message in thread, then exit back to search results."
   (interactive)
-  (notmuch-show-archive-thread-internal nil))
+  (notmuch-show-archive-or-delete-thread-internal nil nil))
 
 (defun notmuch-show-do-stash (text)
   (kill-new text)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index f135bca..372f940 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -254,6 +254,7 @@ For a mouse binding, return nil."
     (define-key map [mouse-1] 'notmuch-search-show-thread)
     (define-key map "*" 'notmuch-search-operate-all)
     (define-key map "a" 'notmuch-search-archive-thread)
+    (define-key map "d" 'notmuch-search-delete-thread)
     (define-key map "-" 'notmuch-search-remove-tag)
     (define-key map "+" 'notmuch-search-add-tag)
     (define-key map (kbd "RET") 'notmuch-search-show-thread)
@@ -551,6 +552,15 @@ This function advances the next thread when finished."
   (notmuch-search-remove-tag-thread "inbox")
   (forward-line))
 
+(defun notmuch-search-delete-thread ()
+  "Delete the currently selected thread (remove its \"inbox\" tag and add \"deleted\" tag).
+
+This function advances the next thread when finished."
+  (interactive)
+  (notmuch-search-remove-tag-thread "inbox")
+  (notmuch-search-add-tag-thread "deleted")
+  (forward-line))
+
 (defun notmuch-search-process-sentinel (proc msg)
   "Add a message to let user know when \"notmuch search\" exits"
   (let ((buffer (process-buffer proc))
-- 
1.6.6.1



More information about the notmuch mailing list