[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: defcustom and :set functions dependencies
From: |
Stefan Monnier |
Subject: |
Re: defcustom and :set functions dependencies |
Date: |
Tue, 24 May 2011 20:01:27 -0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
> 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