Re: [PATCH v2 1/1] emacs: notmuch-show-header-line: allow format strings and functions

Subject: Re: [PATCH v2 1/1] emacs: notmuch-show-header-line: allow format strings and functions

Date: Tue, 17 May 2022 23:30:16 +0300

To: jao, notmuch@notmuchmail.org

Cc:

From: Tomi Ollila


On Mon, May 16 2022, jao@gnu.org wrote:

> If a string value is assigned to notmuch-show-header-line, it's used
> as a format string to be passed passed to format-spec with `%s`
> substituted by the message's subject.  If a function is given, it's
> called with the subject as argument, and its return value used as
> header line.
>
> As before, t means displaying the subject and nil not using any header
> line.
>
> Signed-off-by: jao <jao@gnu.org>
> ---
>  emacs/notmuch-show.el | 37 ++++++++++++++++++++++++++++++-------
>  1 file changed, 30 insertions(+), 7 deletions(-)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index 7c1f02c9..79599480 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -85,8 +85,26 @@ visible for any given message."
>    :group 'notmuch-show)
>  
>  (defcustom notmuch-show-header-line t
> -  "Show a header line with the current message's subject."
> -  :type 'boolean
> +  "Show a header line in notmuch show buffers.
> +
> +If t (the default), the header line will contain the current
> +message's subject.
> +
> +If a string, this value is interpreted as a format string to be
> +passed to `format-spec` with `%s` as the substitution variable
> +for the message's subject.  E.g., to display the subject trimmed
> +to a maximum of 80 columns, you could use \"%>-80s\" as format.
> +
> +If you assign to this variable a function, the function will be
> +called with the subject as argument and its return value used as
> +the header line.
> +
> +Finally, if this variabale is set to nil, no header is
> +displayed."
> +  :type '(choice (const :tag "No header" ni)
> +                 (const :tag "Subject" t)
> +                 (string :tag "Format")
> +		 (function :tag "Function"))
>    :group 'notmuch-show)
>  
>  (defcustom notmuch-show-relative-dates t
> @@ -1351,11 +1369,16 @@ If no messages match the query return NIL."
>         (lambda () (notmuch-show-set-prop :orig-tags (notmuch-show-get-tags))))
>        ;; Set the header line to the subject of the first message.
>        (when notmuch-show-header-line
> -	(setq header-line-format
> -	      (replace-regexp-in-string "%" "%%"
> -					(notmuch-sanitize
> -					 (notmuch-show-strip-re
> -					  (notmuch-show-get-subject))))))
> +        (let* ((s (replace-regexp-in-string "%" "%%"
> +                                            (notmuch-sanitize
> +                                             (notmuch-show-strip-re
> +                                              (notmuch-show-get-subject)))))
> +               (h (cond ((stringp notmuch-show-header-line)
> +                         (format-spec notmuch-show-header-line `((?s . ,s))))
> +			((functionp notmuch-show-header-line)
> +			 (funcall notmuch-show-header-line s))
> +			(notmuch-show-header-line s))))
> +          (setq header-line-format h)))

To me it looks like some lines are indented with tabs and some spaces
(noticed as indentation looked weird to me and then started moving cursor
at the beginning of line -- there is probably a way to highlight tabs in
notmuch show buffer but...)

Otherwise it looks good to me (took a bit to match cond CLAUSES...)

Tomi

>        (run-hooks 'notmuch-show-hook)
>        (if state
>  	  (notmuch-show-apply-state state)
> -- 
> 2.36.1
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: