unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 1/3] emacs: show: make refresh fix point(ish)
Date: Mon,  3 Dec 2012 00:58:35 +0000	[thread overview]
Message-ID: <1354496317-24564-2-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1354496317-24564-1-git-send-email-markwalters1009@gmail.com>

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

  reply	other threads:[~2012-12-03  0:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-03  0:58 [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart Mark Walters
2012-12-03  0:58 ` Mark Walters [this message]
2012-12-03  0:58 ` [PATCH v2 2/3] emacs: allow the user to toggle the visibility of multipart/alternative parts Mark Walters
2012-12-03  0:58 ` [PATCH v2 3/3] emacs: show make default part button toggle view when sensible Mark Walters
2012-12-03 22:45 ` [PATCH v2 0/3] Allow emacs to toggle display of all parts including multipart Mark Walters

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1354496317-24564-2-git-send-email-markwalters1009@gmail.com \
    --to=markwalters1009@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).