On Mon, Jan 10 2022, [email protected] wrote:

> Customizable names for buffers presenting search results, via two
> custom variables (notmuch-search-buffer-name-format and
> notmuch-saved-search-buffer-name-format), defaulting to values
> currently used for plain searches and including too tree and
> unthreaded search buffers.
>
> ---
>
> This is a much improved version of the patch in
> id:[email protected], according to discussion on
> that thread.
>
> This version fixes a doc string.
>
> Signed-off-by: jao <[email protected]>
> ---
> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index 85a54706..afb0a115 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -915,7 +915,37 @@ See `notmuch-tag' for information on the format of 
> TAG-CHANGES."
>         (notmuch-search-get-tags-region (point-min) (point-max)) "Tag all")))
>    (notmuch-search-tag tag-changes (point-min) (point-max) t))
>  
> -(defun notmuch-search-buffer-title (query)
> +(defcustom notmuch-search-buffer-name-format "*notmuch-%t-%s*"
> +  "Format for the name of search results buffers.
> +
> +In this spec, %s will be replaced by a description of the search
> +query and %t by its type (search, tree or unthreaded).
> +
> +See also `notmuch-saved-search-buffer-name-format'"
> +  :type 'string
> +  :group 'notmuch-search)
> +
> +(defcustom notmuch-saved-search-buffer-name-format "*notmuch-saved-%t-%s*"
> +  "Format for the name of search results buffers.
> +
> +In this spec, %s will be replaced by the saved search name and %t
> +by its type (search, tree or unthreaded).
> +
> +See also `notmuch-search-buffer-name-format'"
> +  :type 'string
> +  :group 'notmuch-search)
> +
> +(defun notmuch-search-format-buffer-name (query type saved)
> +  "Compose a buffer name for the given QUERY, TYPE (search, tree,
> +unthreaded) and whether it's SAVED (t or nil)."
> +  (let ((fmt (if saved
> +              notmuch-saved-search-buffer-name-format
> +            notmuch-search-buffer-name-format)))
> +    (if (fboundp 'format-spec)
> +     (format-spec fmt `((?t . ,(or type "search")) (?s . ,query))))
> +    (format (replace-regexp-in-string "\\b%t\\b" (or type "search") fmt) 
> query)))

I am curious about this regexp, \b is matching word/non-word boundary -- so
I had to test it.

(replace-regexp-in-string "\\b%t\\b" "repl" "foo %t bar") ;; no replacement
(replace-regexp-in-string "\\b%t\\b" "repl" "foo-%t-bar") ;; no replacement
...
(replace-regexp-in-string "\\b%t\\b" "repl" "foox%t-bar") ;; replacement!

before % there is "word" character and after t there is "non-word" character.

I wonder whether that works... (or is it just something I don't
understand)..

Also tried (format-spec "foo-%t-bar" '((?t . "repl"))) ;; which works as
I'd expect.


Tomi


_______________________________________________
notmuch mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to