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

From: Alan Mackenzie <[email-masked]>
Date: Thu, 14 Nov 2024 19:53:33 +0000

Hello, Eli.

On Thu, Nov 14, 2024 at 21:23:41 +0200, Eli Zaretskii wrote:
> > Date: Thu, 14 Nov 2024 17:45:28 +0000
> > Cc: [email-masked], [email-masked], [email-masked]
> > From: Alan Mackenzie <[email-masked]>

> > On Thu, Nov 14, 2024 at 18:59:53 +0200, Eli Zaretskii wrote:
> > > > Date: Thu, 14 Nov 2024 16:20:37 +0000
> > > > Cc: [email-masked], [email-masked], [email-masked]
> > > > From: Alan Mackenzie <[email-masked]>

> > [ .... ]

> > > > OK.  It would seem there is then no need to put entries for
> > > > c-mode/c-ts-mode into major-mode-remap-defaults.  I don't think this
> > > > solution is optimal, though.  Perhaps we can come up with something
> > > > better for Emacs 31.  But let's just go with this "last loaded wins"
> > > > strategem for Emacs 30.

> > > OK, thanks.  So I guess you will soon make that change in cc-mode.el
> > > on the release branch?

> > OK, I can manage that.

> > I'll just outline a quick outline of what I see is to be done, so as to
> > fix any misunderstandings before starting to hack the code:

> > (i) CC Mode and c-ts-mode will both keep their autoload directives.
> > (ii) On loading either library, all their auto-mode-alist entries will be
> >   refreshed.  By "refresh" is meant they will be removed from
> >   auto-mode-alist (if present) and put back again at the top of that
> >   alist.
> > (iii) Evaluating a mode command does not change auto-mode-alist (except
> >   when it causes an autoload).
> > (iv) The manipulations of major-mode-remap-defaults by both libraries
> >   will be removed, since they are redundant.

> > Any comments?

> I prefer to make a simpler and more localized change, which only
> manipulates major-mode-remap-defaults.  I would not like to risk
> changes like modifying auto-mode-alist, which might have other
> unintended consequences, at least on the release branch.

I thought we'd agreed to fix things by modifying auto-mode-alist.

What we definitely agreed was that the old modes and the tree-sitter
modes should be handled symmetrically, and that C Mode and friends
wouldn't be disadvantaged.

> Let's stay with major-mode-remap-defaults, since we already understand
> well enough what the code does, and need just to tweak it in minor
> ways.

OK, then the following suggests itself.  We have symbols like
`current-c-mode' which would be remapped in major-mode-defaults-alist,
and would be the cdrs of the entries in auto-mode-alist.  We would remap
`current-c-mode' each time cc-mode.el or c-ts-mode.el was loaded.  This
would avoid the need to modify auto-mode-alist at run time, and also
avoid all the disadvantages of remapping `c-mode' itself.

-- 
Alan Mackenzie (Nuremberg, Germany).