9

I have a mechanism for burning items to disc from a dired buffer. Unfortunately, the file's I've patched are strewn accross the file system. How can I create a dired buffer from all open files?

  • possible duplicate of Programmatically insert files into Dired buffer – Drew Nov 5 '14 at 5:07
  • @Drew I would argue not a duplicate, at least not strictly. This question would simply become 'How do I get a list of all open buffers bound to files?'. – Sean Allred Nov 5 '14 at 5:08
  • @Drew Specifically: (sort (remove nil (mapcar #'buffer-file-name (buffer-list))) #'string<) – Sean Allred Nov 5 '14 at 5:09
  • The information added is that buffer-list exists (which I did know) and that buffer-file-name returns nil when there is no file (which I did not know). Your proposed duplicate doesn't contain this information or have any need to. – Sean Allred Nov 5 '14 at 5:11
  • 1
    @Drew In my experience, trying to make every question as modular as possible is a disadvantage rather than an advantage. It decreases the usefulness with persons who stumble upon this from Google and will never register simply because they Google'd their use case. If I want through every question on TeX.SE and dupe'd questions that had the same conceptual answers, moderation would become a nightmare and the site would plunge into darkness. – Sean Allred Nov 5 '14 at 5:13
12

The dired command accepts a list of file-names as argument. Just create one and pass to it:

(dired
 (cons
  "Open Files"
  (sort (remove nil (mapcar #'buffer-file-name (buffer-list)))
       #'string<))) 
  • I think this misses one file: when you pass a list to dired the first element in that list is taken as the directory name, the rest as the files. How about this: (dired (cons "*Open Files*" (sort (remove nil (mapcar #'buffer-file-name (buffer-list))) #'string<))) – glucas Nov 4 '14 at 19:10
  • Just a note: this will err if there is a file-associated buffer that has not been saved to disk yet. – Sean Allred Nov 4 '14 at 21:28
1

Just provide a list of strings, to the dired function, example:

(dired '("custom dired" ".emacs.d/init.el" "mydotfiles/.bashrc"))

EDIT

@Malabarba answer is the best way to go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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