GNU bug report logs - #27639
25.2; Fix syntax for minor mode enabling in dir locals in manual

Previous Next

Package: emacs;

Reported by: Kaushal Modi <kaushal.modi <at> gmail.com>

Date: Mon, 10 Jul 2017 11:57:01 UTC

Severity: minor

Tags: patch, wontfix

Found in version 25.2

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 27639 in the body.
You can then email your comments to 27639 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#27639; Package emacs. (Mon, 10 Jul 2017 11:57:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Kaushal Modi <kaushal.modi <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 10 Jul 2017 11:57:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Kaushal Modi <kaushal.modi <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.2; Fix syntax for minor mode enabling in dir locals in manual
Date: Mon, 10 Jul 2017 11:55:58 +0000
[Message part 1 (text/plain, inline)]
Hello,

I recently stumbled across this Reddit post[1] where a user is trying to
enable a minor mode in .dir-locals.el. But he was doing that by setting the
mode name to `t'.

We generally(?) enable minor modes by doing (mode . MINOR) in
.dir-locals.el.

So I thought of looking up the Emacs manual to check that:

Here's an example of a .dir-locals.el file:

((nil . ((indent-tabs-mode . t)
        (fill-column . 80)))
<snip>

This sets ‘indent-tabs-mode’ and fill-column for any file in the directory
tree.

That would lead the readers to think that that's how *any* minor mode can
be enabled from .dir-locals.el.

I think that example should be fixed by using a minor mode example that can
be enabled using the (mode . MINOR) syntax.

[1]:
https://www.reddit.com/r/emacs/comments/6malb6/disable_warning_message_when_enabling_minor_modes/
-- 

Kaushal Modi
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27639; Package emacs. (Mon, 10 Jul 2017 22:38:01 GMT) Full text and rfc822 format available.

Message #8 received at 27639 <at> debbugs.gnu.org (full text, mbox):

From: Kaushal Modi <kaushal.modi <at> gmail.com>
To: 27639 <at> debbugs.gnu.org
Subject: 25.2; Fix syntax for minor mode enabling in dir locals in manual
Date: Mon, 10 Jul 2017 22:36:51 +0000
[Message part 1 (text/plain, inline)]
Hello,

I have attached this patch based off emacs-25 branch that clarifies the
documentation about minor mode enabling in .dir-locals.el.
-- 

Kaushal Modi
[Message part 2 (text/html, inline)]
[0001-Add-documentation-on-enabling-minor-modes-using-.dir.patch (application/octet-stream, attachment)]

Added tag(s) patch. Request was from Kaushal Modi <kaushal.modi <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 10 Jul 2017 22:39:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27639; Package emacs. (Tue, 11 Jul 2017 16:38:01 GMT) Full text and rfc822 format available.

Message #13 received at 27639 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Kaushal Modi <kaushal.modi <at> gmail.com>
Cc: 27639 <at> debbugs.gnu.org
Subject: Re: bug#27639: 25.2;
 Fix syntax for minor mode enabling in dir locals in manual
Date: Tue, 11 Jul 2017 19:37:42 +0300
> From: Kaushal Modi <kaushal.modi <at> gmail.com>
> Date: Mon, 10 Jul 2017 11:55:58 +0000
> 
> I recently stumbled across this Reddit post[1] where a user is trying to enable a minor mode in .dir-locals.el.
> But he was doing that by setting the mode name to `t'. 

indent-tabs-mode is the mode variable, so setting it to t is not a
mistake.

> We generally(?) enable minor modes by doing (mode . MINOR) in .dir-locals.el. 

You could do it either way.  Also, some modes don't have such a
variable, so only the latter way will work.

But why do you think we should only advertise one method, but not the
other?  There's no magic here, just legitimate use of public
documented variables: 'mode' is a variable and so is 'indent-tabs-mode'.

So I think I don't get your motivation for the report and for the
patch you provided.

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27639; Package emacs. (Tue, 11 Jul 2017 16:58:01 GMT) Full text and rfc822 format available.

Message #16 received at 27639 <at> debbugs.gnu.org (full text, mbox):

From: Kaushal Modi <kaushal.modi <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 27639 <at> debbugs.gnu.org
Subject: Re: bug#27639: 25.2; Fix syntax for minor mode enabling in dir locals
 in manual
Date: Tue, 11 Jul 2017 16:57:32 +0000
[Message part 1 (text/plain, inline)]
Hi Eli,

Thanks for reviewing this.

