What is the purpose of off-loading definitions with autoload in emacs? Why not autoloading is slow?

佐手、 提交于 2019-12-02 13:41:41

The simplest way to load the content of the file foo.el is to do a load. However, this is costly because you have to read the whole file.

With autoload you are allowed to tell emacs: "function foo is defined in file foo.el". This way emacs does not read the file and you do not pay the loading price. When you use the function foo for the first time, emacs will find the definition for you by reading foo.el.

The ;;;###autoload comment in your file is not doing anything for autoload by itself. You need to use a program that will grab all of these definitions and put them in a file foo-autoloads.el (or any other name). For each function it will put a line telling emacs which file contains it. Then in your .emacs you will load foo-autoloads.el instead of foo.el. foo.el will be read by emacs the first time you use function foo.

Note: require can also be used instead of load in the explanation above.

Where did you get that "understanding" from? Certainly not the manual.

The autoload cookies are used to pull out skeletal function/variable definitions in a separate autoload file. This is usually done at compile time.

Without going through that compilation step the autoload cookies have no effect.

The autoload forms have to be loaded separatly. They can be generated from the autoload cookies, but you can also write them manually. For example, in your .emacs you can put autoload forms for functions which you only use occasionally, so they are only loaded on demand.

For example:

(autoload 'ahk-mode "ahk-mode")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!