]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch.el
notmuch.el: Make archive-thread more efficient for already archived messages.
[notmuch] / notmuch.el
index 062beafc322a2da725d414e228f1bba1c35c4a35..8e752198f240cd1e98f8e5c9628a316fdf2877e9 100644 (file)
@@ -39,7 +39,7 @@
     (define-key map "x" 'kill-this-buffer)
     (define-key map "+" 'notmuch-show-add-tag)
     (define-key map "-" 'notmuch-show-remove-tag)
-    (define-key map " " 'notmuch-show-advance-marking-read)
+    (define-key map " " 'notmuch-show-advance-marking-read-and-archiving)
     map)
   "Keymap for \"notmuch show\" buffers.")
 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
 
 (defun notmuch-show-remove-tag (tag)
   (interactive "sTag to remove: ")
-  (notmuch-call-notmuch-process "tag" (concat "-" tag) (concat "id:" (notmuch-show-get-message-id)))
-  (notmuch-show-set-tags (delete tag (notmuch-show-get-tags))))
+  (let ((tags (notmuch-show-get-tags)))
+    (if (member tag tags)
+       (progn
+         (notmuch-call-notmuch-process "tag" (concat "-" tag) (concat "id:" (notmuch-show-get-message-id)))
+         (notmuch-show-set-tags (delete tag tags))))))
 
 (defun notmuch-show-archive-thread ()
   "Archive each message currrently shown by removing the \"inbox\" tag from each.
@@ -178,12 +181,11 @@ simply move to the beginning of the current message."
 (defun notmuch-show-mark-read-then-next-message ()
   "Remove unread tag from current message, then advance to next message."
   (interactive)
-  (if (member "unread" (notmuch-show-get-tags))
-      (notmuch-show-remove-tag "unread"))
+  (notmuch-show-remove-tag "unread")
   (notmuch-show-next-message))
 
-(defun notmuch-show-advance-marking-read ()
-  "Advance through buffer, marking messages as read.
+(defun notmuch-show-advance-marking-read-and-archiving ()
+  "Advance through buffer, marking read and archiving.
 
 This command is intended to be one of the simplest ways to
 process a thread of email. It does the following:
@@ -193,11 +195,20 @@ scroll by a near screenful to read more of the message.
 
 Otherwise, (the end of the current message is already within the
 current window), remove the \"unread\" tag from the current
-message and advance to the next message."
+message and advance to the next message.
+
+Finally, if there is no further message to advance to, and this
+last message is already read, then archive the entire current
+thread, (remove the \"inbox\" tag from each message)."
   (interactive)
-  (if (< (notmuch-show-find-next-message) (window-end))
-      (notmuch-show-mark-read-then-next-message)
-    (scroll-up nil)))
+  (let ((next (notmuch-show-find-next-message))
+       (unread (member "unread" (notmuch-show-get-tags))))
+    (if (and (not unread)
+            (equal next (point)))
+       (notmuch-show-archive-thread)
+      (if (< (notmuch-show-find-next-message) (window-end))
+         (notmuch-show-mark-read-then-next-message)
+       (scroll-up nil)))))
 
 (defun notmuch-show-markup-citations-region (beg end)
   (goto-char beg)