我在emacs配置中使用以下结构:对于我使用的每种编程模式,我在一个名为programming-mode-config.el的文件中维护配置.(所以python配置将进入python-mode-config.el等).
早些时候,我曾经在init.el中要求每个文件.这种方法的缺点是我的启动时间很长.所以这周末,我坐下来将所有需求转换为自动加载.现在我的init文件看起来像这样:
(autoload 'python-mode "python-mode-config" "Load python config" t)
Run Code Online (Sandbox Code Playgroud)
因此,在我打开python文件之前,不会加载python配置.这有助于将我的启动时间缩短到大约1秒,但在所有情况下都无法正常工作.例如,
(autoload 'erc "erc-mode-config" "Load configuration for ERC" t)
Run Code Online (Sandbox Code Playgroud)
根本没有加载我的erc调整.查看自动加载文档,它指出:
Define FUNCTION to autoload from FILE.
...
If FUNCTION is already defined other than as an autoload,
this does nothing and returns nil.
Run Code Online (Sandbox Code Playgroud)
所以我猜测erc配置没有被加载,因为ERC是用emacs"内置"的,而python-mode是我使用的插件.有没有什么办法可以让我的erc配置只在我实际使用erc时加载?我看到的唯一另一种选择是使用eval-after-load,但是将我的自定义的每一小部分都放入eval-after-load中会非常痛苦.
我担心也可能是因为我没有正确地使用自动加载装置.任何帮助,将不胜感激.
Tre*_*son 10
autoload
用于从某个文件加载函数,而不是加载其他功能 - 这就是你想要做的事情.
eval-after-load
改为使用:
(eval-after-load "erc" '(load "erc-mode-config"))
Run Code Online (Sandbox Code Playgroud)
这告诉Emacs在加载文件erc-mode-config
后加载库"erc"
- 这就是你想要的.'(require 'erc-mode-config)
如果您在其中有provide
声明,也可以使用.
正确使用autoload
是加载包含符号的实际文件.所以,通过拥有
(autoload 'erc "erc-mode-config" "Load configuration for ERC" t)
Run Code Online (Sandbox Code Playgroud)
您告诉Emacs erc
通过加载"erc-mode-config"
库找到该函数,而库不是erc
定义函数的位置.此外,docstring用于有问题的函数,因此autoload
上面的语句使得帮助字符串erc
变为"Load configuration for ERC"
- 这也是不正确的.
我猜你的第一个autoload
例子是有效的,因为你(require 'python)
的配置文件中有一个语句...但这只是猜测.