Subject: bug#61211: 28.2; Feature request; facility for dispatch type major mode

From: Stefan Monnier <[email-masked]>
Date: Tue, 09 May 2023 11:21:20 -0400

> I'd like to discuss dispatch functions or "superficial" major modes.
> AUCTeX has the following major mode functions:
> context-en-mode, context-nl-mode, japanese-latex-mode, japanese-plain-tex-mode
> They only do language-specific set-ups and turn into context-mode,
> latex-mode or plain-tex-mode eventually. In some aspects, they are
> similar with dispatch functions `tex--guess-mode' and `TeX-tex-mode'
> (AUCTeX) which guess a proper major mode and call it:
> - They can be specified as `mode' tag of file local variable and entry
>   of `auto-mode-alist'.
> - They never hold their own `major-mode' value.
> - When called, they eventually turn into another proper major mode.
> For these reasons, they can be called "superficial" major modes.
>
> Note that it isn't enough to define them like
> (define-derived-mode japanese-latex-mode latex-mode "LaTeX"
>   ...
>   (setq major-mode 'latex-mode)
>   ...)

IOW what are the advantages/disadvantages of using (setq major-mode
'latex-mode) above?

Also, this seems different from the case of dispatch functions like
`tex--guess-mode' and `TeX-tex-mode' since these may end up choosing
`latex-mode` but they're definitely not "child" of `latex-mode`.

[ Similarly for the tree-sitter case mentioned in another message: the
  function that dispatches to TS-vs-nonTS major modes can't be considered
  a child of those two major modes.  ]

> because it doesn't respond to directory local variable entry of the form
> ((japanese-latex-mode
>   ...))
> in that case.

If we make `japanese-latex-mode` a proper child mode, then this problem
disappears, right?

I'm also thinking that maybe `set-auto-mode` should remember the name of
the "mode function" it called so we could consult this (in addition to
the value of `major-mode`) when applying directory-local vars?

        Stefan