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 integration on feature/tree-sitter Date: Sat, 7 May 2022 12:11:06 -0700 Message-ID: References: <9E6D13F6-7E50-44EE-A357-C971A11A3636@gmail.com> <837d6xzpac.fsf@gnu.org> <7B1F29B4-045A-420E-8FD7-C7C72FF14DDC@gmail.com> <837d6xxjpv.fsf@gnu.org> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.80.82.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="20758"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat May 07 21:18:17 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 1nnPwW-0005JH-Vl for ged-emacs-devel@m.gmane-mx.org; Sat, 07 May 2022 21:18:16 +0200 Original-Received: from localhost ([::1]:60648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nnPwV-00025e-Tk for ged-emacs-devel@m.gmane-mx.org; Sat, 07 May 2022 15:18:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nnPpg-0003bm-6u for emacs-devel@gnu.org; Sat, 07 May 2022 15:11:13 -0400 Original-Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:36644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nnPpe-000201-28; Sat, 07 May 2022 15:11:11 -0400 Original-Received: by mail-pl1-x634.google.com with SMTP id j14so10398847plx.3; Sat, 07 May 2022 12:11:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=CMnW45o6xX4Vwt6TUQWXVNoNXD4wUhykWZ51Ezor/hY=; b=DFYLS4mf1FQBo0EkQi72YznUW9QJczVnp/W8zSQ+pr/Zvz00txYl6t316Zsc0Tgc/a KfUanS6D7Beb2MmJFDdoYVNwxp2GoQmWDTlPLk+RGPfWX5C00xVHOH7VxBSYfs2F8um1 xzsQ9GPmLL1b5HixHHyh3PYf17x8j9nQGQckCG7EtGSURPPonB0PRig4nCUSvh/MIrVG hzkSx67mBqCW+NTTHLD8xSJClPRmrbE2JLUBTkluQc9llhvg4NwG12pnA5jWBqpwhd4E PB5jj15xIunf/F0pQVmkGOEX9e41mF7AhHkIIdVgQulC8sAQ9cXn3E8xr1adHdPBpQLe Iw4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=CMnW45o6xX4Vwt6TUQWXVNoNXD4wUhykWZ51Ezor/hY=; b=lQ3Dyvqf1TuyL+ggtlE2iVsfFD3fPtSh8xRVgpE1R+BvyZ7mMMM28iqDZA6mXLcn34 Ckh6ZbqPAO8HjN+bugXI+FDurCseg0FS9KBRsFQSVqSygHghXtc2ml2bvPdHAzOtMf0u FkeI5KLklgq/NWpbnONaqnjdGw/MrL7cRog9eqCAL6um1XNTzeoBwf98dT/ElIRABUF2 BJJtAOrGoKTp3m3Btkqbmamb0c9AkQ6I3cX3/fXupWWTZLNPBZLtqz4uQ2yt6iYp23SW W8jPy5UiZKf6R2eRZkEASwXnK9mQxkXmfO0jZv88MqLPvBQ9hc2gCxdWFWDvOzsFDznp C5vQ== X-Gm-Message-State: AOAM5312eDnY1QUA3IU2jGy2hKDjNlxrW3D+oYINNGxJNVD2bhPSvamk YXDg3/MPfVWUOml057sGVxx+qii+veI= X-Google-Smtp-Source: ABdhPJx/EPHUNDuVjGCe0do6MjKEUKL1699bSEKhXHw59gy5yTxvDXikDCHQrQFaIROEOTPEfxPJSQ== X-Received: by 2002:a17:903:182:b0:15e:8de0:2859 with SMTP id z2-20020a170903018200b0015e8de02859mr9142298plg.124.1651950668054; Sat, 07 May 2022 12:11:08 -0700 (PDT) Original-Received: from smtpclient.apple ([2600:1700:2ec7:8c90:148:e841:81b0:7360]) by smtp.gmail.com with ESMTPSA id y16-20020a62f250000000b0050dc76281b4sm5793607pfl.142.2022.05.07.12.11.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 May 2022 12:11:07 -0700 (PDT) In-Reply-To: <837d6xxjpv.fsf@gnu.org> X-Mailer: Apple Mail (2.3696.80.82.1.1) Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=casouri@gmail.com; helo=mail-pl1-x634.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, T_SCC_BODY_TEXT_LINE=-0.01 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:289428 Archived-At: > On May 7, 2022, at 11:48 AM, Eli Zaretskii wrote: >=20 >> From: Yuan Fu >> Date: Sat, 7 May 2022 11:27:11 -0700 >> Cc: emacs-devel@gnu.org >>=20 >>> Would you please suggest how to "play with it"? What features to = turn >>> on and how, what commands and displays to try, etc. Posting such >>> instructions should allow all of us get to testing this branch much >>> sooner and easier. >>=20 >> Some suggestions on top of my head: >>=20 >> - Load the attached treesit-demo.el which contains a very basic C = major mode, ts-c-mode, that gives you some font-locking and indentation = using tree-sitter features. >> - Get a C file, change its extension to .tsc, and open it >> - The major mode should be ts-c-mode, and it should have some basic = fontification. >> - Type M-x treesit-show-buffer-tree RET to see the AST of the C file, = probably want to use this on a smaller C file. >> - Type M-x treesit-inspect-mode RET to display the AST of the node at = point in the mode-line, see more explanation in its doctoring. >> - Set treesit--indent-verbose to t, and try to indent some lines, and = see which indentation rule is matched. >>=20 >> Is this the sort of things you are looking for? >=20 > Yes, thanks. >=20 > However, I hoped that the font-lock and indentation are already > integrated with tree-sitter, and all that is needed for a given > major-mode to use it is to flip some variable. I didn't expect to > need a completely separate major mode for C sources, for example. >=20 > It sounds like we are farther from the goal that I thought we were, > and some serious work is still ahead of us to get this integrated into > the existing major modes. I used a separate major mode because I don=E2=80=99t want to touch the = existing one, and this is only a simple demo. For the author of a = major-mode, they only need to port their font-lock-defaults and indent = function to use tree-sitter features. If you look at the definition of = ts-c-mode, its roughly (if (treesit-should-enable-p) (set tree-sitter font-lock and indent variables) (set font-lock-defaults etc)) Then a user could choose whether to turn on tree-sitter for a particular = major mode by changing treesit-disabled-modes. Maybe it should be = treesit-enabled-modes, or something more elaborate, but that=E2=80=99s = another topic. Of course, if a major-mode author pleases, they could also define = separate major modes, as Theodor pointed out. > However, I hoped that the font-lock and indentation are already > integrated with tree-sitter, and all that is needed for a given > major-mode to use it is to flip some variable. That=E2=80=99s too much magic to ask from tree-sitter. It is just an = incremental-parser, work is still needed from major mode authors to use = the parsed AST to font-lock/indent/etc. But at least I=E2=80=99ve made = that process as easy as possible. Yuan=