(define-key map "x" 'kill-this-buffer)
(define-key map "+" 'notmuch-show-add-tag)
(define-key map "-" 'notmuch-show-remove-tag)
+ (define-key map (kbd "DEL") 'notmuch-show-rewind)
(define-key map " " 'notmuch-show-advance-marking-read-and-archiving)
map)
"Keymap for \"notmuch show\" buffers.")
(if (not (notmuch-show-message-unread-p))
(notmuch-show-next-message)))
+(defun notmuch-show-next-open-message ()
+ "Advance to the the next message which is not hidden.
+
+If read messages are currently hidden, advance to the next unread
+message. Otherwise, advance to the next message."
+ (if (or (memq 'notmuch-show-body-read buffer-invisibility-spec)
+ (assq 'notmuch-show-body-read buffer-invisibility-spec))
+ (notmuch-show-next-unread-message)
+ (notmuch-show-next-message)))
+
(defun notmuch-show-previous-message ()
"Backup to the beginning of the previous message in the buffer.
))
(recenter 0)))
-(defun notmuch-show-mark-read-then-next-unread-message ()
+(defun notmuch-show-find-previous-message ()
+ "Returns the position of the previous message in the buffer.
+
+Or the position of the beginning of the current message if point
+is originally within the message rather than at the beginning of
+it."
+ ; save-excursion doesn't save our window position
+ ; save-window-excursion doesn't save point
+ ; Looks like we have to use both.
+ (save-excursion
+ (save-window-excursion
+ (notmuch-show-previous-message)
+ (point))))
+
+(defun notmuch-show-mark-read-then-next-open-message ()
"Remove unread tag from current message, then advance to next unread message."
(interactive)
(notmuch-show-remove-tag "unread")
- (notmuch-show-next-unread-message))
+ (notmuch-show-next-open-message))
+
+(defun notmuch-show-rewind ()
+ "Do reverse scrolling compared to `notmuch-show-advance-marking-read-and-archiving'
+
+Specifically, if the beginning of the previous email is fewer
+than `window-height' lines from the current point, move to it
+just like `notmuch-show-previous-message'.
+
+Otherwise, just scroll down a screenful of the current message.
+
+This command does not modify any message tags, (it does not undo
+any effects from previous calls to
+`notmuch-show-advance-marking-read-and-archiving'."
+ (interactive)
+ (let ((previous (notmuch-show-find-previous-message)))
+ (if (> (count-lines previous (point)) (- (window-height) next-screen-context-lines))
+ (progn
+ (condition-case nil
+ (scroll-down nil)
+ ((beginning-of-buffer) nil))
+ (goto-char (window-start)))
+ (notmuch-show-previous-message))))
(defun notmuch-show-advance-marking-read-and-archiving ()
"Advance through buffer, marking read and archiving.
Otherwise, (the end of the current message is already within the
current window), remove the \"unread\" tag (if present) from the
-current message and advance to the next message.
+current message and advance to the next open message.
Finally, if there is no further message to advance to, and this
last message is already read, then archive the entire current
(if (> next (window-end))
(scroll-up nil)
(if unread
- (notmuch-show-mark-read-then-next-unread-message)
+ (notmuch-show-mark-read-then-next-open-message)
(if (notmuch-show-last-message-p)
(notmuch-show-archive-thread)
- (notmuch-show-next-unread-message))))))
+ (notmuch-show-next-open-message))))))
(defun notmuch-show-markup-citations-region (beg end)
(goto-char beg)