GNU bug report logs -
#77797
31.0.50; Visit an empty file on creating it
Previous Next
To reply to this bug, email your comments to 77797 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77797
; Package
emacs
.
(Mon, 14 Apr 2025 11:59:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stephen Berman <stephen.berman <at> gmx.net>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 14 Apr 2025 11:59:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
To create an empty file (and perhaps also one or more parent
directories) and then immediately visit the file (e.g., to yank some
copied text into it), you currently have to type `M-x make-empty-file',
enter the file name (possibly with parent directories), and then type
`C-x C-f M-p'. As a more convenient alternative to invoking two
commands, I propose that invoking `make-empty-file' with a prefix
argument should create and visit the empty file. Here is a simple
backward compatible patch to do this:
[Message part 2 (text/x-patch, inline)]
diff --git a/lisp/files.el b/lisp/files.el
index ad6047bd02d..cbd2e2c0992 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6703,7 +6703,8 @@ make-empty-file
"Create an empty file FILENAME.
Optional arg PARENTS, if non-nil then creates parent dirs as needed.
-If called interactively, then PARENTS is non-nil."
+If called interactively, then PARENTS is non-nil. If called with a
+prefix argument, visit the newly created empty file."
(interactive
(let ((filename (read-file-name "Create empty file: ")))
(list filename t)))
@@ -6712,7 +6713,8 @@ make-empty-file
(let ((paren-dir (file-name-directory filename)))
(when (and paren-dir (not (file-exists-p paren-dir)))
(make-directory paren-dir parents)))
- (write-region "" nil filename nil 0))
+ (write-region "" nil filename nil 0)
+ (when current-prefix-arg (find-file filename)))
(defconst directory-files-no-dot-files-regexp
"[^.]\\|\\.\\.\\."
[Message part 3 (text/plain, inline)]
Does anyone see a downside to this addition?
An analogous patch might be desirable for `dired-create-empty-file';
however, after invoking the latter from within Dired, you just have to
hit RET to visit the new empty file (possible multiple times if parent
directories were also added), since point moves to the new entry. So
the use case for Dired seems not as compelling as for `make-empty-file'.
What do others think? (On the other hand, you can also invoke
`dired-create-empty-file' from outside of Dired and in that case the
prefix argument would be helpful; but that's just like
`make-empty-file', so it seems to be an unintended (mis-)feature of
`dired-create-empty-file', and indeed there's a proposal to opt out of
this behavior, see bug#77668.)
Steve Berman
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77797
; Package
emacs
.
(Mon, 14 Apr 2025 13:39:03 GMT)
Full text and
rfc822 format available.
Message #8 received at 77797 <at> debbugs.gnu.org (full text, mbox):
> Date: Mon, 14 Apr 2025 13:57:59 +0200
> From: Stephen Berman via "Bug reports for GNU Emacs,
> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>
> To create an empty file (and perhaps also one or more parent
> directories) and then immediately visit the file (e.g., to yank some
> copied text into it), you currently have to type `M-x make-empty-file',
> enter the file name (possibly with parent directories), and then type
> `C-x C-f M-p'.
That's backwards: in Emacs, you type "C-x C-f NEWFILE RET", then edit
it, then save it. IOW, you don't create an empty file first, because
that's not useful.
The make-empty-file command exists for cases where the only desired
outcome is to make an empty file. Not if the user wants to create a
_new_ _non-empty_ file.
> As a more convenient alternative to invoking two commands, I propose
> that invoking `make-empty-file' with a prefix argument should create
> and visit the empty file. Here is a simple backward compatible
> patch to do this:
I don't necessarily object, but please note that this is non-Emacs'y.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77797
; Package
emacs
.
(Mon, 14 Apr 2025 15:15:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 77797 <at> debbugs.gnu.org (full text, mbox):
On Mon, 14 Apr 2025 16:38:21 +0300 Eli Zaretskii <eliz <at> gnu.org> wrote:
>> Date: Mon, 14 Apr 2025 13:57:59 +0200
>> From: Stephen Berman via "Bug reports for GNU Emacs,
>> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>>
>> To create an empty file (and perhaps also one or more parent
>> directories) and then immediately visit the file (e.g., to yank some
>> copied text into it), you currently have to type `M-x make-empty-file',
>> enter the file name (possibly with parent directories), and then type
>> `C-x C-f M-p'.
>
> That's backwards: in Emacs, you type "C-x C-f NEWFILE RET", then edit
> it, then save it. IOW, you don't create an empty file first, because
> that's not useful.
It's useful in the case I noted above: yanking text into a buffer that
you want to save to a file, and in particular if you want the file to be
in a not-yet-existing subdirectory. In that case, with `C-x C-f' when
you type `C-x C-s' you are queried (from `basic-save-buffer') and have
to confirm that the subdirectory should be created, while with
`make-empty-file' it already has been created. Or have I overlooked an
option to suppress the confirmation query?
> The make-empty-file command exists for cases where the only desired
> outcome is to make an empty file. Not if the user wants to create a
> _new_ _non-empty_ file.
I think the above use case is valid. (Just yesterday I had occasion to
do that and not being able to (without being queried about the
subdirectory) is what prompted me to propose the feature.)
>> As a more convenient alternative to invoking two commands, I propose
>> that invoking `make-empty-file' with a prefix argument should create
>> and visit the empty file. Here is a simple backward compatible
>> patch to do this:
>
> I don't necessarily object, but please note that this is non-Emacs'y.
I didn't mean to offend you :-)
Since you don't necessarily object, what's the next step?
Steve Berman
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77797
; Package
emacs
.
(Mon, 14 Apr 2025 16:25:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 77797 <at> debbugs.gnu.org (full text, mbox):
> From: Stephen Berman <stephen.berman <at> gmx.net>
> Cc: 77797 <at> debbugs.gnu.org
> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77797
; Package
emacs
.
(Mon, 14 Apr 2025 17:00:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 77797 <at> debbugs.gnu.org (full text, mbox):
Hi,
Eli Zaretskii <eliz <at> gnu.org> writes:
>> From: Stephen Berman <stephen.berman <at> gmx.net>
>> Cc: 77797 <at> debbugs.gnu.org
>> 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:
--8<---------------cut here---------------start------------->8---
(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)
--8<---------------cut here---------------end--------------->8---
Best regards,
Eshel
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77797
; Package
emacs
.
(Mon, 14 Apr 2025 21:07:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 77797 <at> debbugs.gnu.org (full text, mbox):
Stephen Berman via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs <at> gnu.org> writes:
> On Mon, 14 Apr 2025 16:38:21 +0300 Eli Zaretskii <eliz <at> gnu.org> wrote:
>
>>> Date: Mon, 14 Apr 2025 13:57:59 +0200
>>> From: Stephen Berman via "Bug reports for GNU Emacs,
>>> the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
>>>
>>> To create an empty file (and perhaps also one or more parent
>>> directories) and then immediately visit the file (e.g., to yank some
>>> copied text into it), you currently have to type `M-x make-empty-file',
>>> enter the file name (possibly with parent directories), and then type
>>> `C-x C-f M-p'.
>>
>> That's backwards: in Emacs, you type "C-x C-f NEWFILE RET", then edit
>> it, then save it. IOW, you don't create an empty file first, because
>> that's not useful.
>
> It's useful in the case I noted above: yanking text into a buffer that
> you want to save to a file, and in particular if you want the file to be
> in a not-yet-existing subdirectory. In that case, with `C-x C-f' when
> you type `C-x C-s' you are queried (from `basic-save-buffer') and have
> to confirm that the subdirectory should be created, while with
> `make-empty-file' it already has been created. Or have I overlooked an
> option to suppress the confirmation query?
Maybe we should add an option to suppress the query? Either as a
defcustom or a prefix argument, or something. Not sure which is best,
because I actually prefer the query, myself.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77797
; Package
emacs
.
(Tue, 15 Apr 2025 06:29:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 77797 <at> debbugs.gnu.org (full text, mbox):
> From: Stefan Kangas <stefankangas <at> gmail.com>
> Date: Mon, 14 Apr 2025 16:06:04 -0500
> Cc: 77797 <at> debbugs.gnu.org
>
> >> That's backwards: in Emacs, you type "C-x C-f NEWFILE RET", then edit
> >> it, then save it. IOW, you don't create an empty file first, because
> >> that's not useful.
> >
> > It's useful in the case I noted above: yanking text into a buffer that
> > you want to save to a file, and in particular if you want the file to be
> > in a not-yet-existing subdirectory. In that case, with `C-x C-f' when
> > you type `C-x C-s' you are queried (from `basic-save-buffer') and have
> > to confirm that the subdirectory should be created, while with
> > `make-empty-file' it already has been created. Or have I overlooked an
> > option to suppress the confirmation query?
>
> Maybe we should add an option to suppress the query? Either as a
> defcustom or a prefix argument, or something. Not sure which is best,
> because I actually prefer the query, myself.
Same here: I prefer the query because it many times saves me from
creating files with wrong names and/or in wrong directorties, due to
simple typos.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77797
; Package
emacs
.
(Tue, 15 Apr 2025 07:20:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 77797 <at> debbugs.gnu.org (full text, mbox):
On Mon, 14 Apr 2025 18:59:11 +0200 Eshel Yaron <me <at> eshelyaron.com> wrote:
> Hi,
>
> Eli Zaretskii <eliz <at> gnu.org> writes:
>
>>> From: Stephen Berman <stephen.berman <at> gmx.net>
>>> Cc: 77797 <at> debbugs.gnu.org
>>> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77797
; Package
emacs
.
(Tue, 15 Apr 2025 07:20:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 77797 <at> debbugs.gnu.org (full text, mbox):
On Tue, 15 Apr 2025 09:28:07 +0300 Eli Zaretskii <eliz <at> gnu.org> wrote:
>> From: Stefan Kangas <stefankangas <at> gmail.com>
>> Date: Mon, 14 Apr 2025 16:06:04 -0500
>> Cc: 77797 <at> debbugs.gnu.org
>>
>> >> That's backwards: in Emacs, you type "C-x C-f NEWFILE RET", then edit
>> >> it, then save it. IOW, you don't create an empty file first, because
>> >> that's not useful.
>> >
>> > It's useful in the case I noted above: yanking text into a buffer that
>> > you want to save to a file, and in particular if you want the file to be
>> > in a not-yet-existing subdirectory. In that case, with `C-x C-f' when
>> > you type `C-x C-s' you are queried (from `basic-save-buffer') and have
>> > to confirm that the subdirectory should be created, while with
>> > `make-empty-file' it already has been created. Or have I overlooked an
>> > option to suppress the confirmation query?
>>
>> Maybe we should add an option to suppress the query? Either as a
>> defcustom or a prefix argument, or something. Not sure which is best,
>> because I actually prefer the query, myself.
>
> Same here: I prefer the query because it many times saves me from
> creating files with wrong names and/or in wrong directorties, due to
> simple typos.
I agree, and consequently think an option is too blunt. A prefix
argument would be better, but as I wrote in my reply to Eshel Yaron, I
prefer adding that to make-empty-file.
Steve Berman
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#77797
; Package
emacs
.
(Tue, 15 Apr 2025 14:12:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 77797 <at> debbugs.gnu.org (full text, mbox):
Stephen Berman <stephen.berman <at> gmx.net> writes:
> On Tue, 15 Apr 2025 09:28:07 +0300 Eli Zaretskii <eliz <at> gnu.org> wrote:
>
>>> From: Stefan Kangas <stefankangas <at> gmail.com>
>>> Date: Mon, 14 Apr 2025 16:06:04 -0500
>>> Cc: 77797 <at> debbugs.gnu.org
>>>
>>> >> That's backwards: in Emacs, you type "C-x C-f NEWFILE RET", then edit
>>> >> it, then save it. IOW, you don't create an empty file first, because
>>> >> that's not useful.
>>> >
>>> > It's useful in the case I noted above: yanking text into a buffer that
>>> > you want to save to a file, and in particular if you want the file to be
>>> > in a not-yet-existing subdirectory. In that case, with `C-x C-f' when
>>> > you type `C-x C-s' you are queried (from `basic-save-buffer') and have
>>> > to confirm that the subdirectory should be created, while with
>>> > `make-empty-file' it already has been created. Or have I overlooked an
>>> > option to suppress the confirmation query?
>>>
>>> Maybe we should add an option to suppress the query? Either as a
>>> defcustom or a prefix argument, or something. Not sure which is best,
>>> because I actually prefer the query, myself.
>>
>> Same here: I prefer the query because it many times saves me from
>> creating files with wrong names and/or in wrong directorties, due to
>> simple typos.
>
> I agree, and consequently think an option is too blunt. A prefix
> argument would be better, but as I wrote in my reply to Eshel Yaron, I
> prefer adding that to make-empty-file.
Yeah, I guess it would be situational, so a defcustom is too blunt.
I won't object to your proposal, unless anyone else can think of a
better use for a prefix argument for that `make-empty-file`.
This bug report was last modified 8 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.