In the customization buffer, you can save a customization
setting by choosing the ‘Save for Future Sessions’ choice from
its ‘[State]’ button. The C-x C-s (
command, or the ‘[Save for Future Sessions]’ button at the top of
the customization buffer, saves all applicable settings in the buffer.
Saving works by writing code to a file, usually your initialization file (see Init File). Future Emacs sessions automatically read this file at startup, which sets up the customizations again.
You can choose to save customizations somewhere other than your
initialization file. To make this work, you must add a couple of
lines of code to your initialization file, to set the variable
custom-file to the name of the desired file, and to load that
file. For example:
(setq custom-file "~/.emacs-custom.el") (load custom-file)
You can even specify different customization files for different Emacs versions, like this:
(cond ((< emacs-major-version 22) ;; Emacs 21 customization. (setq custom-file "~/.custom-21.el")) ((and (= emacs-major-version 22) (< emacs-minor-version 3)) ;; Emacs 22 customization, before version 22.3. (setq custom-file "~/.custom-22.el")) (t ;; Emacs version 22.3 or later. (setq custom-file "~/.emacs-custom.el"))) (load custom-file)
If Emacs was invoked with the -q or --no-init-file options (see Initial Options), it will not let you save your customizations in your initialization file. This is because saving customizations from such a session would wipe out all the other customizations you might have on your initialization file.