Distribute manual page directly?
[notmuch-archives.git] / f3 / 5e6d3b895a8259bd940d9c5ab0ef13bf0c5e10
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 26171431FB6\r
6         for <notmuch@notmuchmail.org>; Fri,  3 May 2013 17:49:46 -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 pkISeT4jYKV1 for <notmuch@notmuchmail.org>;\r
18         Fri,  3 May 2013 17:49:40 -0700 (PDT)\r
19 Received: from mail-we0-f179.google.com (mail-we0-f179.google.com\r
20         [74.125.82.179]) (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 743FB431FAF\r
23         for <notmuch@notmuchmail.org>; Fri,  3 May 2013 17:49:40 -0700 (PDT)\r
24 Received: by mail-we0-f179.google.com with SMTP id t9so1741967wey.10\r
25         for <notmuch@notmuchmail.org>; Fri, 03 May 2013 17:49:37 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=x-received:from:to:cc:subject:date:message-id:x-mailer;\r
28         bh=/NWEjyPCuG+GUgrw/9729Q5EuuFWvMkmLj2bHw7N+KU=;\r
29         b=ZFXDDIzl5wE7KOCwH8paxOtQG2biEkgjbhsdW+kTlpusUtnvjF8EYwxYsb6ooW2O5t\r
30         Kk+wxzByMliN08JS8HxxLrru35mBs2k3DRRELL9vErQKVmVrB4ouXfVf1ro5tIbY5Xpa\r
31         r9Co5UAGUWPwc79HJu9EtLuQ27FdZ8AZm8HHsYcYuykGg2MQNmP2ZeGPyhWdwnvQbYFZ\r
32         fUbAAbevA4ye8hhdXJ8nR5rTDeqLP6ePgU9M6Pq2tKkBScl7FcfP1suHWV8hpci3cfz+\r
33         xw3KLHQp832tO0sVnQVf5hU78exQgSt/ENze+/kwxTd0z+y72Xe1vTC6aa7q7f/n/M+k\r
34         Z0OQ==\r
35 X-Received: by 10.194.58.163 with SMTP id s3mr16654261wjq.6.1367628576610;\r
36         Fri, 03 May 2013 17:49:36 -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 dj7sm346361wib.6.2013.05.03.17.49.35\r
39         for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Fri, 03 May 2013 17:49:35 -0700 (PDT)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [WIP] emacs: show: lazily insert html parts\r
45 Date: Sat,  4 May 2013 01:49:28 +0100\r
46 Message-Id: <1367628568-11656-1-git-send-email-markwalters1009@gmail.com>\r
47 X-Mailer: git-send-email 1.7.9.1\r
48 X-BeenThere: notmuch@notmuchmail.org\r
49 X-Mailman-Version: 2.1.13\r
50 Precedence: list\r
51 List-Id: "Use and development of the notmuch mail system."\r
52         <notmuch.notmuchmail.org>\r
53 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
54         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
55 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
56 List-Post: <mailto:notmuch@notmuchmail.org>\r
57 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
58 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
59         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
60 X-List-Received-Date: Sat, 04 May 2013 00:49:46 -0000\r
61 \r
62 The current code renders all html parts by default and then hides\r
63 them. This is quite slow so this is an attempt to make it only render\r
64 them when the user chooses to show them.\r
65 \r
66 In my testing this code seems to work but has some rough\r
67 edges. However, it may be useful to people in its current form  (and\r
68 I am not sure when I will have enough time to do more).\r
69 \r
70 There are various problems with the current approach and implementation:\r
71 \r
72 It special cases text/html (rather than lazily rendering all initially\r
73 hidden parts).\r
74 \r
75 If you toggle some multipart parts (the whole multipart part not the\r
76 subpart) then you can end up with the html part claiming to be visible\r
77 but not rendered. However toggling the html part twice fixes this. (If\r
78 I didn't special case text/html this might just work.)\r
79 \r
80 It may get the depth wrong by 1 if the text/html is part of a\r
81 multipart part.\r
82 \r
83 I think it adds an extra blank line at the end of the newly rendered\r
84 html part. If I fix this then the following message can get messed up\r
85 (this newly render part can end up inside the following header\r
86 overlay). Maybe someone more familiar with overlays can see how to fix\r
87 this easily.\r
88 \r
89 It just saves all the arguments which would have been passed to the\r
90 html rendering function to the part-button and then calls the\r
91 rendering function with them later. Given that we store the entire\r
92 message json this may not be necessary. On the other hand this does\r
93 make the code relatively simple.\r
94 \r
95 Any feedback on whether it works, much better ways of doing things etc\r
96 gratefully received!\r
97 \r
98 Best wishes\r
99 \r
100 Mark\r
101  \r
102 \r
103 ---\r
104 \r
105  \r
106 \r
107 \r
108 \r
109 \r
110 \r
111 \r
112  emacs/notmuch-show.el |   27 ++++++++++++++++++++++++---\r
113  1 files changed, 24 insertions(+), 3 deletions(-)\r
114 \r
115 diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
116 index face2a0..6749bc9 100644\r
117 --- a/emacs/notmuch-show.el\r
118 +++ b/emacs/notmuch-show.el\r
119 @@ -559,6 +559,7 @@ message at DEPTH in the current thread."\r
120          (overlay (button-get button 'overlay)))\r
121      (when overlay\r
122        (let* ((show (overlay-get overlay 'invisible))\r
123 +            (unparsed-html (button-get button :notmuch-html-properties))\r
124              (new-start (button-start button))\r
125              (button-label (button-get button :base-label))\r
126              (old-point (point))\r
127 @@ -569,7 +570,11 @@ message at DEPTH in the current thread."\r
128         (let ((old-end (button-end button)))\r
129           (move-overlay button new-start (point))\r
130           (delete-region (point) old-end))\r
131 -       (goto-char (min old-point (1- (button-end button))))))))\r
132 +       (goto-char (min old-point (1- (button-end button))))\r
133 +       (when (and show unparsed-html)\r
134 +         (save-excursion\r
135 +           (button-put button :notmuch-html-properties nil)\r
136 +           (notmuch-show-lazy-html-part unparsed-html overlay)))))))\r
137  \r
138  (defun notmuch-show-multipart/*-to-list (part)\r
139    (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
140 @@ -823,8 +828,24 @@ message at DEPTH in the current thread."\r
141    ;; in notmuch. We set mm-inline-text-html-with-w3m-keymap to nil to\r
142    ;; tell w3m not to set a keymap (so the normal notmuch-show-mode-map\r
143    ;; remains).\r
144 -  (let ((mm-inline-text-html-with-w3m-keymap nil))\r
145 -    (notmuch-show-insert-part-*/* msg part content-type nth depth declared-type)))\r
146 +  (let ((button (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename))))\r
147 +    (button-put button :notmuch-html-properties\r
148 +               (list msg part nth content-type notmuch-show-process-crypto)))\r
149 +  ;; We need to insert something or the part toggle gets suppressed.\r
150 +  (save-excursion\r
151 +      (insert "html"))\r
152 +  t)\r
153 +\r
154 +(defun notmuch-show-lazy-html-part (html overlay)\r
155 +  (interactive)\r
156 +  (let ((mm-inline-text-html-with-w3m-keymap nil)\r
157 +       (inhibit-read-only t))\r
158 +    (delete-region (overlay-start overlay) (1- (overlay-end overlay)))\r
159 +    (apply #'notmuch-mm-display-part-inline html))\r
160 +  (indent-rigidly (overlay-start overlay)\r
161 +                 (1- (overlay-end overlay))\r
162 +                 (notmuch-show-get-depth)))\r
163 +\r
164  \r
165  (defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type)\r
166    ;; This handler _must_ succeed - it is the handler of last resort.\r
167 -- \r
168 1.7.9.1\r
169 \r