[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to evaluate a function when a defcustom variable is either set or sa

From: Grant Rettke
Subject: How to evaluate a function when a defcustom variable is either set or saved?
Date: Tue, 14 Jun 2016 20:13:10 -0500

Good evening,

The Easy Customization user guide [explains that] any changes you make will “not
take effect until you set or save [them]”. That makes sense.

After the set or save occurs, I would like to evaluate a function. The goal of
the function is to calculate some runtime values that need to be re-calculated
every time that the variable is changed. The desire to let the users easily
explore reconfiguration via the Easy Customize UI and run the configuration code
each time they make a change *without* restarting Emacs.

For example, it might look like this (fake on-change property added):

│ (defun on-test-string-change (old new)
│   "Testing."
│   (message "test-string just changed from %S to %S" old new))
│ (defcustom test-string "test"
│   "Practice"
│   :type 'string
│   :group 'test
│   :on-change #'on-test-string-change)

Suppose the user enters the Easy Customization interface, makes a change, and
then saves or sets it; this would appear in the `Messages' buffer:

│ "test-string just changed from \"foo\" to \"bar\""

I read the documentation for Easy Customize and didn’t find anything like this.

I read the code for `customize-set-value' and `customize-set-variable' and
didn’t find anything like that.

I searched for Emacs events that would apply and didn’t find any. The buffer
local variable and buffer contents after change events jumped out, but aren’t
the right thing for this.

• How would one normally go about doing something like this?
• Is this a common topic when using the Easy Customization UI?


Grant Rettke

[explains that]

reply via email to

[Prev in Thread] Current Thread [Next in Thread]