Yes. See the doc for defcustom
. What you want, in particular, is :set
, which you specify as a function that does two things:
Sets the value. Just use the standard function for this.
Does whatever else you want to do -- in this case, mirror the new setting, transforming it first, in your external file.
You can do those two things in either order, i.e., whichever order is most useful for you.
:set
VALUE should be a function to set the value of the symbol
when using the Customize user interface. It takes two arguments,
the symbol to set and the value to give it. The function should
not modify its value argument destructively. The default choice
of function is `set-default'.
See also :initialize
, if you need to do something special when initializing the value.
:initialize
VALUE should be a function used to initialize the
variable. It takes two arguments, the symbol and value
given in the `defcustom' call. The default is
`custom-initialize-reset'.
For more information, see the Elisp manual, node Variable Definitions.
Update to respond to your comment --
You can use :initialize
to initialize the variable without the :set
function being called. It sounds like that's what your workaround is trying to accomplish. Again, see the Elisp manual, node Variable Definitions.
Here is an example. You will not see @@@@@@@@@@@@@@@@@@@@@@@@@@
in buffer Messages when the value is initialized (e.g., when the file with the defcustom
is loaded). You will see it each time you use Customize to set the value.
(defcustom titi 42
"jjjjjjjjjj"
:type 'integer
:initialize (lambda (sym defs)
(custom-initialize-default sym defs))
:set (lambda (sym defs)
(custom-set-default sym defs)
(message "@@@@@@@@@@@@@@@@@@@@@@@@@@")(sleep-for 4)))