GNU bug report logs - #79624
[PATCH] (define-globalized-minor-mode): Remove `MODE-mode-name` hack

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Stefan Monnier <monnier@HIDDEN>; Keywords: patch; dated Tue, 14 Oct 2025 14:54:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 79624 <at> debbugs.gnu.org:


Received: (at 79624) by debbugs.gnu.org; 19 Oct 2025 13:57:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Oct 19 09:57:17 2025
Received: from localhost ([127.0.0.1]:34411 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1vATuO-0000Vg-9n
	for submit <at> debbugs.gnu.org; Sun, 19 Oct 2025 09:57:17 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:41708)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1vATuL-0000VG-35
 for 79624 <at> debbugs.gnu.org; Sun, 19 Oct 2025 09:57:13 -0400
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 3CD3A440FF6;
 Sun, 19 Oct 2025 09:57:06 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1760882225;
 bh=7pzNT1sU5hNHiW04+fW657PU/tSWa/szH73sULBXF70=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=LxZ67BTxsBKx7Ka9Keyfq7h4WNrEsWcmI+009JSY/xciW10OrWWYHnG5FK8/Z04RG
 tf+1RVp7R4PQj90RJQHE7USe3bAY2+3ENRzP7eMUu9Ge9cBjsz/d8lCuJsA1A/5ldZ
 FxbGnysgRBwyqgV3q8fpEqwGyuXHQPjEtAUKaZDUXodXBRrbmpyxNfpo+VDtbW8vvV
 HP1mmaBaIVNXA7uhU+3nBLImFbdvObt5uEXc2QVPKl3+Ics/xIiTT18odAq3NVpFaS
 z8+qXR+pt4Vf4yBdNKD2nbcEhruTUvXHvvmNuws7sQaJWsj7DZlDVj8y3+SEPg7MkU
 FS73oNYXb2yoA==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 17012440C8E;
 Sun, 19 Oct 2025 09:57:05 -0400 (EDT)
Received: from asado (unknown [181.28.45.30])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 058301202D5;
 Sun, 19 Oct 2025 09:57:03 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Sean Whitton <spwhitton@HIDDEN>
Subject: Re: bug#79624: further problem with multiple globalised minor modes
In-Reply-To: <87a51qdfjm.fsf@HIDDEN>
Message-ID: <jwvldl7ovjb.fsf-monnier+emacs@HIDDEN>
References: <175991996732.24264.3738480134819024442@HIDDEN>
 <20251008103928.5962CC045BA@HIDDEN>
 <jwv4is9y18d.fsf-monnier+emacs@HIDDEN>
 <87bjmgqlr5.fsf@HIDDEN>
 <jwv1pncc5r0.fsf-monnier+emacs@HIDDEN>
 <874is7q3bj.fsf@HIDDEN>
 <87zf9uixc1.fsf_-_@HIDDEN>
 <jwvo6qa60zs.fsf-monnier+emacs@HIDDEN>
 <877bwxhasp.fsf@HIDDEN>
 <jwvplap4m4w.fsf-monnier+emacs@HIDDEN>
 <87ldldflqj.fsf@HIDDEN>
 <jwv1pn54bcr.fsf-monnier+emacs@HIDDEN>
 <875xcgfch9.fsf@HIDDEN>
 <jwvy0pcyppb.fsf-monnier+emacs@HIDDEN>
 <87a51qdfjm.fsf@HIDDEN>
Date: Sun, 19 Oct 2025 09:56:59 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL 0.026 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 79624
Cc: 79624 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

>> The change I proposed seems to make this test succeed.
>> Have you been able to reproduce the problem you've seen with it with
>> `auto-revert-mode`?
>
> I just tried and I cannot reproduce the problem.

Thanks.  I'll push it shortly, then if there are no further objections.

> Moreover, if I additionally delete the --suppress-set-explicitly
> mechanism, I can't reproduce it then, either.
> So I think that your patch should, in addition to what it already does,
> remove the --suppress-set-explicitly mechanism, and delete the FIXME and
> expected failure in easy-mmode-tests.el.

Hmm... I think the suppress-set-explicitly is still beneficial for other
reasons anyway: what (suppress-)set-explicitly tries to do is
distinguish whether the minor mode was enabled by the globalized mode or
some other way so what when we disable the globalized mode we don't
accidentally also disable the mode in buffers that should not
be affected.

This is not working quite right, as it stands, but it's better than
nothing (e.g. it avoids accidentally disabling a minor mode that the
user enabled with `M-x`).  "Quite right" would require for example that
if you do

    (vc-auto-revert-mode 1)
    (magit-auto-revert-mode 1)
    (vc-auto-revert-mode -1)

you get the same result as if you'd done

    (magit-auto-revert-mode 1)


- Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#79624; Package emacs. Full text available.

Message received at 79624 <at> debbugs.gnu.org:


Received: (at 79624) by debbugs.gnu.org; 16 Oct 2025 15:37:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Oct 16 11:37:01 2025
Received: from localhost ([127.0.0.1]:36653 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1v9Q2G-0000oc-LZ
	for submit <at> debbugs.gnu.org; Thu, 16 Oct 2025 11:37:01 -0400
Received: from sendmail.purelymail.com ([34.202.193.197]:59530)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <spwhitton@HIDDEN>)
 id 1v9Q2A-0000oH-6h
 for 79624 <at> debbugs.gnu.org; Thu, 16 Oct 2025 11:36:56 -0400
DKIM-Signature: a=rsa-sha256;
 b=EzB9PRI2Le4Zs+5KGHvsGhPGEn+6x/Crej2Vj2lBycC9dd2bHJqlrpiSxbzjtom+9EP4HueFyNVqfxKTcL8ZtnAWRYw+OG4oi3Y+OICObgB1dNh9rA9TqLrb8WCPiLHz1zG6hIoEuTwUJVVG6wyuryf5DaPUeF/W9YbeLgYiQRPgA98dbgrccWoW6Bf5Vhho37k6iAUytQ0g3+0jM8wnAq2mrR2hnzYD6uKBVhufcPhvwx5Y7a9P3arhA6OCBYW1Sj3QfPyCZnwZKi7n8hHG+XAWa25f3BZQs1hpkQqweOEUXzz3Xbd7b+0ZYpRLMSWXmE86BgAQUeNWnxcmogY4WA==;
 s=purelymail2; d=spwhitton.name; v=1;
 bh=+NFEt1xD2ym7jV/z5WgVRNiJf71bMB3R6ha2pAlPiw4=;
 h=Received:Received:From:To:Subject:Date; 
