GNU bug report logs - #76535
Recommend against turn-on-<FOO>-mode functions

Previous Next

Package: emacs;

Reported by: Stefan Kangas <stefankangas <at> gmail.com>

Date: Mon, 24 Feb 2025 22:35:02 UTC

Severity: wishlist

Full log


View this message in rfc822 format

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Sean Whitton <spwhitton <at> spwhitton.name>
Cc: Stefan Monnier <monnier <at> iro.umontreal.ca>, 76535 <at> debbugs.gnu.org
Subject: bug#76535: Recommend against turn-on-<FOO>-mode functions
Date: Mon, 10 Mar 2025 05:28:27 +0000
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.




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.