Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs - save current buffer list to a text file

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"))
like image 227
blueFast Avatar asked May 10 '12 15:05

blueFast


1 Answers

This command will do the job for you:

(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")))
like image 85
Trey Jackson Avatar answered Sep 22 '22 13:09

Trey Jackson