DKIM-Signature: a=rsa-sha256;
 b=B69uXfcDreKmx2hXUIdwMTarPEkG0Tx37/sSDEvisESj3B4yoV3gGJnWpM3DHkLFMGQ6XBvK4vS73WGyMvaCTS7m0mA4GYAWRv5ZSXiVMPf9F6uYyrDpb/27+UFV9TFWCuyTTEGGVYlajXAqkWx/jx0IkP2VXcAnhanbTVduijAApiCLLb9qynKY2QNWmpkQfajBtYXTlghBYizjHc3fdNXczNXlJ7Lvr4oiDnOOcLhV2r6vhTmMwd5kL60OGMbGim0LF3S/rrM/Xf8Yk3jm4DjN3ZTSMkNPwyCzbSnE2SjV36HsMU2KUAJIFffzmwKZUSTf0vOAXIFrvKvAeIoLHA==;
 s=purelymail2; d=purelymail.com; v=1;
 bh=+NFEt1xD2ym7jV/z5WgVRNiJf71bMB3R6ha2pAlPiw4=;
 h=Feedback-ID:Received:Received:From:To:Subject:Date; 
Feedback-ID: 20115:3760:null:purelymail
X-Pm-Original-To: 79624 <at> debbugs.gnu.org
Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1015077475; 
 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384);
 Thu, 16 Oct 2025 15:36:47 +0000 (UTC)
Received: by zephyr.silentflame.com (Postfix, from userid 1000)
 id 2411E940867; Thu, 16 Oct 2025 16:36:45 +0100 (BST)
From: Sean Whitton <spwhitton@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#79624: further problem with multiple globalised minor modes
In-Reply-To: <jwvy0pcyppb.fsf-monnier+emacs@HIDDEN>
References: <175991996732.24264.3738480134819024442@HIDDEN>
 <20251008103928.5962CC045BA@HIDDEN>
 <jwv4is9y18d.fsf-monnier+emacs@HIDDEN>
 <87bjmgqlr5.fsf@HIDDEN>
 <jwv1pncc5r0.fsf-monnier+emacs@HIDDEN>
 <874is7q3bj.fsf@HIDDEN>
 <87zf9uixc1.fsf_-_@HIDDEN>
 <jwvo6qa60zs.fsf-monnier+emacs@HIDDEN>
 <877bwxhasp.fsf@HIDDEN>
 <jwvplap4m4w.fsf-monnier+emacs@HIDDEN>
 <87ldldflqj.fsf@HIDDEN>
 <jwv1pn54bcr.fsf-monnier+emacs@HIDDEN>
 <875xcgfch9.fsf@HIDDEN>
 <jwvy0pcyppb.fsf-monnier+emacs@HIDDEN>
Date: Thu, 16 Oct 2025 16:36:45 +0100
Message-ID: <87a51qdfjm.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 79624
Cc: 79624 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello,

On Wed 15 Oct 2025 at 02:43pm -04, Stefan Monnier wrote:

>> I will work on an integration test for this specific scenario which we
>> think should work: two globalised modes for the same minor mode where
>> the minor mode's variable is marked permanent-local.
>
> IIUC commit 6cb7fa36ad0 does that, right?
> [ I just changed its code to actually run the test (but marked it so
>   a failure is considered as normal).  ]

Yes.  Thank you for for the expected result change.

>> Then we can make whatever other simplifications seem appropriate
>> (including to normal-mode; it does indeed seem like we can stop it
>> killing all local variables twice) and verify that they don't break
>> the use case.
>
> The change I proposed seems to make this test succeed.
> Have you been able to reproduce the problem you've seen with it with
> `auto-revert-mode`?

I just tried and I cannot reproduce the problem.

Moreover, if I additionally delete the --suppress-set-explicitly
mechanism, I can't reproduce it then, either.

So I think that your patch should, in addition to what it already does,
remove the --suppress-set-explicitly mechanism, and delete the FIXME and
expected failure in easy-mmode-tests.el.

Thanks!

-- 
Sean Whitton




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#79624; Package emacs. Full text available.

Message received at 79624 <at> debbugs.gnu.org:


Received: (at 79624) by debbugs.gnu.org; 15 Oct 2025 18:44:10 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Oct 15 14:44:10 2025
Received: from localhost ([127.0.0.1]:56874 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1v96Tp-0002z3-LT
	for submit <at> debbugs.gnu.org; Wed, 15 Oct 2025 14:44:09 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39985)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1v96Tk-0002y3-0C
 for 79624 <at> debbugs.gnu.org; Wed, 15 Oct 2025 14:44:05 -0400
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id EA9D3440B0B;
 Wed, 15 Oct 2025 14:43:56 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1760553836;
 bh=E2xxvnlFli1HkwIbx+PBKdgw4S7GSIZgcU6Qx3NfaKQ=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=P1c1y96ezRcDhq4UhyNUe6m2FXYboITYokhX+7pRPipeZrx2ngid2CbHCghyRtl89
 8Ahf/E0236eQOoA2aRBc5v6C6obKJRMVPVQNqeuWdao6BGQNHz/Q3wtKxDpNPbsfGf
 PHQsOddDaCJw2jJ1MjKUEkGFDpmtwF48q7VG8h3I0XnwaDQM8kKUVyN5qKLPKB4nfD
 aYorb6Sanc+p+71SFnOhsQ4Rr4jqQUFDnmkOdw3VnWlW0k8sQwK6MZRc1uytcFe+86
 Q4+Ki8vbo8X19XdsgNccGOQI/NOvTzjBf0T6P6T0LE+bmO0OqPW2TZuItHA8VwDHlb
 zkk14vze7fSMg==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id F1987440AEB;
 Wed, 15 Oct 2025 14:43:55 -0400 (EDT)
