4

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?

Tianxiang Xiong
  • 3,848
  • 16
  • 27
  • What error do you see? You can set customizable variables with `setq` before they are defined without any problems. – Tyler May 16 '17 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 '17 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. – Tianxiang Xiong May 16 '17 at 20:53

1 Answers1

5

This has been discussed more than once on emacs-devel@gnu.org.

  • 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.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • +1 on the benefit of *discovery*. And shouldn't `:intialize` *not* depend on load order of things? – Tianxiang Xiong May 16 '17 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 '17 at 21:23