What is the difference between setq and set-variable in emacs lisp. When should I use setq and when should I set-variable.
set-variable
is an interactive command, meaning that you can type M-x set-variable RET to be interactively prompted for a variable name and value. setq
is not an interactive command, meaning it's only suitable for writing in Emacs Lisp code. Personally, I never use set-variable
in my Lisp code, only interactively, when I want to give a value to a variable that has an immediate effect on my text editing, such as (for example) setting indent-tabs-mode
to t
or nil
.
Another difference is that setq
can set multiple variables at once. For example, in my .emacs file on OS X I have:
(setq mac-command-modifier 'meta
mac-option-modifier 'super)
set-variable
can't do that.