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

From: Stefan Kangas <[email-masked]>
Date: Fri, 15 Nov 2024 12:58:02 -0800

Alan Mackenzie <[email-masked]> writes:

> On Fri, Nov 15, 2024 at 14:01:26 -0500, Stefan Monnier wrote:
>> > One can write, in the Local Variables: section
>
>> >     mode: c-ts
>
>> FWIW, unless this file is personal, this is very bad practice, and not
>> only because `c-ts-mode` may not be available (in older Emacsen or if
>> the user didn't build Emacs with tree-sitter support or doesn't have the
>> appropriate grammar installed): the choice between `c-mode` and
>> `c-ts-mode` is a personal preference, so it's not the file's business to
>> tell the user which mode to use, just like it's not the file's business
>> to tell the user which editor to use.

+1

> Here is a section of a test file sent to bug-cc-mode some while ago:
>
> /*
> ** Local Variables:
> ** mode:c
> ** indent-tabs-mode:nil
> ** c-basic-offset:4
> ** End:
> */
>
> Here it is evident that by "mode:c" the OP means C Mode, not whatever
> random mode happens to have taken the symbol `c-mode'.

Yes, that is how Emacs behaves by default.

However, the point of the new feature, major-mode-remap, is exactly to
allow users to override that.  This new feature is optional, and AFAICT
the user choice is explicit and not "random".

Clearly, c-mode is still favored, as it is the default, and many of us
continue being happy users of it even while running a treesitter build.
So this new feature very clearly only affects users that have somehow
explicitly indicated that they want to use c-ts-mode instead.

>> > ..  This will cause the buffer to start in c-ts-mode regardless of any
>> > other current settings.
>
>> Actually, no: `major-mode-remap-*` can also remap `c-ts-mode` to some
>> other mode, such as `c-mode`.
>
> Maybe I should have said "regardless of any non-crazy settings".

What makes anything about that setting crazy?

I'd use that setting, if I ever ran into any files with a "-*- c-ts -*-"
cookie.  Similarly, I expect that c-ts-mode users will want to use
c-ts-mode precisely when a file has a "-*- c -*-" cookie.

Again, being able to do that is exactly the point of major-mode-remap.
I struggle to understand why that flexibility is controversial.  It
puts more power into users' hands, that's all.