* defcustom and :set functions dependencies
@ 2011-04-29 12:11 hjuvi
2011-04-29 16:37 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: hjuvi @ 2011-04-29 12:11 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I'm trying to define some customization variables, which are dependent
on one another.
(defun setf1 (param value)
(if v2
....
(defun setf2 (param value)
(if v1
....
(defcustom v1
:set 'setf1
(defcustom v2
:set 'setf2
My problem is : symbol v2 does not exist when setf1 is defined.
If I move both defcustoms before defuns, then symbols setf1 and setf2
are not defined when compiling v1 and v2.
Is there anything like a declaration before a definition (like in C
language)?
Are any other way to solve this?
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: defcustom and :set functions dependencies
2011-04-29 12:11 defcustom and :set functions dependencies hjuvi
@ 2011-04-29 16:37 ` Stefan Monnier
2011-05-02 9:08 ` hjuvi
0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2011-04-29 16:37 UTC (permalink / raw)
To: help-gnu-emacs
> I'm trying to define some customization variables, which are dependent
> on one another.
> (defun setf1 (param value)
> (if v2
> ....
> (defun setf2 (param value)
> (if v1
> ....
> (defcustom v1
> :set 'setf1
> (defcustom v2
> :set 'setf2
> My problem is : symbol v2 does not exist when setf1 is defined.
That's not a problem. The byte-compiler may give you a warning, but
that's all. You can silence the warning by adding
(defvar v2)
somewhere before the function definition.
> If I move both defcustoms before defuns, then symbols setf1 and setf2
> are not defined when compiling v1 and v2.
That's not a problem when compiling either (and the compiler will not
issue any warning).
At run-time you'll get a problem maybe because `setf1' will be called
when evaluating v1's defcustom at which point v2 has not been defined
yet (and setf1 may not be defined yet either if you've moved the
function after the defcustoms).
To solve this real problem, two solutions:
1- in setf1, use (boundp 'v2) to check whether v2 has been defined
already or not.
2- use an :initializer for v1 which does not depend on v2 (the :set
function will then only be called when modifying the variable, which
should only happen much later, at which point both v1 and v2 already
exist).
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: defcustom and :set functions dependencies
2011-04-29 16:37 ` Stefan Monnier
@ 2011-05-02 9:08 ` hjuvi
0 siblings, 0 replies; 3+ messages in thread
From: hjuvi @ 2011-05-02 9:08 UTC (permalink / raw)
To: help-gnu-emacs
> That's not a problem. The byte-compiler may give you a warning, but
> that's all. You can silence the warning by adding
>
> (defvar v2)
You're right. I thought I had tried it and that it gave another
warning for the variable being defined twice, but it seems to work.
I try to have no warning !... (like I'm used to when I write in C
language :))
> To solve this real problem, two solutions:
> 1- in setf1, use (boundp 'v2) to check whether v2 has been defined
> already or not.
> 2- use an :initializer for v1 which does not depend on v2 (the :set
> function will then only be called when modifying the variable, which
> should only happen much later, at which point both v1 and v2 already
> exist).
I believe the second solution is the proper way to do it. At
initialization time, I should not test other variables.
Then, in the end of initialization, when everything is defined, I can
start setting things correctly according to all options.
Thanks a lot.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-05-02 9:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-29 12:11 defcustom and :set functions dependencies hjuvi
2011-04-29 16:37 ` Stefan Monnier
2011-05-02 9:08 ` hjuvi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).