emacs - save current buffer list to a text file

醉酒当歌 提交于 2019-12-09 10:50:04

问题


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"))

回答1:


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")))



回答2:


You can change the mode of your *Buffer List* buffer. By default, it will be in mode Buffer Menu, but changing it to text-mode or fundamental-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 with delete-rectangle.

Alternatively, you can access the buffer list programmatically with elisp:

(dolist (buffer (buffer-list))
  (when (buffer-file-name buffer)
    (insert (buffer-file-name buffer) "\n")))



回答3:


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.



来源:https://stackoverflow.com/questions/10537265/emacs-save-current-buffer-list-to-a-text-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!