mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
emacs/show: Accommodate the lack of part header buttons
Various pieces of code assumed (reasonably) that part header buttons are present. Modify them to avoid problems if no part headers were inserted.
This commit is contained in:
parent
92a1f9ba17
commit
c802d12a1e
1 changed files with 48 additions and 40 deletions
|
@ -501,36 +501,37 @@ message at DEPTH in the current thread."
|
||||||
|
|
||||||
(defun notmuch-show-toggle-part-invisibility (&optional button)
|
(defun notmuch-show-toggle-part-invisibility (&optional button)
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((button (or button (button-at (point))))
|
(let ((button (or button (button-at (point)))))
|
||||||
(overlay (button-get button 'overlay))
|
(when button
|
||||||
(lazy-part (button-get button :notmuch-lazy-part)))
|
(let ((overlay (button-get button 'overlay))
|
||||||
;; We have a part to toggle if there is an overlay or if there is a lazy part.
|
(lazy-part (button-get button :notmuch-lazy-part)))
|
||||||
;; If neither is present we cannot toggle the part so we just return nil.
|
;; We have a part to toggle if there is an overlay or if there is a lazy part.
|
||||||
(when (or overlay lazy-part)
|
;; If neither is present we cannot toggle the part so we just return nil.
|
||||||
(let* ((show (button-get button :notmuch-part-hidden))
|
(when (or overlay lazy-part)
|
||||||
(new-start (button-start button))
|
(let* ((show (button-get button :notmuch-part-hidden))
|
||||||
(button-label (button-get button :base-label))
|
(new-start (button-start button))
|
||||||
(old-point (point))
|
(button-label (button-get button :base-label))
|
||||||
(properties (text-properties-at (button-start button)))
|
(old-point (point))
|
||||||
(inhibit-read-only t))
|
(properties (text-properties-at (button-start button)))
|
||||||
;; Toggle the button itself.
|
(inhibit-read-only t))
|
||||||
(button-put button :notmuch-part-hidden (not show))
|
;; Toggle the button itself.
|
||||||
(goto-char new-start)
|
(button-put button :notmuch-part-hidden (not show))
|
||||||
(insert "[ " button-label (if show " ]" " (hidden) ]"))
|
(goto-char new-start)
|
||||||
(set-text-properties new-start (point) properties)
|
(insert "[ " button-label (if show " ]" " (hidden) ]"))
|
||||||
(let ((old-end (button-end button)))
|
(set-text-properties new-start (point) properties)
|
||||||
(move-overlay button new-start (point))
|
(let ((old-end (button-end button)))
|
||||||
(delete-region (point) old-end))
|
(move-overlay button new-start (point))
|
||||||
(goto-char (min old-point (1- (button-end button))))
|
(delete-region (point) old-end))
|
||||||
;; Return nil if there is a lazy-part, it is empty, and we are
|
(goto-char (min old-point (1- (button-end button))))
|
||||||
;; trying to show it. In all other cases return t.
|
;; Return nil if there is a lazy-part, it is empty, and we are
|
||||||
(if lazy-part
|
;; trying to show it. In all other cases return t.
|
||||||
(when show
|
(if lazy-part
|
||||||
(button-put button :notmuch-lazy-part nil)
|
(when show
|
||||||
(notmuch-show-lazy-part lazy-part button))
|
(button-put button :notmuch-lazy-part nil)
|
||||||
;; else there must be an overlay.
|
(notmuch-show-lazy-part lazy-part button))
|
||||||
(overlay-put overlay 'invisible (not show))
|
;; else there must be an overlay.
|
||||||
t)))))
|
(overlay-put overlay 'invisible (not show))
|
||||||
|
t)))))))
|
||||||
|
|
||||||
;; Part content ID handling
|
;; Part content ID handling
|
||||||
|
|
||||||
|
@ -639,14 +640,17 @@ will return nil if the CID is unknown or cannot be retrieved."
|
||||||
t)
|
t)
|
||||||
|
|
||||||
(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button)
|
(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button)
|
||||||
(button-put button 'face 'notmuch-crypto-part-header)
|
(when button
|
||||||
;; add signature status button if sigstatus provided
|
(button-put button 'face 'notmuch-crypto-part-header))
|
||||||
|
;; Add signature status button if sigstatus provided.
|
||||||
(if (plist-member part :sigstatus)
|
(if (plist-member part :sigstatus)
|
||||||
(let* ((from (notmuch-show-get-header :From msg))
|
(let* ((from (notmuch-show-get-header :From msg))
|
||||||
(sigstatus (car (plist-get part :sigstatus))))
|
(sigstatus (car (plist-get part :sigstatus))))
|
||||||
(notmuch-crypto-insert-sigstatus-button sigstatus from))
|
(notmuch-crypto-insert-sigstatus-button sigstatus from))
|
||||||
;; if we're not adding sigstatus, tell the user how they can get it
|
;; If we're not adding the signature status, tell the user how
|
||||||
(button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))
|
;; they can get it.
|
||||||
|
(when button
|
||||||
|
(button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))
|
||||||
|
|
||||||
(let ((inner-parts (plist-get part :content))
|
(let ((inner-parts (plist-get part :content))
|
||||||
(start (point)))
|
(start (point)))
|
||||||
|
@ -660,17 +664,20 @@ will return nil if the CID is unknown or cannot be retrieved."
|
||||||
t)
|
t)
|
||||||
|
|
||||||
(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth button)
|
(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth button)
|
||||||
(button-put button 'face 'notmuch-crypto-part-header)
|
(when button
|
||||||
;; add encryption status button if encstatus specified
|
(button-put button 'face 'notmuch-crypto-part-header))
|
||||||
|
;; Add encryption status button if encryption status is specified.
|
||||||
(if (plist-member part :encstatus)
|
(if (plist-member part :encstatus)
|
||||||
(let ((encstatus (car (plist-get part :encstatus))))
|
(let ((encstatus (car (plist-get part :encstatus))))
|
||||||
(notmuch-crypto-insert-encstatus-button encstatus)
|
(notmuch-crypto-insert-encstatus-button encstatus)
|
||||||
;; add signature status button if sigstatus specified
|
;; Add signature status button if signature status is
|
||||||
|
;; specified.
|
||||||
(if (plist-member part :sigstatus)
|
(if (plist-member part :sigstatus)
|
||||||
(let* ((from (notmuch-show-get-header :From msg))
|
(let* ((from (notmuch-show-get-header :From msg))
|
||||||
(sigstatus (car (plist-get part :sigstatus))))
|
(sigstatus (car (plist-get part :sigstatus))))
|
||||||
(notmuch-crypto-insert-sigstatus-button sigstatus from))))
|
(notmuch-crypto-insert-sigstatus-button sigstatus from))))
|
||||||
;; if we're not adding encstatus, tell the user how they can get it
|
;; If we're not adding the encryption status, tell the user how
|
||||||
|
;; they can get it.
|
||||||
(button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))
|
(button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))
|
||||||
|
|
||||||
(let ((inner-parts (plist-get part :content))
|
(let ((inner-parts (plist-get part :content))
|
||||||
|
@ -980,8 +987,9 @@ useful for quoting in replies)."
|
||||||
|
|
||||||
(if show-part
|
(if show-part
|
||||||
(notmuch-show-insert-bodypart-internal msg part mime-type nth depth button)
|
(notmuch-show-insert-bodypart-internal msg part mime-type nth depth button)
|
||||||
(button-put button :notmuch-lazy-part
|
(when button
|
||||||
(list msg part mime-type nth depth button)))
|
(button-put button :notmuch-lazy-part
|
||||||
|
(list msg part mime-type nth depth button))))
|
||||||
|
|
||||||
;; Some of the body part handlers leave point somewhere up in the
|
;; Some of the body part handlers leave point somewhere up in the
|
||||||
;; part, so we make sure that we're down at the end.
|
;; part, so we make sure that we're down at the end.
|
||||||
|
|
Loading…
Reference in a new issue