emacs-devel
[Top][All Lists]
Advanced

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

Re: address@hidden: Info on define-minor-mode - :init-valueor :initial-v


From: Richard M. Stallman
Subject: Re: address@hidden: Info on define-minor-mode - :init-valueor :initial-value?]
Date: Sat, 30 Jul 2005 19:44:39 -0400

    The _default_ :initialize function is custom-initialize-reset.  That
    means that whenever a file containing a defcustom with a :set function
    is loaded, that :set function is called

That seems like the right thing to me.  If the user set the variable,
he probably wanted to control the mode.

                                            _even_ if the user customized
    the variable outside Custom, possibly in an attempt to avoid the :set
    function.

So what?  One can't please everybody.

      This has repeatedly caused me
    (and other people) problems in practice.

If you describe these problems, we could think about whether they are
worth solving by changing this mechanism.  However, if the problems
only occur with a few particularly troublesome variables, it would be
easier to deal with them one by one.

    hand, I have trouble convincing Stefan that the _much_ more benign
    custom-initialize-set can be safe for minor modes that are natural to
    enable by default.

It seems plausible to me.

     don't know how you'll decide to handle this, but I agree with Luc that it
    is confusing to set the :init-value to, say, `t' and then not see that
    initial value be effective.

I agree completely.

Stefan wrote:

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

    This will turn on the minor mode if you happen to browse the corresponding
    customize group (because Custom will then load the file).
    I.e. it'd be a bug.

Consider minor modes that work in the classical way: just setting the
variable enables the mode, and no :set-function is needed.  If the default
value is t, just loading the file will enable the mode.

What this means is that a minor mode's default value should never be t
unless t is a harmless value for it.

Once we decide that, there's no particular problem about :set
functions.  Regardless of whether the minor mode takes effect through
a :set function or just by setting the variable, either way, the
default value should be nil, unless for specific reasons t is
harmless.

Therefore, it is ok to run the :set function when the minor mode code
is loaded.  It is ok to use custom-initialize-reset for them.

    FWIW, that's OK by me. In the user doc (Elisp), we should say "this is how
    you create a minor mode..." and include the bit about (if foo-mode (foo-mode
    1)) for non-nil init value. That is apparently an integral part of coding a
    minor mode with a non-nil init value. If so, this should not be mentioned
    only as an afterthought in an explanation of one of the examples.

If we can't arrange to make just the defcustom do the job, documenting
this method is ok with me.

Perhaps we should document a simple way and a complex way.  The simple
way is that it all gets done by the :set function when the defcustom's
expansion is executed.  That requires putting the defcustom after the
minor mode function and generating a defvar before the function.
You'd use custom-initialize-reset.

For cases which are more complex, you'd use custom-initialize-default
and then write (if foo-mode (foo-mode 1)) at the end of the file.




reply via email to

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