[PATCH 3/3] emacs: show: add invisibility button action

Austin Clements aclements at csail.mit.edu
Mon Dec 10 20:06:48 PST 2012


On Tue, 04 Dec 2012, Mark Walters <markwalters1009 at gmail.com> wrote:
> This adds a button action to show hidden parts. In this version "t"
> toggles the visibility of a part. In addition "RET" on a non-shown
> part shows it.
>
> The button is used to hide parts when appropriate (eg text/html in
> multipart/alternative).
> ---
>  emacs/notmuch-show.el |   36 +++++++++++++++++++++++++++++++++++-
>  1 files changed, 35 insertions(+), 1 deletions(-)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index 3215ebc..a4daff8 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -478,6 +478,7 @@ message at DEPTH in the current thread."
>      (define-key map "v" 'notmuch-show-part-button-view)
>      (define-key map "o" 'notmuch-show-part-button-interactively-view)
>      (define-key map "|" 'notmuch-show-part-button-pipe)
> +    (define-key map "t" 'notmuch-show-toggle-invisible-part-action)
>      map)
>    "Submap for button commands")
>  (fset 'notmuch-show-part-button-map notmuch-show-part-button-map)
> @@ -555,6 +556,31 @@ message at DEPTH in the current thread."
>      (let ((handle (mm-make-handle (current-buffer) (list content-type))))
>        (mm-pipe-part handle))))
>  
> +;; This is taken from notmuch-wash: maybe it should be unified?
> +(defun notmuch-show-toggle-invisible-part-action (&optional button no-redisplay)
> +  (interactive)
> +  (let* ((button (or button (button-at (point))))
> +	 (overlay (button-get button 'overlay))
> +	 (invis-spec (button-get button 'invisibility-spec))
> +	 (show (invisible-p invis-spec)))
> +    (when overlay
> +      (if show
> +	  (remove-from-invisibility-spec invis-spec)
> +	(add-to-invisibility-spec invis-spec))
> +      (let* ((new-start (button-start button))
> +	     (button-label (button-get button :base-label))
> +	     (old-point (point))
> +	     (inhibit-read-only t))
> +	(goto-char new-start)
> +	(insert "[ " button-label (if show " ]" " (not shown) ]"))

s/not shown/hidden/?

> +	(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)))))
> +      (unless no-redisplay
> +	(force-window-update)
> +	(redisplay t)))))

Is the t argument necessary?  Actually, are either (force-window-update)
or (redisplay) necessary?

> +
>  (defun notmuch-show-multipart/*-to-list (part)
>    (mapcar (lambda (inner-part) (plist-get inner-part :content-type))
>  	  (plist-get part :content)))
> @@ -867,6 +893,11 @@ message at DEPTH in the current thread."
>  
>  	(button-put button 'invisibility-spec invis-spec)
>  	(button-put button 'overlay overlay))
> +
> +      ;; We toggle the button for hidden parts as that gets the
> +      ;; button label right.
> +      (when not-shown
> +	(notmuch-show-toggle-invisible-part-action button t))
>        (goto-char (point-max)))))
>  
>  (defun notmuch-show-insert-bodypart (msg part depth &optional not-shown)
> @@ -1996,7 +2027,10 @@ the user (see `notmuch-show-stash-mlarchive-link-alist')."
>  
>  (defun notmuch-show-part-button-default (&optional button)
>    (interactive)
> -  (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))
> +  (let ((button (or button (button-at (point)))))
> +    (if (invisible-p (button-get button 'invisibility-spec))
> +	(notmuch-show-toggle-invisible-part-action button)
> +      (notmuch-show-part-button-internal button notmuch-show-part-button-default-action))))
>  
>  (defun notmuch-show-part-button-save (&optional button)
>    (interactive)
> -- 
> 1.7.9.1


More information about the notmuch mailing list