shell - Emacs 口齿不清 : is it possible (using lisp) to run command in an eshell working in other buffer?

标签 shell emacs lisp g++ elisp

我有一个 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/

相关文章:

dictionary - 我什么时候会使用 mapc 而不是 mapcar?

rest - 额外的 header 未通过 url.el 发送

python - 使用脚本填充 Sql 表

linux - 在 shell 脚本中向 AWS SNS 消息添加换行符

database - 使用 shell 脚本的 sqlplus 访问和电子邮件访问

objective-c - 如何从 Cocoa 调用的管理员权限 bash 脚本获取输出?

Emacs:俄语是或否-p?

r - Emacs中ESS和rpy2共享R进程

emacs - 右 ALT 键在 emacs 中不能用作元键

Windows 7 上的 LispWorks 无法加载 Quicklisp