X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch.el;h=a6cb82360949206cf2993a23af5f68a5c7e74991;hp=7f087c7240de754e1510af878885129ba3d08a03;hb=c8382b2f0e3e409b9bbaef2fb1c46ebb29d2cab1;hpb=fbf473220b073d58ad19cfef0ad4616149077ecd diff --git a/notmuch.el b/notmuch.el index 7f087c72..a6cb8236 100644 --- a/notmuch.el +++ b/notmuch.el @@ -114,53 +114,52 @@ buffer." (if (not (re-search-forward notmuch-show-message-begin-regexp nil t)) (goto-char (point-max)))))) +(defun notmuch-show-move-to-current-message-summary-line () + "Move to the beginning of the one-line summary of the current message. + +This gives us a stable place to move to and work from since the +summary line is always visible. This is important since moving to +an invisible location is unreliable, (the main command loop moves +point either forward or backward to the next visible character +when a command ends with point on an invisible character). + +Emits an error if point is not within a valid message, (that is +not pattern of `notmuch-show-message-begin-regexp' could be found +by searching backward)." + (beginning-of-line) + (if (not (looking-at notmuch-show-message-begin-regexp)) + (if (re-search-backward notmuch-show-message-begin-regexp nil t) + (forward-line 2) + (error "Not within a valid message.")) + (forward-line 2))) + (defun notmuch-show-next-message () - "Advance point to the beginning of the next message in the buffer. + "Advance to the beginning of the next message in the buffer. -Does nothing if already on the last message." +Moves to the beginning of the current message if already on the +last message in the buffer." (interactive) - ; First, ensure we get off the current message marker - (if (not (eobp)) - (forward-char)) + (notmuch-show-move-to-current-message-summary-line) (re-search-forward notmuch-show-message-begin-regexp nil t) - ; This dance might look pointless, but it's important. I originally - ; just had (beginning-of-line) here which looked right on the - ; display but actually put point all the way back to the first - ; character of the first invisible line. That is, it put point into - ; the closing markers of the previous message rather than at the - ; beginning of the current message. And that in turn meant that - ; looking up the current message-ID would actually return the - ; previous message ID. - ; - ; So this dance ensures that we're actually on the current message - ; when it looks like we are. - (end-of-visible-line) - (beginning-of-line) + (notmuch-show-move-to-current-message-summary-line) (recenter 0)) (defun notmuch-show-previous-message () "Backup to the beginning of the previous message in the buffer. -Does nothing if already on the first message in the buffer." +If within a message rather than at the beginning of it, then +simply move to the beginning of the current message." (interactive) - ; First, ensure we get off the current message marker - (if (not (bobp)) - (previous-line)) - (re-search-backward notmuch-show-message-begin-regexp nil t) - ; This dance might look pointless, but it's important. I originally - ; just had (beginning-of-line) here which looked right on the - ; display but actually put point all the way back to the first - ; character of the first invisible line. That is, it put point into - ; the closing markers of the previous message rather than at the - ; beginning of the current message. And that in turn meant that - ; looking up the current message-ID would actually return the - ; previous message ID. - ; - ; So this dance ensures that we're actually on the current message - ; when it looks like we are. - (end-of-visible-line) - (beginning-of-line) - (recenter 0)) + (let ((start (point))) + (notmuch-show-move-to-current-message-summary-line) + (if (not (< (point) start)) + ; Go backward twice to skip the current message's marker + (progn + (re-search-backward notmuch-show-message-begin-regexp nil t) + (re-search-backward notmuch-show-message-begin-regexp nil t) + (notmuch-show-move-to-current-message-summary-line) + )) + (recenter 0))) (defun notmuch-show-mark-read-then-next-message () "Remove uread tag from current message, then advance to next message." @@ -199,10 +198,10 @@ Does nothing if already on the first message in the buffer." (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)