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.
The simplest way to load the content of the file
foo.elis to do aload.However, this is costly because you have to read the whole file.
With
autoloadyou are allowed to tell emacs: “functionfoois defined in filefoo.el“.This way emacs does not read the file and you do not pay the loading price. When you use the function
foofor the first time, emacs will find the definition for you by readingfoo.el.The
;;;###autoloadcomment 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
.emacsyou willloadfoo-autoloads.elinstead offoo.el.foo.elwill be read by emacs the first time you use functionfoo.Note:
requirecan also be used instead ofloadin the explanation above.