Received: from asado (unknown [181.28.45.30])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id D03E6120343;
 Wed, 15 Oct 2025 14:43:54 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Sean Whitton <spwhitton@HIDDEN>
Subject: Re: bug#79624: further problem with multiple globalised minor modes
In-Reply-To: <875xcgfch9.fsf@HIDDEN>
Message-ID: <jwvy0pcyppb.fsf-monnier+emacs@HIDDEN>
References: <175991996732.24264.3738480134819024442@HIDDEN>
 <20251008103928.5962CC045BA@HIDDEN>
 <jwv4is9y18d.fsf-monnier+emacs@HIDDEN>
 <87bjmgqlr5.fsf@HIDDEN>
 <jwv1pncc5r0.fsf-monnier+emacs@HIDDEN>
 <874is7q3bj.fsf@HIDDEN>
 <87zf9uixc1.fsf_-_@HIDDEN>
 <jwvo6qa60zs.fsf-monnier+emacs@HIDDEN>
 <877bwxhasp.fsf@HIDDEN>
 <jwvplap4m4w.fsf-monnier+emacs@HIDDEN>
 <87ldldflqj.fsf@HIDDEN>
 <jwv1pn54bcr.fsf-monnier+emacs@HIDDEN>
 <875xcgfch9.fsf@HIDDEN>
Date: Wed, 15 Oct 2025 14:43:50 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL 0.126 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 79624
Cc: 79624 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

[ Removing `emacs-devel` since cross-posting between debbugs and
  a mailing-list is problematic.  ]

> I will work on an integration test for this specific scenario which we
> think should work: two globalised modes for the same minor mode where
> the minor mode's variable is marked permanent-local.

IIUC commit 6cb7fa36ad0 does that, right?
[ I just changed its code to actually run the test (but marked it so
  a failure is considered as normal).  ]

> Then we can make whatever other simplifications seem appropriate
> (including to normal-mode; it does indeed seem like we can stop it
> killing all local variables twice) and verify that they don't break
> the use case.

The change I proposed seems to make this test succeed.
Have you been able to reproduce the problem you've seen with it with
`auto-revert-mode`?


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#79624; Package emacs. Full text available.

Message received at 79624 <at> debbugs.gnu.org:


Received: (at 79624) by debbugs.gnu.org; 15 Oct 2025 14:48:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Oct 15 10:48:20 2025
Received: from localhost ([127.0.0.1]:54984 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1v92nY-0002X6-Dt
	for submit <at> debbugs.gnu.org; Wed, 15 Oct 2025 10:48:20 -0400
Received: from sendmail.purelymail.com ([34.202.193.197]:48046)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <spwhitton@HIDDEN>)
 id 1v92nD-0002Ts-V1
 for 79624 <at> debbugs.gnu.org; Wed, 15 Oct 2025 10:48:04 -0400
DKIM-Signature: a=rsa-sha256;
 b=DeClVgZqnux2bB4tVxynNL/+v0t0tRPrToC47j4FNDewxNi2ishtsfqsBr+ViXQFfbuPwBZNP/MuLF8OLKUPmbk1YVzslcV4oHwvrly5SnYilEGSZUcz2eh/hKgeG1lzDlrR/I6fzYxL2ysx5kxnC7hZB9yHdnAVfZFaaDcOaTP/wAZhmcslIJw5nb6itI/MdnmENv+L21zjP+1HXhW2XS0s2ClEeo/enOL3zYLJQmZIZXMU3bmI76fBV/YFf5K3zjXdkNKKfMiP2wtHqZhg8RLDzplvRlxT+u3jilLZkmZEGNLxuhR189oVGB8VZO119zWWVpJCbtrfYQt8339aTA==;
 s=purelymail2; d=spwhitton.name; v=1;
 bh=GkdpbEsT3JC5mYuYSoCHEJu7wWr5fFflnzTh2fnlms8=;
 h=Received:Received:From:To:Subject:Date; 
DKIM-Signature: a=rsa-sha256;
 b=l7SsDp3+uIb6kMwkXbJNJJrFr//r76ZSYQKW3KICbHspMTckP3MYMoRd03u2ByP2vDUuUqkQeIAcJkT/kGujuNQRbCaQXTVtfMa67i9lUHEKYcJj8JN17L4WpV5QLAJimyHELs/RFSyVQdFUswRpKPMYZaye2w5c9NsYTAI3r8+lKkOOdNYnxMO056C0sW0rHqfMx0hiDxzG6NHDD01WBHw8qc1jXbfYiqBE+t/C5RhusB6TRxr2K73SgPVWgnF7by196zNH3QytKjAbhltTYrFPAq2obps6sK6Iz9IZz9wXX5GY1DvDaz3UJvsCJbUG1vfk0Td8+2c9kwhDsZII8Q==;
 s=purelymail2; d=purelymail.com; v=1;
 bh=GkdpbEsT3JC5mYuYSoCHEJu7wWr5fFflnzTh2fnlms8=;
 h=Feedback-ID:Received:Received:From:To:Subject:Date; 
Feedback-ID: 20115:3760:null:purelymail
X-Pm-Original-To: 79624 <at> debbugs.gnu.org
Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -1804116954; 
 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384);
 Wed, 15 Oct 2025 14:47:47 +0000 (UTC)
Received: by zephyr.silentflame.com (Postfix, from userid 1000)
 id A8BF894020F; Wed, 15 Oct 2025 15:47:46 +0100 (BST)
