[PATCH WIP v2 6/6] emacs: show: make `seen' mean user viewed whole message
[notmuch-archives.git] / 33 / 7621df15f62f433ae03a57cd71acef5cba50ae
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 12651431FAF\r
6         for <notmuch@notmuchmail.org>; Sun,  1 Dec 2013 02:02:53 -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 gs-8y-QDBryb for <notmuch@notmuchmail.org>;\r
18         Sun,  1 Dec 2013 02:02:46 -0800 (PST)\r
19 Received: from mail-we0-f171.google.com (mail-we0-f171.google.com\r
20         [74.125.82.171]) (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 6F64D431FDC\r
23         for <notmuch@notmuchmail.org>; Sun,  1 Dec 2013 02:02:44 -0800 (PST)\r
24 Received: by mail-we0-f171.google.com with SMTP id q58so10715515wes.16\r
25         for <notmuch@notmuchmail.org>; Sun, 01 Dec 2013 02:02:43 -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=esAf5rtXuTzLfl/s+hyi6Yc+VwaaY0aMQpAEshwP/rE=;\r
29         b=v9zZMJzUjfAvDtWmsumEPo9BcukVQpXeYeXlGCOsP4V4XAjDBCjUKgNbXsCU1zcYGb\r
30         Q7rytRbI1xBPHlrOJj/uvrUOt6B9OMpfAhbPC3Y3y8PGNty8ibKtm66+njnASQOlISsx\r
31         CR0g5GXfenddyA86eg/BFQhJoAIe6R0k3VRTvRKHiAHfEYhB+E1XzYzc/BNpPpU88o0f\r
32         fYNSHhotgWK86xHMBlCstlmLtboXyLY+3qAGd4Wbo3ZC7XN/ZXYhIgX2xu4f/miH09zA\r
33         oi0NCTzz7bpCvMKWKQ3vikVb4dC8LZk92CGHts6et2JAjkL/0HDZnJeZBzOCoPhAag6l\r
34         QwDA==\r
35 X-Received: by 10.194.237.99 with SMTP id vb3mr49165279wjc.28.1385892163410;\r
36         Sun, 01 Dec 2013 02:02:43 -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\r
39         dn2sm110289612wid.1.2013.12.01.02.02.42 for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Sun, 01 Dec 2013 02:02:42 -0800 (PST)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH WIP v2 6/6] emacs: show: make `seen' mean user viewed whole\r
45         message\r
46 Date: Sun,  1 Dec 2013 10:02:27 +0000\r
47 Message-Id: <1385892147-16994-7-git-send-email-markwalters1009@gmail.com>\r
48 X-Mailer: git-send-email 1.7.9.1\r
49 In-Reply-To: <1385892147-16994-1-git-send-email-markwalters1009@gmail.com>\r
50 References: <1385892147-16994-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: Sun, 01 Dec 2013 10:02:53 -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 |   75 +++++++++++++++++++++++++++++++++++++++++++++++-\r
75  1 files changed, 73 insertions(+), 2 deletions(-)\r
76 \r
77 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
78 index 6b6e94a..a57d8fb 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 @@ -1587,9 +1600,67 @@ we are not marking them."\r
102    (notmuch-show-mark-all-seen-read not-mark)\r
103    (notmuch-kill-this-buffer))\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-seen)\r
123 +       (message "marking seen %s" (current-time))))))\r
124 +\r
125 +(defun notmuch-show-do-message-seen (start end)\r
126 +  "Update seen status for the current message.\r
127 +\r
128 +A message is seen if both the top and enough of the rest of the\r
129 +message have been visible in the buffer.  Enough means either the\r
130 +bottom of the message or a point in the message more than\r
131 +LINES-NEEDED lines into the message. LINES-NEEDED is\r
132 +`notmuch-show-seen-lines-needed` if that is an integer and that\r
133 +times the current window height if it is a float."\r
134 +  (let* ((lines-needed (if (integerp notmuch-show-seen-lines-needed)\r
135 +                          notmuch-show-seen-lines-needed\r
136 +                        (truncate (* notmuch-show-seen-lines-needed (window-body-height)))))\r
137 +        (top (notmuch-show-message-top))\r
138 +        (bottom (notmuch-show-message-bottom)))\r
139 +    (when (notmuch-show-message-visible-p)\r
140 +      (when (>= top start)\r
141 +       (notmuch-show-update-seen 'top))\r
142 +      (when (or (<= bottom end)\r
143 +               (> (count-screen-lines top end) lines-needed))\r
144 +       (notmuch-show-update-seen 'bottom)))))\r
145 +\r
146 +\r
147  (defun notmuch-show-do-seen (start end)\r
148 -  "Update seen status for all messages between start and end."\r
149 -  )\r
150 +  "Update seen status for all messages between start and end.\r
151 +\r
152 +A message is seen if both the top and enough of the rest of the\r
153 +message have been visible in the buffer. See\r
154 +`notmuch-show-do-message-seen` for the definition of enough. Seen\r
155 +is a buffer local property. The unread status is removed from all\r
156 +seen messages when the user quits the show buffer."\r
157 +  (save-excursion\r
158 +    (goto-char start)\r
159 +    (while (and (or (notmuch-show-do-message-seen start end) t)\r
160 +               (< (notmuch-show-message-bottom) end)\r
161 +               (notmuch-show-goto-message-next)))\r
162 +\r
163 +    ;; This is a work around because emacs gives weird answers for\r
164 +    ;; window-end if the buffer ends with invisible text.\r
165 +    (when (and (pos-visible-in-window-p (point-max))\r
166 +              (notmuch-show-message-visible-p))\r
167 +      (notmuch-show-update-seen 'bottom))))\r
168  \r
169  (defun notmuch-show-command-hook ()\r
170    (when (eq major-mode 'notmuch-show-mode)\r
171 -- \r
172 1.7.9.1\r
173 \r