There are several similar setting functions:
so, what's the difference between these functions?
If I want setting my own preferences to an add-on, for these scenario:
The short answer to you question is:
use setq
or setq-default
for variables defined by defvar
.
use setq
, setq-default
, or the Customize
mechanism for variables defined by defcustom
Below is the long answer.
The functions that you are going to use are the following:
set
is the main function to set the value of a variable.
setq
is 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-default
or setq-default
.
The functions that a package writer uses are:
defvar
which 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.
defcustom
builds on defvar
. It tells emacs that it is a variable, and it allows the developer to create a custom
interface 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 defvar
was used, the values can only be set by the user in its .emacs
by using the set
function (or variants)
if defcustom
was used, the values can be set using set
(see 1.) OR by using Customize
. When using the customize mechanism, emacs will generate some code that it will place in custom-set-variables
. The user should not use this function.