Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 0e / 22e60c1d3d0d3f981fc93389a7e9f0f9c513a5
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 2628E429E54\r
6         for <notmuch@notmuchmail.org>; Sat,  1 Jun 2013 01:16:30 -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 9fMz3tpkv9nB for <notmuch@notmuchmail.org>;\r
18         Sat,  1 Jun 2013 01:16:24 -0700 (PDT)\r
19 Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com\r
20         [209.85.212.175]) (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 F27EB429E3F\r
23         for <notmuch@notmuchmail.org>; Sat,  1 Jun 2013 01:16:20 -0700 (PDT)\r
24 Received: by mail-wi0-f175.google.com with SMTP id hn14so1322408wib.8\r
25         for <notmuch@notmuchmail.org>; Sat, 01 Jun 2013 01:16:18 -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:x-mailer:in-reply-to:references;\r
28         bh=yjiuOss1Wa60HfCUem6Cbc9Vv972od92Qo2Xb74tRVA=;\r
29         b=o8wnOa2qyjSqOVyAqEBsYi0HmVcLori0yyyh2bmu+wOt4H0e/jirRWgkcZHfGyYA38\r
30         WG6ao+LoQY3o/O5yqDDlsfGMigvcdS1DY5gina08TxPiESQ3qwchJ3GO3j7f84Vk7S0D\r
31         ZZ9MBYkSbV3g6hS+SxDnfBgRBt1jpjvtOfKoH/DWcvY7AS/2vDAjB7VTzpK1hSaOk5iT\r
32         m5isUV2P50g4N//3vs10J4Hb7eZFjhw7xMRlC081diVD3Kak+W3V0lKXhOH57S37hlX2\r
33         ZAUFb8cwwuUV9MYAgqZhrSqZ4P2w4qoEQ2OY1GEmTm8XePLOcN/92US9tzKy/voreEjM\r
34         GVLQ==\r
35 X-Received: by 10.180.74.81 with SMTP id r17mr6170018wiv.49.1370074578465;\r
36         Sat, 01 Jun 2013 01:16:18 -0700 (PDT)\r
37 Received: from localhost (94.197.247.227.threembb.co.uk. [94.197.247.227])\r
38         by mx.google.com with ESMTPSA id fx7sm8560790wic.11.2013.06.01.01.16.15\r
39         for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Sat, 01 Jun 2013 01:16:17 -0700 (PDT)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org, Austin Clements <aclements@csail.mit.edu>,\r
44         Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
45 Subject: [PATCH v4 2/5] emacs: show: move the insertion of the header button\r
46         to the top level\r
47 Date: Sat,  1 Jun 2013 09:15:44 +0100\r
48 Message-Id: <1370074547-24677-3-git-send-email-markwalters1009@gmail.com>\r
49 X-Mailer: git-send-email 1.7.10.4\r
50 In-Reply-To: <1370074547-24677-1-git-send-email-markwalters1009@gmail.com>\r
51 References: <1370074547-24677-1-git-send-email-markwalters1009@gmail.com>\r
52 X-BeenThere: notmuch@notmuchmail.org\r
53 X-Mailman-Version: 2.1.13\r
54 Precedence: list\r
55 List-Id: "Use and development of the notmuch mail system."\r
56         <notmuch.notmuchmail.org>\r
57 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
58         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
59 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
60 List-Post: <mailto:notmuch@notmuchmail.org>\r
61 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
62 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
63         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
64 X-List-Received-Date: Sat, 01 Jun 2013 08:16:30 -0000\r
65 \r
66 Previously each of the part insertion handlers inserted the part\r
67 button themselves. Move this up into\r
68 notmuch-show-insert-bodypart. Since a small number of the handlers\r
69 modify the button (the encryption/signature ones) we need to pass the\r
70 header button as an argument into the individual part insertion\r
71 handlers. However, the declared-type argument was only used for the\r
72 text for the part buttons we can now omit it.\r
73 \r
74 The patch is large but mostly simple. The only things of note are that\r
75 we let the text/plain handler applies notmuch-wash to the whole part\r
76 including the part button. In particular, notmuch-wash removes leading\r
77 blank lines from a text/plain part, but since the button is counted as\r
78 part of the part this does not happen with text/plain buttons that\r
79 have a button. This is probably a bug in notmuch-wash but changing it\r
80 does make several tests fail (that rely on this blank line) so, for\r
81 the moment, keep the old behaviour.\r
82 ---\r
83  emacs/notmuch-show.el |   97 ++++++++++++++++++++++++-------------------------\r
84  1 file changed, 47 insertions(+), 50 deletions(-)\r
85 \r
86 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
87 index dda5c10..9e119e8 100644\r
88 --- a/emacs/notmuch-show.el\r
89 +++ b/emacs/notmuch-show.el\r
90 @@ -514,8 +514,7 @@ message at DEPTH in the current thread."\r
91    (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
92           (plist-get part :content)))\r
93  \r
94 -(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)\r
95 -  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
96 +(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth button)\r
97    (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
98         (inner-parts (plist-get part :content))\r
99         (start (point)))\r
100 @@ -592,8 +591,7 @@ message at DEPTH in the current thread."\r
101           content-type)\r
102        nil)))\r
103  \r
104 -(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth declared-type)\r
105 -  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
106 +(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth button)\r
107    (let ((inner-parts (plist-get part :content))\r
108         (start (point)))\r
109  \r
110 @@ -612,16 +610,15 @@ message at DEPTH in the current thread."\r
111        (indent-rigidly start (point) 1)))\r
112    t)\r
113  \r
114 -(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth declared-type)\r
115 -  (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))\r
116 -    (button-put button 'face 'notmuch-crypto-part-header)\r
117 -    ;; add signature status button if sigstatus provided\r
118 -    (if (plist-member part :sigstatus)\r
119 -       (let* ((from (notmuch-show-get-header :From msg))\r
120 -              (sigstatus (car (plist-get part :sigstatus))))\r
121 -         (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
122 -      ;; if we're not adding sigstatus, tell the user how they can get it\r
123 -      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
124 +(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button)\r
125 +  (button-put button 'face 'notmuch-crypto-part-header)\r
126 +  ;; add signature status button if sigstatus provided\r
127 +  (if (plist-member part :sigstatus)\r
128 +      (let* ((from (notmuch-show-get-header :From msg))\r
129 +            (sigstatus (car (plist-get part :sigstatus))))\r
130 +       (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
131 +    ;; if we're not adding sigstatus, tell the user how they can get it\r
132 +    (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))\r
133  \r
134    (let ((inner-parts (plist-get part :content))\r
135         (start (point)))\r
136 @@ -634,20 +631,19 @@ message at DEPTH in the current thread."\r
137        (indent-rigidly start (point) 1)))\r
138    t)\r
139  \r
140 -(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth declared-type)\r
141 -  (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))\r
142 -    (button-put button 'face 'notmuch-crypto-part-header)\r
143 -    ;; add encryption status button if encstatus specified\r
144 -    (if (plist-member part :encstatus)\r
145 -       (let ((encstatus (car (plist-get part :encstatus))))\r
146 -         (notmuch-crypto-insert-encstatus-button encstatus)\r
147 -         ;; add signature status button if sigstatus specified\r
148 -         (if (plist-member part :sigstatus)\r
149 -             (let* ((from (notmuch-show-get-header :From msg))\r
150 -                    (sigstatus (car (plist-get part :sigstatus))))\r
151 -               (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
152 -      ;; if we're not adding encstatus, tell the user how they can get it\r
153 -      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
154 +(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth button)\r
155 +  (button-put button 'face 'notmuch-crypto-part-header)\r
156 +  ;; add encryption status button if encstatus specified\r
157 +  (if (plist-member part :encstatus)\r
158 +      (let ((encstatus (car (plist-get part :encstatus))))\r
159 +       (notmuch-crypto-insert-encstatus-button encstatus)\r
160 +       ;; add signature status button if sigstatus specified\r
161 +       (if (plist-member part :sigstatus)\r
162 +           (let* ((from (notmuch-show-get-header :From msg))\r
163 +                  (sigstatus (car (plist-get part :sigstatus))))\r
164 +             (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
165 +    ;; if we're not adding encstatus, tell the user how they can get it\r
166 +    (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))\r
167  \r
168    (let ((inner-parts (plist-get part :content))\r
169         (start (point)))\r
170 @@ -660,8 +656,7 @@ message at DEPTH in the current thread."\r
171        (indent-rigidly start (point) 1)))\r
172    t)\r
173  \r
174 -(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type)\r
175 -  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
176 +(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth button)\r
177    (let ((inner-parts (plist-get part :content))\r
178         (start (point)))\r
179      ;; Show all of the parts.\r
180 @@ -673,8 +668,7 @@ message at DEPTH in the current thread."\r
181        (indent-rigidly start (point) 1)))\r
182    t)\r
183  \r
184 -(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth declared-type)\r
185 -  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
186 +(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth button)\r
187    (let* ((message (car (plist-get part :content)))\r
188          (body (car (plist-get message :body)))\r
189          (start (point)))\r
190 @@ -695,12 +689,13 @@ message at DEPTH in the current thread."\r
191        (indent-rigidly start (point) 1)))\r
192    t)\r
193  \r
194 -(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth declared-type)\r
195 -  (let ((start (point)))\r
196 -    ;; If this text/plain part is not the first part in the message,\r
197 -    ;; insert a header to make this clear.\r
198 -    (if (> nth 1)\r
199 -       (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename)))\r
200 +(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth button)\r
201 +  ;; For backward compatibility we want to apply the text/plain hook\r
202 +  ;; to the whole of the part including the part button if there is\r
203 +  ;; one.\r
204 +  (let ((start (if button\r
205 +                  (button-start button)\r
206 +                (point))))\r
207      (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))\r
208      (save-excursion\r
209        (save-restriction\r
210 @@ -708,8 +703,7 @@ message at DEPTH in the current thread."\r
211         (run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth))))\r
212    t)\r
213  \r
214 -(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth declared-type)\r
215 -  (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename))\r
216 +(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth button)\r
217    (insert (with-temp-buffer\r
218             (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))\r
219             ;; notmuch-get-bodypart-content provides "raw", non-converted\r
220 @@ -732,8 +726,8 @@ message at DEPTH in the current thread."\r
221    t)\r
222  \r
223  ;; For backwards compatibility.\r
224 -(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type)\r
225 -  (notmuch-show-insert-part-text/calendar msg part content-type nth depth declared-type))\r
226 +(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth button)\r
227 +  (notmuch-show-insert-part-text/calendar msg part content-type nth depth button))\r
228  \r
229  (defun notmuch-show-get-mime-type-of-application/octet-stream (part)\r
230    ;; If we can deduce a MIME type from the filename of the attachment,\r
231 @@ -751,7 +745,7 @@ message at DEPTH in the current thread."\r
232                 nil))\r
233           nil))))\r
234  \r
235 -(defun notmuch-show-insert-part-text/html (msg part content-type nth depth declared-type)\r
236 +(defun notmuch-show-insert-part-text/html (msg part content-type nth depth button)\r
237    ;; text/html handler to work around bugs in renderers and our\r
238    ;; invisibile parts code. In particular w3m sets up a keymap which\r
239    ;; "leaks" outside the invisible region and causes strange effects\r
240 @@ -759,11 +753,10 @@ message at DEPTH in the current thread."\r
241    ;; tell w3m not to set a keymap (so the normal notmuch-show-mode-map\r
242    ;; remains).\r
243    (let ((mm-inline-text-html-with-w3m-keymap nil))\r
244 -    (notmuch-show-insert-part-*/* msg part content-type nth depth declared-type)))\r
245 +    (notmuch-show-insert-part-*/* msg part content-type nth depth button)))\r
246  \r
247 -(defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type)\r
248 +(defun notmuch-show-insert-part-*/* (msg part content-type nth depth button)\r
249    ;; This handler _must_ succeed - it is the handler of last resort.\r
250 -  (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename))\r
251    (notmuch-mm-display-part-inline msg part nth content-type notmuch-show-process-crypto)\r
252    t)\r
253  \r
254 @@ -786,13 +779,13 @@ message at DEPTH in the current thread."\r
255  \r
256  ;; \f\r
257 \r
258  \r
259 -(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth declared-type)\r
260 +(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth button)\r
261    (let ((handlers (notmuch-show-handlers-for content-type)))\r
262      ;; Run the content handlers until one of them returns a non-nil\r
263      ;; value.\r
264      (while (and handlers\r
265                 (not (condition-case err\r
266 -                        (funcall (car handlers) msg part content-type nth depth declared-type)\r
267 +                        (funcall (car handlers) msg part content-type nth depth button)\r
268                        (error (progn\r
269                                 (insert "!!! Bodypart insert error: ")\r
270                                 (insert (error-message-string err))\r
271 @@ -820,6 +813,7 @@ message at DEPTH in the current thread."\r
272    "Insert the body part PART at depth DEPTH in the current thread.\r
273  \r
274  If HIDE is non-nil then initially hide this part."\r
275 +\r
276    (let* ((content-type (downcase (plist-get part :content-type)))\r
277          (mime-type (or (and (string= content-type "application/octet-stream")\r
278                              (notmuch-show-get-mime-type-of-application/octet-stream part))\r
279 @@ -827,9 +821,12 @@ If HIDE is non-nil then initially hide this part."\r
280                              "text/x-diff")\r
281                         content-type))\r
282          (nth (plist-get part :id))\r
283 -        (beg (point)))\r
284 +        (beg (point))\r
285 +        ;; We omit the part button for the first (or only) part if this is text/plain.\r
286 +        (button (unless (and (string= mime-type "text/plain") (<= nth 1))\r
287 +                  (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))))\r
288  \r
289 -    (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type)\r
290 +    (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button)\r
291      ;; Some of the body part handlers leave point somewhere up in the\r
292      ;; part, so we make sure that we're down at the end.\r
293      (goto-char (point-max))\r
294 -- \r
295 1.7.10.4\r
296 \r