From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74339: 30.0.92; CC Mode stomps C TS Mode Date: Thu, 14 Nov 2024 12:29:49 -0500 Message-ID: References: <868qtnfd2d.fsf@gnu.org> <86r07elwoh.fsf@gnu.org> <86h68al2qz.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32225"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , 74339@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 14 18:30:34 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 1tBdfs-00088y-V5 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 14 Nov 2024 18:30:33 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBdfU-0003eG-93; Thu, 14 Nov 2024 12:30:08 -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 1tBdfP-0003bz-NH for bug-gnu-emacs@gnu.org; Thu, 14 Nov 2024 12:30:04 -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 1tBdfP-00022Z-EZ for bug-gnu-emacs@gnu.org; Thu, 14 Nov 2024 12:30:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=G7bUEKnHe2MwXev5BlQm5H/TbkRvFaSE5Kqt869QeLU=; b=NdK/Wf05XNY7SDS3gc5ib33Dp+nkADcj6Cdjz2ET0bqcLLLgv6MzYLngW/o2lboiPTtg94GCN4GtHEL4B0uYyO0HjJ8LJ1JbduxVNBmwDzuvueRDv/MQM/zXni+gzXK2kH7Y6CQ82CCgfKe8zJOxgaHcrkxmFnxHwhfXUksHNLe5okPXZERIm3YVXtjS+1jsRTxN6pNKL6io7GJgp4bvzinVks1e36WECe8meWUADlHdeS/AhG+fa+Cl/v7vNnMisDTXu2ThHQaTy8lBa1uYCQf4j6GqIzjsbEITjr9iDedfGusCCSYNujDCHTkfeItrBGhoJqsQrj4DfV+XDHb9rg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tBdfP-00024l-2b for bug-gnu-emacs@gnu.org; Thu, 14 Nov 2024 12:30:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Nov 2024 17:30:03 +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.17316054017932 (code B ref 74339); Thu, 14 Nov 2024 17:30:03 +0000 Original-Received: (at 74339) by debbugs.gnu.org; 14 Nov 2024 17:30:01 +0000 Original-Received: from localhost ([127.0.0.1]:47038 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBdfM-00023s-DV for submit@debbugs.gnu.org; Thu, 14 Nov 2024 12:30:00 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:24746) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBdfJ-00023S-UB for 74339@debbugs.gnu.org; Thu, 14 Nov 2024 12:29:58 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 0560C442B65; Thu, 14 Nov 2024 12:29:52 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1731605390; bh=IFp6tKn8N4smSeIukKPXqVSch16vMJwIhSZ5oS//n6A=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=L3omcXzn2TvSZzQ/nZIo7DYie9HLFBrJtXO4SfiuYpYww25BnLpdkYnx6jdDjfbuN XcWwNgfO/trkrGj/iBljrB2ivam5x7MFR5ToFVnxS8gBfvIT7R6rV02QZCwr/qoewn fM2Yr0nZNuTQq0cjn88CttPef7/kAn/e84sEVdVu8F0qqt38+JgiOIVFe68PmQICfR MOLs9p7OSUOnwu+BpRWLAd6W7E0q0NVmNv/7zHnfLA8eq9h+cQnUj4Ol3TZy/6vDcQ CC+85LOiEYOKFIIpPU1jOwY5CvKrVc5wZ95HGsiQTvdBEmPtAkNzMU0GgOxhqIwrj9 7R1ctaM2WjhdA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 7CD46442B14; Thu, 14 Nov 2024 12:29:50 -0500 (EST) Original-Received: from alfajor (modemcable005.21-80-70.mc.videotron.ca [70.80.21.5]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 5303412030F; Thu, 14 Nov 2024 12:29:50 -0500 (EST) In-Reply-To: (Alan Mackenzie's message of "Thu, 14 Nov 2024 16:20:37 +0000") 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:295351 Archived-At: >> Of course! That's what happens by default if the user didn't load >> c-ts-mode, and (under my suggested idea of a change) will happen if >> the user loads cc-mode after loading c-ts-mode. IOW, the last mode >> loaded will "win". > > This is also not ideal, in that M-x c-ts-mode will mostly not change the > preferred mode, but will do if it causes an autoload. I've been trying > to think up something better, but all that springs to mind would be two > commands `cc-mode-prefer' and `c-ts-mode-prefer'. There are two issues: setting `major-mode-remap-defaults` which is about guessing what the user's preference should be, and setting `major-mode-remap-alist` which reflects an explicit user act to state their preference. New commands `cc-mode-prefer' and `c-ts-mode-prefer' would customize `major-mode-remap-alist` whereas the code we're discussing is the one that sets `major-mode-remap-defaults`. Maybe we shouldn't set `major-mode-remap-defaults` at all, and instead when the user calls `c-(ts-)mode` but the `major-mode-remap-alist` selects the other mode, we should just emit a message telling the users to customize `major-mode-remap-alist` (or to call `c*-mode-prefer`) if they want to use that mode by default. >> > > If we can fix Emacs to behave like I described, i.e. return to the >> > > state where C/C++ files are visited in cc-mode rather than in >> > > c-ts-mode, just by reloading cc-mode, would you agree with such a fix? > >> > I think so, provided there was symmetry between the tree-sitter modes and >> > CC Mode. I would suggest the obvious fix; loading either one of the >> > libraries should append its entries to auto-mode-alist, having removed >> > any "lower down" entries. Not quite: `auto-mode-alist` should always map `.c` files to `c-mode`. The choice between `c-mode` and `c-ts-mode` should be made via `major-mode-remap-*`. That's what those vars are for. So loading either mode should not change `auto-mode-alist`. IIUC the proposal to use the "last loaded" mode would be obtained, by making the two files set `major-mode-remap-defaults` accordingly. `c-ts-mode.el` already does that, so all we need is to change `cc-mode.el` so it puts itself first but doesn't prevent `c-ts-mode.el` from putting itself first in the future (contrary to what it currently does). The patch I sent earlier should do just that (by removing the entries added by `c-ts-mode.el` rather than by adding entries, so as to avoid growing `major-mode-remap-defaults` unnecessarily). Stefan