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 ACB1B431FD7 for ; Sun, 26 May 2013 00:58:00 -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 d1zuUVQoHW6n for ; Sun, 26 May 2013 00:57:56 -0700 (PDT) Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com [209.85.212.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id D5535431FC7 for ; Sun, 26 May 2013 00:57:52 -0700 (PDT) Received: by mail-wi0-f169.google.com with SMTP id hn14so1405833wib.4 for ; Sun, 26 May 2013 00:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=QjqKu2DUsmeJY/yd0s9foIdlA18eZctrQUHqynoiwlk=; b=eszgWsSbjwkHAuQidi+p+hYPAfac3kLy51KdfTjcy+lK/csex3JxyV+9kch4i2uTy7 hjPEB3o0NnTbtlZEWevzk40Hxeac5Ssuh9AwG6ABJMJKm8prPXqnnrJXZnXJZgsiowpY iRihtI533LH9qGACGYfOqjGpjHs0atz0HgBRnIUqsAddKNk4y7c91okZQHI8YZ+7spVE RYL5752B+4QizC1FdYScUhXNCUx/dwP8xUMFDIYfl4twEMNJNr8UwNWpDyJERzdqF7A9 oNXMPvqAj0vnKpWuZrTmbocchPllZoi2pGmfiUttdxwuIwhqINQ2yV2TjqHuFeveRGvO +beA== X-Received: by 10.180.36.147 with SMTP id q19mr4186806wij.26.1369555071803; Sun, 26 May 2013 00:57:51 -0700 (PDT) Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) by mx.google.com with ESMTPSA id b11sm9260844wiv.10.2013.05.26.00.57.50 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 26 May 2013 00:57:51 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH v2 3/3] emacs: show: implement lazy hidden part handling Date: Sun, 26 May 2013 08:57:41 +0100 Message-Id: <1369555061-21361-4-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.9.1 In-Reply-To: <1369555061-21361-1-git-send-email-markwalters1009@gmail.com> References: <1369555061-21361-1-git-send-email-markwalters1009@gmail.com> 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: Sun, 26 May 2013 07:58:01 -0000 This adds the actual code to do the lazy insertion of hidden parts. We use a memory inefficient but simple method: when we come to insert the part if it is hidden we just store all of the arguments to the part insertion function as a button property. This means when we want to show the part we can just resume where we left off. The only slight subtlety/hack is that to simplify the handling of the invisibility overlay (for the hiding unhiding later) we do insert some dummy text which we remove when we show the part. --- emacs/notmuch-show.el | 32 ++++++++++++++++++++++++++++++-- 1 files changed, 30 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 591ad56..94faa9b 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -560,6 +560,7 @@ message at DEPTH in the current thread." (overlay (button-get button 'overlay))) (when overlay (let* ((show (overlay-get overlay 'invisible)) + (lazy-part (button-get button :notmuch-lazy-part)) (new-start (button-start button)) (button-label (button-get button :base-label)) (old-point (point)) @@ -570,7 +571,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 lazy-part) + (save-excursion + (button-put button :notmuch-lazy-part nil) + (notmuch-show-lazy-part lazy-part button))))))) (defun notmuch-show-multipart/*-to-list (part) (mapcar (lambda (inner-part) (plist-get inner-part :content-type)) @@ -854,6 +859,24 @@ message at DEPTH in the current thread." (setq handlers (cdr handlers)))) t) +(defun notmuch-show-lazy-part (part-args button) + (interactive) + ;; We have to save the depth as we can't find the depth when narrowed + (let ((inhibit-read-only t) + (overlay (button-get button 'overlay)) + (depth (notmuch-show-get-depth))) + (save-restriction + (narrow-to-region (overlay-start overlay) (1- (overlay-end overlay))) + (delete-region (overlay-start overlay) (1- (overlay-end overlay))) + (goto-char (overlay-start overlay)) + (apply #'notmuch-show-insert-bodypart-internal (nconc part-args (list button))) + (indent-rigidly (overlay-start overlay) + (1- (overlay-end overlay)) + depth)) + ;; We deferred deleting this character to simplify handling of the + ;; overlay: all of the above takes place inside the overlay. + (delete-region (1- (overlay-end overlay)) (overlay-end overlay)))) + (defun notmuch-show-create-part-overlays (msg beg end hide) "Add an overlay to the part between BEG and END" (let* ((button (button-at beg)) @@ -888,7 +911,12 @@ If HIDE is non-nil then initially hide this part." (button (unless (string= mime-type "text/plain") (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename))))) - (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type button) + (if (not hide) + (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type button) + (insert "lazy part") + (button-put button :notmuch-lazy-part + (list msg part mime-type nth depth content-type))) + ;; Some of the body part handlers leave point somewhere up in the ;; part, so we make sure that we're down at the end. (goto-char (point-max)) -- 1.7.9.1