From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#74339: 30.0.92; CC Mode stomps C TS Mode Date: Wed, 13 Nov 2024 17:13:36 +0200 Message-ID: <86ttcbkvz3.fsf@gnu.org> References: <868qtnfd2d.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6358"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, 74339@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 13 16:14:19 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tBF4T-0001US-CO for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 13 Nov 2024 16:14:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBF4H-0002RJ-3G; Wed, 13 Nov 2024 10:14:05 -0500 Original-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 ) id 1tBF4F-0002Qq-1B for bug-gnu-emacs@gnu.org; Wed, 13 Nov 2024 10:14:03 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tBF4E-00064y-6M for bug-gnu-emacs@gnu.org; Wed, 13 Nov 2024 10:14:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=Yjw6CQ8daflrlwP6LgXiIYBbkUYgsKdO+hM0F2O2zWs=; b=NqlASELOIBSPxZDjrsdLIB6DfShPV/TNwFbW+m6lMs2kgxMDaKqLJ0OjvvJjMOaaBMZ62M8qRS4Ee3igFEeBkKIbrdcBfxBtlJq+bVPvPHURFOK33Eca4/EYevnRYS7QHkYgsoahGeiS8yAdsLb8GKxwiXnxHZRlBSWhpcXSfgQqcKXuemFD6Us7Zf4/MYJB42NbSS8HKN5bJ7bRBajDxmf3EPlONyNC31DZXzccQzXJt6za3M5O+08s977A5YmRm0tKNmJIBY6PLzLm8wq9mykRvOisQdKEUFfx44PJXDf2WKrR9g6vFjFpLuX2scDLZ2CfChR9gKnYdER+T3LSNw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tBF4E-0003yp-1X for bug-gnu-emacs@gnu.org; Wed, 13 Nov 2024 10:14:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 Nov 2024 15:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74339 X-GNU-PR-Package: emacs Original-Received: via spool by 74339-submit@debbugs.gnu.org id=B74339.173151083515279 (code B ref 74339); Wed, 13 Nov 2024 15:14:01 +0000 Original-Received: (at 74339) by debbugs.gnu.org; 13 Nov 2024 15:13:55 +0000 Original-Received: from localhost ([127.0.0.1]:43119 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBF47-0003yN-Bg for submit@debbugs.gnu.org; Wed, 13 Nov 2024 10:13:55 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:57766) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBF46-0003yA-67 for 74339@debbugs.gnu.org; Wed, 13 Nov 2024 10:13:54 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tBF3y-00063i-Ug; Wed, 13 Nov 2024 10:13:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Yjw6CQ8daflrlwP6LgXiIYBbkUYgsKdO+hM0F2O2zWs=; b=GopMfzFA415x p5gezfNyQ/yJCcTyksFpLuk/M2dP7pHbpI5T9rid+BejZKF/1ChSiNjEzOOjF795u6UWphk74NEG1 7mXTkK+jpgsWLa6qdrGA28q3PPlm/LLzS9VJUbjRLrzlZRCa/g+kQoMerQFL0QEbpKvwx+KpyLeov cR1nrnGSiD4RqmCfaEMaJEaoG+1tYCm+9JODv7MT2b2iTIb4HYHURyJ5Ls6u7xfj/G4Sh74T9ExYd ZX3h5vq1v03Jxt6ejeUC0NldGxaiiC7jKB4ra1LIf17sVoRKQGKSvEL/6H5VpKFf+ELP+A1Y0R2mV acf2zWGF12evnGpXazwawA==; In-Reply-To: <868qtnfd2d.fsf@gnu.org> (message from Eli Zaretskii on Wed, 13 Nov 2024 16:00:58 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:295278 Archived-At: > Cc: Alan Mackenzie > Date: Wed, 13 Nov 2024 16:00:58 +0200 > From: Eli Zaretskii > > To reproduce: > > emacs -Q > M-x load-library RET c-ts-mode RET > C-x C-f src/buffer.c > M-: major-mode RET > => c-ts-mode > > So far, so good: the user loads c-ts-mode, which means she prefers > C/C++ TS Mode for C and C++ files, so visiting a C file turns on > c-ts-mode instead of the default CC Mode. > > But: > > emacs -Q > C-x C-f src/dispnew.c RET > M-x load-library RET c-ts-mode RET > C-x C-f src/buffer.c > M-: major-mode RET > => c-mode > > This is unexpected. It means that if even a single file loads CC > Mode, the user's preference of using C TS Mode is effectively ignored. > > This seems to happen due to this code in cc-mode.el: > > ;; Make entries in `major-mode-remap-defaults' to ensure that when CC > ;; Mode has been loaded, the symbols `c-mode' etc., will call CC Mode's > ;; modes rather than c-ts-mode etc.. > (when (boundp 'major-mode-remap-defaults) > (add-to-list 'major-mode-remap-defaults '(c++-mode . c++-ts-mode)) > (add-to-list 'major-mode-remap-defaults '(c-mode . c-ts-mode)) > (add-to-list 'major-mode-remap-defaults '(c-or-c++-mode . c-or-c++-ts-mode)) > (let (entry) > (dolist (mode '(c-mode c++-mode c-or-c++-mode)) > (if (and (setq entry (assq mode major-mode-remap-defaults)) > (null (cdr entry))) > (setq major-mode-remap-defaults > (delq entry major-mode-remap-defaults))) > (push (cons mode nil) major-mode-remap-defaults)))) > > Here's what major-mode-remap-defaults looks like when I load c-ts-mode > into "emacs -Q": > > ((c-or-c++-mode . c-or-c++-ts-mode) (c-mode . c-ts-mode) (c++-mode . c++-ts-mode) (LaTeX-mode . latex-mode) (plain-TeX-mode . plain-tex-mode) (TeX-mode . tex-mode)) > > And here's how it looks if I first visit a C file (which loads > cc-mode): > > ((c-or-c++-mode) (c++-mode) (c-mode) (c-or-c++-mode . c-or-c++-ts-mode) (c-mode . c-ts-mode) (c++-mode . c++-ts-mode) (LaTeX-mode . latex-mode) (plain-TeX-mode . plain-tex-mode) (TeX-mode . tex-mode)) > > The above snippet from cc-mode.el was installed this last May, with > the following log message: > > In normal-mode, make c-mode call c-mode when CC Mode is loaded > > As regards which mode normal-mode calls for the symbols c-mode, > etc., the first of the following which applies holds: > (i) If the user has made a pertinent entry in > major-mode-remap-alist, this is used. > (ii) If CC Mode has been loaded, c-mode is called. > (iii) If library c-ts-mode has been loaded, c-ts-mode is > called. > (iv) Otherwise c-mode is called. > > * lisp/progmodes/cc-mode.el (top level): Add entries to > major-mode-remap-defaults to implement the above. > > I don't quite understand the rationale (and even less the > implementation), and don't recall any discussions of this; there's > also no bug number for it. But clearly the result is not acceptable, > and I very much hope that there's some simple bug here that can be > fixed real soon. If the above is not a bug, but the intended (by you, > Alan) behavior, then we need to talk about changing it, because this > is not how user preferences in this regard are supposed to be heeded > by Emacs. > > The expected behavior is: as soon as the user loads c-ts-mode, all the > subsequent C/C++ files are visited using C/C++ TS Mode. To revert > back to CC Mode, the user must load cc-mode again. And adding Stefan to the discussion, since he wrote the major-mode-remap-defaults stuff in c-ts-mode.el.