From 8c6fbe5cf9e87c6f142d377a38f329c95944269b Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Sat, 4 May 2013 14:01:17 +0100 Subject: [PATCH] [PATCH 4/4] emacs: show: implement lazy hidden part handling --- 9a/ddb3c00dc5e2e9b1ed31132ab40f359c8e3be3 | 144 ++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 9a/ddb3c00dc5e2e9b1ed31132ab40f359c8e3be3 diff --git a/9a/ddb3c00dc5e2e9b1ed31132ab40f359c8e3be3 b/9a/ddb3c00dc5e2e9b1ed31132ab40f359c8e3be3 new file mode 100644 index 000000000..f06932b79 --- /dev/null +++ b/9a/ddb3c00dc5e2e9b1ed31132ab40f359c8e3be3 @@ -0,0 +1,144 @@ +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 5841F429E27 + for ; Sat, 4 May 2013 06:01:42 -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 S04-YULMZ90Y for ; + Sat, 4 May 2013 06:01:38 -0700 (PDT) +Received: from mail-wg0-f44.google.com (mail-wg0-f44.google.com + [74.125.82.44]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + E5568431FC2 for ; Sat, 4 May 2013 06:01:34 -0700 + (PDT) +Received: by mail-wg0-f44.google.com with SMTP id z12so2270349wgg.23 + for ; Sat, 04 May 2013 06:01:33 -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:in-reply-to + :references; bh=6U5D+2I+rcHj/OFpFocWXP1C5uTpnVRglaMZEvjZ0IY=; + b=v0Qe8/Q4ijuqZhLTj+6syX7xDKQ7RP3w2A4i/QPgngQrMPvlmNXf8MI+eEWQh9j9th + 1N1Nbyxg5EQJuenZaqnOz+o0R6JnPMSxkbblCfZbiUsC1wi7d3xreLEQuy/Jy4nEke4n + 5qU3a4jJ48FnV943c6K85+WxYphTNptHmWOyAZBAKmbZOfQNjN0KPvJdJDWRPz0aOT65 + CQe5lWtQ0t8amXUDgUxhbc200dm1UZT5Ha3bIiwGUf2Gesib5VhbWAHAQTAMJljXAr7j + m1KDGjPvfukriM4gjS7T6yWFGo5Ula5BsqF/y/qvMEnyESIdTbflcKKX4B7vJ0r7uEfu + qv/g== +X-Received: by 10.180.187.206 with SMTP id fu14mr1994939wic.11.1367672493805; + Sat, 04 May 2013 06:01:33 -0700 (PDT) +Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) + by mx.google.com with ESMTPSA id ge7sm3122936wib.6.2013.05.04.06.01.32 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Sat, 04 May 2013 06:01:33 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [PATCH 4/4] emacs: show: implement lazy hidden part handling +Date: Sat, 4 May 2013 14:01:17 +0100 +Message-Id: <1367672478-12247-5-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.9.1 +In-Reply-To: <1367672478-12247-1-git-send-email-markwalters1009@gmail.com> +References: <1367672478-12247-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: Sat, 04 May 2013 13:01:43 -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 2c48b24..a14a135 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)) ++ (lazy-part (button-get button :notmuch-lazy-part)) + (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 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)) +@@ -857,6 +862,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)) +@@ -891,7 +914,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 + -- 2.26.2