From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Tree-sitter central configuration variable Date: Fri, 29 Nov 2024 14:02:12 +0200 Message-ID: <86plmeb64b.fsf@gnu.org> References: <4929184.OV4Wx5bFTl@3-191.divsi.unimi.it> <861pznqp9m.fsf@gnu.org> <2730223.lGaqSPkdTl@3-191.divsi.unimi.it> <39CF8919-E0A5-44D7-AA7E-ECD7465620A1@gmail.com> <86a5e8okhx.fsf@gnu.org> <868qtam99v.fsf@gnu.org> <137AE507-F467-4FB2-83DB-EC621F868C60@gmail.com> <86r06ubh3p.fsf@gnu.org> <0D9218A9-C7F5-4D50-B49C-FCE201114C9B@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19120"; mail-complaints-to="usenet@ciao.gmane.io" Cc: v.pupillo@gmail.com, emacs-devel@gnu.org, stefankangas@gmail.com, monnier@iro.umontreal.ca, dmitry@gutov.dev To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 29 13:03:17 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tGziP-0004io-8m for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Nov 2024 13:03:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGzhX-0005Z6-2t; Fri, 29 Nov 2024 07:02:23 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGzhT-0005YU-R0 for emacs-devel@gnu.org; Fri, 29 Nov 2024 07:02:20 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGzhS-0006Nu-9v; Fri, 29 Nov 2024 07:02:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=b2IZLSrlFHNElxlDWDf+LEOwOm8q+54wyiKUy421e3U=; b=N50FAU2s37FyCkiRMi2S 8SYXE1YcxRKqkNObaXGZJoCRLCJkv8uutW1n7EGJfy3BuXIviQQIkT1331nxEaIfNpvK0FqKJZLpa 5jjvdGWErkEsdPEDl53l5FI1aR6Wn2RN34JmfZpF2f41BW97qOmR73gvyaXsojS1DZqJzEv1w5/y2 0IBzW27Fe3JiDV8TSQJysRMHJSzZJjtBtqOMr+et3QlPeHfyMeyV7aVC8Jq0G4t+I6bnjOFVzx/fU 6F1Z4st6LzpcYmO+FtTPBFJUaVeLfSkPTPbZmUsfsyUgmp7WILKY8ipzJTAJ5qa/C/k3T/LtUMldJ svbgXjHNmFXpoQ==; In-Reply-To: <0D9218A9-C7F5-4D50-B49C-FCE201114C9B@gmail.com> (message from Yuan Fu on Fri, 29 Nov 2024 01:07:37 -0800) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:325852 Archived-At: > From: Yuan Fu > Date: Fri, 29 Nov 2024 01:07:37 -0800 > Cc: Vincenzo Pupillo , > Emacs Devel , > Stefan Kangas , > Stefan Monnier , > dmitry@gutov.dev > > >> (setq treesit-global-configuration > >> '((c-ts-mode > >> ;; Set treesit-font-lock-level to 4 > >> (font-lock-level . 4) > >> ;; Disable tree-sitter’s outline support > >> (outline . disable) > >> ;; Enable these features on top of the default ones. > >> (font-lock-enable . (function property variable)) > >> ;; Disable these features. > >> (font-lock-disable . (definition)) > >> ;; Add extra font-lock rules > >> (font-lock-extra-rules > >> ( :feature 'my-rules > >> :language 'c > >> ((some_query) @some-face))) > >> (simple-indent-extra-rules > >> (c > >> (matcher anchor offset)) > >> (d > >> (matcher anchor offset))) > >> ))) > >> > >> This config will apply to c-ts-mode or its derived mode. Users can add extra font-lock and indent rules by setting this variable. > > > > I'm not sure I understand what problem(s) this intends to solve? Why > > should we have a global variable that customizes several different > > modes, if the specific customizations made by that variable depend on > > the individual modes? > > I’m trying to solve several things: first off, turning on/off some tree-sitter features. Originally someone wants to turn off tree-sitter mode’s outline support. Technically they don’t really need to turn of tree-sitter’s outline, they just need to make the minor mode they’re using override tree-sitter’s outline configuration completely. Nevertheless, wanting to turn off a tree-sitter feature seems a reasonable ask so I want to support it. > > Secondly, many people wants to configure tree-sitter modes by setting a variable. Right now, if one needs to add/remove some font-lock features they need to do this: > > (defun x-mode-setup () > (treesit-font-lock-recompute-features '(feature-a) '(feature-b))) > (add-hook 'x-ts-mode-hook #'x-mode-setup) > > If they want to add some custom font-lock rules: > > (defun x-mode-setup () > (setq treesit-font-lock-settings > (append treesit-font-lock-settings > (treesit-font-lock-rules > :feature 'custom-feature > :language 'lang > ((some_node) @face)))) > (treesit-font-lock-recompute-features)) > (add-hook 'x-ts-mode-hook #'x-mode-setup) > > That might be a bit convoluted. I’m hoping that I can simplify things by the proposed variable. But we didn't support any such features with the "traditional" regexp- and syntax-based fontifications, so why would tree-sitter based modes be special in this regard? Are you saying that tree-sitter based modes somehow need to update rules for fontification, indentation, and other stuff much more frequently than the "traditional" modes? If so, why? Btw, I don't see the above hooks more convoluted than your treesit-global-configuration variable. They both need a good understanding of tree-sitter grammars and of Lisp. > > We don't have a notion of "language", we only have major modes. Emacs > > 30 makes it easier to specify settings common to modes that serve the > > same "language" by introducing the notion of "extra parent" modes. > > But that is only a small half-step; I don't think we have figured out > > what should be the goal. > > We’re talking about different things. The language I was talking about are the languages in a multi-language modes. For a HTML mode, you’ll have HTML, CSS, and Javascript, and the we might want to configure the three languages differently in the HTML major mode. Eg, add a custom indent rule for CSS in the mode. How would the variable you propose help in doing that? IOW, I guess I don't see clearly enough the problem you want to solve in this case and the solution you are proposing for that. Please elaborate.