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

From: [email-masked]
Date: Sun, 09 Apr 2023 12:13:31 +0000 (UTC)

Ah, while I'm at it, here's a fix (based on the patch in the preceding
mail) for a different bug which I just noticed: create-file-buffer's
documentations states:

>Emacs treats buffers whose names begin with a space as internal buffers.
>To avoid confusion when visiting a file whose name begins with a space,
>this function prepends a "|" to the final result if necessary.

But uniquify renames the buffer away from having that "|".  This patch
fixes that bug.

diff --git a/lisp/files.el b/lisp/files.el
index c9433938729..e1e8e905fb0 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2079,9 +2079,10 @@ create-file-buffer
   (let* ((lastname (or basename (file-name-nondirectory filename)))
 	 (lastname (if (string= lastname "")
 	               filename lastname))
-	 (buf (generate-new-buffer (if (string-prefix-p " " lastname)
-			               (concat "|" lastname)
-			             lastname))))
+         (basename (if (string-prefix-p " " lastname)
+		       (concat "|" lastname)
+		     lastname))
+	 (buf (generate-new-buffer basename)))
     (uniquify--create-file-buffer-advice buf filename basename)
     buf))
 
diff --git a/lisp/uniquify.el b/lisp/uniquify.el
index 6c0f5468faa..ad6f9797381 100644
--- a/lisp/uniquify.el
+++ b/lisp/uniquify.el
@@ -485,7 +485,7 @@ uniquify--create-file-buffer-advice
   "Uniquify buffer names with parts of directory name."
   (when uniquify-buffer-name-style
     (uniquify-rationalize-file-buffer-names
-     (or basename (file-name-nondirectory filename))
+     basename
      (file-name-directory (expand-file-name (directory-file-name filename)))
      buf)))