Subject: Re: bug#62732: 29.0.60; uniquify-trailing-separator-p affects any buffer whose name matches a dir in CWD

From: Stefan Monnier <[email-masked]>
Date: Fri, 05 May 2023 16:13:52 -0400

> This patch takes the approach of pulling uniquify-trailing-separator-p
> out of uniquify and putting it into dired; now the trailing separator is
> specified when the dired buffer is created.  This is incidentally also
> vastly more efficient: The old way did n² filesystem accesses which is
> not something we should be doing on every buffer creation/rename.

It's indeed a better approach, thanks.
I'm a bit annoyed at the need to add an argument to `create-file-buffer`
and I wonder if we could avoid that by replacing:

> +(defun dired--create-buffer (dirname)
> +  "Create a buffer with an appropriate name for visiting this directory.
> +
> +Obeys `dired-trailing-separator'."
> +  (let* ((filename (directory-file-name dirname))
> +         (base (file-name-nondirectory filename)))
> +    (create-file-buffer filename
> +                        (if dired-trailing-separator
> +                            (cond ((eq uniquify-buffer-name-style 'forward)
> +	                           (file-name-as-directory base))
> +	                          ((eq uniquify-buffer-name-style 'reverse)
> +	                           (concat (or uniquify-separator "\\") base)))))))

with

    (defun dired--create-buffer (dirname)
      "Create a buffer with an appropriate name for visiting this directory.
    Obeys `dired-trailing-separator'."
      (let* ((filename (directory-file-name dirname)))
        (create-file-buffer (if dired-trailing-separator
                                (file-name-as-directory filename)
                              filename))))

or even just

    (defun dired--create-buffer (dirname)
      "Create a buffer with an appropriate name for visiting this directory."
      (create-file-buffer (file-name-as-directory dirname)))

and then do the rest inside `uniquify.el`.

        Stefan