[PATCH v3 3/9] emacs/show: Accommodate the lack of part header buttons
On Mon, 12 May 2014, David Edmondson wrote: > Various pieces of code assumed (reasonably) that part header buttons > are present. Modify them to avoid problems if no part headers were > inserted. Despite your reservations on irc this looks fine to me. MW > --- > emacs/notmuch-show.el | 88 > --- > 1 file changed, 48 insertions(+), 40 deletions(-) > > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el > index f78a0ab..e511655 100644 > --- a/emacs/notmuch-show.el > +++ b/emacs/notmuch-show.el > @@ -494,36 +494,37 @@ message at DEPTH in the current thread." > > (defun notmuch-show-toggle-part-invisibility (&optional button) >(interactive) > - (let* ((button (or button (button-at (point > - (overlay (button-get button 'overlay)) > - (lazy-part (button-get button :notmuch-lazy-part))) > -;; We have a part to toggle if there is an overlay or if there is a lazy > part. > -;; If neither is present we cannot toggle the part so we just return nil. > -(when (or overlay lazy-part) > - (let* ((show (button-get button :notmuch-part-hidden)) > - (new-start (button-start button)) > - (button-label (button-get button :base-label)) > - (old-point (point)) > - (properties (text-properties-at (button-start button))) > - (inhibit-read-only t)) > - ;; Toggle the button itself. > - (button-put button :notmuch-part-hidden (not show)) > - (goto-char new-start) > - (insert "[ " button-label (if show " ]" " (hidden) ]")) > - (set-text-properties new-start (point) properties) > - (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 > - ;; Return nil if there is a lazy-part, it is empty, and we are > - ;; trying to show it. In all other cases return t. > - (if lazy-part > - (when show > - (button-put button :notmuch-lazy-part nil) > - (notmuch-show-lazy-part lazy-part button)) > - ;; else there must be an overlay. > - (overlay-put overlay 'invisible (not show)) > - t) > + (let ((button (or button (button-at (point) > +(when button > + (let ((overlay (button-get button 'overlay)) > + (lazy-part (button-get button :notmuch-lazy-part))) > + ;; We have a part to toggle if there is an overlay or if there is a > lazy part. > + ;; If neither is present we cannot toggle the part so we just return > nil. > + (when (or overlay lazy-part) > + (let* ((show (button-get button :notmuch-part-hidden)) > + (new-start (button-start button)) > + (button-label (button-get button :base-label)) > + (old-point (point)) > + (properties (text-properties-at (button-start button))) > + (inhibit-read-only t)) > + ;; Toggle the button itself. > + (button-put button :notmuch-part-hidden (not show)) > + (goto-char new-start) > + (insert "[ " button-label (if show " ]" " (hidden) ]")) > + (set-text-properties new-start (point) properties) > + (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 > + ;; Return nil if there is a lazy-part, it is empty, and we are > + ;; trying to show it. In all other cases return t. > + (if lazy-part > + (when show > + (button-put button :notmuch-lazy-part nil) > + (notmuch-show-lazy-part lazy-part button)) > + ;; else there must be an overlay. > + (overlay-put overlay 'invisible (not show)) > + t))) > > ;; MIME part renderers > > @@ -632,14 +633,17 @@ message at DEPTH in the current thread." >t) > > (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth > depth button) > - (button-put button 'face 'notmuch-crypto-part-header) > - ;; add signature status button if sigstatus provided > + (when button > +(button-put button 'face 'notmuch-crypto-part-header)) > + ;; Add signature status button if sigstatus provided. >(if (plist-member part :sigstatus) >(let* ((from (notmuch-show-get-header :From msg)) >(sigstatus (car (plist-get part :sigstatus > (notmuch-crypto-insert-sigstatus-button sigstatus from)) > -;; if we're not adding sigstatus, tell the user how they can get it > -(button-put button 'help-echo "Set notmuch-crypto-process-mime to > process cryptographic MIME parts.")) > +;; If we're not adding the signature status, tell the user how > +;; they can get it. > +(when button > + (button-put button 'help-echo "Set notmuch-crypto-process-mime to > process cryptographic M
Re: [PATCH v3 3/9] emacs/show: Accommodate the lack of part header buttons
On Mon, 12 May 2014, David Edmondson wrote: > Various pieces of code assumed (reasonably) that part header buttons > are present. Modify them to avoid problems if no part headers were > inserted. Despite your reservations on irc this looks fine to me. MW > --- > emacs/notmuch-show.el | 88 > --- > 1 file changed, 48 insertions(+), 40 deletions(-) > > diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el > index f78a0ab..e511655 100644 > --- a/emacs/notmuch-show.el > +++ b/emacs/notmuch-show.el > @@ -494,36 +494,37 @@ message at DEPTH in the current thread." > > (defun notmuch-show-toggle-part-invisibility (&optional button) >(interactive) > - (let* ((button (or button (button-at (point > - (overlay (button-get button 'overlay)) > - (lazy-part (button-get button :notmuch-lazy-part))) > -;; We have a part to toggle if there is an overlay or if there is a lazy > part. > -;; If neither is present we cannot toggle the part so we just return nil. > -(when (or overlay lazy-part) > - (let* ((show (button-get button :notmuch-part-hidden)) > - (new-start (button-start button)) > - (button-label (button-get button :base-label)) > - (old-point (point)) > - (properties (text-properties-at (button-start button))) > - (inhibit-read-only t)) > - ;; Toggle the button itself. > - (button-put button :notmuch-part-hidden (not show)) > - (goto-char new-start) > - (insert "[ " button-label (if show " ]" " (hidden) ]")) > - (set-text-properties new-start (point) properties) > - (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 > - ;; Return nil if there is a lazy-part, it is empty, and we are > - ;; trying to show it. In all other cases return t. > - (if lazy-part > - (when show > - (button-put button :notmuch-lazy-part nil) > - (notmuch-show-lazy-part lazy-part button)) > - ;; else there must be an overlay. > - (overlay-put overlay 'invisible (not show)) > - t) > + (let ((button (or button (button-at (point) > +(when button > + (let ((overlay (button-get button 'overlay)) > + (lazy-part (button-get button :notmuch-lazy-part))) > + ;; We have a part to toggle if there is an overlay or if there is a > lazy part. > + ;; If neither is present we cannot toggle the part so we just return > nil. > + (when (or overlay lazy-part) > + (let* ((show (button-get button :notmuch-part-hidden)) > + (new-start (button-start button)) > + (button-label (button-get button :base-label)) > + (old-point (point)) > + (properties (text-properties-at (button-start button))) > + (inhibit-read-only t)) > + ;; Toggle the button itself. > + (button-put button :notmuch-part-hidden (not show)) > + (goto-char new-start) > + (insert "[ " button-label (if show " ]" " (hidden) ]")) > + (set-text-properties new-start (point) properties) > + (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 > + ;; Return nil if there is a lazy-part, it is empty, and we are > + ;; trying to show it. In all other cases return t. > + (if lazy-part > + (when show > + (button-put button :notmuch-lazy-part nil) > + (notmuch-show-lazy-part lazy-part button)) > + ;; else there must be an overlay. > + (overlay-put overlay 'invisible (not show)) > + t))) > > ;; MIME part renderers > > @@ -632,14 +633,17 @@ message at DEPTH in the current thread." >t) > > (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth > depth button) > - (button-put button 'face 'notmuch-crypto-part-header) > - ;; add signature status button if sigstatus provided > + (when button > +(button-put button 'face 'notmuch-crypto-part-header)) > + ;; Add signature status button if sigstatus provided. >(if (plist-member part :sigstatus) >(let* ((from (notmuch-show-get-header :From msg)) >(sigstatus (car (plist-get part :sigstatus > (notmuch-crypto-insert-sigstatus-button sigstatus from)) > -;; if we're not adding sigstatus, tell the user how they can get it > -(button-put button 'help-echo "Set notmuch-crypto-process-mime to > process cryptographic MIME parts.")) > +;; If we're not adding the signature status, tell the user how > +;; they can get it. > +(when button > + (button-put button 'help-echo "Set notmuch-crypto-process-mime to > process cryptographic M
[PATCH v3 3/9] 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. --- emacs/notmuch-show.el | 88 --- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index f78a0ab..e511655 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -494,36 +494,37 @@ message at DEPTH in the current thread." (defun notmuch-show-toggle-part-invisibility (&optional button) (interactive) - (let* ((button (or button (button-at (point -(overlay (button-get button 'overlay)) -(lazy-part (button-get button :notmuch-lazy-part))) -;; We have a part to toggle if there is an overlay or if there is a lazy part. -;; If neither is present we cannot toggle the part so we just return nil. -(when (or overlay lazy-part) - (let* ((show (button-get button :notmuch-part-hidden)) -(new-start (button-start button)) -(button-label (button-get button :base-label)) -(old-point (point)) -(properties (text-properties-at (button-start button))) -(inhibit-read-only t)) - ;; Toggle the button itself. - (button-put button :notmuch-part-hidden (not show)) - (goto-char new-start) - (insert "[ " button-label (if show " ]" " (hidden) ]")) - (set-text-properties new-start (point) properties) - (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 - ;; Return nil if there is a lazy-part, it is empty, and we are - ;; trying to show it. In all other cases return t. - (if lazy-part - (when show - (button-put button :notmuch-lazy-part nil) - (notmuch-show-lazy-part lazy-part button)) - ;; else there must be an overlay. - (overlay-put overlay 'invisible (not show)) - t) + (let ((button (or button (button-at (point) +(when button + (let ((overlay (button-get button 'overlay)) + (lazy-part (button-get button :notmuch-lazy-part))) + ;; We have a part to toggle if there is an overlay or if there is a lazy part. + ;; If neither is present we cannot toggle the part so we just return nil. + (when (or overlay lazy-part) + (let* ((show (button-get button :notmuch-part-hidden)) +(new-start (button-start button)) +(button-label (button-get button :base-label)) +(old-point (point)) +(properties (text-properties-at (button-start button))) +(inhibit-read-only t)) + ;; Toggle the button itself. + (button-put button :notmuch-part-hidden (not show)) + (goto-char new-start) + (insert "[ " button-label (if show " ]" " (hidden) ]")) + (set-text-properties new-start (point) properties) + (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 + ;; Return nil if there is a lazy-part, it is empty, and we are + ;; trying to show it. In all other cases return t. + (if lazy-part + (when show + (button-put button :notmuch-lazy-part nil) + (notmuch-show-lazy-part lazy-part button)) + ;; else there must be an overlay. + (overlay-put overlay 'invisible (not show)) + t))) ;; MIME part renderers @@ -632,14 +633,17 @@ message at DEPTH in the current thread." t) (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button) - (button-put button 'face 'notmuch-crypto-part-header) - ;; add signature status button if sigstatus provided + (when button +(button-put button 'face 'notmuch-crypto-part-header)) + ;; Add signature status button if sigstatus provided. (if (plist-member part :sigstatus) (let* ((from (notmuch-show-get-header :From msg)) (sigstatus (car (plist-get part :sigstatus (notmuch-crypto-insert-sigstatus-button sigstatus from)) -;; if we're not adding sigstatus, tell the user how they can get it -(button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")) +;; If we're not adding the signature status, tell the user how +;; 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)) (start (point))) @@ -653,17 +657,20 @@ message at DEPTH in the current thread." t) (defun notmuch-show-insert-part-multipart/encrypted
[PATCH v3 3/9] 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. --- emacs/notmuch-show.el | 88 --- 1 file changed, 48 insertions(+), 40 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index f78a0ab..e511655 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -494,36 +494,37 @@ message at DEPTH in the current thread." (defun notmuch-show-toggle-part-invisibility (&optional button) (interactive) - (let* ((button (or button (button-at (point -(overlay (button-get button 'overlay)) -(lazy-part (button-get button :notmuch-lazy-part))) -;; We have a part to toggle if there is an overlay or if there is a lazy part. -;; If neither is present we cannot toggle the part so we just return nil. -(when (or overlay lazy-part) - (let* ((show (button-get button :notmuch-part-hidden)) -(new-start (button-start button)) -(button-label (button-get button :base-label)) -(old-point (point)) -(properties (text-properties-at (button-start button))) -(inhibit-read-only t)) - ;; Toggle the button itself. - (button-put button :notmuch-part-hidden (not show)) - (goto-char new-start) - (insert "[ " button-label (if show " ]" " (hidden) ]")) - (set-text-properties new-start (point) properties) - (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 - ;; Return nil if there is a lazy-part, it is empty, and we are - ;; trying to show it. In all other cases return t. - (if lazy-part - (when show - (button-put button :notmuch-lazy-part nil) - (notmuch-show-lazy-part lazy-part button)) - ;; else there must be an overlay. - (overlay-put overlay 'invisible (not show)) - t) + (let ((button (or button (button-at (point) +(when button + (let ((overlay (button-get button 'overlay)) + (lazy-part (button-get button :notmuch-lazy-part))) + ;; We have a part to toggle if there is an overlay or if there is a lazy part. + ;; If neither is present we cannot toggle the part so we just return nil. + (when (or overlay lazy-part) + (let* ((show (button-get button :notmuch-part-hidden)) +(new-start (button-start button)) +(button-label (button-get button :base-label)) +(old-point (point)) +(properties (text-properties-at (button-start button))) +(inhibit-read-only t)) + ;; Toggle the button itself. + (button-put button :notmuch-part-hidden (not show)) + (goto-char new-start) + (insert "[ " button-label (if show " ]" " (hidden) ]")) + (set-text-properties new-start (point) properties) + (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 + ;; Return nil if there is a lazy-part, it is empty, and we are + ;; trying to show it. In all other cases return t. + (if lazy-part + (when show + (button-put button :notmuch-lazy-part nil) + (notmuch-show-lazy-part lazy-part button)) + ;; else there must be an overlay. + (overlay-put overlay 'invisible (not show)) + t))) ;; MIME part renderers @@ -632,14 +633,17 @@ message at DEPTH in the current thread." t) (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth button) - (button-put button 'face 'notmuch-crypto-part-header) - ;; add signature status button if sigstatus provided + (when button +(button-put button 'face 'notmuch-crypto-part-header)) + ;; Add signature status button if sigstatus provided. (if (plist-member part :sigstatus) (let* ((from (notmuch-show-get-header :From msg)) (sigstatus (car (plist-get part :sigstatus (notmuch-crypto-insert-sigstatus-button sigstatus from)) -;; if we're not adding sigstatus, tell the user how they can get it -(button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")) +;; If we're not adding the signature status, tell the user how +;; 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)) (start (point))) @@ -653,17 +657,20 @@ message at DEPTH in the current thread." t) (defun notmuch-show-insert-part-multipart/enc
