emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tree-sitter and major mode inheritance


From: Yuan Fu
Subject: Re: Tree-sitter and major mode inheritance
Date: Sat, 19 Nov 2022 01:41:47 -0800


> On Nov 16, 2022, at 12:45 PM, Yuan Fu <casouri@gmail.com> wrote:
> 
> So I’m trying to merge css-ts-mode with css-mode. Scss-mode inherits 
> css-mode, but if user enables tree-sitter for css-mode, scss-mode will 
> inherit all that tree-sitter setup, and lose all the native css setup. Then 
> if a user doesn’t want to enable tree-sitter in scss-mode, too bad: scss-mode 
> breaks.
> 
> Essentially scss-mode needs to be able to control which parts of css-mode’s 
> setup it wants to inherit—native setup or tree-sitter setup—regardless of 
> whether css-mode enables tree-sitter or not.
> 
> I wonder if we can do something like this:
> 
>             css-mode
>                 |
>       +---------+-----+-----------+
>       |               |           |
> css-native-mode   css-ts-mode  scss-mode
>                                   |
>                              +----+------------+
>                              |                 |
>                        scss-native-mode   scss-ts-mode
> 
> css-mode: a virtual mode, only sets up basic things that both native and 
> tree-sitter mode needs, like comment-start.
> css-native-mode: native setup
> css-ts-mode: tree-sitter setup
> 
> scss-mode: a virtual mode, inherits css-mode
> scss-native-mode: native setup
> scss-ts-mode: tree-sitter setup
> 
> And user could use major-mode-remap-alist to choose which mode they want:
> 
> (css-mode . css-ts-mode) for enabling tree-sitter
> (css-mode . css-native-mode) for not enabling tree-sitter
> 
> This could also used for other modes, like c-mode: c-mode, c-native-mode 
> (cc-mode), c-ts-mode.
> 
> Yuan

Anyway, does anyone think this is a good/bad idea? Should I go implement this 
on css, js, c, etc? It can also be the other way around: instead of having 
c-mode being the virtual mode, we can leave c-mode as-is, and have a 
c-base-mode inherited by c-mode and c-ts-mode. And similarly rss-base-mode, 
rss-mode, and rss-ts-mode.

Yuan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]