[英]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:
原因通常是:
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. 事实上,通常的
buffer-menu
或list-buffers
提供了一个方便的菜单来导航打开的缓冲区,但是将打开的文件的名称复制粘贴到终端或执行上述任何操作都非常不方便以上。 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. 例如:我不能双击一行来选择完整的路径名,我不能使用
kill
/ yank
emacs序列来复制路径名。
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.
没有文件大小,模式或任何其他emacs元数据。
Is there a command for that? 那是否有命令? An extra package I can install?
我可以安装额外的包吗?
Adding solution by Trey Jackson, modified to provide some feedback of what has been done: 添加Trey Jackson的解决方案,经过修改后提供了一些反馈:
(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: 此命令将为您完成以下任务:
(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")))
You can change the mode of your *Buffer List*
buffer. 您可以更改
*Buffer List*
缓冲区的模式。 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. 默认情况下,它将处于模式
Buffer Menu
,但将其更改为text-mode
或fundamental-mode
将删除所有特殊行为,允许您像常规缓冲区一样从中剪切和粘贴。 The metadata can easily be chopped off with delete-rectangle
. 可以使用
delete-rectangle
轻松切断元数据。
Alternatively, you can access the buffer list programmatically with elisp: 或者,您可以使用elisp以编程方式访问缓冲区列表:
(dolist (buffer (buffer-list))
(when (buffer-file-name buffer)
(insert (buffer-file-name buffer) "\n")))
You certainly should be able to copy and yank from the buffer list. 你当然应该能够从缓冲区列表中复制和抽取。
eg copy everything with Cx h Mw and then yank into a new buffer for editing. 例如,用Cx h Mw复制所有内容,然后进入新的缓冲区进行编辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.