From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.bugs Subject: 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-ID: References: <83wp7fhquh.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c1cd7ec216a9005540d9962" X-Trace: blaine.gmane.org 1499794604 882 195.159.176.226 (11 Jul 2017 17:36:44 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 11 Jul 2017 17:36:44 +0000 (UTC) Cc: 27639@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 11 19:36:38 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUz5N-000886-Sa for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Jul 2017 19:36:34 +0200 Original-Received: from localhost ([::1]:47930 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUz5T-0005Qy-CT for geb-bug-gnu-emacs@m.gmane.org; Tue, 11 Jul 2017 13:36:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUyUA-0001Yu-Cg for bug-gnu-emacs@gnu.org; Tue, 11 Jul 2017 12:58:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUyU6-0003An-Dd for bug-gnu-emacs@gnu.org; Tue, 11 Jul 2017 12:58:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59816) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dUyU6-0003Af-8v for bug-gnu-emacs@gnu.org; Tue, 11 Jul 2017 12:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dUyU5-00067V-Ux for bug-gnu-emacs@gnu.org; Tue, 11 Jul 2017 12:58:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Kaushal Modi Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 11 Jul 2017 16:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27639 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 27639-submit@debbugs.gnu.org id=B27639.149979227123504 (code B ref 27639); Tue, 11 Jul 2017 16:58:01 +0000 Original-Received: (at 27639) by debbugs.gnu.org; 11 Jul 2017 16:57:51 +0000 Original-Received: from localhost ([127.0.0.1]:34260 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUyTv-000672-4F for submit@debbugs.gnu.org; Tue, 11 Jul 2017 12:57:51 -0400 Original-Received: from mail-lf0-f44.google.com ([209.85.215.44]:36435) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUyTu-00066q-4l for 27639@debbugs.gnu.org; Tue, 11 Jul 2017 12:57:50 -0400 Original-Received: by mail-lf0-f44.google.com with SMTP id h22so5423258lfk.3 for <27639@debbugs.gnu.org>; Tue, 11 Jul 2017 09:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=So/3XMSt/YwE/kt6w8bOnM43G3MefjYt5KJnZYy9zeQ=; b=mej7yemST8XLr7VeOCe3i2YJEpy1/f3/lJhBPcxxMOKVKpvIB4KQN3prMcevDk7Z4g 3Z4CBtlVCdvLm7FDpVbzFqxV69DZAG7oByeESV2rF6UL2polCXmukmDvUpE3FVzQlT8K TrGMSHqZMkoV9e3lu88bTh2tN+zkKsOlsUPWnHK5SyHw3YCyEOaXup7E9V9D9FOs/OyT tLLD5rB15fLf+82JdHnTvhU1t+2oLG+R4sJbWpUVtjZVRDriD+3HHJGRkezmHwD/bZVT 45U89xJuBkglgX5QIMhKBqd1emZDt922XrWtGCFYXELar+7IgOsm//p1j/Dvf4n2pVF0 LVSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=So/3XMSt/YwE/kt6w8bOnM43G3MefjYt5KJnZYy9zeQ=; b=g86JkWO6heVyHY/e3E+X48zpM9rIAvX7Gk41mrSYjAsOYM3sWblzfoseBhqMsj58ig LpuiWOiWZte53Ho8N26MBbEv641k7VkR6dwkqfZ9IgHX5nktkpnxl/Pg2SKuFbSdMONF w3Y3ATEkp7nLT427gpRHrdoGfnNHtAoNytFjw2grzHmuNLRlKAgWjXLvcDI9oMtmMO+f KV2lefGSdu6GgwyEFSlGdMVQ+Cvahc1Up6jOW2jnnuRxLSVW2ABCrk27CjBmY11sRoiY IGFXWlQq/WZyHGojx8UcYVtVS2yPJyEFKjJ717KBmZ3zI/kp131kLGcmnZi7JJRNes2O EykA== X-Gm-Message-State: AIVw112YSDGCSc5fAb3/iannyDIKjNo/98jkO7sOKkRwID+ANEE8FpEc FoN06eGbeNVCPBiZim+5EM0ijkNu9w== X-Received: by 10.25.79.9 with SMTP id d9mr320155lfb.133.1499792263962; Tue, 11 Jul 2017 09:57:43 -0700 (PDT) In-Reply-To: <83wp7fhquh.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:134436 Archived-At: --94eb2c1cd7ec216a9005540d9962 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Eli, Thanks for reviewing this. On Tue, Jul 11, 2017 at 12:38 PM Eli Zaretskii wrote: > > From: Kaushal Modi > > Date: Mon, 10 Jul 2017 11:55:58 +0000 > > > > I recently stumbled across this Reddit post[1] where a user is trying t= o > 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 =3D=3D=3D=3D=3D Most minor modes also have a "mode variable", with the same name as the mode command. Its value is non-=E2=80=98nil=E2=80=99 if the mode is en= abled, and =E2=80=98nil=E2=80=99 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. =3D=3D=3D=3D=3D 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/ --=20 Kaushal Modi --94eb2c1cd7ec216a9005540d9962 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Eli,

Thanks for reviewing this.

On T= ue, Jul 11, 2017 at 12:38 PM Eli Zaretskii <eliz@gnu.org> wrote:
>= ; From: Kaushal Modi <kaushal.modi@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 t= he 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 e= asily, while trying to do (custom-mode . t) needed him to mark that var as = safe.
=C2=A0
> We generall= y(?) enable minor modes by doing (mode . MINOR) in .dir-locals.el.

You could do it either way.=C2=A0 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. A= t least I have not to come across one where that's not the case in the = user land.=C2=A0

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

From=C2=A0(emacs) Minor Modes=

=3D=3D=3D=3D=3D
=C2=A0 =C2=A0Most = minor modes also have a "mode variable", with the same name as
the mode command.=C2=A0 Its value is non-=E2=80=98nil=E2=80=99 if t= he mode is enabled, and
=E2=80=98nil=E2=80=99 if it is disabled.= =C2=A0 In general, you should not try to enable or
disable the mo= de by changing the value of the mode variable directly in
Lisp; y= ou should run the mode command instead. =C2=A0

(Re= ading further: Does below apply to setting minor mode variables via .dir-lo= cals.el?)

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

In any case, as a user, I find it clearer to u= nderstand 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 instea= d of (minor-mode . t), they do not have to worry about declaring them safe.=

There's no magic he= re, just legitimate use of public
documented variables: 'mode' is a variable and so is 'indent-ta= bs-mode'.

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

It just sets a conventi= on 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)

--

Kaus= hal Modi

--94eb2c1cd7ec216a9005540d9962--