[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#74339: 30.0.92; CC Mode stomps C TS Mode
From: |
Eli Zaretskii |
Subject: |
bug#74339: 30.0.92; CC Mode stomps C TS Mode |
Date: |
Wed, 13 Nov 2024 17:13:36 +0200 |
> Cc: Alan Mackenzie <acm@muc.de>
> Date: Wed, 13 Nov 2024 16:00:58 +0200
> From: Eli Zaretskii <eliz@gnu.org>
>
> 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.
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Eli Zaretskii, 2024/11/13
- bug#74339: 30.0.92; CC Mode stomps C TS Mode,
Eli Zaretskii <=
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Alan Mackenzie, 2024/11/13
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Eli Zaretskii, 2024/11/13
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Alan Mackenzie, 2024/11/13
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Stefan Monnier, 2024/11/13
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Eli Zaretskii, 2024/11/14
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Dmitry Gutov, 2024/11/14
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Eli Zaretskii, 2024/11/14
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Andrea Corallo, 2024/11/16
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Stefan Monnier, 2024/11/14
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Dmitry Gutov, 2024/11/14