Emacs:将缓冲区写入新文件,但保持该文件打开
我想在 Emacs 中执行以下操作:将当前缓冲区保存到新文件,但同时保持当前文件打开。 当我执行 Cx Cw 时,当前缓冲区将被替换,但我想保持两个缓冲区打开。这可以在不重新打开原始文件的情况下实现吗?
I want to do the following in Emacs: Save the current buffer to a new file, but also keep the current file open.
When I do C-x C-w then current buffer gets replaced, but I want to keep open both buffer. Is this possible without reopening the original file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不认为有任何内置的东西,但写起来很容易:
I don't think there's anything built in, but it's easy enough to write:
这是我已经有一段时间这样做的一个片段
Here's a snippet I've had for a while to do just this
我发现将斯科特和克里斯的上述答案结合起来很有帮助。用户可以调用另存为,然后在提示是否切换到新文件时回答“y”或“n”。 (或者,用户可以通过函数名称 save-as-and-switch 或 save-as-but-do-not-switch 选择所需的功能,但这需要更多的击键。这些名称仍然可供其他名称调用不过,将来会起作用。)
I found it helpful to combine Scott's and Chris's answers above. The user can call save-as and then answer "y" or "n" when prompted whether to switch to the new file. (Alternatively, the user can select the desired functionality via the function name save-as-and-switch or save-as-but-do-not-switch, but this requires more keystrokes. Those names are still available for being called by other functions in the future, however.)
选择所有缓冲区,然后
将该区域(本例中为整个缓冲区)写入另一个文件。
编辑:这个函数可以满足您的需要
,有点粗糙,但是可以根据您的意愿进行修改。
交互式代码“G”提示输入“文件名”参数中的文件名。
将其放入 .emacs 中并使用 Mx write-and-open 进行调用(或定义按键序列)。
selects all the buffer, then
writes the region (whole buffer in this example) to another file.
Edit: this function does what you need
It's a bit crude, but modify to your will.
The interactive code 'G' prompts for a filename which goes into the 'filename' argument.
Drop this into your .emacs and call with M-x write-and-open (or define a key sequence).