* How to evaluate a function when a defcustom variable is either set or saved?
@ 2016-06-15 1:13 Grant Rettke
2016-06-15 4:39 ` Drew Adams
0 siblings, 1 reply; 3+ messages in thread
From: Grant Rettke @ 2016-06-15 1:13 UTC (permalink / raw)
To: Emacs Help
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.
Question
• How would one normally go about doing something like this?
• Is this a common topic when using the Easy Customization UI?
Sincerely,
Grant Rettke
[explains that]
https://www.gnu.org/software/emacs/manual/html_node/emacs/Changing-a-Variable.html#Changing-a-Variable
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: How to evaluate a function when a defcustom variable is either set or saved?
2016-06-15 1:13 How to evaluate a function when a defcustom variable is either set or saved? Grant Rettke
@ 2016-06-15 4:39 ` Drew Adams
2016-06-15 17:40 ` Grant Rettke
0 siblings, 1 reply; 3+ messages in thread
From: Drew Adams @ 2016-06-15 4:39 UTC (permalink / raw)
To: Grant Rettke, Emacs Help
> 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.
If you mean every time it is changed using the Customize UI or equivalent
(`custom*' functions), then just use a :set (and possibly an :initialize)
keyword in your defcustom.
See the Elisp manual, node `Variable Definitions',
http://www.gnu.org/software/emacs/manual/html_node/elisp/Variable-Definitions.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to evaluate a function when a defcustom variable is either set or saved?
2016-06-15 4:39 ` Drew Adams
@ 2016-06-15 17:40 ` Grant Rettke
0 siblings, 0 replies; 3+ messages in thread
From: Grant Rettke @ 2016-06-15 17:40 UTC (permalink / raw)
To: Drew Adams; +Cc: Emacs Help
On Tue, Jun 14, 2016 at 11:39 PM, Drew Adams <drew.adams@oracle.com> wrote:
>
>> 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.
>
> If you mean every time it is changed using the Customize UI or equivalent
> (`custom*' functions), then just use a :set (and possibly an :initialize)
> keyword in your defcustom.
>
> See the Elisp manual, node `Variable Definitions',
>
> http://www.gnu.org/software/emacs/manual/html_node/elisp/Variable-Definitions.html
Thank you Drew.
Makes sense to look at the creation parameters for the variable
instead of the Easy Customize documentation.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-15 17:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-15 1:13 How to evaluate a function when a defcustom variable is either set or saved? Grant Rettke
2016-06-15 4:39 ` Drew Adams
2016-06-15 17:40 ` Grant Rettke
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.