[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#77797: 31.0.50; Visit an empty file on creating it
From: |
Stephen Berman |
Subject: |
bug#77797: 31.0.50; Visit an empty file on creating it |
Date: |
Mon, 14 Apr 2025 13:57:59 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
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:
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
"[^.]\\|\\.\\.\\."
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
- bug#77797: 31.0.50; Visit an empty file on creating it,
Stephen Berman <=
- bug#77797: 31.0.50; Visit an empty file on creating it, Eli Zaretskii, 2025/04/14
- bug#77797: 31.0.50; Visit an empty file on creating it, Stefan Kangas, 2025/04/14
- bug#77797: 31.0.50; Visit an empty file on creating it, Eli Zaretskii, 2025/04/15
- bug#77797: 31.0.50; Visit an empty file on creating it, Stephen Berman, 2025/04/15
- bug#77797: 31.0.50; Visit an empty file on creating it, Stefan Kangas, 2025/04/15