sometimes I see a "unkosher" use of autoload coookie, for example:

(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)?

  • (Just something to keep in mind for those who use this in packages.) The autoloading of some non-defun forms changed a bit since Emacs 24.1 (which is what most packages support). In particular, something that's a macro call or a progn will be handled differently depending on the emacs version.
    – Malabarba
    Commented May 20, 2015 at 9:21

1 Answer 1


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 autoload call). 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 loaddefs.el.

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-autoloads copies it to loaddefs.el, where it is executed while building Emacs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.