I am working on implementing my own feature request -- http://debbugs.gnu.org/cgi/bugreport.cgi?bug=31601 -- to give wdired
the ability to handle a dired-
buffer that contains an arbitrary list of absolute paths to directories and files; e.g.,
(dired (directory-files-recursively "/path/to/directory" "" 'include-directories))
However, the files and directories may not necessarily be recursive -- i.e., dired-mode
can handle creating a buffer containing an arbitrary list of files and directories.
I have added draft code to wdired
that places read-only text properties on the file-name-directory
. That way, a user cannot edit those portions of the path while in wdired-mode
.
The next step is to process the renaming of files/directories, which requires they be done in a hierarchical order. For example, a user may have renamed a directory and a file:
OLD NAME: /path/to/directory
NEW NAME: /path/to/the_directory
OLD NAME: /path/to/directory/file
NEW NAME: /path/to/directory/the_file
OLD NAME: /path/to/different_directory
NEW NAME: /path/to/the_different_directory
OLD NAME: /path/to/different_directory/different_file
NEW NAME: /path/to/different_directory/the_different_file
If we first rename the directory from /path/to/directory
to /path/to/the_directory
, then rename-file
will be unable to rename /path/to/directory/file
because the directory
no longer exists; i.e., the directory
was changed to the_directory
.
Therefore, it makes sense to sort all of the files and directories into a hierarchical order such that the deepest file or directory is processed fist in time when renaming the files/directories. For example, if we have a set of files that are 5 directories deep, then those should be processed before processing directories or files that are less than 5 deep.
Q: How to sort a list of files/directories by hierarchical depth?
WORKING LIST:
'("/path/to/different_directory/different_file"
"/path/to/directory/file"
"/X/Y"
"/a/b/c/d/e/f"
"/1/2/3/4"
"/A/B/C/D/e"
"/x/y/Z"
"/Z"
"/path/to/different_directory"
"/path/to/directory")
RESULT DESIRED:
'("/a/b/c/d/e/f"
"/A/B/C/D/e"
"/path/to/different_directory/different_file"
"/1/2/3/4"
"/path/to/directory/file"
"/x/y/Z"
"/path/to/different_directory"
"/path/to/directory"
"/X/Y"
"/Z")
wdired
is to let the user mistakenly believe that he/she is modifying a component of thefile-name-directory
and then when the user typesC-c C-c
orwdired-finish-edit
, the proposed edit to thefile-name-directory
cannot be processed:(file-error Renaming No such file or directory ...
. The reason for that error is because only thefile-name-nondirectory
can be edited without errors, and still there would be the problem described above due to processing of hierarchy/directory-steps.read-only
properties on thefile-name-directory
, it prevents the user from mistakenly thinking he/she has edited something successfully and it prevents the above-mentionedfile-error
. In general, I suggest things through the years to the Emacs team and they choose what, if anything, gets implemented. I am usually happy if it works in my own setup even if the feature never gets implemented.