emacs-pretest-bug
[Top][All Lists]
Advanced

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

Re: custom-set-variables fails to set variable


From: Luc Teirlinck
Subject: Re: custom-set-variables fails to set variable
Date: Thu, 10 Nov 2005 17:36:41 -0600 (CST)

Bill Wohler wrote:

   I've found a problem where my mh-letter-mode-hook (in MH-E) isn't
   getting called. It is listed properly in the custom-set-variables
   stanza, but when I start Emacs, load MH-E, and run customize-option on
   mh-letter-mode-hook, the hook is empty! When I enter the hook function,
   the hook works again.

   Is it because MH-E isn't loaded when custom-set-variables is run? Is it
   something MH-E is doing when it is loaded?

No.  The sequence of events is the following.  (I explain it in a
somewhat simplified version, but it is still complex enough.)

The entry for mh-letter-mode-hook in the custom-set-variables form is
not executed while your .emacs is loaded, _unless_ the variable
already has a value at that time.  If the variable already has a
value, custom-set-variables immediately overwrites it and you will
note that your bug disappears if you put

(defvar mh-letter-mode-hook nil)

in your .emacs _before_ the call to custom-set-variables.  But if
mh-letter-mode-hook is unbound when the custom-set-variables form is
evaluated then all custom-set-variables does is set the 'saved-value
property of mh-letter-mode-hook, which remains unbound.  Later, when
the defcustom is executed mh-letter-mode-hook is set to the
'saved-value property _if_ it is still unbound.  But if it got bound
to some value in the meantime, the defcustom leaves that value unchanged.

Summary, where defvar means a non-compiler defvar, i.e just
(defvar foo) has no effect, except quieting the compiler:

defvar custom-set-variables defvar defcustom:

custom-set-variables wins.

custom-set-variables defcustom defvar:

custom-set-variables wins again.

custom-set-variables defvar defcustom:

The defvar wins.

All of this may look contorted, but the fact is that making a
defcustom compete with a "real" defvar makes no sense.

mh-letter-mode is defined using define-derived-mode, whose macroexpanded
form contains:

(defvar mh-letter-mode-hook nil)

This is normally executed after the custom-set-variables form, but
before the defcustom, so we get:

custom-set-variables defvar defcustom

and the defvar wins.  mh-letter-mode-hook remains nil.

There are probably good, but complex reasons behind Custom's
complexity, as explained above.

I do not immediately know what the best real solution to your problem
is, but a workaround to the problem would be to put the defcustom
before the call to define-derived-mode.  Then you get:

custom-set-variables defcustom defvar

and the defvar looses, as it should.

Sincerely,

Luc.





reply via email to

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