[Top][All Lists]

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

Re: cua: quiet warning messages

From: Stefan Monnier
Subject: Re: cua: quiet warning messages
Date: Mon, 16 Jun 2003 15:12:57 -0400

>     With no argument, the function turns the mode on if it was
>     off and off if it was on.  This is known as "toggling".  A positive
>     argument always turns the mode on, and an explicit zero argument or a
>     negative argument always turns it off.

That's exactly how modes defined by define-minor-mode behave.

> Elisp manual:
>      The command should accept one optional argument.  If the argument
>      is `nil', it should toggle the mode (turn it on if it is off, and
>      off if it is on).  Otherwise, it should turn the mode on if the
>      argument is a positive integer, a symbol other than `nil' or `-',
>      or a list whose CAR is such an integer or symbol; it should turn
>      the mode off otherwise.
> Note that _any_ symbol other than `nil' or `-' should turn the mode
> _on_.  'toggle is a symbol, it is not `nil' and not `-'.

That's also how define-minor-mode behaves.

> If an author fails to carefully read the code and follows the
> stylistic conventions documented in all relevant manuals, as well as
> the documentation string of define-minor-mode itself, and fails to
> follow this completely undocumented stylistic "convention" instead,
> define-minor-mode expresses its distaste for the _programmer's_ style,
> not through a compiler warning, but by printing an error message to
> the _user_ complaining about the author's style.  This seems highly
> unusual.

The 90% of the cases where a minor mode is called non-interactively with
a nil argument is when an unsuspecting user says

        (add-hook 'foo-mode-hook 'bar-minor-mode)

The warning is thus there so that when it ends up turning the mode
OFF, it tells the user that it might not be doing what the
user expected.  If the user (or author) really meant to turn the
mode off, she should pass a -1 argument to make it clear that
she knows what she's doing.


reply via email to

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