From: Eli Zaretskii <eliz@gnu.org>
To: 74339@debbugs.gnu.org
Cc: Alan Mackenzie <acm@muc.de>
Subject: bug#74339: 30.0.92; CC Mode stomps C TS Mode
Date: Wed, 13 Nov 2024 16:00:58 +0200 [thread overview]
Message-ID: <868qtnfd2d.fsf@gnu.org> (raw)
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))
next reply other threads:[~2024-11-13 14:00 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-13 14:00 Eli Zaretskii [this message]
2024-11-13 15:13 ` bug#74339: 30.0.92; CC Mode stomps C TS Mode Eli Zaretskii
2024-11-13 18:58 ` Alan Mackenzie
2024-11-13 20:13 ` Eli Zaretskii
2024-11-13 22:34 ` Alan Mackenzie
2024-11-13 22:57 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 6:59 ` Eli Zaretskii
2024-11-14 9:24 ` Dmitry Gutov
2024-11-14 10:05 ` Eli Zaretskii
2024-11-14 15:51 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 16:29 ` Dmitry Gutov
2024-11-14 16:49 ` Eli Zaretskii
2024-11-14 17:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 19:10 ` Eli Zaretskii
2024-11-14 19:45 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 16:20 ` Alan Mackenzie
2024-11-14 16:59 ` Eli Zaretskii
2024-11-14 17:45 ` Alan Mackenzie
2024-11-14 17:52 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 19:23 ` Eli Zaretskii
2024-11-14 19:53 ` Alan Mackenzie
2024-11-14 20:21 ` Eli Zaretskii
2024-11-14 20:38 ` Alan Mackenzie
2024-11-14 21:06 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 21:26 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 17:29 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 19:20 ` Eli Zaretskii
2024-11-14 19:38 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 20:37 ` Eli Zaretskii
2024-11-14 20:58 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-14 22:06 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-13 20:28 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-13 20:42 ` Eli Zaretskii
2024-11-13 20:46 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=868qtnfd2d.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=74339@debbugs.gnu.org \
--cc=acm@muc.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).