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: Mon, 2 Dec 2024 22:40:56 -0800 Message-ID: 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 (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="2985"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier , Eli Zaretskii , Vincenzo Pupillo , Emacs Devel , Stefan Kangas , Dmitry Gutov To: Ship Mints Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue Dec 03 07:41:50 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 1tIMbU-0000d0-AV for ged-emacs-devel@m.gmane-mx.org; Tue, 03 Dec 2024 07:41:48 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tIMav-0007u6-Qy; Tue, 03 Dec 2024 01:41:13 -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 1tIMat-0007tr-Uz for emacs-devel@gnu.org; Tue, 03 Dec 2024 01:41:12 -0500 Original-Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tIMas-0001Ox-5U; Tue, 03 Dec 2024 01:41:11 -0500 Original-Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-21539e1d09cso47158485ad.1; Mon, 02 Dec 2024 22:41:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733208068; x=1733812868; 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=r4nzf5VGWPAZjfCDFVrF0LWzuHXxc5oaYCd5wjHjNu0=; b=AO9l7BgO0fGKhiXOtyWD62nMbNBcoqWNpyBXYpaZOlioOghimJPwfeFB5WsvmEVq+A XIKZkt9byLkoWsb1LDmYLe7o8iWbepWuZSuPtC9IzWR8ifwzXZJg+ORBoYvC7Pdd5FFt 3EZ8QDEm+okRSjOK/ZlT2l0ThGFinBT7YydPZJQEbKB42QkunI8IWEFDAyXFGnR/Gz5k SRM2N1n/WYyHTf0FiB1N484UeHctJUEb6nLnWfQrOhXpmIcgfegy6+rvdVHyvW5vLzLU Iyfjt7NMGih5+D/desn023vEtwTgvhholFEobbzhGXmZIi3U9a7upl4JuCwbcGUXG1a3 PAvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733208068; x=1733812868; 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=r4nzf5VGWPAZjfCDFVrF0LWzuHXxc5oaYCd5wjHjNu0=; b=GAkpguuL1A8qzlVNXS5zPllpNmW9Zj0+U7AEliJiqNjsIoMA7Z8f1ARVVq8v8pNH/h z5Tb7az8daszMp9pN7OXVJg5zv/OkmHyXNqL48OF6qcjc4VgjeeP8r7wz6zdzI0p35M0 VnehMQo2Epjj/hTEB6YLnai6uw1QdvTeSnZzwYUULRsK5XCUjNyezVUZXnodaJzk8Smc 8jIo9Jz0dhXAR40yS4fSmoT6tTEI9QphUPHV2NHn+8KWqEF63Xa83kUrEDm2+6qI3hwD gZhCnRQj46cYF8BVThHO9C2NUn6083iYD2qL72lgFMHvTPxgwEbWUj0nc8+UJeyWfB+j M++Q== X-Forwarded-Encrypted: i=1; AJvYcCU4nGOQVdH296gtVYryB8KSnI7OTo5bntl5LKyrw471xn0xChv4pX9Jp+g24gq6K82PgVix@gnu.org, AJvYcCVofHMkF7FQHf1ffWdJTdAEkK7eRr/UHSz8jfGl4uWG8CUA+fLNJ6BY078N7DvFAbjuXx+zicnBTrArLjI=@gnu.org X-Gm-Message-State: AOJu0YzAOLIYRLiNnpKNqceLlYbpyiSw+4J3fyr0YOeVk1QY8nXaJZDk qSReVp9wKtN2egUKWlcQUtkGW+2RsEjoY5cyd6TZOn1ahzqB2JW/I6bEOA== X-Gm-Gg: ASbGncs9dVyHbR/re4ELeRYIvk3pP6IsnG+3fnyYhIOAbsA60G7IPNqEtbvctiOiKaz xEVgp2DZjpCSSWStAiDpNIdBfGiACTj6q0KrjUEaYny+Z2tAXS5mHXyIdC5sa3mCT+H7UzQfPTJ iBD3veeiLetUn9uTYLJoIanV0+DjF3eUtT/0nqvY1oc3k6EGd+lpXZHcaUVCRZIktd0eRKJ7ihn JEZ1SsVtvdnQsxLV9SvcJ1WEQZ++CkOzYZwwI9l8GsSgPkJOxOrXqHC1gh0/hTsoWOwrAfWCw== X-Google-Smtp-Source: AGHT+IG8TftTe4Xms1jfNxZdftex7jkwmN4iEEGUwHVZAapiz8iO4dBYqZMLLI2gcUbi7CdChrppaw== X-Received: by 2002:a17:902:ea04:b0:215:7153:5697 with SMTP id d9443c01a7336-215bd200c68mr20629215ad.28.1733208068101; Mon, 02 Dec 2024 22:41:08 -0800 (PST) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:d4a2:bdb3:ccbc:4058]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-215219672d1sm88160905ad.164.2024.12.02.22.41.06 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Dec 2024 22:41:07 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3776.700.51) Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=casouri@gmail.com; helo=mail-pl1-x632.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:325968 Archived-At: > On Nov 29, 2024, at 9:22=E2=80=AFAM, Ship Mints = wrote: >=20 > Chiming in with my minor voice. I prefer my mode configurations = generally self contained and not centralized as a single global = configuration variable would encourage. When I share my configurations = with others, it also suggests that if they adopt a global configuration = variable on top of what I share, it will introduce subtle changes in = behavior that I may not at first understand the source of when helping = others. I definitely prefer proper lisp over an opaque configuration = variable. >=20 > -Stephane >=20 > On Fri, Nov 29, 2024 at 12:04=E2=80=AFPM Stefan Monnier = wrote: > > Since Emacs 29, I see many people ask about how to configure > > tree-sitter modes by setting some variable. >=20 > This is not specific to tree-sitter. >=20 > > It seems that people much prefer setting a variable than adding > > a major mode hook that calls some functions. >=20 > But that boxes them into the subset of possibilities that have been > pre-imagined by those who designed the set of variables. >=20 > > 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))) > > ))) >=20 > Sounds to me like this is inventing a new programming language, just = one > that's a lot more restrictive than ELisp. >=20 > Is it really better than ELisp which could look like: >=20 > (add-hook 'c-ts-mode-hook #'my-c-ts-mode-preferences) > (defun my-c-ts-mode-preferences () > (setq-local treesit-font-lock-level 4) > (treesit-outline-mode -1) > (treesit-font-lock-enable '(function property variable)) > (treesit-font-lock-disable '(definition)) > (treesit-font-lock-add-rules > '( :feature 'my-rules > :language 'c > ((some_query) @some-face))) > (treesit-indent-add-rules > '((c > (matcher anchor offset)) > (d > (matcher anchor offset))) > )) >=20 > Admittedly, the add-hook/defun dance could be improved, and that would > benefit more than just tree-sitter. E.g. a new macro like >=20 > (defmacro custom-set-hook (hook &rest body) > (declare (indent 1) (debug (sexp def-body))) > (let ((funname (intern (format "custom-set-hook--%s" hook)))) > `(progn (add-hook ',hook #',funnmame) > (defun ,funname () ,@body)))) >=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 > I don't really understand what you're referring to, but for > `treesit-font-lock-add-rules` would could try and auto-add the = `:language`? >=20 >=20 > Stefan >=20 >=20 It seems that we=E2=80=99re getting a resounding no here, so I=E2=80=99m = gonna drop this :) On a side note, I was planning to add a convenience = function for adding font-lock rules, so users don=E2=80=99t need to do = the append dance. Turns out I=E2=80=99ve already written one but then = forgot about it :) Maybe what we really need is a good guide/manual section on installing = and configuring tree-sitter major modes. I wrote a detailed guide for = writing tree-sitter major modes, but didn=E2=80=99t write one for = installing and configuring tree-sitter major modes. Yuan=