I understand what autoload does for functions (register file to load when such function is called or its documentation string is retrieved). However, it's not clear how to use autoload facility in conjunction with variables and macros.
I have two questions:
What happens when package has parameter, implemented as a variable that user can set, but it's not autoloaded? Should such variables be autoloaded? If not, it turns out that such variables do not exist, Lisp environment knows nothing about them, including their default values, until some autoloaded function from the package is used (typically after loading of configuration files), then if user sets them in his/her configuration file, it's like setting non-existing variable. If value of the variable is a non-empty list and user uses
pushoradd-to-listto change its value, what exactly happens? Are default values lost?What happens when a macro is autoloaded? When should we autoload a macro?
setqed (i.e. it doesn't matter what values they had before) can have default specified indefvarordefcustomform, but in case of list that can be extended by user it's best to useeval-after-loadright? Also, sometimes good defaults are good, even if they take form of a list ;-) – Mark Karpov Jul 13 '15 at 07:33eval-after-load, it's a bug in the package implementation. Typically,eval-after-loadshould be used for bug fixes or highly unusual customizations. By the way, it may be better to use a hook if the package makes one available. – Harald Hanche-Olsen Jul 13 '15 at 08:12eval-after-loadway, users still won't be able to remove elements from the list! This makes me wonder if I should abandon the defaults at all. – Mark Karpov Jul 13 '15 at 08:16eval-after-loadshould be needed only for unusual situations. It's one of the standard tools in the deferred-loading toolkit. If people don't want to use such tools, they canrequirethe library up front (which is indeed what newcomers are invariably recommended to do -- by the time they get around to thinking "I wish Emacs started a little faster", they've probably learned enough not to be scared off by the new syntax :) – phils Jul 13 '15 at 08:56setqthe relevant variable up front. – Harald Hanche-Olsen Jul 13 '15 at 09:36;;;###autoloadcookie adds declaration of the variable to corresponding autoload file (when installed via package manager, at least) thus it can be used to "predeclare" variables and their values (I think it's also kinda cheap operation). Did you know that? Can you add the fact into your answer for future readers? – Mark Karpov Jul 13 '15 at 11:52defcustomform, you should be careful about its initialization code (e.g., make sure that any functions and variables it uses are autoloaded first or are otherwise available without loading the library). And autoloading a long variable definition can contribute to autoload-file bloat. IOW, (1) it is entirely possible and (2) use it judiciously, if you use it. – Drew Feb 01 '16 at 02:03defcustom. If a user sets the option value before thedefcustomis evaluated, thedefcustomdefault value is not used. "If OPTION already has a default value, it is left unchanged. If the user has already saved a customization for OPTION, the user’s customized value is installed as the default value." – Drew Feb 01 '16 at 02:09setqfor user options. Usecustomize-set-variableor use the Customize UI. Why? Becausesetqknows nothing about:setand initialization triggers (functions). See Advantages of setting variables with setq instead of custom.el?. – Drew Feb 01 '16 at 02:13custom-set-variablesdoes have some of the features I associate with autoloading, i.e., it's not evaluated until needed. – Harald Hanche-Olsen Feb 01 '16 at 12:46eval-after-load. If possible and meaningful, it might be better to provide a customizable variable containing additions to the given list. Perhaps this is better solved with some of the more advanced features of the customize feature; I haven't studied it in that much detail. – Harald Hanche-Olsen Feb 01 '16 at 12:52customize-set-variablerather thansetqmay be a good one. But I don't have the time now for the careful study required to improve my answer in this regard. If you think this is important, why don't you write your own answer? It will be more visible than this long comment thread. – Harald Hanche-Olsen Feb 01 '16 at 12:55