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