Subject: bug#77797: 31.0.50; Visit an empty file on creating it

From: Stephen Berman <[email-masked]>
Date: Tue, 15 Apr 2025 09:18:49 +0200

On Mon, 14 Apr 2025 18:59:11 +0200 Eshel Yaron <[email-masked]> wrote:

> Hi,
>
> Eli Zaretskii <[email-masked]> writes:
>
>>> From: Stephen Berman <[email-masked]>
>>> Cc: [email-masked]
>>> Date: Mon, 14 Apr 2025 17:14:03 +0200
>>> 
>>> Since you don't necessarily object, what's the next step?
>>
>> I'd like to hear more opinions about this, since I think it takes that
>> command in directions we didn't intend it to go.
>
> FWIW, I use C-x C-f to create new files all the time, also in
> non-existing directories.  Then I save the buffer as usual, and that
> prompts me to create the directory if needed, which I find to be fine.
> So I probably wouldn't find much use for this addition.  I wouldn't mind
> if it was added nonetheless, of course.
>
> BTW if you want to suppress the prompt for creating a new directory and
> always just create it when needed, you can (ab)use write-file-functions
> for that:
>
> (defun my-ensure-dir ()
>   (let ((dir (file-name-directory (buffer-file-name))))
>     (unless (file-directory-p dir)
>       (make-directory dir t)))
>   nil)
>
> (add-hook 'write-file-functions #'my-ensure-dir)

Thanks for the suggestion, but I think I'd rather not preempt the
basic-save-buffer prompt, it's a good safeguard, since C-x C-f is a very
high frequency command.  For the much rarer cases where I want to add a
new file in one or more new subdirectories, it's better to use a
command that I know is designed to do that.  If my proposal to enhance
make-empty-file is not accepted, I can just advise it or redefine it in
my init file.

Steve Berman