From: Mark Walters <markwalters1009@gmail.com>
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 [thread overview]
Message-ID: <1369555061-21361-4-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1369555061-21361-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 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
next prev parent reply other threads:[~2013-05-26 7:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-26 7:57 [PATCH v2 0/3] emacs: show: lazy handling of hidden parts Mark Walters
2013-05-26 7:57 ` [PATCH v2 1/3] emacs: show: fake wash parts are handled at insert-bodypart level Mark Walters
2013-05-26 7:57 ` [PATCH v2 2/3] emacs: show: move the insertion of the header button to the top level Mark Walters
2013-05-30 22:30 ` Austin Clements
2013-05-26 7:57 ` Mark Walters [this message]
2013-05-30 23:28 ` [PATCH v2 3/3] emacs: show: implement lazy hidden part handling Austin Clements
2013-05-31 4:16 ` [PATCH v2 0/3] emacs: show: lazy handling of hidden parts Adam Wolfe Gordon
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=1369555061-21361-4-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).