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

2012-02-06 Thread David Edmondson
With an argument, record and reply 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.

Traditional use of refresh with the = key does not retain the
state. The recently introduced toggle commands ($, !, < and >) do
retain the state.
---
 emacs/notmuch-show.el |   56 ++---
 1 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index db9292c..f23aa8d 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -948,7 +948,7 @@ current buffer, if possible."
   (message (if notmuch-show-process-crypto
   "Processing cryptographic MIME parts."
 "Not processing cryptographic MIME parts."))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))

 (defun notmuch-show-toggle-elide-non-matching ()
   "Toggle the display of non-matching messages."
@@ -957,7 +957,7 @@ current buffer, if possible."
   (message (if notmuch-show-elide-non-matching-messages
   "Showing matching messages only."
 "Showing all messages."))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))

 (defun notmuch-show-toggle-thread-indentation ()
   "Toggle the indentation of threads."
@@ -966,7 +966,7 @@ current buffer, if possible."
   (message (if notmuch-show-indent-content
   "Content is indented."
 "Content is not indented."))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))

 (defun notmuch-show-insert-tree (tree depth)
   "Insert the message tree TREE at depth DEPTH in the current thread."
@@ -1070,14 +1070,54 @@ function is used."

 (notmuch-show-mark-read)))

-(defun notmuch-show-refresh-view ()
+(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)))
+  (goto-char (point-min))
+  (message "Previously current message not found."))
+(notmuch-show-message-adjust)))
+
+(defun notmuch-show-refresh-view ( retain-state)
   "Refresh the current view.

-Refreshes the current view, observing changes in cryptographic preferences."
+Refreshes the current view, observing changes in display
+preferences. If RETAIN-STATE is non-nil then the state of the
+buffer is stored and re-applied after the refresh."
   (interactive)
-  (let ((inhibit-read-only t))
-(erase-buffer))
-  (notmuch-show-worker))
+  (let ((inhibit-read-only t)
+   state)
+(if retain-state
+   (setq state (notmuch-show-capture-state)))
+(erase-buffer)
+(notmuch-show-worker)
+(if state
+   (notmuch-show-apply-state state

 (defvar notmuch-show-stash-map
   (let ((map (make-sparse-keymap)))
-- 
1.7.8.3



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

2012-02-06 Thread David Edmondson
With an argument, record and reply 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.

Traditional use of refresh with the = key does not retain the
state. The recently introduced toggle commands ($, !,  and ) do
retain the state.
---
 emacs/notmuch-show.el |   56 ++---
 1 files changed, 48 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index db9292c..f23aa8d 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -948,7 +948,7 @@ current buffer, if possible.
   (message (if notmuch-show-process-crypto
   Processing cryptographic MIME parts.
 Not processing cryptographic MIME parts.))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))
 
 (defun notmuch-show-toggle-elide-non-matching ()
   Toggle the display of non-matching messages.
@@ -957,7 +957,7 @@ current buffer, if possible.
   (message (if notmuch-show-elide-non-matching-messages
   Showing matching messages only.
 Showing all messages.))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))
 
 (defun notmuch-show-toggle-thread-indentation ()
   Toggle the indentation of threads.
@@ -966,7 +966,7 @@ current buffer, if possible.
   (message (if notmuch-show-indent-content
   Content is indented.
 Content is not indented.))
-  (notmuch-show-refresh-view))
+  (notmuch-show-refresh-view t))
 
 (defun notmuch-show-insert-tree (tree depth)
   Insert the message tree TREE at depth DEPTH in the current thread.
@@ -1070,14 +1070,54 @@ function is used.
 
 (notmuch-show-mark-read)))
 
-(defun notmuch-show-refresh-view ()
+(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)))
+  (goto-char (point-min))
+  (message Previously current message not found.))
+(notmuch-show-message-adjust)))
+
+(defun notmuch-show-refresh-view (optional retain-state)
   Refresh the current view.
 
-Refreshes the current view, observing changes in cryptographic preferences.
+Refreshes the current view, observing changes in display
+preferences. If RETAIN-STATE is non-nil then the state of the
+buffer is stored and re-applied after the refresh.
   (interactive)
-  (let ((inhibit-read-only t))
-(erase-buffer))
-  (notmuch-show-worker))
+  (let ((inhibit-read-only t)
+   state)
+(if retain-state
+   (setq state (notmuch-show-capture-state)))
+(erase-buffer)
+(notmuch-show-worker)
+(if state
+   (notmuch-show-apply-state state
 
 (defvar notmuch-show-stash-map
   (let ((map (make-sparse-keymap)))
-- 
1.7.8.3

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch