(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.
+ "Archive each message in thread, and show next thread from search.
+
+Archive each message currrently 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.
-This command is safe from any race condition of new messages
+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."
(if (not (eobp))
(forward-char))
(if (not (re-search-forward notmuch-show-message-begin-regexp nil t))
- (goto-char (point-max))))))
+ (goto-char (point-max)))))
+ (let ((parent-buffer notmuch-show-parent-buffer))
+ (kill-this-buffer)
+ (if parent-buffer
+ (progn
+ (switch-to-buffer parent-buffer)
+ (notmuch-search-show-thread)))))
(defun notmuch-show-move-to-current-message-summary-line ()
"Move to the beginning of the one-line summary 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:
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). Also kill
+this buffer, and display the next thread from the search from
+which this thread was originally shown."
(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)
mode-name "notmuch-show")
(setq buffer-read-only t))
-(defun notmuch-show (thread-id)
- "Run \"notmuch show\" with the given thread ID and display results."
+(defun notmuch-show (thread-id &optional parent-buffer)
+ "Run \"notmuch show\" with the given thread ID and display results.
+
+The optional PARENT-BUFFER is the notmuch-search buffer from
+which this notmuch-show command was executed, (so that the next
+thread from that buffer can be show when done with this one)."
(interactive "sNotmuch show: ")
(let ((buffer (get-buffer-create (concat "*notmuch-show-" thread-id "*"))))
(switch-to-buffer buffer)
(notmuch-show-mode)
+ (set (make-local-variable 'notmuch-show-parent-buffer) parent-buffer)
(let ((proc (get-buffer-process (current-buffer)))
(inhibit-read-only t))
(if proc
(define-key map "s" 'notmuch-search)
(define-key map "t" 'notmuch-search-filter-by-tag)
(define-key map "x" 'kill-this-buffer)
- (define-key map "\r" 'notmuch-search-show-thread)
+ (define-key map (kbd "RET") 'notmuch-search-show-thread)
(define-key map "+" 'notmuch-search-add-tag)
(define-key map "-" 'notmuch-search-remove-tag)
(define-key map "<" 'beginning-of-buffer)
(defun notmuch-search-show-thread ()
(interactive)
- (notmuch-show (notmuch-search-find-thread-id)))
+ (let ((thread-id (notmuch-search-find-thread-id)))
+ (forward-line)
+ (notmuch-show thread-id (current-buffer))))
(defun notmuch-call-notmuch-process (&rest args)
(let ((error-buffer (get-buffer-create "*Notmuch errors*")))
This function advances point to the next line when finished."
(interactive)
(notmuch-search-remove-tag "inbox")
- (next-line))
+ (forward-line))
(defun notmuch-search (query)
"Run \"notmuch search\" with the given query string and display results."