This make notmuch-show-insert-bodypart add an overlay for any
non-trivial part with a button header (currently the first text/plain
part does not have a button). At this point the overlay is available
to the button but there is no action using it yet.

In addition a not-shown variable which is used to request the part be
hidden by default down to the overlay but this is not acted on yet.
---
 emacs/notmuch-show.el |   62 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 48 insertions(+), 14 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index f8ce037..3215ebc 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -569,10 +569,9 @@ message at DEPTH in the current thread."
     ;; should be chosen if there are more than one that match?
     (mapc (lambda (inner-part)
            (let ((inner-type (plist-get inner-part :content-type)))
-             (if (or notmuch-show-all-multipart/alternative-parts
-                     (string= chosen-type inner-type))
-                 (notmuch-show-insert-bodypart msg inner-part depth)
-               (notmuch-show-insert-part-header (plist-get inner-part :id) 
inner-type inner-type nil " (not shown)"))))
+             (notmuch-show-insert-bodypart msg inner-part depth
+                                           (not (or 
notmuch-show-all-multipart/alternative-parts
+                                                    (string= chosen-type 
inner-type))))))
          inner-parts)

     (when notmuch-show-indent-multipart
@@ -840,17 +839,52 @@ message at DEPTH in the current thread."
       (setq handlers (cdr handlers))))
   t)

-(defun notmuch-show-insert-bodypart (msg part depth)
-  "Insert the body part PART at depth DEPTH in the current thread."
+(defun notmuch-show-insert-part-overlays (msg beg end not-shown)
+  "Add an overlay to the part between BEG and END"
+  (let* ((button (button-at beg))
+        (part-beg (and button (1+ (button-end button)))))
+
+    ;; If the part contains no text we do not make it toggleable.
+    (unless (or (not button) (eq part-beg end))
+      (let ((base-label (button-get button :base-label))
+           (overlay (make-overlay part-beg end))
+           (message-invis-spec (plist-get msg :message-invis-spec))
+           (invis-spec (make-symbol "notmuch-part-region")))
+
+       (overlay-put overlay 'invisible (list invis-spec message-invis-spec))
+       (overlay-put overlay 'isearch-open-invisible 
#'notmuch-wash-region-isearch-show)
+       (overlay-put overlay 'priority 10)
+       (overlay-put overlay 'type "part")
+       ;; Now we have to add invis-spec to every overlay this
+       ;; overlay contains, otherwise these inner overlays will
+       ;; override this one.
+       (mapc (lambda (inner)
+               (when (and (>= (overlay-start inner) part-beg)
+                          (<= (overlay-end inner) end))
+                 (overlay-put inner 'invisible
+                              (cons invis-spec (overlay-get inner 
'invisible)))))
+             (overlays-in part-beg end))
+
+       (button-put button 'invisibility-spec invis-spec)
+       (button-put button 'overlay overlay))
+      (goto-char (point-max)))))
+
+(defun notmuch-show-insert-bodypart (msg part depth &optional not-shown)
+  "Insert the body part PART at depth DEPTH in the current thread.
+
+If not-shown is TRUE then initially hide this part."
   (let ((content-type (downcase (plist-get part :content-type)))
-       (nth (plist-get part :id)))
-    (notmuch-show-insert-bodypart-internal msg part content-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))
-  ;; Ensure that the part ends with a carriage return.
-  (unless (bolp)
-    (insert "\n")))
+       (nth (plist-get part :id))
+       (beg (point)))
+
+    (notmuch-show-insert-bodypart-internal msg part content-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))
+    ;; Ensure that the part ends with a carriage return.
+    (unless (bolp)
+      (insert "\n"))
+    (notmuch-show-insert-part-overlays msg beg (point) not-shown)))

 (defun notmuch-show-insert-body (msg body depth)
   "Insert the body BODY at depth DEPTH in the current thread."
-- 
1.7.9.1

Reply via email to