Re: [PATCH 9/9] add has: query prefix to search for specific properties
[notmuch-archives.git] / 50 / 7929b87ddcb8d06379752032a1a069ab12fb6b
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 7C408431FC2\r
6         for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 13:03:34 -0700 (PDT)\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 l2WD0zRWcdGz for <notmuch@notmuchmail.org>;\r
18         Tue, 25 Mar 2014 13:03:28 -0700 (PDT)\r
19 Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com\r
20         [209.85.212.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 C324F431FC0\r
23         for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 13:03:24 -0700 (PDT)\r
24 Received: by mail-wi0-f171.google.com with SMTP id hr14so2383025wib.16\r
25         for <notmuch@notmuchmail.org>; Tue, 25 Mar 2014 13:03:23 -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:in-reply-to:references;\r
28         bh=VbXhcj1KD/Fx/viQT2LO3fUx6Wp7xDrCmlveWmD3TyY=;\r
29         b=IsAhFjdkcrcV6j9NjNLRfTK39TUKvOMRdz+j/7eBvzkNxDcsYbfli1/vD6dOzhjcD1\r
30         EtygqzyLb8NwPyGMHFQsCzT6TDY44kr7ZMaaeMjQwPinJZCGvdMRT9JxNamNEX6b4Faf\r
31         WVpF2KCMsbvbIb6GDZ6Vo/Dx+QbAVd3ipV0xUIIRfziutz7al+SF2V9ZUtfa0vsjmHmN\r
32         7BVRWD8XFgTbzZzUIQ0OmMqZIKBgzyfPYgAoxzyDof/3Hww91JoJI7nuy8xdsZDyTm8O\r
33         jtp7fkZeN76QYJ8SBWw5pBtnWjouZJWh6eTqBvN7Wg83Q0Bm40SsE4uR8vObiabcV39r\r
34         9x/w==\r
35 X-Received: by 10.180.188.169 with SMTP id gb9mr24697346wic.17.1395777803721; \r
36         Tue, 25 Mar 2014 13:03:23 -0700 (PDT)\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         qg3sm53335450wic.10.2014.03.25.13.03.22 for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Tue, 25 Mar 2014 13:03:23 -0700 (PDT)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [Patch v3 3/3] emacs: show: make `seen' mean user viewed whole\r
45  message\r
46 Date: Tue, 25 Mar 2014 20:03:13 +0000\r
47 Message-Id: <1395777793-13297-4-git-send-email-markwalters1009@gmail.com>\r
48 X-Mailer: git-send-email 1.7.10.4\r
49 In-Reply-To: <1395777793-13297-1-git-send-email-markwalters1009@gmail.com>\r
50 References: <1395777793-13297-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, 25 Mar 2014 20:03:34 -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 introduced in\r
72 the previous patch.\r
73 ---\r
74  emacs/notmuch-show.el |   63 +++++++++++++++++++++++++++++++++++++++++++++++--\r
75  1 file changed, 61 insertions(+), 2 deletions(-)\r
76 \r
77 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
78 index 1a7de85..1abf24b 100644\r
79 --- a/emacs/notmuch-show.el\r
80 +++ b/emacs/notmuch-show.el\r
81 @@ -211,6 +211,20 @@ (defcustom notmuch-show-mark-read-tags '("-unread")\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.\r
92 +\r
93 +Enough means either the bottom of the message or a point in the\r
94 +message more than LINES-NEEDED lines into the message, where\r
95 +LINES-NEEDED is this variable if this variable is an integer and\r
96 +this variable times the current window height if it is a float."\r
97 +  :type 'number\r
98 +  :group 'notmuch-show)\r
99  \r
100  (defmacro with-current-notmuch-show-message (&rest body)\r
101    "Evaluate body with current buffer set to the text of current message"\r
102 @@ -1532,9 +1546,54 @@ (defun notmuch-show-mark-read (&optional unread)\r
103      (apply 'notmuch-show-tag-message\r
104            (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))\r
105  \r
106 +(defun notmuch-show-update-seen (top-or-bottom)\r
107 +  "Update seen status of current message\r
108 +\r
109 +Mark that we have seen the TOP-OR-BOTTOM of current message."\r
110 +  (let ((current (notmuch-show-get-prop :seen)))\r
111 +    (unless (or (eq current 'both) (eq current top-or-bottom))\r
112 +      (if (not current)\r
113 +         (notmuch-show-set-prop :seen top-or-bottom)\r
114 +       (notmuch-show-set-prop :seen 'both)\r
115 +       (notmuch-show-mark-read)))))\r
116 +\r
117 +(defun notmuch-show-do-message-seen (start end)\r
118 +  "Update seen status for the current message.\r
119 +\r
120 +A message is seen if both the top and enough of the rest of the\r
121 +message have been visible in the buffer.  See the\r
122 +`notmuch-show-seen-lines-needed' for the definition of `enough'."\r
123 +  (let* ((lines-needed (if (integerp notmuch-show-seen-lines-needed)\r
124 +                          notmuch-show-seen-lines-needed\r
125 +                        (truncate (* notmuch-show-seen-lines-needed (window-body-height)))))\r
126 +        (top (notmuch-show-message-top))\r
127 +        (bottom (notmuch-show-message-bottom)))\r
128 +    (when (notmuch-show-message-visible-p)\r
129 +      (when (>= top start)\r
130 +       (notmuch-show-update-seen 'top))\r
131 +      (when (or (<= bottom end)\r
132 +               (> (count-screen-lines top end) lines-needed))\r
133 +       (notmuch-show-update-seen 'bottom)))))\r
134 +\r
135  (defun notmuch-show-do-seen (start end)\r
136 -  "Update seen status for all messages between start and end."\r
137 -  )\r
138 +  "Update seen status for all messages between start and end.\r
139 +\r
140 +We mark the top (bottom) of a message seen if the top (enough of\r
141 +the rest of the message) respectively have been visible in the\r
142 +buffer. See the `notmuch-show-seen-lines-needed' for the\r
143 +definition of `enough'. When both the top and bottom have been\r
144 +seen we mark the message read."\r
145 +  (save-excursion\r
146 +    (goto-char start)\r
147 +    (notmuch-show-do-message-seen start end)\r
148 +    (while (and (< (notmuch-show-message-bottom) end)\r
149 +               (notmuch-show-goto-message-next))\r
150 +      (notmuch-show-do-message-seen start end))\r
151 +    ;; This is a work around because emacs gives weird answers for\r
152 +    ;; window-end if the buffer ends with invisible text.\r
153 +    (when (and (pos-visible-in-window-p (point-max))\r
154 +              (notmuch-show-message-visible-p))\r
155 +      (notmuch-show-update-seen 'bottom))))\r
156  \r
157  (defun notmuch-show-command-hook ()\r
158    (when (eq major-mode 'notmuch-show-mode)\r
159 -- \r
160 1.7.10.4\r
161 \r