我有一个 eshell
的运行实例在一个缓冲区中,我正在另一个缓冲区中编写 C++ 源代码。我绑定(bind)了compile
至 <F5>
我想知道是否可以在另一个缓冲区中运行的 eshell 实例中运行(编译的)输出文件?
如果没有,那有没有办法在新的框架中打开eshell,并自动在其中运行编译输出?
非常感谢您。
最佳答案
通常,如果你想在编译完成后运行一些东西,你将它添加到编译命令中。例如,而不是
M-x compile RET make RET
你可能会输入
M-x compile RET make && ./test RET
或者您可以将程序添加到您的 makefile 中的某个适当的目标,这样您就可以做
M-x compile RET make test RET
如果你能解释一下为什么要在eshell中运行编译后的程序,我可以给你更好的建议。
但是,如果您坚持使用 eshell,您也许可以使用 compilation-finish-functions
:
Functions to call when a compilation process finishes. Each function is called with two arguments: the compilation buffer, and a string describing how the process finished.
这并没有得到很好的记录,但如果该过程成功完成,则字符串为 "finished\n"
。所以你可以这样做:
(defun run-compilation-output-in-eshell (buf msg)
"If compilation finished successfully, switch to eshell and execute a command."
(when (string= msg "finished\n")
(eshell)
(goto-char (point-max))
(eshell-kill-input)
(insert "echo command goes here")
(eshell-send-input)))
(add-hook 'compilation-finish-functions #'run-compilation-output-in-eshell)
不过,这似乎相当粗鲁:如果您在编译完成时恰好在 eshell
缓冲区中键入内容,那么这将删除您的输入。正如我上面所说,更多的上下文可能会有所帮助。
关于shell - Emacs 口齿不清 : is it possible (using lisp) to run command in an eshell working in other buffer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4253754/