unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Richard M. Stallman" <rms@gnu.org>
Cc: drew.adams@oracle.com, emacs-devel@gnu.org
Subject: Re: [drew.adams@oracle.com: Info on define-minor-mode - :init-valueor :initial-value?]
Date: Sat, 30 Jul 2005 19:44:39 -0400	[thread overview]
Message-ID: <E1Dz10R-0002a4-7L@fencepost.gnu.org> (raw)
In-Reply-To: <200507290256.j6T2uPh18315@raven.dms.auburn.edu> (message from Luc Teirlinck on Thu, 28 Jul 2005 21:56:25 -0500 (CDT))

    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	other threads:[~2005-07-30 23:44 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-27 14:57 [drew.adams@oracle.com: Info on define-minor-mode - :init-value or :initial-value?] Richard M. Stallman
2005-07-27 16:04 ` Luc Teirlinck
2005-07-28 16:58   ` Stefan Monnier
2005-07-28 17:43     ` [drew.adams@oracle.com: Info on define-minor-mode - :init-valueor :initial-value?] Drew Adams
2005-07-29  2:56       ` Luc Teirlinck
2005-07-30 23:44         ` Richard M. Stallman [this message]
2005-07-31  0:43           ` Luc Teirlinck
2005-07-31 14:58             ` Juanma Barranquero
2005-08-01  0:45             ` Richard M. Stallman
2005-08-01  1:47               ` Luc Teirlinck
2005-08-01  5:33               ` Juanma Barranquero
2005-08-01 16:46                 ` Richard M. Stallman
2005-07-31  1:02           ` Luc Teirlinck
2005-08-01  0:45             ` Richard M. Stallman
2005-07-29 15:59       ` Stefan Monnier
2005-07-29 17:43         ` Drew Adams
2005-07-30  4:22         ` Luc Teirlinck
2005-07-30 13:58           ` [drew.adams@oracle.com: Info on define-minor-mode -:init-valueor :initial-value?] Drew Adams
2005-07-30 21:46             ` Luc Teirlinck
2005-07-29  1:48     ` [drew.adams@oracle.com: Info on define-minor-mode - :init-value or :initial-value?] Luc Teirlinck
2005-07-29 17:10       ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1Dz10R-0002a4-7L@fencepost.gnu.org \
    --to=rms@gnu.org \
    --cc=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).