Subject: bug#77157: [PATCH] 'uniquify' user option setters and automatic buffer refresh

From: Eli Zaretskii <[email-masked]>
Date: Fri, 21 Mar 2025 21:50:58 +0200

> From: Ship Mints <[email-masked]>
> Date: Fri, 21 Mar 2025 14:11:01 -0400
> 
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -1566,6 +1566,14 @@ This user option replaces 'follow-mode-prefix', which had to be set
>  before loading Follow mode.  This new option allows you to change the
>  prefix even after it was loaded, using 'customize-option' or 'setopt'.
>  
> +---
> +*** Changing uniquify user options refreshes buffer names.
> +Use customize interactively, or setopt in Elisp, to refresh buffer names
> +when changing 'uniquify' user options.  Previously, reloading or
> +renaming your buffers (or an Emacs restart) was required.

I don't think this change warrants a NEWS entry.  It's a minor
convenience improvement, and arguably a bugfix.

>  (defcustom uniquify-buffer-name-style 'post-forward-angle-brackets
>    "How to construct unique buffer names for files with the same base name.
> @@ -121,6 +135,8 @@ uniquify-buffer-name-style
>  		(const post-forward-angle-brackets)
>                  (function :tag "Other")
>  		(const :tag "numeric suffixes" nil))
> +  :initialize #'custom-initialize-default
> +  :set #'uniquify--set-option

Please tell in the doc string that changing the style in the middle of
an Emacs session must be done via Customize or by using setopt, but
not by setting the variable directly (unless uniquify--set-option is
then invoked).

> @@ -136,11 +152,15 @@ uniquify-ignore-buffers-re
>  For instance, set this to \"^draft-[0-9]+$\" to avoid having uniquify
>  rename draft buffers even if `uniquify-after-kill-buffer-flag' is
>  non-nil and the visited file name isn't the same as that of the buffer."
> -  :type '(choice (const :tag "Uniquify all buffers" nil) regexp))
> +  :type '(choice (const :tag "Uniquify all buffers" nil) regexp)
> +  :initialize #'custom-initialize-default
> +  :set #'uniquify--set-option)
>  
>  (defcustom uniquify-min-dir-content 0
>    "Minimum number of directory name components included in buffer name."
> -  :type 'integer)
> +  :type 'integer
> +  :initialize #'custom-initialize-default
> +  :set #'uniquify--set-option)
>  
>  (defcustom uniquify-separator nil
>    "String separator for buffer name components.
> @@ -148,7 +168,9 @@ uniquify-separator
>  base file name from directory part in buffer names (default \"|\").
>  When `uniquify-buffer-name-style' is `reverse', separates all
>  file name components (default \"\\\")."
> -  :type '(choice (const nil) string))
> +  :type '(choice (const nil) string)
> +  :initialize #'custom-initialize-default
> +  :set #'uniquify--set-option)
>  
>  (define-obsolete-variable-alias 'uniquify-trailing-separator-p
>    'uniquify-trailing-separator-flag "31.1")
> @@ -167,7 +189,9 @@ uniquify-strip-common-suffix
>  E.g. if you open /a1/b/c/d and /a2/b/c/d, the buffer names will say
>  \"d|a1\" and \"d|a2\" instead of \"d|a1/b/c\" and \"d|a2/b/c\".
>  This can be handy when you have deep parallel hierarchies."
> -  :type 'boolean)
> +  :type 'boolean
> +  :initialize #'custom-initialize-default
> +  :set #'uniquify--set-option)
>  
>  (defvar uniquify-list-buffers-directory-modes '(dired-mode cvs-mode vc-dir-mode)
>    "List of modes for which uniquify should obey `list-buffers-directory'.
> @@ -197,6 +221,8 @@ uniquify-dirname-transform
>                   (function-item :tag "Include project name in directory name"
>                                  ,#'project-uniquify-dirname-transform)
>                   function)
> +  :initialize #'custom-initialize-default
> +  :set #'uniquify--set-option
>    :version "30.1"
>    :group 'uniquify)

Likewise for these user options.

Thanks.