GNU bug report logs - #77797
31.0.50; Visit an empty file on creating it

Previous Next

Package: emacs;

Reported by: Stephen Berman <stephen.berman <at> gmx.net>

Date: Mon, 14 Apr 2025 11:59:02 UTC

Severity: normal

Found in version 31.0.50

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stephen Berman <stephen.berman <at> gmx.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 31.0.50; Visit an empty file on creating it
Date: Mon, 14 Apr 2025 13:57:59 +0200
[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

This bug report was last modified 62 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.