]> git.eshelyaron.com Git - emacs.git/commitdiff
Optionally add new empty file to Dired subdirectory
authorStephen Berman <stephen.berman@gmx.net>
Tue, 15 Apr 2025 17:01:19 +0000 (19:01 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 16 Apr 2025 07:35:25 +0000 (09:35 +0200)
Suggested by Kasper GaƂkowski <kpg@posteo.net> (bug#77668)

* etc/NEWS: Announce new Dired user option.

* lisp/dired-aux.el (dired-create-empty-file-in-current-directory):
New user option.
(dired-create-empty-file): Use it.  Update and clarify doc string.

(cherry picked from commit 0ac12aed09702b2d135312e8dad4e173fcd23dae)

lisp/dired-aux.el

index 8b39a497d81cec6a5623c192af204f2ed28881f6..81e3d3679ed7f26d8507be002795d0312f1442a9 100644 (file)
@@ -2854,13 +2854,32 @@ If DIRECTORY already exists, signal an error."
       (dired-add-file new)
       (dired-move-to-filename))))
 
+(defcustom dired-create-empty-file-in-current-directory nil
+  "Whether `dired-create-empty-file' acts on the current directory.
+If non-nil, `dired-create-empty-file' creates a new empty file and adds
+an entry for it (or its topmost new parent directory if created) under
+the current subdirectory in the Dired buffer by default (otherwise, it
+adds the new file (and new subdirectories if provided) to whichever
+directory the user enters at the prompt).  If nil,
+`dired-create-empty-file' acts on the default directory by default."
+  :type 'boolean
+  :version "31.1")
+
 ;;;###autoload
 (defun dired-create-empty-file (file)
   "Create an empty file called FILE.
-Add a new entry for the new file in the Dired buffer.
 Parent directories of FILE are created as needed.
+Add an entry in the Dired buffer for the topmost new parent
+directory of FILE, if created, otherwise for the new file.
+If user option `dired-create-empty-file-in-current-directory' is
+non-nil, act on the current subdirectory by default, otherwise act on
+the default directory by default.
 If FILE already exists, signal an error."
-  (interactive (list (read-file-name "Create empty file: ")) dired-mode)
+  (interactive
+   (list (read-file-name "Create empty file: "
+                         (and dired-create-empty-file-in-current-directory
+                              (dired-current-directory))))
+   dired-mode)
   (let* ((expanded (expand-file-name file))
          new)
     (if (file-exists-p expanded)