I maintain a somewhat popular Emacs package (ido-ubiquitous), and I would like to add the ;;;###autoload
comments to my package so that it does not need to be loaded until its mode is activated. I attempted this a while ago with the same package, and it resulted in a number of cryptic errors that only occurred when the package was autoloaded, so I removed all the autoload stuff and the problems went away. I'd like to try again, but only if I can find definitive documentation on how to do it so I don't end up introducing the same bugs again.
So is there a definitive guide to adding autoload cookies to an Emacs Lisp package?
EDIT: Looking at my Git logs for my package, I see a couple of commits referring to autoloads:
- 283f9e9 Remove unnecessary autoloads
- 66b782f Autoload default values of override variables
- f6086e5 Autoload fix
- 0eed206 Remove unnecessary autoload cookie
These commits show that I was really not sure what to add autoloads to. In particular, f6086e5 and 66b782f shows that I thought I should autoload custom variables, and concluded that I also needed to autoload the defconst
forms that defined their default values. If I recall correctly, this was in response to a void-variable error because the autoloaded defcustom didn't have access to the non-autoloaded default value (issue link). Finally, in 283f9e9 I had a vision of the future and took Stefan's advice by removing all autoloads except for the one on the minor mode definition.