[PATCH v2 1/3] emacs: show: make refresh fix point(ish)

Mark Walters markwalters1009 at gmail.com
Sun Dec 2 16:58:35 PST 2012


This makes a moderate attempt to keep the screen and point in the same
place when refreshing (unless we are resetting state). It does this by
moving to the same point relative to the start of the message, and
moving that to the same line position in the screen relative to the
top of the window.

This fixes some mild annoyances like the whole message resetting when
toggling indentation when reading a diff (ie currently you lose your
place). It also makes the follow up patches in this series for
toggling parts work much more nicely.
---
 emacs/notmuch-show.el |   25 ++++++++++++++++++-------
 1 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 489e32c..cc0487c 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1137,8 +1137,13 @@ function is used."
 
 This includes:
  - the list of open messages,
- - the current message."
-  (list (notmuch-show-get-message-id) (notmuch-show-get-message-ids-for-open-messages)))
+ - the current message
+ - point relative to the top of this message
+ - current line number on screen of point."
+  (list (count-lines (window-start) (point))
+	(- (point) (notmuch-show-message-top))
+	(notmuch-show-get-message-id)
+	(notmuch-show-get-message-ids-for-open-messages)))
 
 (defun notmuch-show-apply-state (state)
   "Apply STATE to the current buffer.
@@ -1147,8 +1152,10 @@ This includes:
  - opening the messages previously opened,
  - closing all other messages,
  - moving to the correct current message."
-  (let ((current (car state))
-	(open (cadr state)))
+  (let* ((height (pop state))
+	 (relative-point (pop state))
+	 (current (pop state))
+	 (open (pop state)))
 
     ;; Open those that were open.
     (goto-char (point-min))
@@ -1158,12 +1165,16 @@ This includes:
 
     ;; Go to the previously open message.
     (goto-char (point-min))
-    (unless (loop if (string= current (notmuch-show-get-message-id))
+    (if (loop if (string= current (notmuch-show-get-message-id))
 		  return t
 		  until (not (notmuch-show-goto-message-next)))
+	(progn
+	  (notmuch-show-message-adjust)
+	  (forward-char relative-point)
+	  (recenter height))
       (goto-char (point-min))
-      (message "Previously current message not found."))
-    (notmuch-show-message-adjust)))
+      (message "Previously current message not found.")
+      (notmuch-show-message-adjust))))
 
 (defun notmuch-show-refresh-view (&optional reset-state)
   "Refresh the current view.
-- 
1.7.9.1



More information about the notmuch mailing list