8
votes

If I bring up emacs' customization interface, edit a variable, and then set+save it, its new value gets stored in a (custom-set-variables ...) list in my init file.

Now, let's say I modified a variable's value in elisp (using (setq ...) or something else).

How can I save this new value to the (custom-set-variables ...) list using elisp instead of the interactive interface?

3
I know I canb just write the (setq command to my init file, but thats's not what I'm looking for. I need an automated method for saving the variable. - Malabarba
The default behavior is to not list variables defined with setq when saving custom set variables with the user interface; and, those setq variables cannot generally be overwritten through the user-interface. For variables set by hand that will be saved with the user interface, you would actually need to use the same format within your elisp code -- i.e., the same format you see after saving with the user interface. Long story short, if you used setq -- you cannot get there from here -- unless you use a new setq that loads after the prior setq effectively redefining it. - lawlist
The magic is occurring with .../lisp/cus-edit.el and .../lisp/custom.el - lawlist
@lawlist I know setq takes priority over custom set variables, but that's not a problem here. I mentioned the variable was edited with setq, but this setq isn't written in the configuration file (which is exactly why I need an automated way of saving this modification permanently). - Malabarba

3 Answers

7
votes

Looks like you are looking for customize-save-variable

0
votes

The value of `custom-file' says where your customizations are stored. It's a plain Emacs Lisp, e.i. text file. You may change the values there from any program, creating an elisp command or change it from outside via sed, perl, python, emacs-batch mode etc.

0
votes

Yes, customize-save-variable is your friend. See also http://www.emacswiki.org/emacs/CustomizingAndSaving about the relation between (a) making changes to options and faces and (b) saving them.