all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
Subject: RE: [drew.adams@oracle.com: Info on define-minor-mode - :init-valueor :initial-value?]
Date: Thu, 28 Jul 2005 10:43:17 -0700	[thread overview]
Message-ID: <DNEMKBNJBGPAOPIJOOICOEPJCKAA.drew.adams@oracle.com> (raw)
In-Reply-To: <m1r7dizxbh.fsf-monnier+emacs@gnu.org>

        For the moment, I just replaced the incorrect keyword
        :initial-value in the example with :init-value.
Thanks.

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

I 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 did this recently, in fact. I saw the mode name appear in the mode-line
after loading the file, saw that the mode variable was indeed `t', and was
confused that the mode was not actually turned on, in spite of the mode-line
indication and the variable value. Not good, in terms of user interface.

This is not very clear to me, I admit, so ignore my comments if they are
off-base. IIUC, users creating a library with a define-minor-mode that has a
non-nil :init-value will need to do something like the following at the end
of the library (otherwise, the lighter and mode variable will indicate that
the mode is on after loading, but it is not really on):

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

If this is correct, couldn't this be made part of the define-minor-mode
macro - say, to execute this code automatically after loading the library?

If my understanding is correct, but such automatic treatment is not a good
idea, shouldn't this `(if foo-mode (foo-mode 1))' cliche be documented as a
guideline? I found it after 1) reading Luc's email and 2) grepping the Lisp
directory to see how other libraries dealt with this issue.

At the least, if nothing special is done to treat non-nil :init-value, and
users need to do something additional themselves, then shouldn't the Info
doc show an example with non-nil :init-value, instead of the current example
using nil?

WRT the guideline of "loading must not change anything" - I agree, but I
think that turning on a minor mode is usually relatively benign, because it
can be turned off easily. Users loading a library that defines a minor mode
will not be shocked if the mode is turned on by default, if the logical
initial value to use is something other than nil.

Otherwise, if we're going to be rigid about this guideline (perhaps there
are good reasons to do that, even in this case), then maybe we should just
get rid of :init-value and have the initial value always be nil - that is,
make users of a library turn on the minor mode explicitly. That would not be
my preference, but it would at least avoid confusion.

  reply	other threads:[~2005-07-28 17:43 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 [this message]
2005-07-29  2:56       ` [drew.adams@oracle.com: Info on define-minor-mode - :init-valueor :initial-value?] Luc Teirlinck
2005-07-30 23:44         ` Richard M. Stallman
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

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

  git send-email \
    --in-reply-to=DNEMKBNJBGPAOPIJOOICOEPJCKAA.drew.adams@oracle.com \
    --to=drew.adams@oracle.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.