--- /dev/null
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1DAF3431FC4\r
+ for <notmuch@notmuchmail.org>; Mon, 6 Feb 2012 01:21:40 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id nQdAiRY84qfR for <notmuch@notmuchmail.org>;\r
+ Mon, 6 Feb 2012 01:21:38 -0800 (PST)\r
+Received: from mail-we0-f181.google.com (mail-we0-f181.google.com\r
+ [74.125.82.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 73F99431FC3\r
+ for <notmuch@notmuchmail.org>; Mon, 6 Feb 2012 01:21:31 -0800 (PST)\r
+Received: by mail-we0-f181.google.com with SMTP id b10so4966843wer.26\r
+ for <notmuch@notmuchmail.org>; Mon, 06 Feb 2012 01:21:31 -0800 (PST)\r
+Received: by 10.216.134.160 with SMTP id s32mr6792296wei.36.1328520091144;\r
+ Mon, 06 Feb 2012 01:21:31 -0800 (PST)\r
+Received: from hotblack-desiato.hh.sledj.net\r
+ (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
+ by mx.google.com with ESMTPS id fl2sm7829213wib.1.2012.02.06.01.21.28\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Mon, 06 Feb 2012 01:21:29 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+ id 2B9D6A0F01; Mon, 6 Feb 2012 09:21:24 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v7 5/8] emacs: Optionally retain the state of the buffer\r
+ during `notmuch-show-refresh-view'.\r
+Date: Mon, 6 Feb 2012 09:21:19 +0000\r
+Message-Id: <1328520082-26659-6-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.8.3\r
+In-Reply-To: <1328520082-26659-1-git-send-email-dme@dme.org>\r
+References: <1327486729-18052-1-git-send-email-dme@dme.org>\r
+ <1328520082-26659-1-git-send-email-dme@dme.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 06 Feb 2012 09:21:40 -0000\r
+\r
+With an argument, record and reply the state of the buffer during\r
+`notmuch-show-refresh-view'.\r
+\r
+In this context, "state" is defined as:\r
+ - the open/closed state of each message,\r
+ - the current message.\r
+\r
+Traditional use of refresh with the = key does not retain the\r
+state. The recently introduced toggle commands ($, !, < and >) do\r
+retain the state.\r
+---\r
+ emacs/notmuch-show.el | 56 ++++++++++++++++++++++++++++++++++++++++++-------\r
+ 1 files changed, 48 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index db9292c..f23aa8d 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -948,7 +948,7 @@ current buffer, if possible."\r
+ (message (if notmuch-show-process-crypto\r
+ "Processing cryptographic MIME parts."\r
+ "Not processing cryptographic MIME parts."))\r
+- (notmuch-show-refresh-view))\r
++ (notmuch-show-refresh-view t))\r
+ \r
+ (defun notmuch-show-toggle-elide-non-matching ()\r
+ "Toggle the display of non-matching messages."\r
+@@ -957,7 +957,7 @@ current buffer, if possible."\r
+ (message (if notmuch-show-elide-non-matching-messages\r
+ "Showing matching messages only."\r
+ "Showing all messages."))\r
+- (notmuch-show-refresh-view))\r
++ (notmuch-show-refresh-view t))\r
+ \r
+ (defun notmuch-show-toggle-thread-indentation ()\r
+ "Toggle the indentation of threads."\r
+@@ -966,7 +966,7 @@ current buffer, if possible."\r
+ (message (if notmuch-show-indent-content\r
+ "Content is indented."\r
+ "Content is not indented."))\r
+- (notmuch-show-refresh-view))\r
++ (notmuch-show-refresh-view t))\r
+ \r
+ (defun notmuch-show-insert-tree (tree depth)\r
+ "Insert the message tree TREE at depth DEPTH in the current thread."\r
+@@ -1070,14 +1070,54 @@ function is used."\r
+ \r
+ (notmuch-show-mark-read)))\r
+ \r
+-(defun notmuch-show-refresh-view ()\r
++(defun notmuch-show-capture-state ()\r
++ "Capture the state of the current buffer.\r
++\r
++This includes:\r
++ - the list of open messages,\r
++ - the current message."\r
++ (list (notmuch-show-get-message-id) (notmuch-show-get-message-ids-for-open-messages)))\r
++\r
++(defun notmuch-show-apply-state (state)\r
++ "Apply STATE to the current buffer.\r
++\r
++This includes:\r
++ - opening the messages previously opened,\r
++ - closing all other messages,\r
++ - moving to the correct current message."\r
++ (let ((current (car state))\r
++ (open (cadr state)))\r
++\r
++ ;; Open those that were open.\r
++ (goto-char (point-min))\r
++ (loop do (notmuch-show-message-visible (notmuch-show-get-message-properties)\r
++ (member (notmuch-show-get-message-id) open))\r
++ until (not (notmuch-show-goto-message-next)))\r
++\r
++ ;; Go to the previously open message.\r
++ (goto-char (point-min))\r
++ (unless (loop if (string= current (notmuch-show-get-message-id))\r
++ return t\r
++ until (not (notmuch-show-goto-message-next)))\r
++ (goto-char (point-min))\r
++ (message "Previously current message not found."))\r
++ (notmuch-show-message-adjust)))\r
++\r
++(defun notmuch-show-refresh-view (&optional retain-state)\r
+ "Refresh the current view.\r
+ \r
+-Refreshes the current view, observing changes in cryptographic preferences."\r
++Refreshes the current view, observing changes in display\r
++preferences. If RETAIN-STATE is non-nil then the state of the\r
++buffer is stored and re-applied after the refresh."\r
+ (interactive)\r
+- (let ((inhibit-read-only t))\r
+- (erase-buffer))\r
+- (notmuch-show-worker))\r
++ (let ((inhibit-read-only t)\r
++ state)\r
++ (if retain-state\r
++ (setq state (notmuch-show-capture-state)))\r
++ (erase-buffer)\r
++ (notmuch-show-worker)\r
++ (if state\r
++ (notmuch-show-apply-state state))))\r
+ \r
+ (defvar notmuch-show-stash-map\r
+ (let ((map (make-sparse-keymap)))\r
+-- \r
+1.7.8.3\r
+\r