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: Re: Tree-sitter central configuration variable Date: Fri, 29 Nov 2024 01:07:37 -0800 Message-ID: <0D9218A9-C7F5-4D50-B49C-FCE201114C9B@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> <137AE507-F467-4FB2-83DB-EC621F868C60@gmail.com> <86r06ubh3p.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="7361"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Vincenzo Pupillo , Emacs Devel , Stefan Kangas , Stefan Monnier , dmitry@gutov.dev To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 29 10:09:00 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 1tGwzk-0001kk-9G for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Nov 2024 10:09:00 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGwyl-0003is-6C; Fri, 29 Nov 2024 04:07:59 -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 1tGwyh-0003ia-Sp for emacs-devel@gnu.org; Fri, 29 Nov 2024 04:07:55 -0500 Original-Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tGwye-0003Se-81; Fri, 29 Nov 2024 04:07:55 -0500 Original-Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-2ede8c4fedeso1330713a91.3; Fri, 29 Nov 2024 01:07:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732871270; x=1733476070; 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=24agsogTgB8p87OB1lurr45VFHP0o6qMl2eXJYL8Kp4=; b=gDovSNcbeeDZH+NdJrj9EDBch3tn/bdyIh5wMG+Ii/e+Cxpps+IL5KxqPXOHy7Ymso IJeuRnlCvaX7EEUwZ0hmAQ4AogDCAXh6vbumIt7OCorn9X3mq2/M4cdrLNdsSbNBq2Dq Q1s3GDMSYhrP6xdkVpjXuLuhUL9roS8oOM3fqdurgVKkxec9acNxg2Wv6ibC7caVwgeS 769jaRmgO2PYozwLvygcjHSPikbgDiwyHXbS56hpN4TayfjoyGeAOnlxxnmyIdhpHvgA A3FSFsXfGMpfX52/NMXqpcrkrA/kz4jQCFdOVORj4nKTxYo7TibdwAgVLyNsp51tV10S eVtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732871270; x=1733476070; 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=24agsogTgB8p87OB1lurr45VFHP0o6qMl2eXJYL8Kp4=; b=RMyn2LsfWHmhyPR2mqCkoS7z8Kyfi2TOlbCwoeH3JSAQ+RwKS0zEHaUA5p1gOJCxsP feAW3qoEo88sfc8X9/cIoc9FcvzBcxncASIKorJ3StRKER5iukZXRHi7OI9CZbU+ULi4 nAjLLyA1RPK5bxCE7tSHE76ShLdVDSnS55JemlR/h1CwdikGJ8oD0b/Pv3+nnSp+835V Xg2/AHCFWG3TB99ZvvmYYi2aOykc0f/gEJNhfY7O+eu+FIakC1mfQdEEaWtlAozM3K1d orK98oNYmfgN0feeFAEcsvYhxeIxxSVWPv8RVQvzeZKfnNrUmzjyU7HMaJZ/PCbTIghw TeCQ== X-Forwarded-Encrypted: i=1; AJvYcCX+sMdYEr9lDM8Yh6AxGoUIFCkUDsPUODS+vaoPnTBuDqD95ZnjDodlPw445GCXRVKQzEr4/wcr6SK4AQ==@gnu.org X-Gm-Message-State: AOJu0YxZHUD9/JCAt7Jz6L5POevMuoHf3yHrNjBSlrf4X7qYb1GCHqi8 jUd2WKvqFeYoW9ZqZHiKiHtlg99Krzh6apfJO8VolWRrrjbZvWWetZrjiA== X-Gm-Gg: ASbGncv5crQba8VVUi6IPGZMM31cS4hl59jrG/v+Xp3PEGKHkBW2VTCbYQSvjmTfqeq +hUcmpO196eV5lrpkBEK8cxyXwczWPJRt0XkcbP/DGqSl8oZIwUceyBWMbags0zRB2GcPmcFgIF slGlKtSEYlwzmoNMIhd4uF/R+pO74W9RSFdSp4qKcXA25QHosbMAdmt8BOsX24e6OXG44w8uxq3 OjoTC10b/b5pVJNL1OXKg6Qm1FC1sx1hkoVu/tXwd/8quhwi7m4jd//3C91XouGBrh/ZG5y1A== X-Google-Smtp-Source: AGHT+IGvK3wiCXNngy5WTJc5vSg7gha51IQL7w10cfTU41FrkOpodZxBXxnamARqVhZDrC5rmzDCIg== X-Received: by 2002:a17:90b:4b4f:b0:2ea:3d2e:a0d7 with SMTP id 98e67ed59e1d1-2ee08eb2f04mr13933459a91.15.1732871269728; Fri, 29 Nov 2024 01:07:49 -0800 (PST) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:c885:af5e:9679:e419]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2ee0fb0dd04sm4799096a91.46.2024.11.29.01.07.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Nov 2024 01:07:49 -0800 (PST) In-Reply-To: <86r06ubh3p.fsf@gnu.org> X-Mailer: Apple Mail (2.3776.700.51) Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=casouri@gmail.com; helo=mail-pj1-x1031.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:325851 Archived-At: > On Nov 29, 2024, at 12:04=E2=80=AFAM, Eli Zaretskii = wrote: >=20 >> From: Yuan Fu >> Date: Thu, 28 Nov 2024 21:49:33 -0800 >> Cc: Vincenzo Pupillo , >> Emacs Devel , >> Stefan Kangas , >> Stefan Monnier , >> Dmitry Gutov >>=20 >> Actually, I want to expand this to something that allows users to = configure tree-sitter modes and toggle on/off tree-sitter features. >>=20 >> 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. >>=20 >> 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=99= 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=E2=80=99t add any confusion, it=E2=80=99ll be a = net-gain. >=20 > We are discussing the solutions to these issues in this thread: >=20 > https://lists.gnu.org/archive/html/emacs-devel/2024-11/msg00636.html >=20 > Feel free to chime in and state your opinions about the solutions > being proposed there. That thread is about turning tree-sitter modes on and off. I think = Dmitry=E2=80=99s proposal seems pretty good, and I don=E2=80=99t have = much to add. What I=E2=80=99m proposing here is rather about configuring = tree-sitter modes: turning features (outline, imenu, etc) on and off, = customizing things (font-lock, indent, etc). >=20 >> What do you guys think about something like this: >>=20 >> (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))) >> ))) >>=20 >> 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. >=20 > 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=E2=80=99m trying to solve several things: first off, turning on/off = some tree-sitter features. Originally someone wants to turn off = tree-sitter mode=E2=80=99s outline support. Technically they don=E2=80=99t= really need to turn of tree-sitter=E2=80=99s outline, they just need to = make the minor mode they=E2=80=99re using override tree-sitter=E2=80=99s = 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=E2=80=99m hoping that I can simplify = things by the proposed variable. >=20 >> 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. >=20 > 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=E2=80=99re talking about different things. The language I was talking = about are the languages in a multi-language modes. For a HTML mode, = you=E2=80=99ll 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. Yuan