通过管道将 emacs shell 输出传输到新缓冲区

发布于 2024-12-22 11:04:20 字数 100 浏览 0 评论 0原文

例如,我希望能够输入类似以下内容:

$ 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

那些过往 2024-12-29 11:04:21

您可以只使用 M-! ——它将在与 shell 缓冲区相同的 cwd 中运行命令,并将结果输出到 *Shell Command Output* 缓冲区。

请注意,如果结果很简短,则不会提升该缓冲区,并且输出将被复制到回显区域;但是缓冲区仍然在使用并且可用。 Chf shell-command RET 包含构成“简短”输出的详细信息:

如果输出足够短以显示在回显区域中
(由变量 max-mini-window-height 确定,如果
resize-mini-windows 是非零),它显示在那里。
否则,将显示包含输出的缓冲区。

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:

If the output is short enough to display in the echo area
(determined by the variable max-mini-window-height if
resize-mini-windows is non-nil), it is shown there.
Otherwise, the buffer containing the output is displayed.

故人爱我别走 2024-12-29 11:04:21

如果您使用eshell,您可以将输出重定向到缓冲区,例如

 print foo > #<buffer bar>

,它会创建一个内容为“foo”的新缓冲区bar。有关更多详细信息,请参阅 Emacswiki,网址为 http://www.emacswiki.org/emacs/EshellRedirection

If you use eshell you can redirect output to a buffer, e.g.

 print foo > #<buffer bar>

which creates a new buffer bar with the content 'foo'. For further details, see the Emacswiki at http://www.emacswiki.org/emacs/EshellRedirection.

请别遗忘我 2024-12-29 11:04:21

不幸的是,emacsclient 无法读取其标准输入,因此您需要某种包装器。这是一个适合我的 Bash shell 函数:

tempbuffer() {
  perl -MFile::Temp -MFile::Copy -e \
  'copy *STDIN, $file = File::Temp->new; system "emacsclient", $file';
}

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:

tempbuffer() {
  perl -MFile::Temp -MFile::Copy -e \
  'copy *STDIN, $file = File::Temp->new; system "emacsclient", $file';
}
寒冷纷飞旳雪 2024-12-29 11:04:21

我个人的偏好是您可以在 Bash 中键入内容而无需管理任何文件:

git diff | (f=$(mktemp); cat > $f; emacsclient $f; rm -v $f)

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:

git diff | (f=$(mktemp); cat > $f; emacsclient $f; rm -v $f)

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'.

温柔戏命师 2024-12-29 11:04:21

我使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文