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 16:00:58 +0200 Message-ID: <868qtnfd2d.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21092"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Alan Mackenzie To: 74339@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Nov 13 15:02:15 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 1tBDwl-0005MW-GK for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 13 Nov 2024 15:02:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tBDwf-0008M6-2h; Wed, 13 Nov 2024 09:02:09 -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 1tBDwZ-0008Lk-KC for bug-gnu-emacs@gnu.org; Wed, 13 Nov 2024 09:02: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 1tBDwZ-0005V3-Ae for bug-gnu-emacs@gnu.org; Wed, 13 Nov 2024 09:02:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=From:Date:To:Subject; bh=E28xLmGTdsxMDXfCC/ZH5uc7nplRjzR+kyORy3v1UUE=; b=oYsZtzEMGuv2MffVvfGkgsjcIk3Q5naSXVcNOGPymNzmz4M6IFfkMhmpAb/yhLBsOwOCfff/BRGY7yRZpMgeOL+TMZ1bF2qdE7aJQcHDMNxpVXF3MP0jZ8Cd+atf5+MMVuTw9rX0rCaf4hIRpY3g+WJzcLhhMx3kf6d326gGxv34qTrb3V1/E6Cy0P2MJ/TKIK6OsjAnQw2kbK63PtSELKWguaGlZ2p7eXWwx8YHxE0/jOBCQkGprx3EgQFmTyH3m+OKa0EmYjdWh9F4LkFweGmHE7UcBRwyZ/ds9hPfnL5TBUtmNWWEoMbnKTNNmPFYTFb0t2qtMjK0NPcaUACb6Q==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tBDwY-0000Eg-Ll; Wed, 13 Nov 2024 09:02:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: acm@muc.de, bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 Nov 2024 14:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 74339 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Alan Mackenzie Original-Received: via spool by submit@debbugs.gnu.org id=B.1731506514881 (code B ref -1); Wed, 13 Nov 2024 14:02:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 13 Nov 2024 14:01:54 +0000 Original-Received: from localhost ([127.0.0.1]:41316 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBDwQ-0000E9-8r for submit@debbugs.gnu.org; Wed, 13 Nov 2024 09:01:54 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:36396) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tBDwO-0000E0-Os for submit@debbugs.gnu.org; Wed, 13 Nov 2024 09:01:53 -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 1tBDwK-0008B9-TL for bug-gnu-emacs@gnu.org; Wed, 13 Nov 2024 09:01:52 -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 1tBDw1-0005SB-HF for bug-gnu-emacs@gnu.org; Wed, 13 Nov 2024 09:01:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=Subject:To:From:Date:mime-version:in-reply-to: references; bh=E28xLmGTdsxMDXfCC/ZH5uc7nplRjzR+kyORy3v1UUE=; b=JFWXKcsFua78Nh VsaWpVUfYDMWCCjqVeSapqfja98OMjEJI5kMmM9ANMQi6dMCKy86Hv4VqoPWxbX/rNUrAMQi1dCLD Kz3qUTnFGLfincDWYzHZaGGB6gyRmFp0uxM6RPOAVQPJIqbCxmN2rOiUzDT7ABnIhk3SRQFt5tczL fVp3wbCpQa2ylJsz4vhJ6y9dyScy844tgbziuSR3xCsVzAC1jeiRcJRBDGiBhrEM5kvr6HEJdY9kl 77bKAj0CNWFKRP0ichAuF9Uc4+tV9VDn0V59+waJfOw7FAp1mywe9yDm1Y318QkeBWWge+3Y2/RHj 2zzDiuUaJWD0oXrWOH4g==; 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:295273 Archived-At: 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. In GNU Emacs 30.0.92 (build 21, i686-pc-mingw32) of 2024-11-11 built on ELIZ-PC Windowing system distributor 'Microsoft Corp.', version 10.0.22631 System Description: Microsoft Windows 10 Enterprise (v10.0.2009.22631.4460) Configured using: 'configure -C --prefix=/d/usr --with-wide-int --enable-checking=yes,glyphs --without-native-compilation 'CFLAGS=-O0 -gdwarf-4 -g3'' Configured features: ACL GIF GMP GNUTLS HARFBUZZ JPEG LCMS2 LIBXML2 MODULES NOTIFY W32NOTIFY PDUMPER PNG RSVG SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XPM ZLIB Important settings: value of $LANG: ENU locale-coding-system: cp1252 Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t minibuffer-regexp-mode: t line-number-mode: t indent-tabs-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message mailcap yank-media puny dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util text-property-search time-date subr-x mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils c++-ts-mode c-ts-mode c-ts-common treesit cl-loaddefs cl-lib thingatpt find-func rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel touch-screen dos-w32 ls-lisp disp-table term/w32-win w32-win w32-vars term/common-win tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic indonesian philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget keymap hashtable-print-readable backquote threads w32notify w32 lcms2 multi-tty move-toolbar make-network-process emacs) Memory information: ((conses 16 49304 16294) (symbols 48 6997 0) (strings 16 17805 2859) (string-bytes 1 375146) (vectors 16 10077) (vector-slots 8 114927 6271) (floats 8 25 6) (intervals 40 301 140) (buffers 896 10))