I am teaching myself autoloads for "home-made" packages.
suggest to use
update-directory-autoloads on the related package file or directory, which will add the corresponding autoload calls into
loaddefs.el. This does not seem to be the strategy followed by most packages, which instead create a distinct
*-autoloads.el file for each source equipped with the magic autoload comments (perhaps to avoid cluttering
I haven't found any tutorial on this, by the way a user suggested to use
package-generate-autoloads. Indeed, it works up to a certain point, and this is my attempt.
I created the file
;;;###autoload (defun foofunc () (message "I'm foo")) (provide 'foo)
Then, I executed on the
(package-generate-autoloads "foo" "foo")
Much like for any package, it generates in
foo-autoloads.el file, where there is a line:
(autoload 'foofunc "foo" nil nil nil)
When restarting Emacs, by inspecting the value of the variable
load-path, I see that the
foo is automatically included, being under
site-lisp. However, evaluating
Debugger entered--Lisp error: (void-function foofunc)
Not surprisingly, if I manually evaluate
(autoload 'foofunc "foo" nil nil nil) or
foofunc works. However, there should be some way to have this done automatically by Emacs for all autoloads files in the path.
Note that, while this question focuses on
package-generate-autoloads function, if there is a better way to activate autoloads, your answer is welcomed.
As a side note, I have seen that applying
package-generate-autoloads to some ELPA packages adds to the corresponding
*-autoloads.el files a convenient call to
register-definition-prefix. As I understand, with this function you can add a custom prefix
mypref-, such that, whenever you try to autocomplete
mypref- in the minibuffer, you autoload the relevant lisp file.
What (magic cookies) in the source files trigger(s) the insertion of these calls in the