例如,我想要能够输入类似以下内容的东西:
$ git diff | tempbuffer
并且在一个新的、未保存的缓冲区中打开差异。
eshell
,您可以将输出重定向到缓冲区,例如。 print foo > #<buffer bar>
该命令创建一个名为 bar
,并包含内容为 'foo' 的新缓冲区。有关更多详细信息,请参见 Emacswiki 上的http://www.emacswiki.org/emacs/EshellRedirection。
*Shell Command Output*
缓冲区。shell-command
RET可以了解什么构成“简要”输出的详细信息:
如果输出足够短以显示在回声区域中 (由变量
max-mini-window-height
确定,如果resize-mini-windows
为非nil),则在其中显示。 否则,显示包含输出的缓冲区。
git diff
的结果发送到一个新缓冲区,我希望该缓冲区处于 diff 模式。 - Mary Rose CookM-!
,然后执行了git diff
,我可以使用M-x diff-mode
来设置缓冲区的差异模式。 - Mary Rose Cook很遗憾,emacsclient
不能读取标准输入,所以你需要一些包装器。这里是一个适用于我个人的Bash shell函数:
tempbuffer() {
perl -MFile::Temp -MFile::Copy -e \
'copy *STDIN, $file = File::Temp->new; system "emacsclient", $file';
}
git diff
)。 - Mary Rose Cookgit diff | tempbuffer
。 - Sean我的个人偏好是能够在Bash中键入而无需管理任何文件的内容:
git diff | (f=$(mktemp); cat > $f; emacsclient $f; rm -v $f)
emacsclient 在 Bash 删除临时文件之前等待您完成对缓冲区的操作。
如果我从头开始启动 shell 命令,我会使用 M-!(phils 的答案),如果我正在 shell 中间某个位置并决定“我想将此管道传输到 Emacs”,那么我会使用上述方法(类似于 Sean 的答案)。