emacs-devel
[Top][All Lists]
Advanced

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

Tree-sitter and major mode inheritance


From: Yuan Fu
Subject: Tree-sitter and major mode inheritance
Date: Wed, 16 Nov 2022 12:45:30 -0800

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


reply via email to

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