mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
emacs: show: modify the way hidden state is recorded.
Previously, whether a part was hidden or shown was recorded in the invisibility/visibility of the part overlay. Since we are going to have lazily rendered parts with no overlay store the hidden/shown state in the part button itself. Additionally, in preparation for the invisible part handling move the actual hiding of the hidden parts to insert-bodypart from create-part-overlays. Finally, we will need to know whether a part-insertion has done anything (it won't if the invisible part cannot be displayed by emacs) so we slightly rejig the code order in notmuch-show-toggle-part-invisibility to make it easier for the function to set an appropriate return value.
This commit is contained in:
parent
81c199c962
commit
490b02345e
1 changed files with 14 additions and 11 deletions
|
@ -482,7 +482,8 @@ message at DEPTH in the current thread."
|
||||||
(insert-button
|
(insert-button
|
||||||
(concat "[ " base-label " ]")
|
(concat "[ " base-label " ]")
|
||||||
:base-label base-label
|
:base-label base-label
|
||||||
:type 'notmuch-show-part-button-type))
|
:type 'notmuch-show-part-button-type
|
||||||
|
:notmuch-part-hidden nil))
|
||||||
(insert "\n")
|
(insert "\n")
|
||||||
;; return button
|
;; return button
|
||||||
button))
|
button))
|
||||||
|
@ -493,20 +494,22 @@ message at DEPTH in the current thread."
|
||||||
(let* ((button (or button (button-at (point))))
|
(let* ((button (or button (button-at (point))))
|
||||||
(overlay (button-get button 'overlay)))
|
(overlay (button-get button 'overlay)))
|
||||||
(when overlay
|
(when overlay
|
||||||
(let* ((show (overlay-get overlay 'invisible))
|
(let* ((show (button-get button :notmuch-part-hidden))
|
||||||
(new-start (button-start button))
|
(new-start (button-start button))
|
||||||
(button-label (button-get button :base-label))
|
(button-label (button-get button :base-label))
|
||||||
(old-point (point))
|
(old-point (point))
|
||||||
(properties (text-properties-at (point)))
|
(properties (text-properties-at (point)))
|
||||||
(inhibit-read-only t))
|
(inhibit-read-only t))
|
||||||
(overlay-put overlay 'invisible (not show))
|
;; Toggle the button itself.
|
||||||
|
(button-put button :notmuch-part-hidden (not show))
|
||||||
(goto-char new-start)
|
(goto-char new-start)
|
||||||
(insert "[ " button-label (if show " ]" " (hidden) ]"))
|
(insert "[ " button-label (if show " ]" " (hidden) ]"))
|
||||||
(set-text-properties new-start (point) properties)
|
(set-text-properties new-start (point) properties)
|
||||||
(let ((old-end (button-end button)))
|
(let ((old-end (button-end button)))
|
||||||
(move-overlay button new-start (point))
|
(move-overlay button new-start (point))
|
||||||
(delete-region (point) old-end))
|
(delete-region (point) old-end))
|
||||||
(goto-char (min old-point (1- (button-end button))))))))
|
(goto-char (min old-point (1- (button-end button))))
|
||||||
|
(overlay-put overlay 'invisible (not show))))))
|
||||||
|
|
||||||
;; MIME part renderers
|
;; MIME part renderers
|
||||||
|
|
||||||
|
@ -793,7 +796,7 @@ message at DEPTH in the current thread."
|
||||||
(setq handlers (cdr handlers))))
|
(setq handlers (cdr handlers))))
|
||||||
t)
|
t)
|
||||||
|
|
||||||
(defun notmuch-show-create-part-overlays (button beg end hide)
|
(defun notmuch-show-create-part-overlays (button beg end)
|
||||||
"Add an overlay to the part between BEG and END"
|
"Add an overlay to the part between BEG and END"
|
||||||
|
|
||||||
;; If there is no button (i.e., the part is text/plain and the first
|
;; If there is no button (i.e., the part is text/plain and the first
|
||||||
|
@ -801,11 +804,8 @@ message at DEPTH in the current thread."
|
||||||
;; toggleable.
|
;; toggleable.
|
||||||
(when (and button (/= beg end))
|
(when (and button (/= beg end))
|
||||||
(button-put button 'overlay (make-overlay beg end))
|
(button-put button 'overlay (make-overlay beg end))
|
||||||
;; We toggle the button for hidden parts as that gets the
|
;; Return true if we created an overlay.
|
||||||
;; button label right.
|
t))
|
||||||
(save-excursion
|
|
||||||
(when hide
|
|
||||||
(notmuch-show-toggle-part-invisibility button)))))
|
|
||||||
|
|
||||||
(defun notmuch-show-insert-bodypart (msg part depth &optional hide)
|
(defun notmuch-show-insert-bodypart (msg part depth &optional hide)
|
||||||
"Insert the body part PART at depth DEPTH in the current thread.
|
"Insert the body part PART at depth DEPTH in the current thread.
|
||||||
|
@ -832,7 +832,10 @@ If HIDE is non-nil then initially hide this part."
|
||||||
;; Ensure that the part ends with a carriage return.
|
;; Ensure that the part ends with a carriage return.
|
||||||
(unless (bolp)
|
(unless (bolp)
|
||||||
(insert "\n"))
|
(insert "\n"))
|
||||||
(notmuch-show-create-part-overlays button content-beg (point) hide)
|
(notmuch-show-create-part-overlays button content-beg (point))
|
||||||
|
(when hide
|
||||||
|
(save-excursion
|
||||||
|
(notmuch-show-toggle-part-invisibility button)))
|
||||||
;; Record part information. Since we already inserted subparts,
|
;; Record part information. Since we already inserted subparts,
|
||||||
;; don't override existing :notmuch-part properties.
|
;; don't override existing :notmuch-part properties.
|
||||||
(notmuch-map-text-property beg (point) :notmuch-part
|
(notmuch-map-text-property beg (point) :notmuch-part
|
||||||
|
|
Loading…
Reference in a new issue