--- /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 A6A80431FC9\r
+ for <notmuch@notmuchmail.org>; Sat, 6 Sep 2014 09:22:29 -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 aS7uEH18ZMXQ for <notmuch@notmuchmail.org>;\r
+ Sat, 6 Sep 2014 09:22:24 -0700 (PDT)\r
+Received: from mail-we0-f179.google.com (mail-we0-f179.google.com\r
+ [74.125.82.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 74CE9431FBD\r
+ for <notmuch@notmuchmail.org>; Sat, 6 Sep 2014 09:22:19 -0700 (PDT)\r
+Received: by mail-we0-f179.google.com with SMTP id t60so13004364wes.38\r
+ for <notmuch@notmuchmail.org>; Sat, 06 Sep 2014 09:22:18 -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=KjyWvD6uthdBToASOkGKWvGoe4QzlekxHceLBhw5fUk=;\r
+ b=dKjq2dpM0nnBlNl1G1Opv4Ki6upsA8OPg6nKLgMQz49kPHUBd5xRtKD4JtgH1XAZTV\r
+ rVtiFM+EK2c+wFUuaQp7sQp5u4cwVH2ezL3EHf+AXx8skRZVtvkUOAGmoRLU+w7X8pv/\r
+ wiiEnSAbaCne9xSlIQyqYFSB05SXaQuNkfrRGlZY3UPXLV2uBhnny1oPEGO2+fr1y2Eq\r
+ x+vExw8ohAnbZs/oSQ34c/K4+gzNkrNKZXYCZtQNGtPFOhJDhk4R/nUo/BpEoldZj6j8\r
+ dgrj7do18+IuhE0hzB410N7tYdZZ6FvifLc29CUtj0Hg4Nv5zICkjaKv8U5bwXETxO6R\r
+ VI3g==\r
+X-Received: by 10.194.58.244 with SMTP id u20mr22729067wjq.36.1410020538330;\r
+ Sat, 06 Sep 2014 09:22:18 -0700 (PDT)\r
+Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
+ by mx.google.com with ESMTPSA id h6sm4976836wjb.33.2014.09.06.09.22.17\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 06 Sep 2014 09:22:17 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [Patch v2 2/2] emacs: show: mark messages unread if seen in buffer\r
+Date: Sat, 6 Sep 2014 17:22:11 +0100\r
+Message-Id: <1410020531-24419-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1410020531-24419-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1410020531-24419-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: Sat, 06 Sep 2014 16:22:29 -0000\r
+\r
+This adds a function that marks messages unread if they are "seen"\r
+that is a user configurable amount of them has been visible in the\r
+buffer.\r
+---\r
+ emacs/notmuch-show.el | 74 ++++++++++++++++++++++++++++++++++++++++++++++++-\r
+ 1 file changed, 73 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 5695d95..7d2c5d2 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -231,7 +231,27 @@ be the start and end of the visible portion of the buffer and\r
+ should mark the appropriate messages read by applying\r
+ `notmuch-show-mark-read'. This function will be called after\r
+ every user interaction with notmuch."\r
+- :type 'function\r
++ :type '(radio (const :format "%h" :doc "Mark current message read.\r
++\r
++Marks the message containing point read."\r
++ notmuch-show-seen-current-message)\r
++ (group :format "%v"\r
++ (const :inline t :format "" (lambda (start end)))\r
++ (list :format "%h %v\n"\r
++ :doc "Mark read if enough of the message has been visible.\r
++\r
++A message is marked read if both the top of the message and a\r
++point far \"enough\" down in the message have each been visible\r
++in the buffer at some point. The definition of enough is\r
++controlled by the following paramater. Seeing the bottom of message is\r
++always deemed enough. Additionally, it is deemed enough if a\r
++point n lines into the message has been visible in the window\r
++where n is this variable if this variable is an integer and n is\r
++this variable times the height of the window if this variable is\r
++a float."\r
++ (const :inline t :tag "" :format "" (notmuch-show-do-seen start end))\r
++ (number :tag "Proportion needed" 0.75)))\r
++ (function))\r
+ :group 'notmuch-show)\r
+ \r
+ (defmacro with-current-notmuch-show-message (&rest body)\r
+@@ -1576,6 +1596,58 @@ marked as unread, i.e. the tag changes in\r
+ (apply 'notmuch-show-tag-message\r
+ (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))\r
+ \r
++(defun notmuch-show-update-seen (top-or-bottom)\r
++ "Update seen status of current message\r
++\r
++Mark that we have seen the TOP-OR-BOTTOM of current message."\r
++ (let ((current (notmuch-show-get-prop :seen)))\r
++ (unless (or (eq current 'both) (eq current top-or-bottom))\r
++ (if (not current)\r
++ (notmuch-show-set-prop :seen top-or-bottom)\r
++ (notmuch-show-set-prop :seen 'both)\r
++ (notmuch-show-mark-read)))))\r
++\r
++(defun notmuch-show-do-message-seen (needed start end)\r
++ "Update seen status for the current message.\r
++\r
++A message is seen if both the top and enough of the rest of the\r
++message have been visible in the buffer. Enough means either the\r
++bottom of the message or a point in the message more than\r
++LINES-NEEDED lines into the message. LINES-NEEDED is\r
++NEEDED if NEEDED is an integer and NEEDED\r
++times the current window height if NEEDED is a float."\r
++ (let* ((lines-needed (if (integerp needed)\r
++ needed\r
++ (truncate (* needed (window-body-height)))))\r
++ (top (notmuch-show-message-top))\r
++ (bottom (notmuch-show-message-bottom)))\r
++ (when (notmuch-show-message-visible-p)\r
++ (when (>= top start)\r
++ (notmuch-show-update-seen 'top))\r
++ (when (or (<= bottom end)\r
++ (> (count-screen-lines top end) lines-needed))\r
++ (notmuch-show-update-seen 'bottom)))))\r
++\r
++(defun notmuch-show-do-seen (start end needed)\r
++ "Update seen status for all messages between start and end.\r
++\r
++We mark the top (bottom) of a message seen if the top (enough of\r
++the rest of the message) respectively have been visible in the\r
++buffer. See `notmuch-show-do-message-seen` for the definition of\r
++enough. When both the top and bottom have been seen we mark the\r
++message read."\r
++ (save-excursion\r
++ (goto-char start)\r
++ (notmuch-show-do-message-seen needed start end)\r
++ (while (and (< (notmuch-show-message-bottom) end)\r
++ (notmuch-show-goto-message-next))\r
++ (notmuch-show-do-message-seen needed start end))\r
++ ;; This is a work around because emacs gives weird answers for\r
++ ;; window-end if the buffer ends with invisible text.\r
++ (when (and (pos-visible-in-window-p (point-max))\r
++ (notmuch-show-message-visible-p))\r
++ (notmuch-show-update-seen 'bottom))))\r
++\r
+ (defun notmuch-show-seen-current-message (start end)\r
+ "Mark the current message read if it is open.\r
+ \r
+-- \r
+1.7.10.4\r
+\r