summaryrefslogtreecommitdiff
path: root/lisp/wdired.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/wdired.el')
-rw-r--r--lisp/wdired.el19
1 files changed, 18 insertions, 1 deletions
diff --git a/lisp/wdired.el b/lisp/wdired.el
index 795e50d16d5..d943dada030 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.
@@ -666,7 +683,7 @@ If OLD, return the old target. If MOVE, move point before it."
(funcall command 1)
(setq arg (1- arg)))
(error
- (if (forward-word-strictly)
+ (if (forward-word)
;; Skip any non-word characters to avoid triggering a read-only
;; error which would cause skipping the next word characters too.
(skip-syntax-forward "^w")