On Tue, Jul 11, 2017 at 12:38 PM Eli Zaretskii <eliz <at> gnu.org> wrote:

> > From: Kaushal Modi <kaushal.modi <at> gmail.com>
> > Date: Mon, 10 Jul 2017 11:55:58 +0000
> >
> > I recently stumbled across this Reddit post[1] where a user is trying to
> enable a minor mode in .dir-locals.el.
> > But he was doing that by setting the mode name to `t'.
>
> indent-tabs-mode is the mode variable, so setting it to t is not a
> mistake.
>

The mistake (as explained in the Reddit post) was setting a 'custom-mode'
to t and expecting that that would rightaway enable that 'custom-mode'
minor mode. The OP on that Reddit thread later confirms[2] that doing (mode
. custom) worked easily, while trying to do (custom-mode . t) needed him to
mark that var as safe.


> > We generally(?) enable minor modes by doing (mode . MINOR) in
> .dir-locals.el.
>
> You could do it either way.  Also, some modes don't have such a
> variable, so only the latter way will work.
>

Almost all the user minor modes are created using define-minor-mode. At
least I have not to come across one where that's not the case in the user
land.

But why do you think we should only advertise one method, but not the
> other?


From (emacs) Minor Modes

=====
   Most minor modes also have a "mode variable", with the same name as
the mode command.  Its value is non-‘nil’ if the mode is enabled, and
‘nil’ if it is disabled.  In general, you should not try to enable or
disable the mode by changing the value of the mode variable directly in
Lisp; you should run the mode command instead.

(Reading further: Does below apply to setting minor mode variables via
.dir-locals.el?)

However, setting the
mode variable through the Customize interface (*note Easy
Customization::) will always properly enable or disable the mode, since
Customize automatically runs the mode command for you.
=====

In any case, as a user, I find it clearer to understand that you must never
enable minor modes by just setting their var; you should call that minor
mode fn instead. That realization also lead me to summarize minor mode
enabling conventions here[1] few years ago.

Also, if a user uses the (mode . minor) convention instead of (minor-mode .
t), they do not have to worry about declaring them safe.

There's no magic here, just legitimate use of public
> documented variables: 'mode' is a variable and so is 'indent-tabs-mode'.
>
> So I think I don't get your motivation for the report and for the
> patch you provided.


It just sets a convention that does not cause confusion (or create hurdle
like marking vars safe).

- If you want to set a plain var: do (var . value)
- If you want to enable a minor-mode: do (mode . minor)

[1]: https://emacs.stackexchange.com/a/10971/115
[2]:
https://www.reddit.com/r/emacs/comments/6malb6/disable_warning_message_when_enabling_minor_modes/dk0yxur/
-- 

Kaushal Modi
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27639; Package emacs. (Tue, 11 Jul 2017 17:33:01 GMT) Full text and rfc822 format available.

Message #19 received at 27639 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Kaushal Modi <kaushal.modi <at> gmail.com>
Cc: 27639 <at> debbugs.gnu.org
Subject: Re: bug#27639: 25.2; Fix syntax for minor mode enabling in dir locals
 in manual
Date: Tue, 11 Jul 2017 20:32:22 +0300
> From: Kaushal Modi <kaushal.modi <at> gmail.com>
> Date: Tue, 11 Jul 2017 16:57:32 +0000
> Cc: 27639 <at> debbugs.gnu.org
> 
>  indent-tabs-mode is the mode variable, so setting it to t is not a
>  mistake.
> 
> The mistake (as explained in the Reddit post) was setting a 'custom-mode' to t and expecting that that would
> rightaway enable that 'custom-mode' minor mode.

There's no variable by that name, so it's little surprise that it
didn't work.

>  But why do you think we should only advertise one method, but not the
>  other? 
> 
> From (emacs) Minor Modes
> 
> =====
> Most minor modes also have a "mode variable", with the same name as
> the mode command. Its value is non-‘nil’ if the mode is enabled, and
> ‘nil’ if it is disabled. In general, you should not try to enable or
> disable the mode by changing the value of the mode variable directly in
> Lisp; you should run the mode command instead. 

That's unrelated to file-local variables, IMO.

> In any case, as a user, I find it clearer to understand that you must never enable minor modes by just setting
> their var; you should call that minor mode fn instead.

And I object to the "never" part.  This is Emacs: we should teach
users to know and understand what they are doing, not follow recipes
prepared by others like a kind of cookbook.  If the mode variable is a
simple variable, and setting it is all that it takes to turn on or off
the mode, why should we tell users it's wrong?

> Also, if a user uses the (mode . minor) convention instead of (minor-mode . t), they do not have to worry
> about declaring them safe.

Let them find that out by themselves, and see if they care.  Who
knows, we might even find a few bugs that way -- perhaps some mode
variable should have a safe-local-variable property that we failed to
specify.

IOW, I think it's wrong to try to save users from themselves.  We
should provide clear documentation which explains the pros and cons,
and then let the users decide based on knowledge, not on blindly
following advice that makes some of the methods "magic".

OK, that's my opinion.  What do others think?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27639; Package emacs. (Sat, 15 Jul 2017 03:13:02 GMT) Full text and rfc822 format available.

Message #22 received at 27639 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Kaushal Modi <kaushal.modi <at> gmail.com>
Cc: 27639 <at> debbugs.gnu.org
Subject: Re: bug#27639: 25.2;
 Fix syntax for minor mode enabling in dir locals in manual
Date: Fri, 14 Jul 2017 23:14:13 -0400
Kaushal Modi <kaushal.modi <at> gmail.com> writes:

> I recently stumbled across this Reddit post[1] where a user is trying to
> enable a minor mode in .dir-locals.el. But he was doing that by setting the
> mode name to `t'.

