all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#4102: 23.1.50; recentf-mode nil but toggles
@ 2009-08-10  8:06 Xah Lee
  2009-08-10 16:40 ` Stefan Monnier
  0 siblings, 1 reply; 8+ messages in thread
From: Xah Lee @ 2009-08-10  8:06 UTC (permalink / raw)
  To: bug-gnu-emacs


gosh, stung by this bug.

in my elisp code, i have:

 (recentf-mode nil)

this should turn it off, but actually it toggles.

here's a quote of its inline doc:
«
(recentf-mode &optional arg)

Toggle recentf mode.
With prefix argument arg, turn on if positive, otherwise off.
»

this is reproduciable in the following:

GNU Emacs 23.1.1 (i386-mingw-nt6.0.6002) of 2009-07-29 on SOFT-MJASON

GNU Emacs 23.1.50.1 (i386-mingw-nt6.0.6002) of 2009-06-30 on LENNART-69DE564 
(patched)

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#4102: 23.1.50; recentf-mode nil but toggles
  2009-08-10  8:06 bug#4102: 23.1.50; recentf-mode nil but toggles Xah Lee
@ 2009-08-10 16:40 ` Stefan Monnier
  2009-08-11  2:01   ` Xah Lee
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2009-08-10 16:40 UTC (permalink / raw)
  To: Xah Lee; +Cc: bug-gnu-emacs, 4102

> in my elisp code, i have:
> (recentf-mode nil)
> this should turn it off, but actually it toggles.

That's indeed the standard behavior for all minor modes.  Use integers
to avoid such surprises.

> With prefix argument arg, turn on if positive, otherwise off.

It's not clear whether nil is positive or negative.


        Stefan





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#4102: 23.1.50; recentf-mode nil but toggles
  2009-08-10 16:40 ` Stefan Monnier
@ 2009-08-11  2:01   ` Xah Lee
  2009-08-12  4:05     ` Kevin Rodgers
       [not found]     ` <mailman.4441.1250051225.2239.bug-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Xah Lee @ 2009-08-11  2:01 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: bug-gnu-emacs, 4102

>> With prefix argument arg, turn on if positive, otherwise off.
>
> It's not clear whether nil is positive or negative.

Thanks. That's interesting.

Can the doc adds a warning like:

The argument should be a integer. Do not use t or nil.

?

  Xah
∑ http://xahlee.org/

☄

----- Original Message ----- 
From: "Stefan Monnier" <monnier@iro.umontreal.ca>
To: "Xah Lee" <xah@xahlee.org>
Cc: <4102@emacsbugs.donarmstrong.com>; <bug-gnu-emacs@gnu.org>
Sent: Monday, August 10, 2009 9:40 AM
Subject: Re: bug#4102: 23.1.50; recentf-mode nil but toggles


>> in my elisp code, i have:
>> (recentf-mode nil)
>> this should turn it off, but actually it toggles.
>
> That's indeed the standard behavior for all minor modes.  Use integers
> to avoid such surprises.
>
>> With prefix argument arg, turn on if positive, otherwise off.
>
> It's not clear whether nil is positive or negative.







^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#4102: 23.1.50; recentf-mode nil but toggles
  2009-08-11  2:01   ` Xah Lee
@ 2009-08-12  4:05     ` Kevin Rodgers
  2009-08-13 17:36       ` Stefan Monnier
       [not found]     ` <mailman.4441.1250051225.2239.bug-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Kevin Rodgers @ 2009-08-12  4:05 UTC (permalink / raw)
  To: bug-gnu-emacs

Xah Lee wrote:
>>> With prefix argument arg, turn on if positive, otherwise off.
>>
>> It's not clear whether nil is positive or negative.

It seems clear to me that nil is not positive, so the "otherwise"
condition holds.

> Thanks. That's interesting.
> 
> Can the doc adds a warning like:
> 
> The argument should be a integer. Do not use t or nil.

Do not use `supercalifragilisticexpialidocious' either.

How about: Use nil to toggle the mode on or off.

-- 
Kevin Rodgers
Denver, Colorado, USA







^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: bug#4102: 23.1.50; recentf-mode nil but toggles
       [not found]     ` <mailman.4441.1250051225.2239.bug-gnu-emacs@gnu.org>
@ 2009-08-12 19:33       ` Xah Lee
  2009-08-13  4:15         ` Drew Adams
  0 siblings, 1 reply; 8+ messages in thread
From: Xah Lee @ 2009-08-12 19:33 UTC (permalink / raw)
  To: bug-gnu-emacs

On Aug 11, 9:05 pm, Kevin Rodgers <kevin.d.rodg...@gmail.com> wrote:
> Xah Lee wrote:
> >>> With prefix argument arg, turn on if positive, otherwise off.
>
> >> It's not clear whether nil is positive or negative.
>
> It seems clear to me that nil is not positive, so the "otherwise"
> condition holds.
>
> > Thanks. That's interesting.
>
> > Can the doc adds a warning like:
>
> > The argument should be a integer. Do not use t or nil.
>
> Do not use `supercalifragilisticexpialidocious' either.
>
> How about: Use nil to toggle the mode on or off.

hi Kevin,

i think that's a bit unreasonable.

the use of 1 and 0 for on and off for minor mode function, is not
exactly intuitive, because in elisp, although the lang does not have
boolean datatype, but by convention, t is for true, and nil for false,
and technically, nil is false, everything else is true.

So, minor modes using 1 and 0 is kinda unclean, un-elegant, or counter
intuitive. The reason it does that, is of course due to the fact that
emacs commands thru interactive use by convention takes universal-
argument, and universal-argument only take integer as arguments, not
some string or lisp symbol. So, there's the justification for 1 and 0.

However, in lisp code, it is also reasonable to expect that nil would
be equivalent to 0, as by lisp convention. This logic may not look
logical to you, but i think is reasonable alternative expectation.
When a mode gets its arg thru interactive use, the arg is expected to
be integers by the way emacs do things interactively, and thus
positive int is considered true or turn on, negative is considered
false/off. But in lisp code, besides 1 and 0, you can also specify t
and nil as usual by lisp convention. This could easily be considered
as a alternative design decision.

(adding to the mess is that some command will change behavior as kinda
on/off or true/false depending on whether universal-argument is called
regardless of its argument)

all things considered, i think it is reasonable that a average lisp
coder will be confused by this. Thus my recommendation that a warning
or notes be added to the doc. Is there somewhere in elisp manual that
explicitly explains/warns that commands that turn minor mode on/off
stick to 1 and 0 and consider t and nil not acceptable argument?

PS i didn't receive your previous email, i just happened to see your
reply in google group. I'm not much in the emacs dev community so i'm
not regular gnu emacs bug database reader... please cc me too on this.
thanks.

  Xah
∑ http://xahlee.org/^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#4102: 23.1.50; recentf-mode nil but toggles
  2009-08-12 19:33       ` Xah Lee
@ 2009-08-13  4:15         ` Drew Adams
  2009-08-13  4:53           ` Xah Lee
  0 siblings, 1 reply; 8+ messages in thread
From: Drew Adams @ 2009-08-13  4:15 UTC (permalink / raw)
  To: 'Xah Lee', bug-gnu-emacs

> Is there somewhere in elisp manual that
> explicitly explains/warns that commands that turn minor mode on/off
> stick to 1 and 0 and consider t and nil not acceptable argument?

(elisp) Minor Mode Conventions:

   * Define a command whose name is the same as the mode variable.  Its
     job is to enable and disable the mode by setting the variable.

     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).  It should turn the mode on if the argument is a
     positive integer, the symbol `t', or a list whose CAR is one of
     those.  It should turn the mode off if the argument is a negative
     integer or zero, the symbol `-', or a list whose CAR is a negative
     integer or zero.  The meaning of other arguments is not specified.

     Here is an example taken from the definition of
     `transient-mark-mode'.  It shows the use of `transient-mark-mode'
     as a variable that enables or disables the mode's behavior, and
     also shows the proper way to toggle, enable or disable the minor
     mode based on the raw prefix argument value.

          (setq transient-mark-mode
                (if (null arg) (not transient-mark-mode)
                  (> (prefix-numeric-value arg) 0)))

Any positive integer is the same as 1.
Any negative integer is the same as 0.

 t  is the same as 1.
