--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 26171431FB6\r
+ for <notmuch@notmuchmail.org>; Fri, 3 May 2013 17:49:46 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id pkISeT4jYKV1 for <notmuch@notmuchmail.org>;\r
+ Fri, 3 May 2013 17:49:40 -0700 (PDT)\r
+Received: from mail-we0-f179.google.com (mail-we0-f179.google.com\r
+ [74.125.82.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 743FB431FAF\r
+ for <notmuch@notmuchmail.org>; Fri, 3 May 2013 17:49:40 -0700 (PDT)\r
+Received: by mail-we0-f179.google.com with SMTP id t9so1741967wey.10\r
+ for <notmuch@notmuchmail.org>; Fri, 03 May 2013 17:49:37 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=x-received:from:to:cc:subject:date:message-id:x-mailer;\r
+ bh=/NWEjyPCuG+GUgrw/9729Q5EuuFWvMkmLj2bHw7N+KU=;\r
+ b=ZFXDDIzl5wE7KOCwH8paxOtQG2biEkgjbhsdW+kTlpusUtnvjF8EYwxYsb6ooW2O5t\r
+ Kk+wxzByMliN08JS8HxxLrru35mBs2k3DRRELL9vErQKVmVrB4ouXfVf1ro5tIbY5Xpa\r
+ r9Co5UAGUWPwc79HJu9EtLuQ27FdZ8AZm8HHsYcYuykGg2MQNmP2ZeGPyhWdwnvQbYFZ\r
+ fUbAAbevA4ye8hhdXJ8nR5rTDeqLP6ePgU9M6Pq2tKkBScl7FcfP1suHWV8hpci3cfz+\r
+ xw3KLHQp832tO0sVnQVf5hU78exQgSt/ENze+/kwxTd0z+y72Xe1vTC6aa7q7f/n/M+k\r
+ Z0OQ==\r
+X-Received: by 10.194.58.163 with SMTP id s3mr16654261wjq.6.1367628576610;\r
+ Fri, 03 May 2013 17:49:36 -0700 (PDT)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+ by mx.google.com with ESMTPSA id dj7sm346361wib.6.2013.05.03.17.49.35\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Fri, 03 May 2013 17:49:35 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP] emacs: show: lazily insert html parts\r
+Date: Sat, 4 May 2013 01:49:28 +0100\r
+Message-Id: <1367628568-11656-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sat, 04 May 2013 00:49:46 -0000\r
+\r
+The current code renders all html parts by default and then hides\r
+them. This is quite slow so this is an attempt to make it only render\r
+them when the user chooses to show them.\r
+\r
+In my testing this code seems to work but has some rough\r
+edges. However, it may be useful to people in its current form (and\r
+I am not sure when I will have enough time to do more).\r
+\r
+There are various problems with the current approach and implementation:\r
+\r
+It special cases text/html (rather than lazily rendering all initially\r
+hidden parts).\r
+\r
+If you toggle some multipart parts (the whole multipart part not the\r
+subpart) then you can end up with the html part claiming to be visible\r
+but not rendered. However toggling the html part twice fixes this. (If\r
+I didn't special case text/html this might just work.)\r
+\r
+It may get the depth wrong by 1 if the text/html is part of a\r
+multipart part.\r
+\r
+I think it adds an extra blank line at the end of the newly rendered\r
+html part. If I fix this then the following message can get messed up\r
+(this newly render part can end up inside the following header\r
+overlay). Maybe someone more familiar with overlays can see how to fix\r
+this easily.\r
+\r
+It just saves all the arguments which would have been passed to the\r
+html rendering function to the part-button and then calls the\r
+rendering function with them later. Given that we store the entire\r
+message json this may not be necessary. On the other hand this does\r
+make the code relatively simple.\r
+\r
+Any feedback on whether it works, much better ways of doing things etc\r
+gratefully received!\r
+\r
+Best wishes\r
+\r
+Mark\r
+ \r
+\r
+---\r
+\r
+ \r
+\r
+\r
+\r
+\r
+\r
+\r
+ emacs/notmuch-show.el | 27 ++++++++++++++++++++++++---\r
+ 1 files changed, 24 insertions(+), 3 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index face2a0..6749bc9 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -559,6 +559,7 @@ message at DEPTH in the current thread."\r
+ (overlay (button-get button 'overlay)))\r
+ (when overlay\r
+ (let* ((show (overlay-get overlay 'invisible))\r
++ (unparsed-html (button-get button :notmuch-html-properties))\r
+ (new-start (button-start button))\r
+ (button-label (button-get button :base-label))\r
+ (old-point (point))\r
+@@ -569,7 +570,11 @@ message at DEPTH in the current thread."\r
+ (let ((old-end (button-end button)))\r
+ (move-overlay button new-start (point))\r
+ (delete-region (point) old-end))\r
+- (goto-char (min old-point (1- (button-end button))))))))\r
++ (goto-char (min old-point (1- (button-end button))))\r
++ (when (and show unparsed-html)\r
++ (save-excursion\r
++ (button-put button :notmuch-html-properties nil)\r
++ (notmuch-show-lazy-html-part unparsed-html overlay)))))))\r
+ \r
+ (defun notmuch-show-multipart/*-to-list (part)\r
+ (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
+@@ -823,8 +828,24 @@ message at DEPTH in the current thread."\r
+ ;; in notmuch. We set mm-inline-text-html-with-w3m-keymap to nil to\r
+ ;; tell w3m not to set a keymap (so the normal notmuch-show-mode-map\r
+ ;; remains).\r
+- (let ((mm-inline-text-html-with-w3m-keymap nil))\r
+- (notmuch-show-insert-part-*/* msg part content-type nth depth declared-type)))\r
++ (let ((button (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename))))\r
++ (button-put button :notmuch-html-properties\r
++ (list msg part nth content-type notmuch-show-process-crypto)))\r
++ ;; We need to insert something or the part toggle gets suppressed.\r
++ (save-excursion\r
++ (insert "html"))\r
++ t)\r
++\r
++(defun notmuch-show-lazy-html-part (html overlay)\r
++ (interactive)\r
++ (let ((mm-inline-text-html-with-w3m-keymap nil)\r
++ (inhibit-read-only t))\r
++ (delete-region (overlay-start overlay) (1- (overlay-end overlay)))\r
++ (apply #'notmuch-mm-display-part-inline html))\r
++ (indent-rigidly (overlay-start overlay)\r
++ (1- (overlay-end overlay))\r
++ (notmuch-show-get-depth)))\r
++\r
+ \r
+ (defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type)\r
+ ;; This handler _must_ succeed - it is the handler of last resort.\r
+-- \r
+1.7.9.1\r
+\r