From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.devel Subject: Tree-sitter central configuration variable Date: Thu, 28 Nov 2024 21:49:33 -0800 Message-ID: <137AE507-F467-4FB2-83DB-EC621F868C60@gmail.com> 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> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2924"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Vincenzo Pupillo , Emacs Devel , Stefan Kangas , Stefan Monnier , Dmitry Gutov To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 29 06:50:42 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 1tGttq-0000dT-6T for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Nov 2024 06:50:42 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGtt2-00071U-2t; Fri, 29 Nov 2024 00:49:52 -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 1tGtt0-000713-LX for emacs-devel@gnu.org; Fri, 29 Nov 2024 00:49:50 -0500 Original-Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tGtsv-0005Mx-8C; Fri, 29 Nov 2024 00:49:48 -0500 Original-Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-212348d391cso11376825ad.2; Thu, 28 Nov 2024 21:49:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732859382; x=1733464182; darn=gnu.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mesHikvA1K2qb1JdBzJz2+GNkU5ZeCzXbqb5uOgVcas=; b=gGlj9He5v/FIc+bLgC8bo7sWlHrxgHX+IIhLD3zRMN1KngVFlXB6Ce2fjsPz+SY+Jx 1kahS63m84zrU/XemPMbBpt2EL21Bj5Hx/P5XXKp0EVcjJD1jEBOth8+tqaxJMiu1/H+ oY2wCg4pHmdDYtxkpc+4kAQlnPtwA8T5KcCtTAemkmM0i8NVJlB8bnX9DqoyvMf0mapA IAPmAvdJD1BvdzazMHqy963UKKjy8ypT+U6M3Gqyb0YsJJvYApYHQLJOYMJnjEGobfzY R4vDONrBXdEXZg8JFXhBNRpTzki0VQ8P5+3krtZdK7TP3YahddXZ3kZ/oD1xMi7bwn1M xMGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732859382; x=1733464182; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mesHikvA1K2qb1JdBzJz2+GNkU5ZeCzXbqb5uOgVcas=; b=I7bbRwxafsc1/QcEKLZw07N89PGjl5nVtXS8DIvgcXJuLOVi68S0Xv8LebsC0LH5Lx bS5X0GidWfB8BCEZw6dezSx5kknNZ447nFyJXjm86WZkDg4Ae+ruT3gmz73l/lo56VB8 AqtBl6xlEuCfPBth1Oln88ORiO4n89Hn9pqeSoJzv1XLLf+beNwvZDOzjhL4Ot/Qnh9p 0mmn52wDq4WUH4nG1eRxKAViLSCLeXDLTUSebjjfu3MmKADk09j7qCV16tDpSjgTZrB7 q3eWjAHurzdvzv0Fv5NKe/CFoJyGclT3IavulCGHnaOTZ0GA8zDLpVVAzXWfbPnD66+H YyZw== X-Forwarded-Encrypted: i=1; AJvYcCUMc9+TZTAtGymChb+AZKQlDSdOjv3w7t+pAOFwmATu73VHqsXvYbmDF8kfsQptvRcjPEFTjzEE21DO8w==@gnu.org X-Gm-Message-State: AOJu0Yw9xxUPgTgvxPL7ilRLDGJl3XJWqUl1oONj3ff6A+lY9nD9hcT8 8YERxA26dihAkj4cOAwi6EGdnYze2J8+szMrNai7+xSR5pLF6CyK3RsygQ== X-Gm-Gg: ASbGncu82h8rqmaz+SVreJr3DhdU2fscbo0ovjhl5Y8KZ6S28McsOinxqUoG6YfuzgI 0QkubbYPiSWlBA0BzsJ0y3VR+ZcRZZKL96dOnfnHihUlVkXQcz92265m8W0J+RoKjAZaoB+50S0 ZBxEVakuKbZNd+N92xZOLuwUGn4MBAzamdLQqnm2915rjFtL6kt8C63YRXCq9BRv0c1NcIgvDB+ qtHE/dCzcKRckQahu5z28/4j/F2gPvIw1dQeCTxPfNzDmLoukZjVQz9VWCPugtjscHEWKU7bw== X-Google-Smtp-Source: AGHT+IEjI9BJoMtGUyZRESKGXVTpCa7Oqbd9IDKkUz4Bkpl7ROKVKUSBh0lCk6Ly7xVhwJWrM4O1AA== X-Received: by 2002:a17:90b:224b:b0:2ea:4633:1a64 with SMTP id 98e67ed59e1d1-2ee097c1d81mr11578228a91.27.1732859381678; Thu, 28 Nov 2024 21:49:41 -0800 (PST) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:c885:af5e:9679:e419]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ee0fb14dcfsm4467873a91.53.2024.11.28.21.49.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Nov 2024 21:49:41 -0800 (PST) In-Reply-To: <868qtam99v.fsf@gnu.org> X-Mailer: Apple Mail (2.3776.700.51) Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=casouri@gmail.com; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:325838 Archived-At: > On Nov 23, 2024, at 4:20=E2=80=AFAM, Eli Zaretskii = wrote: >=20 >> From: Yuan Fu >> Date: Sun, 10 Nov 2024 00:04:00 -0800 >> Cc: Vincenzo Pupillo , >> emacs-devel@gnu.org >>=20 >>=20 >>=20 >>> On Nov 9, 2024, at 12:54=E2=80=AFAM, Eli Zaretskii = wrote: >>>=20 >>>> From: Yuan Fu >>>> Date: Sat, 9 Nov 2024 00:36:31 -0800 >>>> Cc: Eli Zaretskii , >>>> emacs-devel@gnu.org >>>>=20 >>>>>> Also, we could support a value of that variable which is a list, = like >>>>>> we do with font-lock-maximum-decoration. This will be more = useful >>>>>> than making the variable buffer-local, since presumably your >>>>>> preferences are per-mode, not per-buffer. =20 >>>>> Yes, this would be a better solution. >>>>>=20 >>>>>> Yuan, WDYT? >>>>>>=20 >>>>=20 >>>> Perhaps even per-language, for multi-language modes. I think it=E2=80= =99s a valid use case. IMO, specify the level by language is better than = mode. For single language modes, using the language is equivalent to = using the mode; for multi-language modes, using the language allows more = flexibility.=20 >>>=20 >>> Patches welcome. >>=20 >> I=E2=80=99ll prepare one soon. >=20 > Did you have time to work on this? 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=E2=80=99t = very straightforward for users. In Emacs 29, we went with the major-mode hook approach for customization = since the major mode inheritance situation wasn=E2=80=99t yet clear, the = hook approach provides most flexibility, and we don=E2=80=99t 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=E2=80=99t add any confusion, it=E2=80=99ll be a = net-gain. 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=E2=80=99s 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. One thing I don=E2=80=99t like is how it handles languages. In this POC = language-specific settings are nested under the mode. I=E2=80=99m ok = with mode-language hierarchy, but the nesting adds a lot of nesting = levels to the variable. And the language nesting isn=E2=80=99t = consistent, some settings have language nesting, some don=E2=80=99t. Implementation wise, it shouldn=E2=80=99t be difficult. We just make = treesit-major-mode-setup aware of this variable and use it to override = stuff when setting things up. Yuan=