Just as addition, the differences between those commands have increased due to the introduction of lexical binding, though those differences will not really be relevant if you just want to customize some variables.
The def...
constructs declare global variables. The set...
functions set variables, whether global or local. When x
is neither a local variable (a formal parameter of the current function or declared by a let
form or similiar) nor defined by a def...
form and you write (setq x 0)
the byte compiler will even show a warning
Warning: assignment to free variable `x'
Variables declared with defvar
, defcustom
, defconst
are dynamically bound, i.e. when you have a construct
(let ((lisp-indent-offset 2))
(pp (some-function)))
the function some-function
will see the change of the global variable lisp-indent-offset
.
When a variable is not dynamically bound, in something like
(let ((my-local-var 1))
(some-function))
where my-local-var
has no global value, then some-function
will not see the assigned value, as it is lexically scoped.
On the other hand, dynamically scoped variables will not be captured into lexical closures.
More details can be seen in http://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.html