From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Tree-sitter central configuration variable Date: Fri, 29 Nov 2024 12:01:53 -0500 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 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="18953"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , Vincenzo Pupillo , Emacs Devel , Stefan Kangas , Dmitry Gutov To: Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Nov 29 18:03:22 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 1tH4On-0004lT-Hm for ged-emacs-devel@m.gmane-mx.org; Fri, 29 Nov 2024 18:03:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tH4NZ-0001fr-UD; Fri, 29 Nov 2024 12:02:05 -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 1tH4NU-0001Zh-Rx for emacs-devel@gnu.org; Fri, 29 Nov 2024 12:02:02 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tH4NS-0005wF-SQ; Fri, 29 Nov 2024 12:02:00 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 2FD06805E9; Fri, 29 Nov 2024 12:01:55 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1732899714; bh=i4wzX4VbCyla7Xt54EVaS8qCIgwqMLZKzgFV4YOTHT4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=OzmOskmdnHNi69SKna8JnLetJWC5uob+HszHrDmYkjCrdVWweOgro5ozrZzPWS1c3 3mPhyuCwSE7tmhJYfmGx0AvVDI2VxkAvRZ+CVhRW+ViGJoVLifnCyagfqx1UDLmItq 3R7MXVC8DzJlrtqLn3iObzYUVroXLovn+kMgf2ffs7cI2Mdo1V+GR0pNwnV6g35oRi F6RV6LreNpeGBQwT2k/PfYQeo/Rz/E50q/ld1Q5bs66qrbICSJRF3ilW50SkF0ZKG4 g8gibIXdQlcDqirbXxhClT/XTU84SpkpmAGqZ3dGezBjHqAnqQaFW1YEfFl3+HTyCe ttEZ+5Kb8CJ0Q== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 2BAA1802B3; Fri, 29 Nov 2024 12:01:54 -0500 (EST) Original-Received: from alfajor (unknown [23.233.149.155]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 021E712056E; Fri, 29 Nov 2024 12:01:53 -0500 (EST) In-Reply-To: <137AE507-F467-4FB2-83DB-EC621F868C60@gmail.com> (Yuan Fu's message of "Thu, 28 Nov 2024 21:49:33 -0800") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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:325856 Archived-At: > Since Emacs 29, I see many people ask about how to configure > tree-sitter modes by setting some variable. This is not specific to tree-sitter. > It seems that people much prefer setting a variable than adding > a major mode hook that calls some functions. But that boxes them into the subset of possibilities that have been pre-imagined by those who designed the set of variables. > 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))) > ))) Sounds to me like this is inventing a new programming language, just one that's a lot more restrictive than ELisp. Is it really better than ELisp which could look like: (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))) )) Admittedly, the add-hook/defun dance could be improved, and that would benefit more than just tree-sitter. E.g. a new macro like (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)))) > 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. 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`? Stefan