Subject: bug#74339: 30.0.92; CC Mode stomps C TS Mode

From: Eli Zaretskii <[email-masked]>
Date: Sun, 24 Nov 2024 09:41:29 +0200

> From: Richard Stallman <[email-masked]>
> Cc: [email-masked]
> Date: Sat, 23 Nov 2024 23:35:10 -0500
> 
>   > I've now made changes in c-ts-mode.el on the emacs-30 branch that
>   > allow to remap CC Mode's C/C++ modes to the corresponding tree-sitter
>   > based modes as result of loading c-ts-mode, which resolves this bug.
>   > (cc-mode.el remains unchanged, so loading cc-mode will revert to using
>   > CC Mode, as it did before this change.  IOW, the changes I installed
>   > make it possible for users to prefer c-ts-mode if they want, and leave
>   > intact the ability of users to prefer cc-mode if that is what they
>   > want.)
> 
> This does help a user insist on c-mode rather than c-ts-mode.
> However, setting that switch by loading file A or file B is not
> natural.  In Emacs we try to have a user option to control such a
> choice.
> 
> How about making a user option that will be tested on every occasion
> whet it is time to put a buffer in one of those modes?

It's more complicated than that.  The situation where more than one
major mode is appropriate for certain contents of a buffer is new in
Emacs, we first encountered it in Emacs 29, quite close to its
release.  The solution took a couple of iterations, but eventually I
decided that loading a mode will be the best alternative in the short
term, although it has known issues.

We are currently discussing the possible improvements, which include
user option and more, in this thread:

  https://lists.gnu.org/archive/html/emacs-devel/2024-11/msg00636.html

> The simplest way is to call the option `c-mode-use-tree-sitter'.  I
> think a similar option will be needed for each major mode that has a
> TS counterpart.  We could have an option like that for each of those
> major modes.

That is one possibility, but I'm not sure it's the best one.  For
example, if the user wants to prefer several such modes, calling a
command for each one of them would be a nuisance.  Also, having a
separate command for each mode makes this harder to remember.

There are also some issues regarding the implementation that we need
to figure out.

> Other user interfaces involving a single option to specify which
> modes should get tree-sitter handling can be considered.
> I think the goals are
> 
> (1) the Customize interface should handle these options cleanly.
> 
> (2) a user should be able to set this just once, and the setting will
> stick in future Emacs versions (unless the user explicitly changes it)
> as long as this aspect of Emacs doesn't fundamentally change.
> 
> There could also be a command M-x major-mode-use-tree-sitter which
> would toggle that switch for the current major mode.  So if you use
> that command while in a C mode buffer, it would change the value of
> `c-mode-use-tree-sitter'.  Perhaps it would also change the major mode
> in each buffer that uses `c-mode' or `c-ts-mode'.

All of this (and more) is in scope of the above discussion.  I hope we
will have a much better solution for this in Emacs 31.