--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\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 192A3431FBF\r
+ for <notmuch@notmuchmail.org>; Thu, 8 May 2014 17:20:28 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ 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 D2Fo8i94+dD7 for <notmuch@notmuchmail.org>;\r
+ Thu, 8 May 2014 17:20:24 -0700 (PDT)\r
+Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com\r
+ [209.85.212.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 0A03B431FC0\r
+ for <notmuch@notmuchmail.org>; Thu, 8 May 2014 17:20:23 -0700 (PDT)\r
+Received: by mail-wi0-f169.google.com with SMTP id hi2so1775839wib.0\r
+ for <notmuch@notmuchmail.org>; Thu, 08 May 2014 17:20:22 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
+ bh=vluGkX3vL5l6nusE434lNUa06J/f/OoNW38OHt2K/Us=;\r
+ b=dDrJZlBrsuaxV5cE9vwt6TsYGnhxW9csHXYqfJaPaT/waxqPJgoD3QC4qZqiVAR0Q9\r
+ xpPiqi2LOjhc5/G2RUZvf4OY35nUUNayXwpHT/dlmdiqwXSbwIcTs1BM/0U5z/NEv6Vh\r
+ 4k5GoWCL7Rob9baVpDgKeGGIAHtd/jDSo0Gs5MLLfrkWqs8rjGiZ4Th03iey1+kO95VB\r
+ WiqJZcDDQd51hee3BCn90YdcYR+S0bAvpCy9e9YcFzpR1ClBURmhrML9y9ywR/K9h+9i\r
+ hHNkrooqs1qXL7PYpSM+m5mp+pH0s7nC7HNKI0Rrs636ZdKTeONQOP3tOTes3Fq5yTlO\r
+ 8aDw==\r
+X-Received: by 10.194.80.7 with SMTP id n7mr5688320wjx.8.1399594822949;\r
+ Thu, 08 May 2014 17:20:22 -0700 (PDT)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by mx.google.com with ESMTPSA id iy13sm2048708wic.1.2014.05.08.17.20.22\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Thu, 08 May 2014 17:20:22 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 2/2] emacs: show: add an update seen function to\r
+ post-command-hook\r
+Date: Fri, 9 May 2014 01:20:08 +0100\r
+Message-Id: <1399594808-2815-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1399594808-2815-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1399594808-2815-1-git-send-email-markwalters1009@gmail.com>\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: Fri, 09 May 2014 00:20:28 -0000\r
+\r
+Add a function for updating seen messages to the\r
+post-command-hook. This function calls a customizable (by eg\r
+defcustom) function with parameters the start and end of the current\r
+window and that function can decide what to mark read based on that\r
+and the current point.\r
+\r
+Since this is in the post-command-hook it should get called after most\r
+user actions (exceptions include user resizing the window) so it\r
+should be possible to make sure the seen status gets updated whether\r
+the user uses notmuch commands like next-message or normal emacs\r
+commands like scroll-up.\r
+\r
+It removes all of the old mark read/seen points but introduces a\r
+simple example function that just marks the current message read if it\r
+is open. This function has one small subtlety: it makes sure it\r
+doesn't mark the same message read twice (in the same instance of the\r
+same buffer); otherwise the post-command-hook makes it impossible for\r
+a user to manually mark a message unread.\r
+\r
+This fixes the current bugs (imo) that closed messages can be marked\r
+read, and that opening a closed message does not mark it read.\r
+\r
+Another advantage of using the post-command-hook any programmatic use\r
+with point passing through a message will not mark it read.\r
+---\r
+ emacs/notmuch-show.el | 43 ++++++++++++++++++++++++++++---------------\r
+ 1 file changed, 28 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 10fc872..2620f84 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -222,6 +222,10 @@ (defcustom notmuch-show-mark-read-tags '("-unread")\r
+ :type '(repeat string)\r
+ :group 'notmuch-show)\r
+ \r
++(defcustom notmuch-show-mark-read-function #'notmuch-show-seen-current-message\r
++ "Function to control which messages are marked read."\r
++ :type 'function\r
++ :group 'notmuch-show)\r
+ \r
+ (defmacro with-current-notmuch-show-message (&rest body)\r
+ "Evaluate body with current buffer set to the text of current message"\r
+@@ -1156,6 +1160,8 @@ (defun notmuch-show-build-buffer ()\r
+ (let ((inhibit-read-only t))\r
+ \r
+ (notmuch-show-mode)\r
++ (add-hook 'post-command-hook #'notmuch-show-command-hook nil t)\r
++\r
+ ;; Don't track undo information for this buffer\r
+ (set 'buffer-undo-list t)\r
+ \r
+@@ -1544,6 +1550,23 @@ (defun notmuch-show-mark-read (&optional unread)\r
+ (apply 'notmuch-show-tag-message\r
+ (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))\r
+ \r
++(defun notmuch-show-seen-current-message (start end)\r
++ "Mark the current message read if it is open.\r
++\r
++We only mark it read once: if it is changed back then that is a\r
++user decision and we should not override it."\r
++ (when (and (notmuch-show-message-visible-p)\r
++ (not (notmuch-show-get-prop :seen)))\r
++ (notmuch-show-mark-read)\r
++ (notmuch-show-set-prop :seen t)))\r
++\r
++(defun notmuch-show-command-hook ()\r
++ (when (eq major-mode 'notmuch-show-mode)\r
++ ;; We need to redisplay to get window-start and window-end correct.\r
++ (redisplay)\r
++ (save-excursion\r
++ (funcall notmuch-show-mark-read-function (window-start) (window-end)))))\r
++\r
+ ;; Functions for getting attributes of several messages in the current\r
+ ;; thread.\r
+ \r
+@@ -1679,9 +1702,7 @@ (defun notmuch-show-next-message (&optional pop-at-end)\r
+ thread, navigate to the next thread in the parent search buffer."\r
+ (interactive "P")\r
+ (if (notmuch-show-goto-message-next)\r
+- (progn\r
+- (notmuch-show-mark-read)\r
+- (notmuch-show-message-adjust))\r
++ (notmuch-show-message-adjust)\r
+ (if pop-at-end\r
+ (notmuch-show-next-thread)\r
+ (goto-char (point-max)))))\r
+@@ -1692,7 +1713,6 @@ (defun notmuch-show-previous-message ()\r
+ (if (= (point) (notmuch-show-message-top))\r
+ (notmuch-show-goto-message-previous)\r
+ (notmuch-show-move-to-message-top))\r
+- (notmuch-show-mark-read)\r
+ (notmuch-show-message-adjust))\r
+ \r
+ (defun notmuch-show-next-open-message (&optional pop-at-end)\r
+@@ -1707,9 +1727,7 @@ (defun notmuch-show-next-open-message (&optional pop-at-end)\r
+ (while (and (setq r (notmuch-show-goto-message-next))\r
+ (not (notmuch-show-message-visible-p))))\r
+ (if r\r
+- (progn\r
+- (notmuch-show-mark-read)\r
+- (notmuch-show-message-adjust))\r
++ (notmuch-show-message-adjust)\r
+ (if pop-at-end\r
+ (notmuch-show-next-thread)\r
+ (goto-char (point-max))))\r
+@@ -1722,9 +1740,7 @@ (defun notmuch-show-next-matching-message ()\r
+ (while (and (setq r (notmuch-show-goto-message-next))\r
+ (not (notmuch-show-get-prop :match))))\r
+ (if r\r
+- (progn\r
+- (notmuch-show-mark-read)\r
+- (notmuch-show-message-adjust))\r
++ (notmuch-show-message-adjust)\r
+ (goto-char (point-max)))))\r
+ \r
+ (defun notmuch-show-open-if-matched ()\r
+@@ -1735,8 +1751,7 @@ (defun notmuch-show-open-if-matched ()\r
+ (defun notmuch-show-goto-first-wanted-message ()\r
+ "Move to the first open message and mark it read"\r
+ (goto-char (point-min))\r
+- (if (notmuch-show-message-visible-p)\r
+- (notmuch-show-mark-read)\r
++ (unless (notmuch-show-message-visible-p)\r
+ (notmuch-show-next-open-message))\r
+ (when (eobp)\r
+ ;; There are no matched non-excluded messages so open all matched\r
+@@ -1744,8 +1759,7 @@ (defun notmuch-show-goto-first-wanted-message ()\r
+ (notmuch-show-mapc 'notmuch-show-open-if-matched)\r
+ (force-window-update)\r
+ (goto-char (point-min))\r
+- (if (notmuch-show-message-visible-p)\r
+- (notmuch-show-mark-read)\r
++ (unless (notmuch-show-message-visible-p)\r
+ (notmuch-show-next-open-message))))\r
+ \r
+ (defun notmuch-show-previous-open-message ()\r
+@@ -1755,7 +1769,6 @@ (defun notmuch-show-previous-open-message ()\r
+ (notmuch-show-goto-message-previous)\r
+ (notmuch-show-move-to-message-top))\r
+ (not (notmuch-show-message-visible-p))))\r
+- (notmuch-show-mark-read)\r
+ (notmuch-show-message-adjust))\r
+ \r
+ (defun notmuch-show-view-raw-message ()\r
+-- \r
+1.7.10.4\r
+\r