문제

When I type r in Emacs dirmode, it goes into a mode that allows directory operations (such as renaming, moving, deleting) by editing the list.

I have a certain file, say, foo, and I want to create a new directory below its original directory, name that directory as foo, and move the file into that directory, and give it a different name, say bar:

/path/to/the/file/foo
↓
/path/to/the/file/foo/bar

I edited the list in this mode, and did save, but the operation failed. It looks like editing like this does not allow creating directories. Is there some hack that I can do to let this possible?

I have lots of similar tasks to do, and editing on the emacs dirmode is easiest for me to do than writing a shell script to do it.

도움이 되었습니까?

해결책

You can override your implementation of wdired-do-renames as follows (the idea being just to create each destination file's parent directory before doing the rename):

diff --git a/lisp/wdired.el b/lisp/wdired.el
index 2e53944..cc838cf 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -490,6 +490,7 @@ non-nil means return old filename."
               (require 'dired-aux)
               (condition-case err
                   (let ((dired-backup-overwrite nil))
+                    (wdired-create-parentdirs file-new)
                     (dired-rename-file file-ori file-new
                                        overwrite))
                 (error
@@ -499,6 +500,10 @@ non-nil means return old filename."
                             err)))))))))
     errors))

+(defun wdired-create-parentdirs (file-new)
+  "Create parent directories of destination filename."
+  (message "create dir for file %s" file-new)
+  (make-directory (file-name-directory file-new) t))

 (defun wdired-exit ()
   "Exit wdired and return to dired mode.

Source: Joakim Verona via http://www.emacswiki.org/emacs/WDired#toc1 (I cleaned up the patch just a bit)

다른 팁

AFAIK, you cannot create a directory that way, i.e., when in wdired mode (which is what you are in when the Dired buffer is editable).

However, you can just exit wdired (C-x C-q) and then use + to create a directory.

(BTW, I think you have a typo: C-r in Dired does not toggle wdired mode, i.e., editability/read-only. It just invokes isearch-backward. You use C-x C-q to toggle read-only.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top