[PATCH 1/5] emacs: show: make `seen' mean user viewed whole message
authorMark Walters <markwalters1009@gmail.com>
Sat, 14 Dec 2013 23:44:32 +0000 (23:44 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:58:43 +0000 (09:58 -0800)
f1/1eb1aa9533b0afa8d1ae625842117ca291ebc9 [new file with mode: 0644]

diff --git a/f1/1eb1aa9533b0afa8d1ae625842117ca291ebc9 b/f1/1eb1aa9533b0afa8d1ae625842117ca291ebc9
new file mode 100644 (file)
index 0000000..b2b961c
--- /dev/null
@@ -0,0 +1,170 @@
+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 770D5431FD6\r
+       for <notmuch@notmuchmail.org>; Sat, 14 Dec 2013 15:44:53 -0800 (PST)\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 rr3gZQOuODwK for <notmuch@notmuchmail.org>;\r
+       Sat, 14 Dec 2013 15:44:48 -0800 (PST)\r
+Received: from mail-wi0-f194.google.com (mail-wi0-f194.google.com\r
+       [209.85.212.194]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id C5A47431FD0\r
+       for <notmuch@notmuchmail.org>; Sat, 14 Dec 2013 15:44:47 -0800 (PST)\r
+Received: by mail-wi0-f194.google.com with SMTP id e4so293234wiv.9\r
+       for <notmuch@notmuchmail.org>; Sat, 14 Dec 2013 15:44:46 -0800 (PST)\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=VKppVlhkumcYb6e3h/MgHQaeYzWWMYjKK63rruOZ0LQ=;\r
+       b=KYs7Ex44uv0SB4gXvELpvGTJHYNDJeNiI7CH1d/ZVUeS2oL6SV5jLaiUvWluG5Oe7P\r
+       sKcxOc6fBU8kAFYHTvgi0hf8y9pUF9BVCs/epbxjRLepnNQY/u3f/eyOhhoZrOqtxU7b\r
+       f8Tbbyz2xYC1a4pGpPxQHzEzBfLC3b0kUg6Z75Q4IkK+D7K3ZucNjNmEdff9XO42xnHk\r
+       5rSKfi/1kppWsX/18fyEjXQtPETgQcFvHYeR5vJEl2GtM8E2W4pTH6wYvLgl3lgPr03G\r
+       nguh7bonFvSCv9wm78+5gRrN4lKxr5UGhIw/LyQ/FtYRQwJl3kCg6vUB41QgPuSmNqJV\r
+       SilQ==\r
+X-Received: by 10.180.189.49 with SMTP id gf17mr8034142wic.23.1387064686581;\r
+       Sat, 14 Dec 2013 15:44:46 -0800 (PST)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPSA id fj8sm28126705wib.1.2013.12.14.15.44.45\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sat, 14 Dec 2013 15:44:46 -0800 (PST)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/5] emacs: show: make `seen' mean user viewed whole message\r
+Date: Sat, 14 Dec 2013 23:44:32 +0000\r
+Message-Id: <1387064676-15508-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1387064676-15508-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1387064676-15508-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, 14 Dec 2013 23:44:53 -0000\r
+\r
+This changes `seen' to mean that the user viewed `enough' of the whole\r
+message: more precisely, a message is deemed seen if the top of the\r
+message and either the bottom of the message or a point at least some\r
+customisable number of lines into the message have each been visible\r
+in the buffer at some point.\r
+\r
+This is placed into the post-command-hook infrastructure introudced in\r
+the previous patch.\r
+---\r
+ emacs/notmuch-show.el |   73 +++++++++++++++++++++++++++++++++++++++++++++++-\r
+ 1 files changed, 71 insertions(+), 2 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 51366e9..4850bd0 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -211,6 +211,19 @@ For example, if you wanted to remove an \"unread\" tag and add a\r
+   :type '(repeat string)\r
+   :group 'notmuch-show)\r
\r
++(defcustom notmuch-show-seen-lines-needed 0.75\r
++  "Control which messages get marked seen.\r
++\r
++A message is marked seen 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. This parameter controls the\r
++definition of enough.  Seeing the bottom of message is always\r
++deemed enough, but additionally...it an integer n then at least n\r
++lines of message must be visible in the window. If it is a float\r
++x then at least that proportion of the window must contain the\r
++message."\r
++  :type 'number\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
+@@ -1541,9 +1554,65 @@ 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-local))\r
++       new)\r
++    (unless (eq current 'both)\r
++      (if (eq top-or-bottom 'top)\r
++        (if (eq current 'bottom)\r
++            (setq new 'both)\r
++          (setq new 'top))\r
++      (if (eq current 'top)\r
++          (setq new 'both)\r
++        (setq new 'bottom)))\r
++      (unless (eq current new)\r
++      (notmuch-show-set-prop :seen-local new))\r
++      (when (eq new 'both)\r
++      (notmuch-show-mark-read)))))\r
++\r
++(defun notmuch-show-do-message-seen (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
++`notmuch-show-seen-lines-needed` if that is an integer and that\r
++times the current window height if it is a float."\r
++  (let* ((lines-needed (if (integerp notmuch-show-seen-lines-needed)\r
++                         notmuch-show-seen-lines-needed\r
++                       (truncate (* notmuch-show-seen-lines-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)\r
+-  "Update seen status for all messages between start and end."\r
+-  )\r
++  "Update seen status for all messages between start and end.\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. See\r
++`notmuch-show-do-message-seen` for the definition of enough. Seen\r
++is a buffer local property. The unread status is removed from all\r
++seen messages when the user quits the show buffer."\r
++  (save-excursion\r
++    (goto-char start)\r
++    (while (and (or (notmuch-show-do-message-seen start end) t)\r
++              (< (notmuch-show-message-bottom) end)\r
++              (notmuch-show-goto-message-next)))\r
++\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-command-hook ()\r
+   (when (eq major-mode 'notmuch-show-mode)\r
+-- \r
+1.7.9.1\r
+\r