sometimes I see a "unkosher" use of autoload coookie, for example:
;;;###autoload (add-hook 'some-hook 'some-fun)
How will the above work? Will it add a hook just by being installed (as autoloads get loaded automatically)?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
You can find the answer yourself, by using
i autoload in the Elisp manual. That takes you to node
Autoload (funny about that).
This part of that node gives you the answer:
The same magic comment can copy any kind of form into
loaddefs.el. The form following the magic comment is copied verbatim, except if it is one of the forms which the autoload facility handles specially (e.g., by conversion into an
autoloadcall). The forms which are not copied verbatim are the following:...
That means that your
(add-hook 'some-hook 'some-fun) is executed when the file is loaded, and it is also added to
If the form is on the same line as the autoload cookie then it is just copied to
loaddefs.el. If on the same line, the form is effectively commented out, so it has no effect when the file is loaded. From the same node:
You can also use a magic comment to execute a form at build time without executing it when the file itself is loaded. To do this, write the form on the same line as the magic comment. Since it is in a comment, it does nothing when you load the source file; but
M-x update-file-autoloadscopies it to
loaddefs.el, where it is executed while building Emacs.