Emacs lisp:是否有可能(使用lisp)在其他缓冲区中运行eshell命令?

zer*_*ble 3 lisp emacs shell elisp g++

eshell在一个缓冲区中有一个正在运行的实例,而我正在另一个缓冲区中编写c ++源代码.我已经绑定compile<F5>,我想知道是否可以在另一个缓冲区中运行的eshell实例中运行输出文件(编译)?

如果没有,那么也许有一种方法可以在新框架中打开eshell并自动运行编译输出?

非常感谢你提前.

Gar*_*ees 5

通常,如果要在编译完成后运行某些内容,请将其添加到编译命令中.例如,而不是

M-x compile RET make RET
Run Code Online (Sandbox Code Playgroud)

你可以输入

M-x compile RET make && ./test RET
Run Code Online (Sandbox Code Playgroud)

或者您可以将程序添加到makefile中的某个适当的目标,这样就可以了

M-x compile RET make test RET
Run Code Online (Sandbox Code Playgroud)

也许如果您能解释为什么要在eshell中运行已编译的程序,我可以为您提供更好的建议.


但是,如果您坚持使用eshell,则可以使用compilation-finish-functions:

编译过程完成时调用的函数.每个函数都使用两个参数调用:编译缓冲区和描述进程如何完成的字符串.

这不是所有文档都记录"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)
Run Code Online (Sandbox Code Playgroud)

但这似乎相当粗鲁:如果您eshell在编译完成时碰巧输入缓冲区,那么这将删除您的输入.正如我上面所说,更多的上下文可能会有所帮助.