`-' is the same as 0.

 (4) is the same as 1.
(-4) is the same as 0.
 (0) is the same as 0.

(t) is the same as 1.

(nil) and (-): behavior not conventionally defined

nil always toggles. It lets you do just `M-x foo' to toggle (the most common
change).

You can do `C-u M-x foo' or `C-9 M-x foo' to turn it on and `C-- M-x foo' to
turn it off.

etc.







^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#4102: 23.1.50; recentf-mode nil but toggles
  2009-08-13  4:15         ` Drew Adams
@ 2009-08-13  4:53           ` Xah Lee
  0 siblings, 0 replies; 8+ messages in thread
From: Xah Lee @ 2009-08-13  4:53 UTC (permalink / raw)
  To: Drew Adams; +Cc: bug-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 2067 bytes --]

Thanks Drew and all in this thread for the info.
 Xah

On Wed, Aug 12, 2009 at 9:15 PM, Drew Adams <drew.adams@oracle.com> wrote:

> > Is there somewhere in elisp manual that
> > explicitly explains/warns that commands that turn minor mode on/off
> > stick to 1 and 0 and consider t and nil not acceptable argument?
>
> (elisp) Minor Mode Conventions:
>
>   * Define a command whose name is the same as the mode variable.  Its
>     job is to enable and disable the mode by setting the variable.
>
>     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).  It should turn the mode on if the argument is a
>     positive integer, the symbol `t', or a list whose CAR is one of
>     those.  It should turn the mode off if the argument is a negative
>     integer or zero, the symbol `-', or a list whose CAR is a negative
>     integer or zero.  The meaning of other arguments is not specified.
>
>     Here is an example taken from the definition of
>     `transient-mark-mode'.  It shows the use of `transient-mark-mode'
>     as a variable that enables or disables the mode's behavior, and
>     also shows the proper way to toggle, enable or disable the minor
>     mode based on the raw prefix argument value.
>
>          (setq transient-mark-mode
>                (if (null arg) (not transient-mark-mode)
>                  (> (prefix-numeric-value arg) 0)))
>
> Any positive integer is the same as 1.
> Any negative integer is the same as 0.
>
>  t  is the same as 1.
> `-' is the same as 0.
>
>  (4) is the same as 1.
> (-4) is the same as 0.
>  (0) is the same as 0.
>
> (t) is the same as 1.
>
> (nil) and (-): behavior not conventionally defined
>
> nil always toggles. It lets you do just `M-x foo' to toggle (the most
> common
> change).
>
> You can do `C-u M-x foo' or `C-9 M-x foo' to turn it on and `C-- M-x foo'
> to
> turn it off.
>
> etc.
>
>


-- 
 Xah
∑ http://xahlee.org/

[-- Attachment #2: Type: text/html, Size: 2617 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#4102: 23.1.50; recentf-mode nil but toggles
  2009-08-12  4:05     ` Kevin Rodgers
@ 2009-08-13 17:36       ` Stefan Monnier
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2009-08-13 17:36 UTC (permalink / raw)
  To: Kevin Rodgers; +Cc: bug-gnu-emacs, 4102

> Do not use `supercalifragilisticexpialidocious' either.
> How about: Use nil to toggle the mode on or off.

Actually, the docstring already says that nil toggles.  If you remember
that the docstring is written here to describe the command rather than
the function, then you'll immediately conclude that

  With prefix argument arg, turn on if positive, otherwise off.

only applies when there's a prefix argument, so when there isn't, arg is
necessarily nil and the normal behavior (described on the previous line:

   Toggle recentf mode.

) applies.


        Stefan





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-08-13 17:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-10  8:06 bug#4102: 23.1.50; recentf-mode nil but toggles Xah Lee
2009-08-10 16:40 ` Stefan Monnier
2009-08-11  2:01   ` Xah Lee
2009-08-12  4:05     ` Kevin Rodgers
2009-08-13 17:36       ` Stefan Monnier
     [not found]     ` <mailman.4441.1250051225.2239.bug-gnu-emacs@gnu.org>
2009-08-12 19:33       ` Xah Lee
2009-08-13  4:15         ` Drew Adams
2009-08-13  4:53           ` Xah Lee

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.