--- /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 857E7431FC0\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Jul 2014 10:56:10 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.7\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.7 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
+ FREEMAIL_REPLY=2.499, 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 c9bSoQFTCfTv for <notmuch@notmuchmail.org>;\r
+ Wed, 16 Jul 2014 10:56:05 -0700 (PDT)\r
+Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com\r
+ [209.85.212.180]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id D42E8431FBD\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Jul 2014 10:56:04 -0700 (PDT)\r
+Received: by mail-wi0-f180.google.com with SMTP id n3so1787077wiv.7\r
+ for <notmuch@notmuchmail.org>; Wed, 16 Jul 2014 10:56:02 -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;\r
+ bh=T2Go5F+rzQh6l6ku5sDQfFV8eeO2ywGp+dnuq4ZVRjQ=;\r
+ b=FIe6T/fuvbsFpT2Y0BTaY+gqNHI8jU6sLZ33hmvc+Q0lO5Orfv7V9uGCHIy5sfv5zW\r
+ BgNEbz307W28OmmvTO2UF6mHRbSlcB56tKNIfrOEyrtGmiYVAZkSAH/7Bnbz8aVKPz0b\r
+ m0GvGc5ilKnXjkMYlF05ochc44RjDU4+X/0UkpeyLL9aLn6O4S8Xl5YVbY1f8haheQw5\r
+ EC3+OHh2TiQ/Fco/rWY4RGNWU7idlBEe5vJ5kxT9b8+58C2l5SVZ1GFl/yBozSo+DlVf\r
+ P9ow/uuK2WgFK93wgXqY4cv05mj9BBNX5wJ8NzaRgHJoAeK4LREorqxtraWukPJ5KbCi\r
+ BgIw==\r
+X-Received: by 10.194.92.115 with SMTP id cl19mr38437606wjb.29.1405533362352; \r
+ Wed, 16 Jul 2014 10:56:02 -0700 (PDT)\r
+Received: from localhost ([194.42.225.52])\r
+ by mx.google.com with ESMTPSA id hi2sm55656wjb.29.2014.07.16.10.56.01\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Wed, 16 Jul 2014 10:56:01 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: show: mark messages unread if seen in buffer\r
+Date: Wed, 16 Jul 2014 18:55:39 +0100\r
+Message-Id: <1405533339-7666-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.10.4\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: Wed, 16 Jul 2014 17:56:10 -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
+---\r
+This adds my preferred mark unread function as an option: see\r
+id:1399650320-1382-1-git-send-email-markwalters1009@gmail.com for a\r
+previous version. This version moves this functions configuration\r
+parameter inside the defcustom. I am not sure if this (using :set) is\r
+the best way to do that but it works and will work if other people\r
+want to add functions which have parameters too.\r
+\r
+Best wishes \r
+\r
+Mark\r
+\r
+\r
+\r
+ emacs/notmuch-show.el | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-\r
+ 1 file changed, 75 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 529baa9..9563a74 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -225,7 +225,29 @@ For example, if you wanted to remove an \"unread\" tag and add a\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
++ :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
++ (list :format "%v"\r
++ (const :tag "Mark read if enough of the message has been visible" notmuch-show-do-seen)\r
++ (number :format "%h %v"\r
++ :doc "Proportion or Lines needed\r
++\r
++A message is marked read if both the top of the message\r
++and a point far \"enough\" down in the message have each been\r
++visible in the buffer at some point. This parameter controls the\r
++definition of enough. Seeing the bottom of message is always\r
++deemed enough. Additionally, it is deemed enough if a point n\r
++lines into the message has been visible in the window where n is\r
++this variable if this variable is an integer and n is this\r
++variable times the height of the window if this variable is a\r
++float."\r
++ :value 0.75))\r
++ (function))\r
++ :set (lambda (symbol value) (if (listp value)\r
++ (set-default symbol (apply 'apply-partially (car value) (cdr value)))\r
++ (set-default symbol value)))\r
+ :group 'notmuch-show)\r
+ \r
+ (defmacro with-current-notmuch-show-message (&rest body)\r
+@@ -1569,6 +1591,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 (needed start end)\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