[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#74339: 30.0.92; CC Mode stomps C TS Mode
From: |
Stefan Monnier |
Subject: |
bug#74339: 30.0.92; CC Mode stomps C TS Mode |
Date: |
Thu, 14 Nov 2024 12:29:49 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
>> 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
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, (continued)
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Dmitry Gutov, 2024/11/15
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Eli Zaretskii, 2024/11/21
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Alan Mackenzie, 2024/11/21
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Dmitry Gutov, 2024/11/21
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Eli Zaretskii, 2024/11/21
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Eli Zaretskii, 2024/11/23
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Dmitry Gutov, 2024/11/23
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Eli Zaretskii, 2024/11/24
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Richard Stallman, 2024/11/23
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Eli Zaretskii, 2024/11/24
- bug#74339: 30.0.92; CC Mode stomps C TS Mode,
Stefan Monnier <=
- 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, Stefan Monnier, 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, Stefan Monnier, 2024/11/14
- 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, Eli Zaretskii, 2024/11/15
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Eli Zaretskii, 2024/11/15
- bug#74339: 30.0.92; CC Mode stomps C TS Mode, Stefan Monnier, 2024/11/15
- 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/13