[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: Stefan Monnier
Subject: Re: address@hidden: Info on define-minor-mode - :init-value or :initial-value?]
Date: Fri, 29 Jul 2005 13:10:14 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

>> 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.

That's an interesting case indeed.
With define-minor-mode you'd have to add

  (if foo-mode (foo-mode 1))

at the end of the file.  It may not be the best solution, but it doesn't
seem much worse than using custom-initialize-set since it saves you from
having to worry about the ordering of defcustoms and defuns and it makes it
very clear that code is run at the toplevel and that it thus needs to be
checked for "no visible effect".


reply via email to

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