From: Sean Whitton <spwhitton@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: bug#79624: further problem with multiple globalised minor modes
In-Reply-To: <jwv1pn54bcr.fsf-monnier+emacs@HIDDEN>
References: <175991996732.24264.3738480134819024442@HIDDEN>
 <20251008103928.5962CC045BA@HIDDEN>
 <jwv4is9y18d.fsf-monnier+emacs@HIDDEN>
 <87bjmgqlr5.fsf@HIDDEN>
 <jwv1pncc5r0.fsf-monnier+emacs@HIDDEN>
 <874is7q3bj.fsf@HIDDEN>
 <87zf9uixc1.fsf_-_@HIDDEN>
 <jwvo6qa60zs.fsf-monnier+emacs@HIDDEN>
 <877bwxhasp.fsf@HIDDEN>
 <jwvplap4m4w.fsf-monnier+emacs@HIDDEN>
 <87ldldflqj.fsf@HIDDEN>
 <jwv1pn54bcr.fsf-monnier+emacs@HIDDEN>
Date: Wed, 15 Oct 2025 15:47:46 +0100
Message-ID: <875xcgfch9.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 79624
Cc: emacs-devel@HIDDEN, 79624 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello,

On Tue 14 Oct 2025 at 01:56pm -04, Stefan Monnier wrote:

>> - Why does auto-revert-mode remain non-nil across the
>>   kill-all-local-variables?  It's not permanent-local.
>
> I see (put 'auto-revert-mode 'permanent-local t) in lisp/autorevert.el.
>
> [ Sorry, haven't had the time to try your recipe or look any further
>   into it.  ]

Thanks, so, it turns out auto-revert-mode is special.

I will work on an integration test for this specific scenario which we
think should work: two globalised modes for the same minor mode where
the minor mode's variable is marked permanent-local.

Then we can make whatever other simplifications seem appropriate
(including to normal-mode; it does indeed seem like we can stop it
killing all local variables twice) and verify that they don't break the
use case.

-- 
Sean Whitton




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#79624; Package emacs. Full text available.

Message received at 79624 <at> debbugs.gnu.org:


Received: (at 79624) by debbugs.gnu.org; 14 Oct 2025 18:28:57 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Oct 14 14:28:57 2025
Received: from localhost ([127.0.0.1]:42748 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1v8jlZ-00012I-5g
	for submit <at> debbugs.gnu.org; Tue, 14 Oct 2025 14:28:57 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:53288)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1v8jlV-000120-8s
 for 79624 <at> debbugs.gnu.org; Tue, 14 Oct 2025 14:28:54 -0400
Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id A77D710013E;
 Tue, 14 Oct 2025 14:28:46 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1760466525;
 bh=84xRwgnWrhiOhMMg/dBRqkz4QlH2ROUvfaCh1nA5Dho=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=lerpLOWr4NWclJuM8PcjucsHmhTmIVFYuCg6o4vE5ykcwqgRZRl386QgvyD/BUSk9
 ZyyK1VlIHxscAgi9e9qJC1SUYmaMyKR8MM3D/H0P5T+uMTrmumsL7byLkKG102NRXQ
 akCRU+/nldEcMB4zf1Kduwr29IdF53nTZhvHsRk/Z/AhLAAxLhKbWlebaM8CIaRXjT
 CGRpRXXPQyHiX/0CWC/wJcO+kw0+ptODJsLf0kXHQ2NPxuPLhaU3sEy/KP62Xr1wS+
 aK5GZ38vNf3aTiWGof6n9/mRKL0G5cQZWXNNUCfILLYd34U4kJ91JwD+4u0/MNuNUb
 ycRbNFZzMO0rA==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 9415710002E;
 Tue, 14 Oct 2025 14:28:45 -0400 (EDT)
Received: from asado (unknown [181.28.45.30])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 59CAE120342;
 Tue, 14 Oct 2025 14:28:44 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Sean Whitton <spwhitton@HIDDEN>
Subject: Re: further problem with multiple globalised minor modes
In-Reply-To: <87ldldflqj.fsf@HIDDEN>
Message-ID: <jwvv7kh2vyx.fsf-monnier+emacs@HIDDEN>
References: <175991996732.24264.3738480134819024442@HIDDEN>
 <20251008103928.5962CC045BA@HIDDEN>
 <jwv4is9y18d.fsf-monnier+emacs@HIDDEN>
 <87bjmgqlr5.fsf@HIDDEN>
 <jwv1pncc5r0.fsf-monnier+emacs@HIDDEN>
 <874is7q3bj.fsf@HIDDEN>
 <87zf9uixc1.fsf_-_@HIDDEN>
 <jwvo6qa60zs.fsf-monnier+emacs@HIDDEN>
 <877bwxhasp.fsf@HIDDEN>
 <jwvplap4m4w.fsf-monnier+emacs@HIDDEN>
 <87ldldflqj.fsf@HIDDEN>
Date: Tue, 14 Oct 2025 14:28:41 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL 0.128 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 79624
Cc: 79624 <at> debbugs.gnu.org, emacs-devel@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> 1. normal-mode invokes change-major-mode-after-body-hook and
>    after-change-major-mode-hook.

Side note: I don't know why `normal-mode` calls
`kill-all-local-variables` and runs those two hooks.
Looks like a bug to me, since we're about to run the major mode function
which will do both of those things anyway.

