Re: [PATCH 3/3] emacs/show: use n-s-i-headerline to update tags

Subject: Re: [PATCH 3/3] emacs/show: use n-s-i-headerline to update tags

Date: Sun, 13 Nov 2022 20:11:35 +0200

To: David Bremner, David Bremner, notmuch@notmuchmail.org

Cc:

From: Tomi Ollila


On Fri, Nov 11 2022, David Bremner wrote:

> Although this has more steps than the previous regular expression
> search and replace, it should be more robust against changes in the
> headerline format, such as the inclusion of duplicate numbers (which
> broke the previous version).
> ---
>  emacs/notmuch-show.el | 22 ++++++++++++++--------
>  1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index 5fb5ab31..c4e88be2 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -452,14 +452,20 @@ operation on the contents of the current buffer."
>  (defun notmuch-show-update-tags (tags)
>    "Update the displayed tags of the current message."
>    (save-excursion
> -    (goto-char (notmuch-show-message-top))
> -    (when (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)
> -      (let ((inhibit-read-only t))
> -	(replace-match (concat "("
> -			       (notmuch-tag-format-tags
> -				tags
> -				(notmuch-show-get-prop :orig-tags))
> -			       ")"))))))
> +    (let ((inhibit-read-only t)
> +	  (start (notmuch-show-message-top))
> +	  (depth (notmuch-show-get-prop :depth))
> +	  (orig-tags (notmuch-show-get-prop :orig-tags))
> +	  (props (notmuch-show-get-message-properties))
> +	  (extent (notmuch-show-message-extent)))
> +      (goto-char start)
> +      (notmuch-show-insert-headerline props depth tags orig-tags)
> +      (put-text-property start (1+ start)
> +			 :notmuch-message-properties props)
> +      (put-text-property (car extent) (cdr extent) :notmuch-message-extent extent)
> +      ;; delete original headerline, but do not save to kill ring
> +      (delete-region
> +       (point) (save-excursion (end-of-line nil) (1+ (point)))))))

Series looks good to me (as much as I understand it)

This last changed line got me checking docstring of (line-end-position),
which says:

 -- line-end-position is a built-in function in ‘C source code’.
 -- Probably introduced at or before Emacs version 20.4.
 -- This function does not change global state, including the match data.

and then grepping thru notmuch source code:

notmuch-tree.el:497:      (delete-region (point) (1+ (line-end-position)))

-- it looks to me this could be simpler and faster alternative.

Tomi

PS: something that is nasty but probably does not hit here (there is
newline always)

(delete-region (line-end-position) 1000000)
-> Debugger entered--Lisp error: (args-out-of-range #<buffer *scratch*> 215 1000000

>  
>  (defun notmuch-clean-address (address)
>    "Try to clean a single email ADDRESS for display. Return a cons
> -- 
> 2.35.1
>
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: