mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-07 12:20:39 -08:00
Optionally add new empty file to Dired subdirectory
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.
This commit is contained in:
parent
74842b4cb2
commit
0ac12aed09
2 changed files with 35 additions and 2 deletions
14
etc/NEWS
14
etc/NEWS
|
|
@ -1423,6 +1423,20 @@ a control panel window.
|
|||
|
||||
** Dired
|
||||
|
||||
---
|
||||
*** New user option 'dired-create-empty-file-in-current-directory'.
|
||||
When 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 adds the new file (and new subdirectories if
|
||||
provided) to whichever directory the user enters at the prompt). When
|
||||
nil, `dired-create-empty-file' acts on the default directory by default.
|
||||
|
||||
Note that setting this user option to non-nil makes invoking
|
||||
'dired-create-empty-file' outside of a Dired buffer raise an error (like
|
||||
other Dired commands that always prompt with the current subdirectory,
|
||||
such as 'dired-create-directory').
|
||||
|
||||
+++
|
||||
*** New user option 'dired-check-symlinks' allows disabling validity checks.
|
||||
Dired uses 'file-truename' to check symbolic link validity when
|
||||
|
|
|
|||
|
|
@ -2872,13 +2872,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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue