Some people might think it is simpler to use setq
. Some people might think it is more lispy. In reality, it is naive in the general case.
It is true that for some user options it does not matter. But for others, it does matter, and setq
is the wrong approach for those options. So as a general rule, setq
is the wrong approach.
If you use custom-set-variables
or customize-set-variable
instead of setq
, or if you use the Customize user interface (e.g. M-x customize-option
), then you are sure that any intended initialization or updating code that is needed for the option value will be automatically triggered and run as needed. If you use setq
, this will not be done.
Now, it is also the case that most user options, especially many of them written for 3rd-party libraries, do not make use of the defcustom
keywords :set
and :initialize
, and using setq
does not matter for them. But lots of vanilla Emacs options do use such keywords, and for those that do, setq
is not the right thing.
So if you want to use Lisp code and not the Customize UI to set your options, then you are better off using custom-set-variables
or customize-set-variable
instead of setq
. It never hurts and it sometimes helps (a lot).
But what I recommend is to do both of these things:
Use the Customize UI instead of writing Lisp code for this.
Define variable custom-file
, so that Customize writes customizations to that file and not to your init file (~/.emacs
). IOW, keep your hand-written initialization code separate from the automatic code written by Customize.
:type
withdefvar
- I don't think it should be limited to user options. Unfortunately, many programmers are lazy in their use of:type
, and the result is not very helpful (that's not the fault of Customize). – Drew Sep 25 '14 at 15:08setq
instead ofcustomize-set-variable
exactly once. (That one time was forauto-revert-interval
, and I later realized that usingsetq
before loadingautorevert
was actually much faster than usingcustomize-set-variable
.) – Resigned June 2023 Mar 26 '17 at 22:50customize-set-variable
was introduced in 21.1. My init file works against 19 with very sparing conditional code. That and the fact that you can set multiple variables at once withsetq
is why I tend to prefer that mechanism. – cyberbisson Nov 16 '22 at 22:31customize-set-variable
(and the other Customize functions) work in Emacs 20 (which I still use, in addition to later versions). I don't have Emacs 19, so I can't speak to that... – Drew Nov 17 '22 at 02:15