In my init file, I often find myself trying to set a customizable variable before the file (usually a mode of some sort) is loaded. This, of course, results in an error.

While this problem could be addressed through use-package and other means, it seems that making autoloading customizable variables should be a general good practice.

Customizable variables are by definition part of the user interface of a package. Packages tend to autoload functions (e.g. foo-mode) that users are expected to invoke directly--why not customizable variables as well?

Is there any problem with autoloading customizable variables?

  • What error do you see? You can set customizable variables with setq before they are defined without any problems.
    – Tyler
    May 16, 2017 at 20:35
  • What @Tyler says is true, of course. Did you really get an error, or did you just have trouble trying to find such an option - e.g., by C-h v?
    – Drew
    May 16, 2017 at 20:50
  • I'm not always using setq first. E.g. when adding to a list, I often (cl-pushnew x my-list), which errors if my-list is not defined. The solution is to wrap everything in with-eval-after-load, but I don't care for that /shrug. May 16, 2017 at 20:53

1 Answer 1


This has been discussed more than once on [email protected].

  • Here is one such thread, from 2016.

  • And here is something from Stefan, who dislikes such autoloading, from 2014.

  • Likewise, Glenn, in this 2010 thread.

  • And Stefan again, in 2009.

  • And here is an earlier 2009 thread about it.

There are many more such discussions, going back further.

One reason given against is that the autoload file gets bloated.

Another reason, more practical, is that it can be problematic if the definition (e.g. the initial value or something used in :initialize) depends on other things in the library being loaded first.

Personally, I happen to favor autoloading defcustoms, generally. It's about discovery.

  • +1 on the benefit of discovery. And shouldn't :intialize not depend on load order of things? May 16, 2017 at 20:55
  • :initialize is a function. It could check some variable or try to use some function that will be defined after the file is loaded. But yes, clearly one doesn't want to couple things like that. Better to avoid that.
    – Drew
    May 16, 2017 at 21:23

Your Answer

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

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