In ELisp, you can skip the evaluation of a definition with the autoload cookie. The definition is evaluated only once it's used.
;; File foo.el
;;;###autoload
(defun foo ()
"Doc"
42)
(defun bar ()
"Doc"
43)
So, if I understand correctly the autoload functionnality is a hack to load file faster. But when I load foo.el
, in order to skip the definition of foo the interpreter still has to read the whole form. I don't understand why it's faster.
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 simplest way to load the content of the file
foo.el
is to do aload
. However, this is costly because you have to read the whole file.With
autoload
you are allowed to tell emacs: "functionfoo
is defined in filefoo.el
". This way emacs does not read the file and you do not pay the loading price. When you use the functionfoo
for the first time, emacs will find the definition for you by readingfoo.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 filefoo-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 willload
foo-autoloads.el
instead offoo.el
.foo.el
will be read by emacs the first time you use functionfoo
.Note:
require
can also be used instead ofload
in the explanation above.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: