qaz*_*wsx 8 bash emacs command-line
如何在已经打开的 Emacs 而不是新实例中从 bash 命令行打开文件?当我打字
$ emacs file.txt
Run Code Online (Sandbox Code Playgroud)
它会打开一个新的 Emacs 实例,而不是在现有的 Emacs 实例中打开文件。Mac OS X 10.6.8。和
GNU Emacs 23.4.1 (x86_64-apple-darwin10.8.0, NS apple-appkit-1038.36)
Run Code Online (Sandbox Code Playgroud)
2012-02-27 在 beta.macosforge.org 上
您正在寻找的是 emacs 服务器模式。将此行添加到您的 .emacs 文件中:
(server-start)
Run Code Online (Sandbox Code Playgroud)
然后,使用 emacsclient 打开文件:
emacsclient foobar.txt
Run Code Online (Sandbox Code Playgroud)
查看此页面了解更多信息。
为避免必须手动启动 emacs 或将其设置为自动启动,您可以编写一个小函数来尝试连接到正在运行的服务器(通过运行emacsclient),如果没有,则emacs改为运行。将此添加到您的 shell 的配置文件(例如~/.bashrc):
emacs(){
emacsclient "$@" 2>/dev/null || /usr/bin/emacs "$@"
}
Run Code Online (Sandbox Code Playgroud)
现在,只需运行即可emacs file启动服务器或连接到现有实例。
| 归档时间: |
|
| 查看次数: |
3356 次 |
| 最近记录: |