[PATCH 5/5] emacs: Retain the state of the buffer during `notmuch-show-refresh-view'.

David Edmondson dme at dme.org
Mon Jan 30 08:31:04 PST 2012


Record the state of the buffer during `notmuch-show-refresh-view'.

In this context, "state" is defined as:
 - the open/closed state of each message,
 - the current message.
---
 emacs/notmuch-show.el |   41 +++++++++++++++++++++++++++++++++++++----
 1 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 8b07adf..a77cd52 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1053,15 +1053,48 @@ function is used."
 
     (notmuch-show-mark-read)))
 
+(defun notmuch-show-capture-state ()
+  "Capture the state of the current buffer.
+
+This includes:
+ - the list of open messages,
+ - the current message."
+  (list (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.
+
+This includes:
+ - opening the messages previously opened,
+ - closing all other messages,
+ - moving to the correct current message."
+  (let ((current (car state))
+	(open (cadr state)))
+
+    ;; Open those that were open.
+    (goto-char (point-min))
+    (loop do (notmuch-show-message-visible (notmuch-show-get-message-properties)
+					   (member (notmuch-show-get-message-id) open))
+	  until (not (notmuch-show-goto-message-next)))
+
+    ;; Go to the previously open message.
+    (goto-char (point-min))
+    (unless (loop if (string= current (notmuch-show-get-message-id))
+		  return t
+		  until (not (notmuch-show-goto-message-next)))
+      (message "Previously current message not found."))))
+
 (defun notmuch-show-refresh-view ()
   "Refresh the current view.
 
 Refreshes the current view, observing changes in cryptographic preferences."
   (interactive)
-  (let ((inhibit-read-only t))
-    (erase-buffer))
-  (notmuch-show-worker notmuch-show-thread-id notmuch-show-parent-buffer
-		       notmuch-show-query-context))
+  (let ((inhibit-read-only t)
+	(state (notmuch-show-capture-state)))
+    (erase-buffer)
+    (notmuch-show-worker notmuch-show-thread-id notmuch-show-parent-buffer
+			 notmuch-show-query-context)
+    (notmuch-show-apply-state state)))
 
 (defvar notmuch-show-stash-map
   (let ((map (make-sparse-keymap)))
-- 
1.7.8.3



More information about the notmuch mailing list