Subject: Re: bug#74610: 31.0.50; Submitting mhtml-ts-mode, treesitter alternative to mhtml-mode

From: Yuan Fu <[email-masked]>
Date: Fri, 17 Jan 2025 17:37:53 -0800

> On Jan 14, 2025, at 1:41 PM, Vincenzo Pupillo <[email-masked]> wrote:
> 
> Ciao Yuan and Juri, 
> this is an updated version of mhtml-ts-mode. 
> I have tried to reduce as much as possible copies of parts of the major modes 
> from which it is derived.
> To do this, I had to move some values that were assigned directly to treesit's 
> own variables  (in ccs-mode.el, in js.el, and in html-ts-mode.el) into new 
> variables. 
> I also added three new functions to treesit.el to make it easier to combine 
> parts derived from the other major modes. So now any changes to these new 
> variables are directly reflected in the behavior of mhtml-ts-mode.
> There are a few things I would like to highlight:
> 1. treesit-font-lock-feature-lists are not defined per parser, so simply 
> merging the different lists will cause display differences from the original 
> major-modes; for example “function” is defined at level 3 in css-ts-mode but 
> at level 4 in js-ts-mode.

Yeah, that’s not pretty, I don’t have a good solution for now. Technically a major mode can use treesit-font-lock-recompute-features after treesit-major-mode-setup to do fine adjustments, but it’s ugly.

> 2. treesit-defun-type-regexp has the same problem as treesit-font-lock-
> feature-list, so I had to define it myself.

Maybe you can use treesit-thing-settings instead?

> 
> But other than that, it works pretty well.
> 
> IMHO, a global "list" where you can define "font-lock", "indent-list", "font-
> lock-feature", etc. by language (perhaps with getter and setter methods) might 
> make it easier to define new multilingual major-modes. It could improve the 
> decoupling between multilingual major-modes and the major-modes they are 
> derived from. It could also better decouple the internal implementation of 
> treesit.el from the treesitter-based major-modes.
> 
> Let me know what you think.

That’s what I had in mind. That’s also why I added a new variable treesit-aggregated-simple-imenu-settings instead of piggybacking on treesit-simple-imenu-settings. A separate variable is simpler to borrow settings from.

But I didn’t have time to think it though yet. (By language, or by mode and language? Should packages set it on load, or define a function that loads these settings? Etc.) 

Yuan