GNU bug report logs -
#76535
Recommend against turn-on-<FOO>-mode functions
Previous Next
To reply to this bug, email your comments to 76535 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org
:
bug#76535
; Package
emacs
.
(Mon, 24 Feb 2025 22:35:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Kangas <stefankangas <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
monnier <at> iro.umontreal.ca, bug-gnu-emacs <at> gnu.org
.
(Mon, 24 Feb 2025 22:35:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Severity: wishlist
How about adding to tips.texi a recommendation not to add any new
functions like these?
(defun turn-on-<FOO>-mode ()
(<FOO>-mode 1))
(defun turn-off-<FOO>-mode ()
(<FOO>-mode -1))
I think they are redundant in almost all cases, but it seems to me that
they are sometimes added pretty much routinely.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76535
; Package
emacs
.
(Tue, 25 Feb 2025 02:19:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 76535 <at> debbugs.gnu.org (full text, mbox):
> Severity: wishlist
>
> How about adding to tips.texi a recommendation not to add any new
> functions like these?
>
> (defun turn-on-<FOO>-mode ()
> (<FOO>-mode 1))
> (defun turn-off-<FOO>-mode ()
> (<FOO>-mode -1))
>
> I think they are redundant in almost all cases, but it seems to me that
> they are sometimes added pretty much routinely.
They aren't redundant for global minor modes created using
`define-global-minor-mode' and `define-globalized-minor-mode',
AFAIK. Arg TURN-ON is a required argument.
TURN-ON is a function that will be called with no args in every buffer
and that should try to turn MODE on if applicable for that buffer.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76535
; Package
emacs
.
(Tue, 25 Feb 2025 04:24:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 76535 <at> debbugs.gnu.org (full text, mbox):
> They aren't redundant for global minor modes created using
> `define-global-minor-mode' and `define-globalized-minor-mode',
> AFAIK. Arg TURN-ON is a required argument.
>
> TURN-ON is a function that will be called with no args in every buffer
> and that should try to turn MODE on if applicable for that buffer.
Just because the arg is called "TURN-ON" doesn't mean it needs to take
an argument called `turn-on-FOO-mode` nor that it should behave the same
as `turn-on-FOO-mode`.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76535
; Package
emacs
.
(Tue, 25 Feb 2025 05:37:01 GMT)
Full text and
rfc822 format available.
Message #14 received at 76535 <at> debbugs.gnu.org (full text, mbox):
> > They aren't redundant for global minor modes created using
> > `define-global-minor-mode' and `define-globalized-minor-mode',
> > AFAIK. Arg TURN-ON is a required argument.
> >
> > TURN-ON is a function that will be called with no args in every
> > buffer and that should try to turn MODE on if applicable for
> > that buffer.
>
> Just because the arg is called "TURN-ON" doesn't mean it needs to take
> an argument called `turn-on-FOO-mode` nor that it should behave the same
> as `turn-on-FOO-mode`.
Maybe I misunderstood the bug request; sorry, if so.
I didn't understand it to be about functions named
that way (or any particular way).
I don't think the wishlist wish was very clear, if
my understanding was indeed incorrect:
How about adding to tips.texi a recommendation
not to add any new functions like these?
^^^^^^^^^^
(defun turn-on-<FOO>-mode () (<FOO>-mode 1))
(defun turn-off-<FOO>-mode () (<FOO>-mode -1))
Just what was meant by "like these"?
I understood "any new functions like these" to mean
any TURN-ON functions, with whatever name and with
whatever behavior, as long as they try to turn on
the mode whenever applicable in some buffer. IOW,
just what the doc for arg TURN-ON says:
a function that will be called with no args in
every buffer and that should try to turn MODE on
if applicable for that buffer
What else is the wish advising against, if not such
a function?
Provided you're right, and such a TURN-ON function
wasn't what was meant, and won't be what's proscribed
in the proposed "tips", great.
In that case, please at least come up with some clear
wording for the tips. And for the wishlist proposal,
please say clearly what's being proposed - just what
do you want to advise users not to do?
But in that case, why would any such tips be needed?
Would anyone really think, reading that doc, that the
required TURN-ON arg needs to be a function named
`turn-on-...-mode'? Has that actually been a problem
- users thinking that?
It's also not clear to me just what you mean by
"nor that it should behave the same as
`turn-on-FOO-mode`"
What exactly is the `turn-on-FOO-mode' behavior that
you want to tell users the function doesn't need to
provide, if by that you mean something other than
just be able to be called with no args in any buffer
and when called "try to turn MODE on if applicable
for that buffer"?
You say it doesn't need to behave "the same as
`turn-on-FOO-mode'". What does that mean? How does
the presumed function `turn-on-FOO-mode' behave, if
not just as described for arg TURN-ON? What behavior
doesn't the function need to have?
Sorry I'm not getting your drift. Can you clarify
it a bit?
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76535
; Package
emacs
.
(Mon, 10 Mar 2025 05:17:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 76535 <at> debbugs.gnu.org (full text, mbox):
Hello,
On Mon 24 Feb 2025 at 04:34pm -06, Stefan Kangas wrote:
> Severity: wishlist
>
> How about adding to tips.texi a recommendation not to add any new
> functions like these?
>
> (defun turn-on-<FOO>-mode ()
> (<FOO>-mode 1))
> (defun turn-off-<FOO>-mode ()
> (<FOO>-mode -1))
>
> I think they are redundant in almost all cases, but it seems to me that
> they are sometimes added pretty much routinely.
What about when you want to put
(add-hook 'foo-mode 'turn-on-bar-mode)
in your init? Without the wrapper, you need a (lambda () ...) which
isn't great.
--
Sean Whitton
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76535
; Package
emacs
.
(Mon, 10 Mar 2025 05:29:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 76535 <at> debbugs.gnu.org (full text, mbox):
Sean Whitton <spwhitton <at> spwhitton.name> writes:
> On Mon 24 Feb 2025 at 04:34pm -06, Stefan Kangas wrote:
>
>> Severity: wishlist
>>
>> How about adding to tips.texi a recommendation not to add any new
>> functions like these?
>>
>> (defun turn-on-<FOO>-mode ()
>> (<FOO>-mode 1))
>> (defun turn-off-<FOO>-mode ()
>> (<FOO>-mode -1))
>>
>> I think they are redundant in almost all cases, but it seems to me that
>> they are sometimes added pretty much routinely.
>
> What about when you want to put
>
> (add-hook 'foo-mode 'turn-on-bar-mode)
>
> in your init? Without the wrapper, you need a (lambda () ...) which
> isn't great.
I think `define-minor-mode` is supposed to generate code that makes
(add-hook 'foo-mode 'bar-mode)
always turn the minor mode on, without the wrapper.
See (info "(elisp) Minor Mode Conventions"):
Enabling or disabling a minor mode twice in direct succession
should not fail and should do the same thing as enabling or
disabling it only once. In other words, the minor mode command
should be idempotent.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76535
; Package
emacs
.
(Mon, 10 Mar 2025 05:41:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 76535 <at> debbugs.gnu.org (full text, mbox):
Stefan Kangas <stefankangas <at> gmail.com> writes:
> Sean Whitton <spwhitton <at> spwhitton.name> writes:
>
>> On Mon 24 Feb 2025 at 04:34pm -06, Stefan Kangas wrote:
>>
>>> Severity: wishlist
>>>
>>> How about adding to tips.texi a recommendation not to add any new
>>> functions like these?
>>>
>>> (defun turn-on-<FOO>-mode ()
>>> (<FOO>-mode 1))
>>> (defun turn-off-<FOO>-mode ()
>>> (<FOO>-mode -1))
>>>
>>> I think they are redundant in almost all cases, but it seems to me that
>>> they are sometimes added pretty much routinely.
>>
>> What about when you want to put
>>
>> (add-hook 'foo-mode 'turn-on-bar-mode)
>>
>> in your init? Without the wrapper, you need a (lambda () ...) which
>> isn't great.
>
> I think `define-minor-mode` is supposed to generate code that makes
>
> (add-hook 'foo-mode 'bar-mode)
>
> always turn the minor mode on, without the wrapper.
>
> See (info "(elisp) Minor Mode Conventions"):
I quoted the wrong part:
If the mode command is called from Lisp (i.e., non-interactively),
it should enable the mode if the argument is omitted or ‘nil’;
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76535
; Package
emacs
.
(Mon, 10 Mar 2025 06:03:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 76535 <at> debbugs.gnu.org (full text, mbox):
Hello,
On Mon 10 Mar 2025 at 05:28am GMT, Stefan Kangas wrote:
> I think `define-minor-mode` is supposed to generate code that makes
>
> (add-hook 'foo-mode 'bar-mode)
>
> always turn the minor mode on, without the wrapper.
Oh, thanks, I guess that's new since I last looked into this.
--
Sean Whitton
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76535
; Package
emacs
.
(Mon, 10 Mar 2025 15:30:01 GMT)
Full text and
rfc822 format available.
Message #29 received at 76535 <at> debbugs.gnu.org (full text, mbox):
> Oh, thanks, I guess that's new since I last looked into this.
etc/NEWS.24:
* Incompatible Lisp Changes in Emacs 24.1
** Passing a nil argument to a minor mode function call now ENABLES
the minor mode unconditionally. This is so that you can write e.g.
(add-hook 'text-mode-hook #'foo-mode)
to enable foo-mode in Text mode buffers, removing the need for
'turn-on-foo-mode' style functions. This affects all mode commands
defined by 'define-minor-mode'. If called interactively, the mode
command still toggles the minor mode.
- Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#76535
; Package
emacs
.
(Tue, 11 Mar 2025 01:58:01 GMT)
Full text and
rfc822 format available.
Message #32 received at 76535 <at> debbugs.gnu.org (full text, mbox):
Hello,
Sometimes you just miss things for years, huh?
Thanks for the reference.
--
Sean Whitton
This bug report was last modified 151 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.