How can I put a buffer into dired mode?

399 views Asked by At

I've created a list of file names, and done some qualification of the ones I want. Now I'd like to run "ls -l" on that list, and put the result in a dired-mode buffer. Right now I'm running find-grep-dired to get files which have matches to a regular expression. But the find command takes minutes to run in my environment, and I have to run it multiple times for each of several patterns. I'm too impatient to wait for the results.

I tried just reading the ls -l value into a buffer and then executing "dired-mode". But "dired-mode" is not a function, more's the pity.

Thanks.

1

There are 1 answers

1
phils On

Strictly speaking, the answer to the question is:

M-x virtual-dired RET

If you have a buffer containing the output of ls -lR <dir> then this command will convert it into a dired buffer.

The -R argument means that the path to each of the listed directories is included, and Emacs will pick that up as the default value when it prompts you for the directory path.

Of course you don't always want a recursive listing; but if you have just a single directory listing via ls -l then that header line isn't included, and you'll need to enter the directory manually at the prompt.

Of course you can easily generate that line yourself to work around the problem:

printf "%s:\n" $(pwd) && ls -l

Edit: I didn't notice that this was part of the dired-x library, which isn't auto-loaded. See the manual:
C-hig (dired-x) RET