The short answer to you question is:
-
use
setqorsetq-defaultfor variables defined bydefvar. -
use
setq,setq-default, or theCustomizemechanism for variables defined bydefcustom
Below is the long answer.
The functions that you are going to use are the following:
-
setis the main function to set the value of a variable. -
setqis another version that automatically quotes its first argument. This is useful since quoting the first argument is what you want to do almost all the time. -
Some variables cannot be set globally. Whenever you set the variable it is only set for the current buffer. If you want to simulate setting this variable globally you use
set-defaultorsetq-default.
The functions that a package writer uses are:
-
defvarwhich allows the package writer to define a variable and to give some documentation. This function is not required but makes the life of users easier. -
defcustombuilds ondefvar. It tells emacs that it is a variable, and it allows the developer to create acustominterface to set the value. The developer can say, things like “this variable can contain only the value ‘foo or ‘bar”.
Setting variables can be done two ways:
-
if
defvarwas used, the values can only be set by the user in its.emacsby using thesetfunction (or variants) -
if
defcustomwas used, the values can be set usingset(see 1.) OR by usingCustomize. When using the customize mechanism, emacs will generate some code that it will place incustom-set-variables. The user should not use this function.