AFAICT we started in 1991 with:

    (defun normal-mode (&optional find-file)
      "..."
      (interactive)
      (or find-file (funcall (or default-major-mode 'fundamental-mode)))
      (condition-case err
          (set-auto-mode)
        (error (message "File mode specification error: %s"
                        (prin1-to-string err))))
      (condition-case err
          (hack-local-variables (not find-file))
        (error (message "File local-variables error: %s"
                        (prin1-to-string err)))))

Then

    commit e8f30180f4fad05b793829966e4cb78539f38d33
    Author: Richard M. Stallman <rms@HIDDEN>
    Date:   Tue Aug 9 13:35:12 2005 +0000

    (find-file-noselect): Don't call set-buffer-major-mode.
    (find-file-noselect-1): Call it here, only if RAWFILE.
    (normal-mode): Always set some major mode.
    (save-some-buffers-action-alist): Change some explanation strings.
    (file-name-non-special): In the `quote' method, use unwind-protect.

changed it to:

    (defun normal-mode (&optional find-file)
      "..."
      (interactive)
      (funcall (or default-major-mode 'fundamental-mode))
      (let ((enable-local-variables (or (not find-file) enable-local-variables)))
        (report-errors "File mode specification error: %s"
          (set-auto-mode))
        (report-errors "File local-variables error: %s"
          (hack-local-variables)))
      (if (fboundp 'ucs-set-table-for-input) ; don't lose when building
          (ucs-set-table-for-input)))

Since then this initial `funcall` has been demoted First by

    commit 91e8293cc55d1de50796300412084e8774c60e7f
    Author: Stefan Monnier <monnier@HIDDEN>
    Date:   Sat Apr 13 22:55:21 2013 -0400

    * lisp/files.el (normal-mode): Only use default major-mode if no other mode
    was specified.
    
    Fixes: debbugs:14089

which replaced the `funcall ...` with just a call to `fundamental-mode`
and added the (set-buffer-major-mode (current-buffer)) at the end
instead (which has since moved to `set-auto-mode`).

and then by

    commit 26171e02773b9b2383f412dd79d241385d2d20df
    Author: Alan Mackenzie <acm@HIDDEN>
    Date:   Fri May 6 18:58:49 2016 +0000

    Correct hack-local-variables change from Thu May 5 11:05:49 2016 +0000
    
    Prevent hack-local-variables being called from the fundamental-mode mode call
    early in normal-mode.  This fixes bug #23460 and bug #23463.
    
    * lisp/files.el (normal-mode) Replace call to fundamental-mode with calls to
    the things it calls, with the exception of hack-local-variables.
    
    * etc/NEWS: Add an entry to note the calling of hack-local-variables at each
    major mode initialization.

which replaced the call to `fundamental-mode` with

    (kill-all-local-variables)
    (unless delay-mode-hooks
      (run-hooks 'change-major-mode-after-body-hook
                 'after-change-major-mode-hook))

I'm beginning to think it could be removed altogether.


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#79624; Package emacs. Full text available.

Message received at 79624 <at> debbugs.gnu.org:


Received: (at 79624) by debbugs.gnu.org; 14 Oct 2025 17:57:07 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Oct 14 13:57:07 2025
Received: from localhost ([127.0.0.1]:42262 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1v8jGl-0006rZ-Cl
	for submit <at> debbugs.gnu.org; Tue, 14 Oct 2025 13:57:07 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:9343)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1v8jGh-0006qi-Gy
 for 79624 <at> debbugs.gnu.org; Tue, 14 Oct 2025 13:57:04 -0400
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id A8759441087;
 Tue, 14 Oct 2025 13:56:57 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1760464616;
 bh=roEngf4rhlFW+31U4RvFw2BZi3ndfJz6wNzXkQMQGc4=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=BQtuYWQhoZYgkF2ugPDwZ0mSdoueHAIcLIqn0LJnb8TXu1qFi8F8eKPud3PTeC4nE
 LaDhwb7TzzezfNsuq2y02CLdoSy/2Q0wWeyA/mhbGUu+fgkqigJecVGZu3+rKC3Wgb
 Jk+yIXAOrMkbv4P4UF1yGXTgjhTNwJkYwKauG+S4Lxnc1xwquKer6SqrNbzJa53TFY
 bVv8dscxY3VKvk6UzDGkWAlhzRUs0HsKnZD2ttrs1HSvr7mhmRuoTtYDfjhCllHIT+
 +gnhNB8Oy5oEjZ3MuK6E1QvyJlPxBvAf5DgwHamBweCsPxSUgJ5QFy5QPTMx2JheWa
 X93WXYhVqBxgQ==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id C0DB84408D4;
 Tue, 14 Oct 2025 13:56:56 -0400 (EDT)
Received: from asado (unknown [181.28.45.30])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 563361204CB;
 Tue, 14 Oct 2025 13:56:55 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: Sean Whitton <spwhitton@HIDDEN>
Subject: Re: further problem with multiple globalised minor modes
In-Reply-To: <87ldldflqj.fsf@HIDDEN>
Message-ID: <jwv1pn54bcr.fsf-monnier+emacs@HIDDEN>
References: <175991996732.24264.3738480134819024442@HIDDEN>
 <20251008103928.5962CC045BA@HIDDEN>
 <jwv4is9y18d.fsf-monnier+emacs@HIDDEN>
 <87bjmgqlr5.fsf@HIDDEN>
 <jwv1pncc5r0.fsf-monnier+emacs@HIDDEN>
 <874is7q3bj.fsf@HIDDEN>
 <87zf9uixc1.fsf_-_@HIDDEN>
 <jwvo6qa60zs.fsf-monnier+emacs@HIDDEN>
 <877bwxhasp.fsf@HIDDEN>
 <jwvplap4m4w.fsf-monnier+emacs@HIDDEN>
 <87ldldflqj.fsf@HIDDEN>
Date: Tue, 14 Oct 2025 13:56:51 -0400
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL 0.056 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 79624
Cc: 79624 <at> debbugs.gnu.org, emacs-devel@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> - Why does auto-revert-mode remain non-nil across the
>   kill-all-local-variables?  It's not permanent-local.

I see (put 'auto-revert-mode 'permanent-local t) in lisp/autorevert.el.

[ Sorry, haven't had the time to try your recipe or look any further
  into it.  ]


        Stefan





Information forwarded to bug-gnu-emacs@HIDDEN:
bug#79624; Package emacs. Full text available.

Message received at 79624 <at> debbugs.gnu.org:


Received: (at 79624) by debbugs.gnu.org; 14 Oct 2025 17:15:53 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Oct 14 13:15:53 2025
Received: from localhost ([127.0.0.1]:41652 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1v8icq-00014D-FM
	for submit <at> debbugs.gnu.org; Tue, 14 Oct 2025 13:15:52 -0400
Received: from sendmail.purelymail.com ([34.202.193.197]:47370)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <spwhitton@HIDDEN>)
 id 1v8ick-00012Q-Co
 for 79624 <at> debbugs.gnu.org; Tue, 14 Oct 2025 13:15:50 -0400
DKIM-Signature: a=rsa-sha256;
 b=nrAq3FAl7oaLOodMYIuKvJKZ7DtZzhocSjYtb77QQyyhw5D1Vmn9+VDWRMK3WUvjoBvR8Rqu3y5mgaI3/L65Kz8ixO6IINZkSbJDT+HPuJp43HXevNI2Xf3lQ5rSiHgdk7Z+rthQnqBCuirzTEuuZzuSaRwcswEbd3vkOgn9c2RA2BuklCR/4CGGlPtUB9WH4SYJmq5j1VDpf2xwYPuvdOMGYOkhB6geKmBnmc4dWKYl9lmO5mc25Qpc55QwS+QG5+2J90TkRZzyqMDz6VGRuuZjH34T2RHBFTppj/O0e29d64JGeOqNdU4ZYzi9Ppol36dzgcUDSYVUVKsgX0Qdbg==;
 s=purelymail1; d=spwhitton.name; v=1;
 bh=9RIXv+PFf/08fLtyquzaEXT7YBi0dLnqRfCjXt4eW9A=;
 h=Received:Received:From:To:Subject:Date; 
DKIM-Signature: a=rsa-sha256;
 b=nrdRFc6Lx3OAxyi9HYUGsrAh3PDaGagSNhOZo0FbXiG2WAgN+Ta58Dj8Ia+5bJjEGbqJoEaa3w3sNz30d+12LLB2onngM1MFF+hFZhhluPBpn7zX0NrSg9GuqNlPhnLUrLUXeOBbq2H44lJbz1LKik9rQVbA/C/vYRSNBeyX2RGP1Q2KHjAmY/gVxPU+QEMNxUHVry3gpEgQZKiiNXgz/GptNT8jmQ10N/knc51kb8KYy8n5g3VP0m0IshwJq9+uS7XWnUdYYNA338NX/r5Lg2ZdneL/F5hX6+BFZY9PldCtNGYqsM250pQhNeDl8NDardGEpUxE9VaVi1BsO/+tMQ==;
 s=purelymail1; d=purelymail.com; v=1;
 bh=9RIXv+PFf/08fLtyquzaEXT7YBi0dLnqRfCjXt4eW9A=;
 h=Feedback-ID:Received:Received:From:To:Subject:Date; 
Feedback-ID: 20115:3760:null:purelymail
X-Pm-Original-To: 79624 <at> debbugs.gnu.org
Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -907640942; 
 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384);
 Tue, 14 Oct 2025 17:15:35 +0000 (UTC)
Received: by zephyr.silentflame.com (Postfix, from userid 1000)
 id BD93F94078D; Tue, 14 Oct 2025 18:15:32 +0100 (BST)
From: Sean Whitton <spwhitton@HIDDEN>
To: Stefan Monnier <monnier@HIDDEN>
Subject: Re: further problem with multiple globalised minor modes
In-Reply-To: <jwvplap4m4w.fsf-monnier+emacs@HIDDEN>
References: <175991996732.24264.3738480134819024442@HIDDEN>
 <20251008103928.5962CC045BA@HIDDEN>
 <jwv4is9y18d.fsf-monnier+emacs@HIDDEN>
 <87bjmgqlr5.fsf@HIDDEN>
 <jwv1pncc5r0.fsf-monnier+emacs@HIDDEN>
 <874is7q3bj.fsf@HIDDEN>
 <87zf9uixc1.fsf_-_@HIDDEN>
 <jwvo6qa60zs.fsf-monnier+emacs@HIDDEN>
 <877bwxhasp.fsf@HIDDEN>
 <jwvplap4m4w.fsf-monnier+emacs@HIDDEN>
Date: Tue, 14 Oct 2025 18:15:32 +0100
Message-ID: <87ldldflqj.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 79624
Cc: 79624 <at> debbugs.gnu.org, emacs-devel@HIDDEN
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello,

On Tue 14 Oct 2025 at 10:56am -04, Stefan Monnier wrote:

> Consider:
>
>     (add-hook 'js-mode-hook #'font-lock-mode)
>
>     (defun my-json-mode ()
>       (js-mode)
>       (setq-local font-lock-defaults '(...))
>       (run-mode-hooks 'my-json-mode-hook))
>
> Then if you set a buffer in `my-js-mode`, `font-lock-mode` will be
> enabled first when `js-mode` is called (at which point
> `font-lock-defaults` is set to its `js-mode` value, which is not the one
> we want), and then when `my-json-mode` ends, `global-font-lock-mode`
> kicks in and wants to enable `font-lock-mode` as well.  It could say
> "oh, it's already enabled, let's do nothing", or it could call
> `font-lock-mode`, which itself may (will?) decide to do nothing because
> it's already enabled, but instead it turns the mode off and then back
> on, so as to force a full setup, which will let `font-lock-mode` obey
> the right value of `font-lock-defaults`.
>
> The above scenario doesn't actually involve MODE-major-mode, but that's
> part of my point above: with commit 17e26cf57e18, the code has changed
> such that it seems very difficult to reproduce a scenario like the above
> one where MODE-major-mode in involved.
>
> Before commit 17e26cf57e18, `MODE-enable-in-buffer` was called
> `MODE-enable-in-buffers` (notice the "s" at the end) because it cycled
> through all the buffers which were "pending", making it easier for
> `MODE-enable-in-buffers` to accidentally enable a minor mode in a buffer
> before the buffer's major mode was fully setup.
>
> See bug#79624 which I just submitted.

Thanks.  I agree with installing the patch in bug#79624, though I'd like
to resolve the following first.

I think that we might also want to drop or replace the
--suppress-set-explicitly mechanism.  I have discovered that my
understanding of the bug I was trying to fix was wrong and so the
--suppress-set-explicitly mechanism may not be the best fix.

To reproduce the problem:

1. Revert 43cbdfb6984 locally.
2. Have Magit installed.
3. emacs -q
4. M-x vc-auto-revert-mode
5. 'M-x magit-auto-revert-mode' twice such that the mode is *on* and
   appears *first* in after-change-major-mode-hook.
6. Visit a file in a VCS repository that isn't Git, e.g. a Mercurial
   repository.  "ARev" does not appear in the mode line, but it should.

This is the sequence of events that lead to the problem, I now think:

1. normal-mode invokes change-major-mode-after-body-hook and
   after-change-major-mode-hook.
2. magit-auto-revert-mode-enable-in-buffer declines to enable the mode,
   changing no state.
3. vc-auto-revert-mode-enable-in-buffer enables auto-revert-mode and
   this calls auto-revert-mode--set-explicitly for the first time.
4. normal-mode invokes the actual major mode for the file.  This kills
   all local variables so auto-revert-mode--set-explicitly is nil again.
   However, auto-revert-mode is still t.
5. The major mode calls run-mode-hooks which calls
   after-change-major-mode-hook a second time.
6. magit-auto-revert-mode-enable-in-buffer sees that auto-revert-mode is
   still turned on and does (auto-revert-mode -1) which calls
   auto-revert-mode--set-explicitly again.  It again declines to turn on
   the mode.
7. Now vc-auto-revert-mode-enable-in-buffer does nothing because
   auto-revert-mode--set-explicitly is non-nil.

There are two things I don't understand yet:

- Why does auto-revert-mode remain non-nil across the
  kill-all-local-variables?  It's not permanent-local.
- Why doesn't the following ERT test reproduce the problem?  These tests
  pass.  What is different about this setup from the actual case?

--8<---------------cut here---------------start------------->8---
;; More selective globalized major mode: like `magit-auto-revert-mode'.
(define-globalized-minor-mode easy-mmode-test-globalized-mode-1
  easy-mmode-test-mode
  (lambda ()
    (when (string-search "both" (buffer-name))
      (easy-mmode-test-mode 1))))

;; Less selective globalized major mode: like `vc-auto-revert-mode'.
(define-globalized-minor-mode easy-mmode-test-globalized-mode-2
  easy-mmode-test-mode
  (lambda ()
    (when (string-match "both\\|only" (buffer-name))
      (easy-mmode-test-mode 1))))

(ert-deftest easy-mmode--two-globalized-modes ()
  (cl-flet ((do-tests ()
              (let ((only-file (expand-file-name (make-temp-name "only")
                                                 temporary-file-directory))
                    (both-file (expand-file-name (make-temp-name "both")
                                                 temporary-file-directory)))
                (with-temp-file only-file (insert "-*- text -*-"))
                (with-temp-file both-file (insert "-*- text -*-"))
                (should-not (find-buffer-visiting only-file))
                (should-not (find-buffer-visiting both-file))
                (with-current-buffer (find-file-noselect only-file)
                  ;; !! Without 43cbdfb6984 this should fail, but it doesn't!
                  (should easy-mmode-test-mode))
                (with-current-buffer (find-file-noselect both-file)
                  (should easy-mmode-test-mode)))))
    (easy-mmode-test-globalized-mode-1 -1)
    (easy-mmode-test-globalized-mode-2 -1)

    ;; Test with the more selective mode going first.
    ;; This is what should fail without the --suppress-set-explicitly commit.
    (easy-mmode-test-globalized-mode-2 1)
    (easy-mmode-test-globalized-mode-1 1)
    (should (memq 'easy-mmode-test-globalized-mode-2-enable-in-buffer
                  (memq 'easy-mmode-test-globalized-mode-1-enable-in-buffer
                        after-change-major-mode-hook)))
    (do-tests)

    ;; Test with the less selective mode going first.
    (easy-mmode-test-globalized-mode-2 -1)
    (easy-mmode-test-globalized-mode-2 1)
    (should (memq 'easy-mmode-test-globalized-mode-1-enable-in-buffer
                  (memq 'easy-mmode-test-globalized-mode-2-enable-in-buffer
                        after-change-major-mode-hook)))
    (do-tests)))
--8<---------------cut here---------------end--------------->8---

-- 
Sean Whitton




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#79624; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 14 Oct 2025 14:53:25 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Oct 14 10:53:25 2025
Received: from localhost ([127.0.0.1]:39723 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1v8gOy-00047H-DH
	for submit <at> debbugs.gnu.org; Tue, 14 Oct 2025 10:53:25 -0400
Received: from lists.gnu.org ([2001:470:142::17]:53392)
 by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.84_2) (envelope-from <monnier@HIDDEN>)
 id 1v8gOu-00046t-16
 for submit <at> debbugs.gnu.org; Tue, 14 Oct 2025 10:53:20 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@HIDDEN>)
 id 1v8gOo-0002t9-KO
 for bug-gnu-emacs@HIDDEN; Tue, 14 Oct 2025 10:53:14 -0400
Received: from mailscanner.iro.umontreal.ca ([132.204.25.50])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <monnier@HIDDEN>)
 id 1v8gOl-000322-Pu
 for bug-gnu-emacs@HIDDEN; Tue, 14 Oct 2025 10:53:14 -0400
Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 85C7F440FFE
 for <bug-gnu-emacs@HIDDEN>; Tue, 14 Oct 2025 10:53:08 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca;
 s=mail; t=1760453587;
 bh=zS1GEk71CTTlH7XCZw4AaKR6NgiTDaRdLM6uFOJ28tE=;
 h=From:To:Subject:Date:From;
 b=Tm2EH7gLE51JdPt05mO3NpmuHCnonFBUilgrTg2LQCdCiB7tzg9C1lYmCg+MxJ1Gh
 Ey9qeTNfHvffs4SI7eiFQVtHsuWIDhPKZp0rGqfDKNKtSuPlI33hB3Yt5FenzQ8bjr
 tAvsPpZTeLc+lC4y/CYBf3RqOHelaVojHcC3G3Vt3zcTa1CsWPxwApPcdDFeWp0usl
 q7y0mn/Ff40YLgnFNrD1uPOLhuc0RrrdTqp89NMvDt0dncWp//ZbevrNk+rkqZwLCO
 +ObnKWop1tZAgRHNE4Blsa2Tfw/GCfYohDVJMHZite06ea0iRt9C22fZaHS8tKvzNu
 7dR8A87YF5now==
Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1])
 by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 094BE440FE4
 for <bug-gnu-emacs@HIDDEN>; Tue, 14 Oct 2025 10:53:07 -0400 (EDT)
Received: from asado (unknown [181.28.45.30])
 by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 72DCE1206AC
 for <bug-gnu-emacs@HIDDEN>; Tue, 14 Oct 2025 10:53:06 -0400 (EDT)
From: Stefan Monnier <monnier@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: [PATCH] (define-globalized-minor-mode): Remove `MODE-mode-name` hack
X-Debbugs-Cc: <monnier@HIDDEN>, Stefan Monnier <monnier@HIDDEN>
Date: Tue, 14 Oct 2025 10:52:43 -0400
Message-ID: <jwvplap358k.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-SPAM-INFO: Spam detection results:  0
 ALL_TRUSTED                -1 Passed through trusted hosts only via SMTP
 AWL -0.045 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DKIM_SIGNED               0.1 Message has a DKIM or DK signature,
 not necessarily valid
 DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature
 DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's
 domain
 DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from
 domain
X-SPAM-LEVEL: 
Received-SPF: pass client-ip=132.204.25.50;
 envelope-from=monnier@HIDDEN; helo=mailscanner.iro.umontreal.ca
X-Spam_score_int: -42
X-Spam_score: -4.3
X-Spam_bar: ----
X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3,
 RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,
 SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Tags: patch

`MODE-mode-name` and surrounding code was added by:

    commit 876daebc85940a3c6ff11c7077e1d74c87d87705
    Author: Luc Teirlinck <teirllm@HIDDEN>
    Date:   Sat Jun 4 22:13:57 2005 +0000

    (define-global-minor-mode): Make it keep track of which major mode it
    enabled the minor mode for.  Use find-file-hook again.  Update docstring.

This was designed to deal with cases where `global-font-lock-mode`
ended up enabling `font-lock-mode` too early, because
`MODE-enable-in-buffers` was called in the middle of the major mode's
setup, at a time where a parent mode's code had run, typically because
the buffer's major mode was not written with `define-derived-mode`, tho
there were other cases such as when major modes were enabled recursively
(e.g. because the outer major mode somehow called `find-file-noselect`
during its setup).

In the intervening years, major modes have learned to follow the
conventions, which made us recently install commit 17e26cf57e18.
With that commit, the circumstances where the problem can show up are
even less common, so I think it's time to remove that hack.


        Stefan


--=-=-=
Content-Type: text/x-patch
Content-Disposition: attachment;
 filename=0001-define-globalized-minor-mode-Remove-MODE-mode-name-h.patch

From 925856b6a29537ae4f4ebeb57f28fa90e080e63d Mon Sep 17 00:00:00 2001
From: Stefan Monnier <monnier@HIDDEN>
Date: Tue, 14 Oct 2025 10:29:13 -0400
Subject: [PATCH] (define-globalized-minor-mode): Remove `MODE-mode-name` hack

Stop trying to detect when a globalized mode enabled its
minor mode "too early".  This reverts the core of commit 876daebc8594
since the problem it tried to circumvent has been made almost impossible
by commit 17e26cf57e18.

* lisp/emacs-lisp/easy-mmode.el (define-globalized-minor-mode):
Remove the `MODE-mode-name` variable, don't remember in which major
mode we enabled the minor mode, and don't disable the minor mode
before (re)enabling it.
---
 lisp/emacs-lisp/easy-mmode.el | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 25e4f882295..a07636fa023 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -506,7 +506,6 @@ define-globalized-minor-mode
 	 (MODE-set-explicitly (intern (concat mode-name "--set-explicitly")))
          (MODE-suppress-set-explicitly (intern (concat mode-name
                                                        "--suppress-set-explicitly")))
-	 (MODE-major-mode (intern (concat global-mode-name "--major-mode")))
          (MODE-predicate (intern (concat (replace-regexp-in-string
                                           "-mode\\'" "" global-mode-name)
                                          "-modes")))
@@ -533,7 +532,6 @@ define-globalized-minor-mode
        (progn
          (put ',global-mode 'globalized-minor-mode t)
          :autoload-end
-         (defvar-local ,MODE-major-mode nil)
          ,@(when predicate `((defvar ,MODE-predicate))))
        ;; The actual global minor-mode
        (define-minor-mode ,global-mode
@@ -625,8 +623,7 @@ define-globalized-minor-mode
 
        ;; The function that calls TURN-ON in the current buffer.
        (defun ,MODE-enable-in-buffer ()
-         (unless (or ,MODE-set-explicitly
-                     (eq ,MODE-major-mode major-mode))
+         (unless ,MODE-set-explicitly
            (let (;; We are not part of the major mode hook so we don't
                  ;; want to set MODE-set-explicitly to t.
                  ;; In particular this is necessary when there are
@@ -634,12 +631,7 @@ define-globalized-minor-mode
                  ;; If one of them declines to turn the minor mode on,
                  ;; that should not mean the others can't.
                  (,MODE-suppress-set-explicitly t))
-             (if ,MODE-variable
-                 (progn
-                   (,mode -1)
-                   (funcall ,turn-on-function))
-               (funcall ,turn-on-function))))
-         (setq ,MODE-major-mode major-mode))
+             (funcall ,turn-on-function))))
        (put ',MODE-enable-in-buffer 'definition-name ',global-mode))))
 
 (defun easy-mmode--globalized-predicate-p (predicate)
-- 
2.51.0


--=-=-=--





Acknowledgement sent to Stefan Monnier <monnier@HIDDEN>:
New bug report received and forwarded. Copy sent to monnier@HIDDEN, monnier@HIDDEN, bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to monnier@HIDDEN, monnier@HIDDEN, bug-gnu-emacs@HIDDEN:
bug#79624; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 19 Oct 2025 14:00:01 UTC

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