【发布时间】:2011-08-06 15:21:57
【问题描述】:
随着我向我的 emacs 的 init.el 添加越来越多的插件和配置,它的启动变得越来越慢。有什么办法可以避免吗?
【问题讨论】:
随着我向我的 emacs 的 init.el 添加越来越多的插件和配置,它的启动变得越来越慢。有什么办法可以避免吗?
【问题讨论】:
你可以将compile it作为.elc文件(M-x byte-compile-file)
【讨论】:
您的.emacs 或init.el 不应该有很多require 或load 命令,它应该主要有autoload。 autoload 函数告诉 Emacs “如果你需要这个函数,加载那个文件”。这样,只有在您实际使用该功能时才加载文件。在两种情况下你只需要require(或者很少需要load):
(require 'cl),颜色主题);autoloads 和包的其他启动定义(例如 (require 'tex-site)。如果您还没有这样做,调用 autoload 进行特定于模式的自定义可以显着缩短启动时间,因为 Emacs 将需要加载更少的文件。
此外,请确保您的文件是字节编译的;它们的加载速度会更快(更少的 CPU 时间)。在每个 .el 文件上调用 M-x emacs-lisp-byte-compile,或 M-x byte-recompile-directory(这些命令位于 Emacs-Lisp 菜单中)。
最后,请注意加载时间并不重要,因为您应该是starting Emacs at most once per session。登录时自动启动 Emacs,无论是使用窗口还是在后台使用 --daemon 选项。然后,要编辑文件,请运行 emacsclient。如果您不想在登录时启动它,也可以tell emacsclient to start Emacs if it's not running yet。
【讨论】:
(byte-recompile-directory "~/where-i-put-my-packages/" nil nil) 或将最后一个 nil 值更改为非 nil 以强制重新编译。 (describe-function 'byte-recompile-directory) 岩石 :)