summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorPhil Sung <philbert@gmail.com>2016-02-28 15:07:02 +1030
committerLars Ingebrigtsen <larsi@gnus.org>2016-02-28 15:07:02 +1030
commite00974a7d1981d716d38ecf45b689dd30a381c65 (patch)
tree635c1677b80ec6db07e52e8c1c45bf7c4348ef0e /lisp
parentd5f270f2965f3c52963e2bf0057756e350d771d1 (diff)
downloademacs-e00974a7d1981d716d38ecf45b689dd30a381c65.tar.gz
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'
Diffstat (limited to 'lisp')
-rw-r--r--lisp/wdired.el17
1 files changed, 17 insertions, 0 deletions
diff --git a/lisp/wdired.el b/lisp/wdired.el
index 9f258794f96..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.