contrib: pick: move save-excursion closer to message insertion

Pick keeps point roughly at the top of the buffer while inserting
messages at the end as they come in (from the async
parser). Previously the save-excursion to do this was done once for
each thread inserted: now it is done for each individual message.

The advantage is that the message insertion code can decide where to
leave point. In the next patch point will be left on the target message.

Note notmuch-pick-insert-msg is unchanged as that is used by the tag
display update code.
This commit is contained in:
Mark Walters 2013-01-10 10:41:16 +00:00 committed by David Bremner
parent c8589e4eb8
commit 740f0cda55

View file

@ -638,6 +638,11 @@ unchanged ADDRESS if parsing fails."
(notmuch-pick-set-message-properties msg) (notmuch-pick-set-message-properties msg)
(insert "\n")) (insert "\n"))
(defun notmuch-pick-goto-and-insert-msg (msg)
"Insert msg at the end of the buffer."
(save-excursion
(goto-char (point-max))
(notmuch-pick-insert-msg msg)))
(defun notmuch-pick-insert-tree (tree depth tree-status first last) (defun notmuch-pick-insert-tree (tree depth tree-status first last)
"Insert the message tree TREE at depth DEPTH in the current thread." "Insert the message tree TREE at depth DEPTH in the current thread."
(let ((msg (car tree)) (let ((msg (car tree))
@ -659,7 +664,7 @@ unchanged ADDRESS if parsing fails."
(push "" tree-status))) (push "" tree-status)))
(push (concat (if replies "" "") "") tree-status) (push (concat (if replies "" "") "") tree-status)
(notmuch-pick-insert-msg (plist-put msg :tree-status tree-status)) (notmuch-pick-goto-and-insert-msg (plist-put msg :tree-status tree-status))
(pop tree-status) (pop tree-status)
(pop tree-status) (pop tree-status)
@ -678,12 +683,10 @@ unchanged ADDRESS if parsing fails."
do (notmuch-pick-insert-tree tree depth tree-status (eq count 1) (eq count n))))) do (notmuch-pick-insert-tree tree depth tree-status (eq count 1) (eq count n)))))
(defun notmuch-pick-insert-forest-thread (forest-thread) (defun notmuch-pick-insert-forest-thread (forest-thread)
(save-excursion
(goto-char (point-max))
(let (tree-status) (let (tree-status)
;; Reset at the start of each main thread. ;; Reset at the start of each main thread.
(setq notmuch-pick-previous-subject nil) (setq notmuch-pick-previous-subject nil)
(notmuch-pick-insert-thread forest-thread 0 tree-status)))) (notmuch-pick-insert-thread forest-thread 0 tree-status)))
(defun notmuch-pick-insert-forest (forest) (defun notmuch-pick-insert-forest (forest)
(mapc 'notmuch-pick-insert-forest-thread forest)) (mapc 'notmuch-pick-insert-forest-thread forest))