【发布时间】:2021-10-26 12:00:16
【问题描述】:
是否可以从另一个程序向 Gnu Emacs 发送命令?
它会例如如果我能告诉 emacs 转到当前文本文档中的某一行,那就太好了。
【问题讨论】:
是否可以从另一个程序向 Gnu Emacs 发送命令?
它会例如如果我能告诉 emacs 转到当前文本文档中的某一行,那就太好了。
【问题讨论】:
首先,在 Emacs 中 M-x server-start(或将 (server-start) 放入 init.el 文件中)。
那么您应该能够使用 emacsclient 发送 Emacs 命令 - 例如,在任何有焦点的缓冲区中转到第 10 行:
emacsclient --eval "(with-current-buffer (window-buffer) (goto-line 10))"
(感谢下面的 cmets 指出错误!总是测试?)
【讨论】:
emacsclient --eval '(with-current-buffer (window-buffer) (goto-line 12))'
emacs --daemon。它只是在 shell 输出中显示“正在启动 emacs 守护程序”,但没有打开编辑器窗口(即使我提供了文件名)——此时是否应该打开 emacs 窗口?然后我用我要编辑的文件 (emacs myfile) 打开一个 emacs。然后我尝试了 Tommy Jollyboat 和 Tom Regner 的版本,但没有任何反应(尽管命令在 shell 中执行没有错误)。我做错了什么?
emacsclient myfile打开文件。然后汤姆雷格纳给出的命令起作用了。但是在shell中打开了emacs,怎么才能得到一个X窗口呢?
-c。总结一下:emacs --daemon 后跟 emacsclient -c myfile 后跟 emacsclient --eval '(with-current-buffer (window-buffer) (goto-line 12))',正如 Tom Regner 所建议的那样。完美,非常感谢!