--- /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 5841F429E27\r
+ for <notmuch@notmuchmail.org>; Sat, 4 May 2013 06:01:42 -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 S04-YULMZ90Y for <notmuch@notmuchmail.org>;\r
+ Sat, 4 May 2013 06:01:38 -0700 (PDT)\r
+Received: from mail-wg0-f44.google.com (mail-wg0-f44.google.com\r
+ [74.125.82.44]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ E5568431FC2 for <notmuch@notmuchmail.org>; Sat, 4 May 2013 06:01:34 -0700\r
+ (PDT)\r
+Received: by mail-wg0-f44.google.com with SMTP id z12so2270349wgg.23\r
+ for <notmuch@notmuchmail.org>; Sat, 04 May 2013 06:01:33 -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:in-reply-to\r
+ :references; bh=6U5D+2I+rcHj/OFpFocWXP1C5uTpnVRglaMZEvjZ0IY=;\r
+ b=v0Qe8/Q4ijuqZhLTj+6syX7xDKQ7RP3w2A4i/QPgngQrMPvlmNXf8MI+eEWQh9j9th\r
+ 1N1Nbyxg5EQJuenZaqnOz+o0R6JnPMSxkbblCfZbiUsC1wi7d3xreLEQuy/Jy4nEke4n\r
+ 5qU3a4jJ48FnV943c6K85+WxYphTNptHmWOyAZBAKmbZOfQNjN0KPvJdJDWRPz0aOT65\r
+ CQe5lWtQ0t8amXUDgUxhbc200dm1UZT5Ha3bIiwGUf2Gesib5VhbWAHAQTAMJljXAr7j\r
+ m1KDGjPvfukriM4gjS7T6yWFGo5Ula5BsqF/y/qvMEnyESIdTbflcKKX4B7vJ0r7uEfu\r
+ qv/g==\r
+X-Received: by 10.180.187.206 with SMTP id fu14mr1994939wic.11.1367672493805; \r
+ Sat, 04 May 2013 06:01:33 -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 ge7sm3122936wib.6.2013.05.04.06.01.32\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sat, 04 May 2013 06:01:33 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/4] emacs: show: implement lazy hidden part handling\r
+Date: Sat, 4 May 2013 14:01:17 +0100\r
+Message-Id: <1367672478-12247-5-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1367672478-12247-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1367672478-12247-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: Sat, 04 May 2013 13:01:43 -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 2c48b24..a14a135 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
++ (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
+@@ -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 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
+@@ -857,6 +862,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
+@@ -891,7 +914,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