[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master e00974a 1/2: Create subdirectories automatically in
From: |
Lars Ingebrigtsen |
Subject: |
[Emacs-diffs] master e00974a 1/2: Create subdirectories automatically in wdired |
Date: |
Sun, 28 Feb 2016 04:46:39 +0000 |
branch: master
commit e00974a7d1981d716d38ecf45b689dd30a381c65
Author: Phil Sung <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>
Create subdirectories automatically in wdired
* lisp/wdired.el (wdired-create-parent-directories): New
variable (bug#6817).
(wdired-create-parentdirs): New function.
(wdired-do-renames): Use it.
* doc/emacs/dired.texi (Wdired): Mention
`wdired-create-parent-directories'
---
doc/emacs/dired.texi | 4 ++++
etc/NEWS | 6 ++++++
lisp/wdired.el | 17 +++++++++++++++++
3 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index 13242d1..60542df 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -1294,6 +1294,10 @@ relative). To mark a file for deletion, delete the
entire file name.
To change the target of a symbolic link, edit the link target name
which appears next to the link name.
+ If you edit the file names to create a new subdirectory, Wdired will
+automatically create these new directories. To inhibit this behavior,
+set @code{wdired-create-parent-directories} to @code{nil}.
+
The rest of the text in the buffer, such as the file sizes and
modification dates, is marked read-only, so you can't edit it.
However, if you set @code{wdired-allow-to-change-permissions} to
diff --git a/etc/NEWS b/etc/NEWS
index 29b013a..c12f4d1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1426,6 +1426,12 @@ compression command is determined from the new
`dired-compress-files-alist' variable.
+++
+*** In wdired, when editing files to contain slash characters,
+the resulting directories are automatically created. Whether
+to do this or not is controlled by the
+`wdired-create-parent-directories' variable.
+
++++
*** `W' is now bound to `browse-url-of-dired-file', and is useful for
viewing HTML files and the like.
diff --git a/lisp/wdired.el b/lisp/wdired.el
index 9f25879..d943dad 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -152,6 +152,16 @@ renamed by `dired-do-rename' and `dired-do-rename-regexp'."
:version "24.3"
:group 'wdired)
+(defcustom wdired-create-parent-directories t
+ "If non-nil, create parent directories of destination files.
+If non-nil, when you rename a file to a destination path within a
+nonexistent directory, wdired will create any parent directories
+necessary. When nil, attempts to rename a file into a
+nonexistent directory will fail."
+ :version "25.2"
+ :type 'boolean
+ :group 'wdired)
+
(defvar wdired-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "\C-x\C-s" 'wdired-finish-edit)
@@ -490,6 +500,8 @@ non-nil means return old filename."
(require 'dired-aux)
(condition-case err
(let ((dired-backup-overwrite nil))
+ (and wdired-create-parent-directories
+ (wdired-create-parentdirs file-new))
(dired-rename-file file-ori file-new
overwrite))
(error
@@ -499,6 +511,11 @@ non-nil means return old filename."
err)))))))))
errors))
+(defun wdired-create-parentdirs (file-new)
+ "Create parent directories for FILE-NEW if they don't exist."
+ (and (not (file-exists-p (file-name-directory file-new)))
+ (message "Creating directory for file %s" file-new)
+ (make-directory (file-name-directory file-new) t)))
(defun wdired-exit ()
"Exit wdired and return to dired mode.