Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / f1 / 1eb1aa9533b0afa8d1ae625842117ca291ebc9
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 770D5431FD6\r
6         for <notmuch@notmuchmail.org>; Sat, 14 Dec 2013 15:44: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 rr3gZQOuODwK for <notmuch@notmuchmail.org>;\r
18         Sat, 14 Dec 2013 15:44:48 -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 C5A47431FD0\r
23         for <notmuch@notmuchmail.org>; Sat, 14 Dec 2013 15:44:47 -0800 (PST)\r
24 Received: by mail-wi0-f194.google.com with SMTP id e4so293234wiv.9\r
25         for <notmuch@notmuchmail.org>; Sat, 14 Dec 2013 15:44:46 -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=KYs7Ex44uv0SB4gXvELpvGTJHYNDJeNiI7CH1d/ZVUeS2oL6SV5jLaiUvWluG5Oe7P\r
30         sKcxOc6fBU8kAFYHTvgi0hf8y9pUF9BVCs/epbxjRLepnNQY/u3f/eyOhhoZrOqtxU7b\r
31         f8Tbbyz2xYC1a4pGpPxQHzEzBfLC3b0kUg6Z75Q4IkK+D7K3ZucNjNmEdff9XO42xnHk\r
32         5rSKfi/1kppWsX/18fyEjXQtPETgQcFvHYeR5vJEl2GtM8E2W4pTH6wYvLgl3lgPr03G\r
33         nguh7bonFvSCv9wm78+5gRrN4lKxr5UGhIw/LyQ/FtYRQwJl3kCg6vUB41QgPuSmNqJV\r
34         SilQ==\r
35 X-Received: by 10.180.189.49 with SMTP id gf17mr8034142wic.23.1387064686581;\r
36         Sat, 14 Dec 2013 15:44:46 -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 fj8sm28126705wib.1.2013.12.14.15.44.45\r
39         for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Sat, 14 Dec 2013 15:44:46 -0800 (PST)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH 1/5] emacs: show: make `seen' mean user viewed whole message\r
45 Date: Sat, 14 Dec 2013 23:44:32 +0000\r
46 Message-Id: <1387064676-15508-2-git-send-email-markwalters1009@gmail.com>\r
47 X-Mailer: git-send-email 1.7.9.1\r
48 In-Reply-To: <1387064676-15508-1-git-send-email-markwalters1009@gmail.com>\r
49 References: <1387064676-15508-1-git-send-email-markwalters1009@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Sat, 14 Dec 2013 23:44:53 -0000\r
63 \r
64 This changes `seen' to mean that the user viewed `enough' of the whole\r
65 message: more precisely, a message is deemed seen if the top of the\r
66 message and either the bottom of the message or a point at least some\r
67 customisable number of lines into the message have each been visible\r
68 in the buffer at some point.\r
69 \r
70 This is placed into the post-command-hook infrastructure introudced in\r
71 the previous patch.\r
72 ---\r
73  emacs/notmuch-show.el |   73 +++++++++++++++++++++++++++++++++++++++++++++++-\r
74  1 files changed, 71 insertions(+), 2 deletions(-)\r
75 \r
76 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
77 index 51366e9..4850bd0 100644\r
78 --- a/emacs/notmuch-show.el\r
79 +++ b/emacs/notmuch-show.el\r
80 @@ -211,6 +211,19 @@ For example, if you wanted to remove an \"unread\" tag and add a\r
81    :type '(repeat string)\r
82    :group 'notmuch-show)\r
83  \r
84 +(defcustom notmuch-show-seen-lines-needed 0.75\r
85 +  "Control which messages get marked seen.\r
86 +\r
87 +A message is marked seen if both the top of the message and a\r
88 +point far \"enough\" down in the message have each been visible\r
89 +in the buffer at some point. This parameter controls the\r
90 +definition of enough.  Seeing the bottom of message is always\r
91 +deemed enough, but additionally...it an integer n then at least n\r
92 +lines of message must be visible in the window. If it is a float\r
93 +x then at least that proportion of the window must contain the\r
94 +message."\r
95 +  :type 'number\r
96 +  :group 'notmuch-show)\r
97  \r
98  (defmacro with-current-notmuch-show-message (&rest body)\r
99    "Evaluate body with current buffer set to the text of current message"\r
100 @@ -1541,9 +1554,65 @@ marked as unread, i.e. the tag changes in\r
101      (apply 'notmuch-show-tag-message\r
102            (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))\r
103  \r
104 +(defun notmuch-show-update-seen (top-or-bottom)\r
105 +  "Update seen status of current message\r
106 +\r
107 +Mark that we have seen the TOP-OR-BOTTOM of current message."\r
108 +  (let* ((current (notmuch-show-get-prop :seen-local))\r
109 +        new)\r
110 +    (unless (eq current 'both)\r
111 +      (if (eq top-or-bottom 'top)\r
112 +         (if (eq current 'bottom)\r
113 +             (setq new 'both)\r
114 +           (setq new 'top))\r
115 +       (if (eq current 'top)\r
116 +           (setq new 'both)\r
117 +         (setq new 'bottom)))\r
118 +      (unless (eq current new)\r
119 +       (notmuch-show-set-prop :seen-local new))\r
120 +      (when (eq new 'both)\r
121 +       (notmuch-show-mark-read)))))\r
122 +\r
123 +(defun notmuch-show-do-message-seen (start end)\r
124 +  "Update seen status for the current message.\r
125 +\r
126 +A message is seen if both the top and enough of the rest of the\r
127 +message have been visible in the buffer.  Enough means either the\r
128 +bottom of the message or a point in the message more than\r
129 +LINES-NEEDED lines into the message. LINES-NEEDED is\r
130 +`notmuch-show-seen-lines-needed` if that is an integer and that\r
131 +times the current window height if it is a float."\r
132 +  (let* ((lines-needed (if (integerp notmuch-show-seen-lines-needed)\r
133 +                          notmuch-show-seen-lines-needed\r
134 +                        (truncate (* notmuch-show-seen-lines-needed (window-body-height)))))\r
135 +        (top (notmuch-show-message-top))\r
136 +        (bottom (notmuch-show-message-bottom)))\r
137 +    (when (notmuch-show-message-visible-p)\r
138 +      (when (>= top start)\r
139 +       (notmuch-show-update-seen 'top))\r
140 +      (when (or (<= bottom end)\r
141 +               (> (count-screen-lines top end) lines-needed))\r
142 +       (notmuch-show-update-seen 'bottom)))))\r
143 +\r
144  (defun notmuch-show-do-seen (start end)\r
145 -  "Update seen status for all messages between start and end."\r
146 -  )\r
147 +  "Update seen status for all messages between start and end.\r
148 +\r
149 +A message is seen if both the top and enough of the rest of the\r
150 +message have been visible in the buffer. See\r
151 +`notmuch-show-do-message-seen` for the definition of enough. Seen\r
152 +is a buffer local property. The unread status is removed from all\r
153 +seen messages when the user quits the show buffer."\r
154 +  (save-excursion\r
155 +    (goto-char start)\r
156 +    (while (and (or (notmuch-show-do-message-seen start end) t)\r
157 +               (< (notmuch-show-message-bottom) end)\r
158 +               (notmuch-show-goto-message-next)))\r
159 +\r
160 +    ;; This is a work around because emacs gives weird answers for\r
161 +    ;; window-end if the buffer ends with invisible text.\r
162 +    (when (and (pos-visible-in-window-p (point-max))\r
163 +              (notmuch-show-message-visible-p))\r
164 +      (notmuch-show-update-seen 'bottom))))\r
165  \r
166  (defun notmuch-show-command-hook ()\r
167    (when (eq major-mode 'notmuch-show-mode)\r
168 -- \r
169 1.7.9.1\r
170 \r