如何让我的自定义 emacs 加载速度更快?
当我向 emacs 的 init.el 添加越来越多的插件和配置时,它的启动变得越来越慢。有什么办法可以避免这种情况吗?
As I add more and more plugins and configurations to my emacs' init.el , it's startup is getting more and more slow. Is there any way to avoid this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
.emacs
或init.el
不应该有很多require
或load
命令,它应该主要有 <代码>自动加载。autoload
函数告诉Emacs“如果您需要此功能,请加载该文件”。这样,只有当您实际使用该函数时才会加载该文件。在两种情况下,您只需要require
(或者很少需要load
):(require 'cl)< /code>,颜色主题);
自动加载
和其他启动定义(例如(require 'tex-site)
。如果您'如果您尚未执行此操作,则调用
autoload
进行特定于模式的自定义等操作可以显着缩短启动时间,因为 Emacs 必须加载更少的文件。此外,请确保您的文件是字节编译的;它们的加载速度会更快一些(CPU 时间更少)。在每个
.el
文件上调用Mx emacs-lisp-byte-compile
或Mx byte-recompile -directory
(这些命令位于 Emacs-Lisp 菜单中)。最后,请注意,加载时间并不那么重要,因为您应该 每个会话最多启动一次 Emacs。登录时自动启动 Emacs,无论是通过窗口还是在后台然后,要编辑文件,请运行
emacsclient
。您还可以告诉emacsclient
如果 Emacs 尚未运行,请启动它(如果您不想在登录时启动它)。Your
.emacs
orinit.el
shouldn't have manyrequire
orload
commands, it should mostly haveautoload
. Theautoload
function tells Emacs “if you ever need this function, load that file”. This way, the file is only loaded when and if you actually use the function. You only needrequire
(or very rarelyload
) in two cases:(require 'cl)
, a color theme);autoloads
and other start-up definitions of a package (e.g.(require 'tex-site)
.If you're not doing this already, calling
autoload
for things like mode-specific customizations can cut your startup time down significantly, because Emacs will have to load fewer files.Furthermore, make sure your files are byte-compiled; they'll load a little faster (less CPU time). Call
M-x emacs-lisp-byte-compile
on each.el
file, orM-x byte-recompile-directory
(these commands are in the Emacs-Lisp menu).Finally, note that load times don't matter so much because you should be starting Emacs at most once per session. Start Emacs automatically when you log in, either with a window or in the background with the
--daemon
option. Then, to edit a file, runemacsclient
. You can also tellemacsclient
to start Emacs if it's not running yet if you'd rather not start it when you log in.您可以将其编译为.elc 文件(Mx 字节编译文件)
You can compile it as an .elc file (M-x byte-compile-file)