If the variable is a user option, do it before loading the package. The package contains a defcustom
that defines the option, but defcustom
will not set the value if the variable already has a value (e.g., from your setq
).
Similarly, if the variable is a globally defined variable that is not a user option, i.e., is defined by the package using defvar
. defvar
, like defcustom
, will not override an existing value.
On the other hand, depending on the variable, sometimes you want to change its value after the package has been loaded. It all depends on what the package does and how that variable is used.
Regardless of what I've said above, IMO it is generally a bad idea to alter global variable values (whether options or not) using setq
in your init file.
For an option, it is preferable to customize it using the Customize UI, or else to use one of the functions custom-set-variables
or customize-set-variable
in your init file (i.e., explicitly, yourself). This is because a defcustom
defining an option can have "triggers" for value initialization and updating (and it can have other special handling). And a given defcustom
can depend, for evaluating its default value expression, on other stuff that appears before it in the file.
If you just use setq
to initialize or update the option then you bypass any such special handling, which is probably not what you want, and which can lead to surprises.
Similarly, but less importantly in general, unless you are sure of what you are doing, it can be a bad idea to simply use setq
on a non-option (i.e., defvar
) variable.
My recommendation: Use Customize, but do not let it write to your init file. Instead, define variable custom-file
(actually, it is an option, but you cannot really use it like one), so that Customize writes to that separate file and leaves your init file for you to modify manually. (You can still use customize-set-variable
in your init file.)
If you do that, you need to load file custom-file
from your init file. And you can decide at what point in your init file to do that, i.e., whether a given variable setting in your init file should come before or after loading custom-file
(the settings that Customize manages).