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

From: Eli Zaretskii <[email-masked]>
Date: Thu, 14 Nov 2024 12:05:07 +0200

> Date: Thu, 14 Nov 2024 11:24:32 +0200
> Cc: [email-masked], [email-masked]
> From: Dmitry Gutov <[email-masked]>
> 
> On 14/11/2024 08:59, Eli Zaretskii wrote:
> >> 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".
> 
> JFYI, 'M-x js-ts-mode' loads cc-mode.

That's because js.el does that.  This was so in Emacs 29 already.  And
there are other packages that do the same:

  $ fgrep -R "(require 'cc-mode)" ../lisp --include="*.el"
  ../lisp/generic-x.el:1275:(require 'cc-mode)
  ../lisp/org/ob-C.el:39:(require 'cc-mode)
  ../lisp/org/ob-fortran.el:36:(require 'cc-mode)
  ../lisp/progmodes/antlr-mode.el:84:(require 'cc-mode)
  ../lisp/progmodes/cmacexp.el:91:(require 'cc-mode)
  ../lisp/progmodes/csharp-mode.el:34:(require 'cc-mode)
  ../lisp/progmodes/cwarn.el:107:(require 'cc-mode)
  ../lisp/progmodes/hideif.el:120:(require 'cc-mode)
  ../lisp/progmodes/js.el:48:(require 'cc-mode)

I guess users who use these features and want to use c-ts-mode as
their C major mode will need to use with-eval-after-load to restore
the preferences after loading one of these packages (or customize
major-mode-remap-alist).  Ugh!

> >> 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 personally skeptical that loading a package (or invoking a mode) 
> indicates a strong user preference, but ok, let's call it that.

We can change this in Emacs 31, but it's too late for Emacs 30.