Subject: bug#68246: 30.0.50; Add non-TS mode as extra parent of TS modes

From: João Távora <[email-masked]>
Date: Fri, 5 Jan 2024 23:37:46 +0000

On Fri, Jan 5, 2024 at 7:03 PM Stefan Kangas <[email-masked]> wrote:
>
> João Távora <[email-masked]> writes:
>
> > In summary, my position is that regardless of Stefan's patch, which
> > I'm not opposed to, we should:
> >
> > 1. Use add-derived-mode-parents sparingly and consider foo-base-mode when
> > possible.
>
> I agree that inheriting from a `foo-base-mode' is a good way to reuse
> code between different modes.  It's easy to think of examples of where
> this will be useful: looking up some documentation, running a REPL,
> interacting with a debugger, and so on and so forth.

Exactly.  It's much cleaner and I am happy to see exactly what
I had idealized is already in the tree.

> But even if we added all the base modes today (as empty stubs), AFAIU it
> wouldn't solve the exact problem that Monnier's patch is addressing,
> namely to make packages and customizations work in both foo-mode and
> foo-ts-mode even if they only say:
>
>     (derived-mode-p 'foo-mode)

That's why these packages should be changed to say

  (derived-mode-p 'foo-base-mode)

Or maybe

   (cl-some #'derived-mode-p '(foo-mode foo-base-mode))

I'm not sure there is a problem in doing that, is there?  I can confirm
there isn't in Eglot and Yasnippet, two packages that use major-mode
how Stefan Monnier described it.  How many more are there
and is it really so hard to change them?

Or is it that we're deliberately trying to establish that
'foo-mode' is the canonical symbol designating a family
of potentially many major modes -- including, somewhat
confusingly, 'foo-mode' itself -- that are used for editing foo
source code?

If so, fine, but this should be very well documented.  And yes,
definitely called out in *Help*.  The concept of "major-mode family"
could emerge, perhaps.

> So I'm not sure doing one excludes the other, or that one should be
> considered preferred over the other.  IOW, I'm not sure about the
> recommendation to use `add-derived-mode-parents' sparingly, as that
> would seem to defeat the point.

Indeed one may not exclude the other, depending on how feasible
it is for extensions to start using the foo-base-mode.

Maybe it depends what are these many packages that
use "major-mode" in such ways.

João