Skip to main content

49.1.4 Saving Customizations

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 (Custom-save) command, or the ‘[Apply and Save]’ 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 "~/.config/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 "~/.config/custom-21.el"))
((and (= emacs-major-version 22)
(< emacs-minor-version 3))
;; Emacs 22 customization, before version 22.3.
(setq custom-file "~/.config/custom-22.el"))
(t
;; Emacs version 22.3 or later.
(setq custom-file "~/.config/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.

Please note that any customizations you have not chosen to save for future sessions will be lost when you terminate Emacs. If you’d like to be prompted about unsaved customizations at termination time, add the following to your initialization file:

(add-hook 'kill-emacs-query-functions
'custom-prompt-customize-unsaved-options)