The reddit thread talks about "custom-mode" which seems to be a major
mode.  Unless "custom-mode" was some kind of meta-variable for "a custom
mode that I created"?  It's a bit unclear.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27639; Package emacs. (Fri, 08 Nov 2019 01:32:02 GMT) Full text and rfc822 format available.

Message #25 received at 27639 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 27639 <at> debbugs.gnu.org, Kaushal Modi <kaushal.modi <at> gmail.com>
Subject: Re: bug#27639: 25.2; Fix syntax for minor mode enabling in dir
 locals in manual
Date: Fri, 08 Nov 2019 02:31:23 +0100
tags 27639 + wontfix
close 27639
thanks

Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Kaushal Modi <kaushal.modi <at> gmail.com>
>> Date: Tue, 11 Jul 2017 16:57:32 +0000
>> Cc: 27639 <at> debbugs.gnu.org
>> 
>>  indent-tabs-mode is the mode variable, so setting it to t is not a
>>  mistake.
>> 
>> The mistake (as explained in the Reddit post) was setting a 'custom-mode' to t and expecting that that would
>> rightaway enable that 'custom-mode' minor mode.
>
> There's no variable by that name, so it's little surprise that it
> didn't work.
>
>>  But why do you think we should only advertise one method, but not the
>>  other? 
>> 
>> From (emacs) Minor Modes
>> 
>> =====
>> Most minor modes also have a "mode variable", with the same name as
>> the mode command. Its value is non-‘nil’ if the mode is enabled, and
>> ‘nil’ if it is disabled. In general, you should not try to enable or
>> disable the mode by changing the value of the mode variable directly in
>> Lisp; you should run the mode command instead. 
>
> That's unrelated to file-local variables, IMO.
>
>> In any case, as a user, I find it clearer to understand that you must never enable minor modes by just setting
>> their var; you should call that minor mode fn instead.
>
> And I object to the "never" part.  This is Emacs: we should teach
> users to know and understand what they are doing, not follow recipes
> prepared by others like a kind of cookbook.  If the mode variable is a
> simple variable, and setting it is all that it takes to turn on or off
> the mode, why should we tell users it's wrong?
>
>> Also, if a user uses the (mode . minor) convention instead of (minor-mode . t), they do not have to worry
>> about declaring them safe.
>
> Let them find that out by themselves, and see if they care.  Who
> knows, we might even find a few bugs that way -- perhaps some mode
> variable should have a safe-local-variable property that we failed to
> specify.
>
> IOW, I think it's wrong to try to save users from themselves.  We
> should provide clear documentation which explains the pros and cons,
> and then let the users decide based on knowledge, not on blindly
> following advice that makes some of the methods "magic".
>
> OK, that's my opinion.  What do others think?

I agree with you Eli, and since no one else has commented in the last
2 years, I'm closing this bug report as wontfix.

Best regards,
Stefan Kangas




Added tag(s) wontfix. Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Fri, 08 Nov 2019 01:32:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 27639 <at> debbugs.gnu.org and Kaushal Modi <kaushal.modi <at> gmail.com> Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Fri, 08 Nov 2019 01:32:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 06 Dec 2019 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 136 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.