[Top][All Lists]

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

Re: address@hidden: Info on define-minor-mode - :init-value or :initial-

From: Luc Teirlinck
Subject: Re: address@hidden: Info on define-minor-mode - :init-value or :initial-value?]
Date: Thu, 28 Jul 2005 20:48:09 -0500 (CDT)

Stefan Monnier wrote:

   > There is more.  You can not specify a non-nil :init-value, unless
   > either the minor mode is enabled by just setting the variable or
   > unless you do something extra.

   In what way is this a limitation?
   I.e. if you don't use define-minor-mode, how would you do it differently?
   [ I don't mean to say that "manual" code can't do it differently, but that
   if it does it differently, it'll most likely break the convention that just
   loading a file shouldn't make any visible changes. ]

Suppose that you have a minor mode that only makes a difference when
you are using the speedbar.  (I just take this as an example; any
option that is itself not enabled by default will do.)  The minor mode
would be part of the intended default behavior of speedbar, but not
everybody might like it, hence the need for a defcustom with default
t.  You use `custom-initialize-set' as the :initialize function.  You
put the minor mode code in speedbar.el.  Now loading speedbar.el will
enable the minor mode, unless the user overwrote that by setting the
minor mode variable to nil.  However, this will not change the behavior
of Emacs in any way that is unrelated to the speedbar.

With the current define-minor-mode code, you can _try_ to set the
:initialize keyword to `custom-initialize-set', but it will not work,
because define-minor-mode writes the defcustom before the minor mode
function, hence executing the defcustom will yield an error.  It is
possible to change the define-minor-mode code to get around that, but
I guess that it would require define-minor-mode to first write a
compiler defvar, then the mode function, and then the defcustom.
Also, all functions used by the minor mode function would have to be
defined before the define-minor-mode (if the minor mode is enabled by



reply via email to

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