通过管道将 emacs shell 输出传输到新缓冲区
例如,我希望能够输入类似以下内容:
$ git diff | tempbuffer
并在新的未保存的缓冲区中打开差异。
For example, I want to be able to type something like:
$ git diff | tempbuffer
and have the diff opened in a new, unsaved buffer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以只使用 M-! ——它将在与 shell 缓冲区相同的 cwd 中运行命令,并将结果输出到
*Shell Command Output*
缓冲区。请注意,如果结果很简短,则不会提升该缓冲区,并且输出将被复制到回显区域;但是缓冲区仍然在使用并且可用。 Chf
shell-command
RET 包含构成“简短”输出的详细信息:You can just use M-! -- it will run the command within the same cwd as your shell buffer, and output the results to a
*Shell Command Output*
buffer.Note that if the results are brief, that buffer will not be raised and the output will be copied to the echo area; however the buffer is still used and available. C-hf
shell-command
RET has details of what constitutes "brief" output:如果您使用
eshell
,您可以将输出重定向到缓冲区,例如,它会创建一个内容为“foo”的新缓冲区
bar
。有关更多详细信息,请参阅 Emacswiki,网址为 http://www.emacswiki.org/emacs/EshellRedirection。If you use
eshell
you can redirect output to a buffer, e.g.which creates a new buffer
bar
with the content 'foo'. For further details, see the Emacswiki at http://www.emacswiki.org/emacs/EshellRedirection.不幸的是,
emacsclient
无法读取其标准输入,因此您需要某种包装器。这是一个适合我的 Bash shell 函数:Unfortunately
emacsclient
doesn't read its standard input, so you need some kind of wrapper. Here's a Bash shell function that works for me:我个人的偏好是您可以在 Bash 中键入内容而无需管理任何文件:
emacsclient 会在 Bash 删除临时文件之前等待您完成缓冲区的操作。
我会用M-! (phils 的答案)如果我从头开始启动 shell 命令,上面的命令(类似于 Sean 的答案)如果我在 shell 中“处于某件事的中间”,然后决定“我想将其通过管道传输到 Emacs”。
My personal preference is for something you can type in Bash without having to manage any files:
emacsclient waits for you to be finished with the buffer before Bash deletes the temporary file.
I would use M-! (phils's answer) if I was starting the shell command from scratch and the above (which is similar to Sean's answer) if I was 'in the middle of something' in the shell and then decided 'I want to pipe this to Emacs'.
我使用 emacs wiki 中的信息作为起点制作了一个包 (e-sink)。它按照您所描述的方式工作,并且“尾部”输出,而不是等到进程完成才显示所有内容。
I made a package (e-sink)using information from the emacs wiki as a starting point. It works as you described and "tail"s the ouput instead of waiting until the process finishes to display everything.