I am creating a dired-mode buffer with:

(dired (directory-files-recursively default-directory ""))

This gives me absolute paths for each file, which is great. I am still unsure how the default-directory in the resulting new dired-mode buffer is chosen.

Example, my dired- heading is: /Users/HOME/Desktop/0.r_d_w_1/Chase Checking/2015:. The file list, however, was recursively generated from /Users/HOME/Desktop/0.r_d_w_1/ with many sub-directories -- i.e., not just "Chase Checking/2015".

The problem that I am trying to solve is that wdired-get-filename assumes that the filenames are relative. When wdired-get-filename gets the NEW filename (i.e., after the wdired-mode buffer has been edited), it is incorrect. What happens is that the absolute path of the NEW filename is concatenated to the end of the default-directory. The problematic code looks like this: (concat (dired-current-directory) file), where FILE is the absolute path.

I would like to make wdired-get-filename play nice with absolute paths in addition to the default behavior which uses the default-directory and the modified relative-name for the NEW filename.

My initial thinking was to come up with a test to see if the the filename is absolute or relative, and then only concatenate if the latter. However, I would certainly be amenable to a better solution.

1 Answer 1


It's likely that wdired does not play well with Dired buffers that have an arbitrary set of files. I think you've discovered an example of that. Please consider filing a wdired bug report (M-x report-emacs-bug).

It's not too surprising. Few people know about or use the arbitrary-files feature of Dired. Wdired was written decades after Dired, by a single person I think, and probably that person was not aware of this Dired feature.

I don't really bother with wdired much, so I doubt if I've tried what you did. I do use Dired buffers with arbitrary files, though.

See C-h f dired for the buffer name - it's the non-directory part of the first element of the list you pass as the arg. It's just a buffer name, not necessarily the name of a directory. But if it corresponds to a directory then that directory becomes the default-directory.

In your case you passed (directory-files-recursively default-directory "") as the file list. The first element of this is used for the buffer name and, if it names a directory or a file in a directory then that directory becomes the default-directory. It was apparently "/Users/HOME/Desktop/0.r_d_w_1/Chase Checking/2015". Since it is a directory it is used as default-directory for the buffer.

If you use Dired+ then there are several ways you can take advantage of this feature. But as you've discovered, some tweaking of wdired is probably in order, to get reasonable behavior.

Wrt your subquestion about testing whether a file name is absolute or relative: see function file-name-absolute-p. ;-)

  • Thank you for the write-up and also for file-name-absolute-p. I was tentatively thinking of using expand-file-name or true-filename (which according to one of the threads incorporates expand-file-name and also follows symbolic links). It looks like some additional tinkering of the code will be required, and I'll have to just advance one hurdle at a time. I'll probably wait to submit a bug report until I get a basic version working, and I'll need to compare that to the master branch to see whether some of these fixes may already be implemented (although that is probably unlikely).
    – lawlist
    Apr 30, 2018 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.