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