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: Call for volunteers: add tree-sitter support to major modes Date: Mon, 10 Oct 2022 13:54:38 -0700 Message-ID: References: <83czb1jrm3.fsf@gnu.org> <878rlo7on0.fsf@thornhill.no> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) 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="28675"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Theodor Thornhill , Eli Zaretskii , emacs-devel To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 10 22:55:28 2022 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 1ohzo8-0007LP-HK for ged-emacs-devel@m.gmane-mx.org; Mon, 10 Oct 2022 22:55:28 +0200 Original-Received: from localhost ([::1]:58048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohzo7-0000Qc-C0 for ged-emacs-devel@m.gmane-mx.org; Mon, 10 Oct 2022 16:55:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohznR-00088C-6n for emacs-devel@gnu.org; Mon, 10 Oct 2022 16:54:45 -0400 Original-Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:46643) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ohznP-0004ts-Ki; Mon, 10 Oct 2022 16:54:44 -0400 Original-Received: by mail-pf1-x430.google.com with SMTP id y8so11715311pfp.13; Mon, 10 Oct 2022 13:54:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=yaqxGKkWC6H+XhkAAX5sTM1JDG5DdKheOv3HznEWJ20=; b=Ps2BZ9KumdsmREI0s4un8WWgw81jWaxsD2WrtPRFEnw1RchNN3g1c+tp9xN5chPcJ4 7mf/6dGARn4BK9iyjgFFJZtJN8iO7Q1JpSmKiOj0j9Dp0YGRYpwqs6KXX/9+LUVkQt/G T0vXuKy+N0fuiYHODt6eEgZQ1f8C4635zgVYPzzgMAPn43b+bX3+6sCxOF0myye4Z0K4 rXGA05Nj3XxfNzE7iBcPJlYt3YKN4psi0VKnIUrtVUTAfMfLglrKOK5TaSv1JBFzlMKr xoE2UsAAD0cPwPwlYdYxVoWeeWSUfzpHnQ32+zVnOIjZXmc+GNEZ1Ue5++CxDRgLgtnZ +TwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=yaqxGKkWC6H+XhkAAX5sTM1JDG5DdKheOv3HznEWJ20=; b=MZhBjghxTz62wTolanEMQrctiQjgo4vt5zziKledX90qI3yHFfW8gVgLYL/BBdCEjR vk5nuaM6RoFXhkxZwHRONCAt0svkIO68KD09bPOLtnA4J4XT2phA/A6M385b197KlPFM PyWk+b/oiIRPt7bdW09L/ftecx9/haJD8eJK41cSQwFCfJsF5J3RbKgHkRxlihI15RR8 RuJcLF+Td3p4OcdphEAqKKLFMs57lFlWm3KtPG0WQqh5JYpgPIIxUDFMpjiFOpxWaM6F ecbUyRyaX9w6LL9e3F+CA1DVqawJONYIDxvjYeAk5tKg+80iLLXtEmgT3YMq8XxfiZYZ yk8w== X-Gm-Message-State: ACrzQf0Zrx4zohsWj+JVfJYjbWTKAHMnu/rs/TKh1wXrn7SnU9B1XTTD VLxDk8oA6hthAOZGl4jjA/k= X-Google-Smtp-Source: AMsMyM7ukjli28zbz09qRbMJV10X5MPwXGfoj3tv3ZkON2OTG0zGXgLQxiMxd/Vp5P2T9X9o7ewaOw== X-Received: by 2002:a63:814a:0:b0:460:9253:bf8e with SMTP id t71-20020a63814a000000b004609253bf8emr10726474pgd.469.1665435281039; Mon, 10 Oct 2022 13:54:41 -0700 (PDT) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id l14-20020a170903244e00b0017f61576dbesm7060933pls.304.2022.10.10.13.54.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Oct 2022 13:54:40 -0700 (PDT) In-Reply-To: X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::430; envelope-from=casouri@gmail.com; helo=mail-pf1-x430.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" Xref: news.gmane.io gmane.emacs.devel:297400 Archived-At: >=20 >> I think we can use the same major mode, just skip the cc-mode >> initialization and only enable tree-sitter stuff if >> java-use-tree-sitter is true. But I want to know Alan=E2=80=99s = thought on >> this. I included him in CC. >=20 > Thanks! At the moment, I'm still trying to get a handle on what > tree-sitter is and can do. The idea of including lots of tree-sitter > modes in Emacs 29 came up very suddenly over the weekend. I can fill you in :-) Basically tree-sitter gives you a parser so fast that it can produce a = correct syntax tree of the buffer as you edit the buffer. For us = developers, having a syntax tree available all the time simplifies many = things.=20 For example, font-lock: instead of writing regex patterns to find = entities to highlight, you now asks the syntax tree: =E2=80=9Cgive me = all the function_definition nodes between BEG and END=E2=80=9D. And you = get a bunch of function_definition nodes. We know function_definition = nodes has the following structure: (function_definition name: (identifier) body: (block_statement =E2=80=A6))= So we can just get the =E2=80=9Cname=E2=80=9D child node, which is an = identifier, and apply font-lock-function-name-face to the text = corresponding to that node. Basically there is no need to parse or pattern-match ourselves anymore, = the answer is readily available. Another example, for beginning/end-of-defun, there is no need to look = for the beginning/end pattern for a function anymore. We just ask the = syntax tree to give us the next/previous (say) =E2=80=9Cfunction_definitio= n=E2=80=9D node after/before POS, and if there is one, jump to the = end/beginning of that node. For indent it=E2=80=99s the same story: you can get the node at the = beginning of current line, then by its type (identifier, statement, = expression, bracket, etc) and its relative position in the tree, you can = decide how to indent it. Hope that helps, Yuan=