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: Wed, 12 Jul 2023 09:04:40 -0400

I'm not sure what to make of this discussion.

The issue at hand is the following: `create-file-buffer` needs to know
if the filename it receives is for a directory or not so it can decide
whether the buffer name should end in / or not according to
`uniquify-trailing-separator-p`.

I can see 3 ways to provide this info:

1- use `file-directory-p`.
2- add a boolean `directory` argument to `create-file-buffer`.
3- use the presence of a trailing directory separator in the filename.

Those 3 are very close to each other, in practice, so we're pretty much
in bikeshed territory.

My preference is (3) first, (2) second, and (1) last.

(1) is my least favorite because it makes it impossible/difficult to
create a "directory buffer" if `file-directory-p` returns nil and
vice versa, even tho I can imagine scenarios where this could be useful
(such as the scenario mentioned by Spencer where we want to create
a "directory buffer" for an archive that Emacs's file-name-handlers
don't understand).

(3) is my favorite because it doesn't need an extra argument and instead
uses an existing piece of information: if I pass "/a/b/c/" then it seems
clear that I mean this to be a "directory buffer" rather than a "file
buffer".  Representing the information "this is meant to be a directory"
in the file name via a trailing / is a standard practice in ELisp (and
POSIX in general), embodied by things like `file-name-as-directory` and
`directory-file-name`, so it seems only natural (or even a mere a bug
fix) to let `create-file-buffer` make use of that info instead of
throwing it away.

But I prefer any one of those 3 choices over the status quo, so I'll
stop arguing here.  Just let me know which one I should install.

        Stefan

Eli Zaretskii [2023-07-11 18:31:07] wrote:

>> From: Spencer Baugh <[email-masked]>
>> Cc: Stefan Monnier <[email-masked]>,  [email-masked],
>>    [email-masked]
>> Date: Tue, 11 Jul 2023 08:31:51 -0400
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> > My comments assumed that indeed we will (almost) always want to tell
>> > create-file-buffer this is a directory.
>> 
>> One contribution, not intended to be exhaustive of all use cases, and
>> not intended to be definitively a good idea: a user could want opened
>> tar files with their file listing view to have a trailing slash, even
>> though they aren't actually directories.
>
> But users don't call create-file-buffer, do they?  So this is not
> user-level option, at least not directly so.
>
>> And with my approach that is possibly just by running
>> file-name-as-directory over the name before passing it to
>> create-file-buffer.
>
> If you worry about users, they can be told to append a slash by hand,
> when they mean a directory and that directory does not yet exist.  We
> do this elsewhere in Emacs.