1 Return-Path: <markwalters1009@gmail.com>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 857E7431FC0
\r
6 for <notmuch@notmuchmail.org>; Wed, 16 Jul 2014 10:56:10 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=2.7 tagged_above=-999 required=5
\r
12 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
\r
13 FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,
\r
14 FREEMAIL_REPLY=2.499, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
15 Received: from olra.theworths.org ([127.0.0.1])
\r
16 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
17 with ESMTP id c9bSoQFTCfTv for <notmuch@notmuchmail.org>;
\r
18 Wed, 16 Jul 2014 10:56:05 -0700 (PDT)
\r
19 Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com
\r
20 [209.85.212.180]) (using TLSv1 with cipher RC4-SHA (128/128 bits))
\r
21 (No client certificate requested)
\r
22 by olra.theworths.org (Postfix) with ESMTPS id D42E8431FBD
\r
23 for <notmuch@notmuchmail.org>; Wed, 16 Jul 2014 10:56:04 -0700 (PDT)
\r
24 Received: by mail-wi0-f180.google.com with SMTP id n3so1787077wiv.7
\r
25 for <notmuch@notmuchmail.org>; Wed, 16 Jul 2014 10:56:02 -0700 (PDT)
\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
\r
27 h=from:to:cc:subject:date:message-id;
\r
28 bh=T2Go5F+rzQh6l6ku5sDQfFV8eeO2ywGp+dnuq4ZVRjQ=;
\r
29 b=FIe6T/fuvbsFpT2Y0BTaY+gqNHI8jU6sLZ33hmvc+Q0lO5Orfv7V9uGCHIy5sfv5zW
\r
30 BgNEbz307W28OmmvTO2UF6mHRbSlcB56tKNIfrOEyrtGmiYVAZkSAH/7Bnbz8aVKPz0b
\r
31 m0GvGc5ilKnXjkMYlF05ochc44RjDU4+X/0UkpeyLL9aLn6O4S8Xl5YVbY1f8haheQw5
\r
32 EC3+OHh2TiQ/Fco/rWY4RGNWU7idlBEe5vJ5kxT9b8+58C2l5SVZ1GFl/yBozSo+DlVf
\r
33 P9ow/uuK2WgFK93wgXqY4cv05mj9BBNX5wJ8NzaRgHJoAeK4LREorqxtraWukPJ5KbCi
\r
35 X-Received: by 10.194.92.115 with SMTP id cl19mr38437606wjb.29.1405533362352;
\r
36 Wed, 16 Jul 2014 10:56:02 -0700 (PDT)
\r
37 Received: from localhost ([194.42.225.52])
\r
38 by mx.google.com with ESMTPSA id hi2sm55656wjb.29.2014.07.16.10.56.01
\r
39 for <multiple recipients>
\r
40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
\r
41 Wed, 16 Jul 2014 10:56:01 -0700 (PDT)
\r
42 From: Mark Walters <markwalters1009@gmail.com>
\r
43 To: notmuch@notmuchmail.org
\r
44 Subject: [PATCH] emacs: show: mark messages unread if seen in buffer
\r
45 Date: Wed, 16 Jul 2014 18:55:39 +0100
\r
46 Message-Id: <1405533339-7666-1-git-send-email-markwalters1009@gmail.com>
\r
47 X-Mailer: git-send-email 1.7.10.4
\r
48 X-BeenThere: notmuch@notmuchmail.org
\r
49 X-Mailman-Version: 2.1.13
\r
51 List-Id: "Use and development of the notmuch mail system."
\r
52 <notmuch.notmuchmail.org>
\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
54 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
56 List-Post: <mailto:notmuch@notmuchmail.org>
\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
59 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
60 X-List-Received-Date: Wed, 16 Jul 2014 17:56:10 -0000
\r
62 This adds a function that marks messages unread if they are "seen"
\r
63 that is a user configurable amount of them has been visible in the
\r
67 This adds my preferred mark unread function as an option: see
\r
68 id:1399650320-1382-1-git-send-email-markwalters1009@gmail.com for a
\r
69 previous version. This version moves this functions configuration
\r
70 parameter inside the defcustom. I am not sure if this (using :set) is
\r
71 the best way to do that but it works and will work if other people
\r
72 want to add functions which have parameters too.
\r
80 emacs/notmuch-show.el | 76 ++++++++++++++++++++++++++++++++++++++++++++++++-
\r
81 1 file changed, 75 insertions(+), 1 deletion(-)
\r
83 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
\r
84 index 529baa9..9563a74 100644
\r
85 --- a/emacs/notmuch-show.el
\r
86 +++ b/emacs/notmuch-show.el
\r
87 @@ -225,7 +225,29 @@ For example, if you wanted to remove an \"unread\" tag and add a
\r
89 (defcustom notmuch-show-mark-read-function #'notmuch-show-seen-current-message
\r
90 "Function to control which messages are marked read."
\r
92 + :type '(radio (const :format "%h" :doc "Mark current message read.
\r
94 +Marks the message containing point read."
\r
95 + notmuch-show-seen-current-message)
\r
96 + (list :format "%v"
\r
97 + (const :tag "Mark read if enough of the message has been visible" notmuch-show-do-seen)
\r
98 + (number :format "%h %v"
\r
99 + :doc "Proportion or Lines needed
\r
101 +A message is marked read if both the top of the message
\r
102 +and a point far \"enough\" down in the message have each been
\r
103 +visible in the buffer at some point. This parameter controls the
\r
104 +definition of enough. Seeing the bottom of message is always
\r
105 +deemed enough. Additionally, it is deemed enough if a point n
\r
106 +lines into the message has been visible in the window where n is
\r
107 +this variable if this variable is an integer and n is this
\r
108 +variable times the height of the window if this variable is a
\r
112 + :set (lambda (symbol value) (if (listp value)
\r
113 + (set-default symbol (apply 'apply-partially (car value) (cdr value)))
\r
114 + (set-default symbol value)))
\r
115 :group 'notmuch-show)
\r
117 (defmacro with-current-notmuch-show-message (&rest body)
\r
118 @@ -1569,6 +1591,58 @@ marked as unread, i.e. the tag changes in
\r
119 (apply 'notmuch-show-tag-message
\r
120 (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))
\r
122 +(defun notmuch-show-update-seen (top-or-bottom)
\r
123 + "Update seen status of current message
\r
125 +Mark that we have seen the TOP-OR-BOTTOM of current message."
\r
126 + (let ((current (notmuch-show-get-prop :seen)))
\r
127 + (unless (or (eq current 'both) (eq current top-or-bottom))
\r
128 + (if (not current)
\r
129 + (notmuch-show-set-prop :seen top-or-bottom)
\r
130 + (notmuch-show-set-prop :seen 'both)
\r
131 + (notmuch-show-mark-read)))))
\r
133 +(defun notmuch-show-do-message-seen (needed start end)
\r
134 + "Update seen status for the current message.
\r
136 +A message is seen if both the top and enough of the rest of the
\r
137 +message have been visible in the buffer. Enough means either the
\r
138 +bottom of the message or a point in the message more than
\r
139 +LINES-NEEDED lines into the message. LINES-NEEDED is
\r
140 +NEEDED if NEEDED is an integer and NEEDED
\r
141 +times the current window height if NEEDED is a float."
\r
142 + (let* ((lines-needed (if (integerp needed)
\r
144 + (truncate (* needed (window-body-height)))))
\r
145 + (top (notmuch-show-message-top))
\r
146 + (bottom (notmuch-show-message-bottom)))
\r
147 + (when (notmuch-show-message-visible-p)
\r
148 + (when (>= top start)
\r
149 + (notmuch-show-update-seen 'top))
\r
150 + (when (or (<= bottom end)
\r
151 + (> (count-screen-lines top end) lines-needed))
\r
152 + (notmuch-show-update-seen 'bottom)))))
\r
154 +(defun notmuch-show-do-seen (needed start end)
\r
155 + "Update seen status for all messages between start and end.
\r
157 +We mark the top (bottom) of a message seen if the top (enough of
\r
158 +the rest of the message) respectively have been visible in the
\r
159 +buffer. See `notmuch-show-do-message-seen` for the definition of
\r
160 +enough. When both the top and bottom have been seen we mark the
\r
163 + (goto-char start)
\r
164 + (notmuch-show-do-message-seen needed start end)
\r
165 + (while (and (< (notmuch-show-message-bottom) end)
\r
166 + (notmuch-show-goto-message-next))
\r
167 + (notmuch-show-do-message-seen needed start end))
\r
168 + ;; This is a work around because emacs gives weird answers for
\r
169 + ;; window-end if the buffer ends with invisible text.
\r
170 + (when (and (pos-visible-in-window-p (point-max))
\r
171 + (notmuch-show-message-visible-p))
\r
172 + (notmuch-show-update-seen 'bottom))))
\r
174 (defun notmuch-show-seen-current-message (start end)
\r
175 "Mark the current message read if it is open.
\r