Emacs的server/client模式只需要加载一次配置文件,所以打开文件会快一些。
EmacsClient allows one to open a file for editing in an already running Emacs. Because it doesn’t start a new Emacs instance at each invocation, you can set up EmacsClient as the default editor, e.g. in the environment variable EDITOR or VISUAL.
所以,简单的说就是,emacs client通过tcp/ip链接server,告诉server打开文件。
启动server端命令如下,启动后这个后台命令一直在运行。
emacs -daemon
也可以先打开一个空的emacs,再M-x server-start
。
emacsclient xxx.v
启动时,emacs会与server通信,把文件名传递给server,让server打开文件,再在client编辑。
如果Server没有提前运行,client默认会报错。但我们也可以用client的命令行参数来自动启动server。
emacsclient --alternate-editor="" xxx.v
或者
emacsclient -a="" xxx.v
当然,Emacs启动速度慢也可能是你配置文件里要加载的东西太多了,或者有bug,可以用benchmark-init来分析一下。这篇文章写了一些优化的方法,大家可以参考一下:
https://manateelazycat.github.io/emacs/2019/05/12/emacs-optimize-startup-speed.html
参考资料:
https://www.emacswiki.org/emacs/EmacsClient
https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html