X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch.el;h=747f60c4dad7c0cddce7bd2ff33801eefa527e49;hp=5f394cdd39584b34474160fbf1e4e44a2f5ad570;hb=9a02b950a35a159a3b86ed052c8f1a1349c7bb72;hpb=446459a5eab3d5a085950a25476079d5188c7528 diff --git a/notmuch.el b/notmuch.el index 5f394cdd..747f60c4 100644 --- a/notmuch.el +++ b/notmuch.el @@ -39,6 +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-and-archiving) map) "Keymap for \"notmuch show\" buffers.") (fset 'notmuch-show-mode-map notmuch-show-mode-map) @@ -94,8 +95,11 @@ (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. @@ -144,6 +148,19 @@ last message in the buffer." (notmuch-show-move-to-current-message-summary-line) (recenter 0)) +(defun notmuch-show-find-next-message () + "Returns the position of the next message in the buffer. + +Or the beginning of the current message if already within the last +message in the buffer." + ; 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-next-message) + (point)))) + (defun notmuch-show-previous-message () "Backup to the beginning of the previous message in the buffer. @@ -162,12 +179,46 @@ simply move to the beginning of the current message." (recenter 0))) (defun notmuch-show-mark-read-then-next-message () - "Remove uread tag from current message, then advance to 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-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: + +If the current message in the thread is not yet fully visible, +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. + +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) + (let ((next (notmuch-show-find-next-message)) + (unread (member "unread" (notmuch-show-get-tags)))) + (if (and (not unread) + (equal next (point))) + (progn + (notmuch-show-archive-thread) + (let ((parent-buffer notmuch-show-parent-buffer)) + (kill-this-buffer) + (if parent-buffer + (progn + (switch-to-buffer parent-buffer) + (notmuch-search-show-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) (beginning-of-line) @@ -198,10 +249,10 @@ simply move to the beginning of the current message." (let ((beg (point))) (re-search-forward notmuch-show-body-end-regexp) (let ((end (match-beginning 0))) + (notmuch-show-markup-citations-region beg end) (if (not (member "unread" (notmuch-show-get-tags))) (overlay-put (make-overlay beg end) - 'invisible 'notmuch-show-body-read)) - (notmuch-show-markup-citations-region beg end)))) + 'invisible 'notmuch-show-body-read))))) (defun notmuch-show-markup-header () (re-search-forward notmuch-show-header-begin-regexp) @@ -322,12 +373,17 @@ view, (remove the \"inbox\" tag from each), with 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 @@ -352,7 +408,7 @@ view, (remove the \"inbox\" tag from each), with (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) @@ -436,7 +492,9 @@ global search. (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*"))) @@ -489,7 +547,7 @@ global search. 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."