From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: treesit: how to get it to parse multiple languages Date: Mon, 04 Nov 2024 14:02:42 +0200 Message-ID: <868qtzw6jh.fsf@gnu.org> References: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3495"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Andrew De Angelis , Yuan Fu Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Nov 04 13:03:52 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 1t7voG-0000oF-HH for ged-emacs-devel@m.gmane-mx.org; Mon, 04 Nov 2024 13:03:52 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t7vnz-0000Hn-Gv; Mon, 04 Nov 2024 07:03:37 -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 1t7vnl-0008V3-7a for emacs-devel@gnu.org; Mon, 04 Nov 2024 07:03:25 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t7vnk-0004NS-Uh; Mon, 04 Nov 2024 07:03:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=hf7dWgc3h13cedTkslJ7OGiEgK7cF+WNI8k5ISp5biY=; b=XnOCXG/IFg9q 8ku+nQA0HnBHfQ4Zu8WLyfJh+0IG9A5E291VHsL44EVLgaSDb5ulXJwNSsUPKioDYXosFBYcdiPq1 n422Mnvafi966lIy+Vsv07PZYY94HMgqKkdkJiZDVOVsdH7sMCqlPadzE+zGglGuz2i5mciZyOoZ2 aI08xP8+1gbV+MnlWn87Gv1NsEeaWUggu8/yd63wzuQH5Wb3QkLATdy4YOPf7EX6wi46OVKWwXjIU QnMZaSTohCLDfuXH3XYHwd0kDtyEPVD1qYhgqhCes6h3CdqTaZ6Cq9pctRbcB8gSbgkN/4v3bHU3+ avY+YHa1RPuFxKoUvoKq6w==; In-Reply-To: (message from Andrew De Angelis on Sun, 3 Nov 2024 13:28:57 -0500) 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:325092 Archived-At: > From: Andrew De Angelis > Date: Sun, 3 Nov 2024 13:28:57 -0500 > > I'm trying to get a better understanding of treesit.el, and I've stumbled on a couple of things that make me > think the manual is either outdated/faulty, or just not entirely clear and I'm missing something. > > The latter is most likely, but I'd appreciate any help in figuring out what exactly is wrong in my > approach/setup. I would be happy to contribute to the manual, if needed, to ensure it is clearer. > > This is the relevant section of the manual: > https://www.gnu.org/software/emacs/manual/html_node/elisp/Multiple-Languages.html > I've started out with simply trying to recreate the setup described in the manual, but I've run into some > issues. > Here's what I've done so far: > - I've defined a very simple `html-ts-mode`, using the elisp functions from the manual: > https://github.com/andrewdea/poc-html-ts-mode/blob/main/html-ts-mode.el > - I activate this mode when visiting the example.html file (which is also copied from the manual): > https://github.com/andrewdea/poc-html-ts-mode/blob/main/example.html > - the queries seem to be working as expected: when I'm in a buffer visiting example.html, evaluating > `(treesit-query-capture 'html css-query)` and `(treesit-query-capture 'html js-query)` return the expected > nodes > - ISSUE: `treesit-update-ranges` doesn't seem to be working as expected: even if I call it multiple times, the > parser for the whole buffer seems to still be 'html. `(treesit-language-at (point))` always returns 'html, even > when I'm inside the nodes captured by the css-query or js-query. > > Some additional context: the reason I'm looking into tree-sitter (and its functionalities to support multiple > languages) is to potentially use it to fontify markdown code blocks and to improve emacs support for python > notebooks. For markdown, I was trying a similar approach to the HTML one described in the manual, but ran > into other similar issues: > https://www.reddit.com/r/emacs/comments/1gcrv8k/syntaxhighlighting_codeblocks_in_markdown/. > I'm just including this as context. > > Let me know if any of this is not clear. > > Thanks in advance for all your help! Yuan, can you help Andrew?