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 10:04:58 +0200 Message-ID: <86r06ubh3p.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> 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="7332"; 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 09:06:11 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 1tGw0w-0001gM-57 for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Nov 2024 09:06:10 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGw0E-0004Ky-Tj; Fri, 29 Nov 2024 03:05:26 -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 1tGw0B-0004KT-Ec for emacs-devel@gnu.org; Fri, 29 Nov 2024 03:05:23 -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 1tGw0A-0003uL-71; Fri, 29 Nov 2024 03:05:22 -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=L32NzePNsf7yfXVxQMlzKvdFgkIZP09oaW/tsdwT9rc=; b=YyZZpXz5Vdepku6mbe0V x4Dc0kqi6QFAwuZUKD5Khuo//jxBwlLQ+mDV1vP98TmukFQwxVTdppV3eXvWBvb8oXYDVcRrgmbSY oFeTUbrAA/NXJ7021j1bRnwvM2W/Je0VA4yaoANIz4ezsYHvBnInuMJJGOy/pYFwQWv2ljFH3SUHK R1a2EfchFMIcCkMZWP5k2a6Uyp/6rg1a4Eyawf2ekD2IhysIkLod6LfFyKbdQ5t8+F7JZ8otOiEIW qDbN2qJJuWz7y2VxUteNqzdv/IaohBFmXA4GHJiUCQqEJUXWUy4TPnQrqMSsnczf2fZ+jgoc01QLx xBgJXBRUyXAc2Q==; In-Reply-To: <137AE507-F467-4FB2-83DB-EC621F868C60@gmail.com> (message from Yuan Fu on Thu, 28 Nov 2024 21:49:33 -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:325848 Archived-At: > From: Yuan Fu > Date: Thu, 28 Nov 2024 21:49:33 -0800 > Cc: Vincenzo Pupillo , > Emacs Devel , > Stefan Kangas , > Stefan Monnier , > Dmitry Gutov > > Actually, I want to expand this to something that allows users to configure tree-sitter modes and toggle on/off tree-sitter features. > > Since Emacs 29, I see many people ask about how to configure tree-sitter modes by setting some variable. It seems that people much prefer setting a variable than adding a major mode hook that calls some functions. Also, admittedly adding custom font-lock or indent rules aren’t very straightforward for users. > > In Emacs 29, we went with the major-mode hook approach for customization since the major mode inheritance situation wasn’t yet clear, the hook approach provides most flexibility, and we don’t really know what we want. But at this point I think we can add another layer of convenience. As long as this convenience layer handles 90% of the use-cases and doesn’t add any confusion, it’ll be a net-gain. We are discussing the solutions to these issues in this thread: https://lists.gnu.org/archive/html/emacs-devel/2024-11/msg00636.html Feel free to chime in and state your opinions about the solutions being proposed there. > What do you guys think about something like this: > > (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? > One thing I don’t like is how it handles languages. In this POC language-specific settings are nested under the mode. I’m ok with mode-language hierarchy, but the nesting adds a lot of nesting levels to the variable. And the language nesting isn’t consistent, some settings have language nesting, some don’t. 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.