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

From: Eli Zaretskii <[email-masked]>
Date: Thu, 14 Nov 2024 08:59:32 +0200

> Date: Wed, 13 Nov 2024 22:34:19 +0000
> Cc: [email-masked], Stefan Monnier <[email-masked]>,
>   [email-masked]
> From: Alan Mackenzie <[email-masked]>
> 
> > > I did indeed amend CC Mode as I suggested, and that was the patch
> > > currently under discussion.  It is indeed not ideal.
> 
> > It isn't "not ideal", it is simply buggy!  We cannot possibly ignore
> > user preferences in this way.  Users are used to load c-ts-mode and
> > expect that all the C/C++ files after that are visited using that
> > mode.  Now this expression of user preferences is completely ignored!
> 
> Can I take it that you will respect the choice of users who wish to
> remain on CC Mode as much as those who wish the new tree-sitter modes?

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".

> > If the user prefers to use c-ts-mode, then revert-buffer _should_ use
> > c-ts-mode, not c-mode.  The same happens if you change the way
> > normal-mode determines the mode and then revert the buffer.  This
> > change in what revert-buffer does is now another user expectation your
> > change has broken, and it, too, must be fixed.
> 
> And if a user has made no such choice, normal-mode will forcibly change
> the major modes of their buffers, whether they like it or not.

No, it won't.  This could happen only if the user loads c-ts-mode
in-between, which means the user prefers c-ts-mode.  Without that,
normal-mode will always revert to c-mode in the default Emacs
configuration.

> > I'm not interested in having revert-buffer ignore user preferences of
> > using c-ts-mode, .....
> 
> Instead Emacs ignores the perfectly reasonable preference to have
> buffers modes stay the same as when the user set them.

Reverting the buffer activates whatever major mode corresponds to the
file name and other relevant settings at the moment of the reverting.
If you modify those settings in-between, it is quite possible (and
expected!) that normal-mode will activate a different mode.  This is
how Emacs always behaved (and should keep behaving).  Anything else is
against user expectations.

> > 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.

That's what I suggested.  If you agree, let's make that change and
move on.