[PATCH WIP v4 3/3] emacs: show: make `seen' mean user viewed whole message
[notmuch-archives.git] / d3 / be53b0f62900479c7e1c7f2846bd56c61bfa4d
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 6E004431FD2\r
6         for <notmuch@notmuchmail.org>; Tue, 10 Dec 2013 00:57:49 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 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         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 1cYmg6mYV9F4 for <notmuch@notmuchmail.org>;\r
18         Tue, 10 Dec 2013 00:57:42 -0800 (PST)\r
19 Received: from mail-wi0-f194.google.com (mail-wi0-f194.google.com\r
20         [209.85.212.194]) (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 EFF93431FBF\r
23         for <notmuch@notmuchmail.org>; Tue, 10 Dec 2013 00:57:38 -0800 (PST)\r
24 Received: by mail-wi0-f194.google.com with SMTP id f13so1620995wiv.1\r
25         for <notmuch@notmuchmail.org>; Tue, 10 Dec 2013 00:57:37 -0800 (PST)\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:in-reply-to:references;\r
28         bh=VKppVlhkumcYb6e3h/MgHQaeYzWWMYjKK63rruOZ0LQ=;\r
29         b=Otq3ZNIpaI+sAzabtJkBlwyi5A+Ph0wpnPW8w6RxSCYgmAhIvIIRo6SebG0esegCHN\r
30         ZJX4/hMEtDiqf/m3F7Fm17+jJKRk5pbVZY2mzMRC72fdU8DU5bdL+pkSkxuYZB73XcmD\r
31         EXGmLpJ4CfnndgZT2PoN0fW89ZDqlVZ7ktysz9eYRCEkUm3sbNr6vodNzpcENd/0w9kH\r
32         bhzJqW+1RViuCM5tWcx65SX6qOkBVI2cVqKWfEb5zpD31C+fo7f8D/lhZyaIpYUR2DXD\r
33         NpwzqPnStyS0mljVSor21bAZe4rh8ufVIKLHfuezmIvkZE6Draqr4ayRMOHsl7nuqsaI\r
34         UaFw==\r
35 X-Received: by 10.194.63.228 with SMTP id j4mr19684674wjs.34.1386665857871;\r
36         Tue, 10 Dec 2013 00:57:37 -0800 (PST)\r
37 Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
38         by mx.google.com with ESMTPSA id q19sm3185637wiw.4.2013.12.10.00.57.36\r
39         for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Tue, 10 Dec 2013 00:57:37 -0800 (PST)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH WIP v4 3/3] emacs: show: make `seen' mean user viewed whole\r
45         message\r
46 Date: Tue, 10 Dec 2013 08:57:27 +0000\r
47 Message-Id: <1386665847-6439-4-git-send-email-markwalters1009@gmail.com>\r
48 X-Mailer: git-send-email 1.7.9.1\r
49 In-Reply-To: <1386665847-6439-1-git-send-email-markwalters1009@gmail.com>\r
50 References: <1386665847-6439-1-git-send-email-markwalters1009@gmail.com>\r
51 X-BeenThere: notmuch@notmuchmail.org\r
52 X-Mailman-Version: 2.1.13\r
53 Precedence: list\r
54 List-Id: "Use and development of the notmuch mail system."\r
55         <notmuch.notmuchmail.org>\r
56 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
57         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
58 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
59 List-Post: <mailto:notmuch@notmuchmail.org>\r
60 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
61 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
62         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
63 X-List-Received-Date: Tue, 10 Dec 2013 08:57:49 -0000\r
64 \r
65 This changes `seen' to mean that the user viewed `enough' of the whole\r
66 message: more precisely, a message is deemed seen if the top of the\r
67 message and either the bottom of the message or a point at least some\r
68 customisable number of lines into the message have each been visible\r
69 in the buffer at some point.\r
70 \r
71 This is placed into the post-command-hook infrastructure introudced in\r
72 the previous patch.\r
73 ---\r
74  emacs/notmuch-show.el |   73 +++++++++++++++++++++++++++++++++++++++++++++++-\r
75  1 files changed, 71 insertions(+), 2 deletions(-)\r
76 \r
77 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
78 index 51366e9..4850bd0 100644\r
79 --- a/emacs/notmuch-show.el\r
80 +++ b/emacs/notmuch-show.el\r
81 @@ -211,6 +211,19 @@ For example, if you wanted to remove an \"unread\" tag and add a\r
82    :type '(repeat string)\r
83    :group 'notmuch-show)\r
84  \r
85 +(defcustom notmuch-show-seen-lines-needed 0.75\r
86 +  "Control which messages get marked seen.\r
87 +\r
88 +A message is marked seen if both the top of the message and a\r
89 +point far \"enough\" down in the message have each been visible\r
90 +in the buffer at some point. This parameter controls the\r
91 +definition of enough.  Seeing the bottom of message is always\r
92 +deemed enough, but additionally...it an integer n then at least n\r
93 +lines of message must be visible in the window. If it is a float\r
94 +x then at least that proportion of the window must contain the\r
95 +message."\r
96 +  :type 'number\r
97 +  :group 'notmuch-show)\r
98  \r
99  (defmacro with-current-notmuch-show-message (&rest body)\r
100    "Evaluate body with current buffer set to the text of current message"\r
101 @@ -1541,9 +1554,65 @@ marked as unread, i.e. the tag changes in\r
102      (apply 'notmuch-show-tag-message\r
103            (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))\r
104  \r
105 +(defun notmuch-show-update-seen (top-or-bottom)\r
106 +  "Update seen status of current message\r
107 +\r
108 +Mark that we have seen the TOP-OR-BOTTOM of current message."\r
109 +  (let* ((current (notmuch-show-get-prop :seen-local))\r
110 +        new)\r
111 +    (unless (eq current 'both)\r
112 +      (if (eq top-or-bottom 'top)\r
113 +         (if (eq current 'bottom)\r
114 +             (setq new 'both)\r
115 +           (setq new 'top))\r
116 +       (if (eq current 'top)\r
117 +           (setq new 'both)\r
118 +         (setq new 'bottom)))\r
119 +      (unless (eq current new)\r
120 +       (notmuch-show-set-prop :seen-local new))\r
121 +      (when (eq new 'both)\r
122 +       (notmuch-show-mark-read)))))\r
123 +\r
124 +(defun notmuch-show-do-message-seen (start end)\r
125 +  "Update seen status for the current message.\r
126 +\r
127 +A message is seen if both the top and enough of the rest of the\r
128 +message have been visible in the buffer.  Enough means either the\r
129 +bottom of the message or a point in the message more than\r
130 +LINES-NEEDED lines into the message. LINES-NEEDED is\r
131 +`notmuch-show-seen-lines-needed` if that is an integer and that\r
132 +times the current window height if it is a float."\r
133 +  (let* ((lines-needed (if (integerp notmuch-show-seen-lines-needed)\r
134 +                          notmuch-show-seen-lines-needed\r
135 +                        (truncate (* notmuch-show-seen-lines-needed (window-body-height)))))\r
136 +        (top (notmuch-show-message-top))\r
137 +        (bottom (notmuch-show-message-bottom)))\r
138 +    (when (notmuch-show-message-visible-p)\r
139 +      (when (>= top start)\r
140 +       (notmuch-show-update-seen 'top))\r
141 +      (when (or (<= bottom end)\r
142 +               (> (count-screen-lines top end) lines-needed))\r
143 +       (notmuch-show-update-seen 'bottom)))))\r
144 +\r
145  (defun notmuch-show-do-seen (start end)\r
146 -  "Update seen status for all messages between start and end."\r
147 -  )\r
148 +  "Update seen status for all messages between start and end.\r
149 +\r
150 +A message is seen if both the top and enough of the rest of the\r
151 +message have been visible in the buffer. See\r
152 +`notmuch-show-do-message-seen` for the definition of enough. Seen\r
153 +is a buffer local property. The unread status is removed from all\r
154 +seen messages when the user quits the show buffer."\r
155 +  (save-excursion\r
156 +    (goto-char start)\r
157 +    (while (and (or (notmuch-show-do-message-seen start end) t)\r
158 +               (< (notmuch-show-message-bottom) end)\r
159 +               (notmuch-show-goto-message-next)))\r
160 +\r
161 +    ;; This is a work around because emacs gives weird answers for\r
162 +    ;; window-end if the buffer ends with invisible text.\r
163 +    (when (and (pos-visible-in-window-p (point-max))\r
164 +              (notmuch-show-message-visible-p))\r
165 +      (notmuch-show-update-seen 'bottom))))\r
166  \r
167  (defun notmuch-show-command-hook ()\r
168    (when (eq major-mode 'notmuch-show-mode)\r
169 -- \r
170 1.7.9.1\r
171 \r