Quite often I need to get a simple text copy of my currently opened files. The reasons are usually:
- I want to send the list to a colleague
- I want to document whatever I am working on (usually in an org document)
- I want to act on one of my currently opened files, on the shell. I need to copy-paste the pathname for that.
The fact is that the usual buffer-menu
or list-buffers
provide a convenient menu to navigate the opened buffers, but are very inconvenient to copy-paste to the the terminal the names of the opened files, or to perform any of the actions mentioned above. For example: I can not double-click in a line to select the full path-name, and I can not use the kill
/yank
emacs sequence to copy around the path-name.
Summary: I would like a way to export to a text file (or to a new buffer) the list of opened files, without other data; no file size, mode, or any other emacs metadata.
Is there a command for that? An extra package I can install?
EDIT
Adding solution by Trey Jackson, modified to provide some feedback of what has been done:
(defun copy-open-files ()
"Add paths to all open files to kill ring"
(interactive)
(kill-new (mapconcat 'identity
(delq nil (mapcar 'buffer-file-name (buffer-list)))
"\n"))
(message "List of files copied to kill ring"))
This command will do the job for you:
You can change the mode of your
*Buffer List*
buffer. By default, it will be in modeBuffer Menu
, but changing it totext-mode
orfundamental-mode
will remove all the special behavior allowing you to cut and paste from it just like a regular buffer. The metadata can easily be chopped off withdelete-rectangle
.Alternatively, you can access the buffer list programmatically with elisp:
You certainly should be able to copy and yank from the buffer list.
e.g. copy everything with C-xhM-w and then yank into a new buffer for editing.