From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH 4/4] emacs: show: implement lazy hidden part handling
Date: Sat, 4 May 2013 14:01:17 +0100 [thread overview]
Message-ID: <1367672478-12247-5-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1367672478-12247-1-git-send-email-markwalters1009@gmail.com>
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
prev parent reply other threads:[~2013-05-04 13:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-04 13:01 [PATCH 0/4] emacs: show: lazy handling of hidden parts Mark Walters
2013-05-04 13:01 ` [PATCH 1/4] emacs:show: separate out handling of application/octet-stream Mark Walters
2013-05-04 13:01 ` [PATCH 2/4] emacs: show: handle inline patch fake parts at top level Mark Walters
2013-05-20 18:43 ` David Bremner
2013-05-04 13:01 ` [PATCH 3/4] emacs: show: move the insertion of the header button to the " Mark Walters
2013-05-04 13:01 ` Mark Walters [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1367672478-12247-5-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).