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: Questions about tree-sitter Date: Fri, 8 Sep 2023 09:43:34 -0700 Message-ID: <1F227B69-6195-4115-A7B6-BD2F7EA08E1F@gmail.com> References: <12fe5895-7d34-4f3e-b1cf-aa133b718c24@mailo.com> <52f09345-85c8-4049-b12d-bf8b84b08f75@mailo.com> <2B46C452-DC8B-4BD0-A64B-8773235C1FA8@gmail.com> <3b3f90e8-a318-4b63-915e-6477701de897@mailo.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) 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="5235"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel To: =?utf-8?B?IkF1Z3VzdGluIENow6luZWF1IChCVHVpbiki?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Sep 08 18:44:35 2023 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 1qeeax-00018P-KG for ged-emacs-devel@m.gmane-mx.org; Fri, 08 Sep 2023 18:44:35 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeeaH-0005gR-7S; Fri, 08 Sep 2023 12:43:53 -0400 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 1qeeaF-0005fw-Md for emacs-devel@gnu.org; Fri, 08 Sep 2023 12:43:51 -0400 Original-Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qeeaD-0003lH-B9 for emacs-devel@gnu.org; Fri, 08 Sep 2023 12:43:51 -0400 Original-Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1c0c6d4d650so18795845ad.0 for ; Fri, 08 Sep 2023 09:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694191427; x=1694796227; 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=x0qGzPgL3XJJoydFeUkMCR1FJbkE12DEUFEsAg3x0HY=; b=WdQocfsZIeVrg2jgG6ZnCn4rWZBHfP59h5kQlYCp2AZuDQbT9tH0EdUcGiKz3MyZ4C U7XFOao4UoQ2yUXEFFk4It0h1vp3WQsb8jmtZt2bxwwRbdWfXm2bQVbZGzSzXIv0IEb/ 3H+tlxx45dbZHzfrmW9fHZfZ2BhiuAslAso5hehlajtct8+WUF9beGcGtAWG+okXYJh/ ujisCgSxcMiQ38bHRiJwyQpQKmryLRZaQPdkuWzwEoMoq6FHjnD1BYAKtoKXGQGSmmZt okXx+nt3/dNRYKW2Z7aVahrM30sa4OieRt9LVXNKHJHKgxWe72adds1cfsHbaIcS3A8p rkUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694191427; x=1694796227; 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=x0qGzPgL3XJJoydFeUkMCR1FJbkE12DEUFEsAg3x0HY=; b=pGr5JziUrt6aW33dRBJSQpdpztVGY/sWoMtye1xcmtiYdS2fbAS0SvFa4zqcIGXgc+ 4PiRarrHWKOsTfiKNIIG3b/sKWa+QaAWryYs1Z93MRJwiP+1FobTTotnOzgk3naRqppf 2D65KbCJVyOZ3Bznx6PbBIM5zQIXb/YGIXomOQRLvnAIBwnA/E/rCff9lRLshNaDzfrH IDYIGUvuDoqBrVUlXAWx5RVQh9ycVOglha92zSdxZngfuEMew7Y35W44cG7gI3YqlFMD lCZeP9eiw0KketG7NNK7Ghz8GJXfg53NX31R6VyglFZhoyATMhItz0eyFJ0lLXS1pYwG mzjA== X-Gm-Message-State: AOJu0YxvcYeb6nsqoIvehHXg9wkSTCNXL23djuuodhKvutFskVR0fz4g Gn4rWAB3n8fKTt17Y11lxd3n7WFw7sNjgA== X-Google-Smtp-Source: AGHT+IErRQAoCIcC2GIo6suKdhHtdfpSj3Te/i3C2omerEx6svOSH5wv0dx43psxiuqHOYGjGkxttA== X-Received: by 2002:a17:90a:fa02:b0:263:311f:9bcc with SMTP id cm2-20020a17090afa0200b00263311f9bccmr2781614pjb.35.1694191426751; Fri, 08 Sep 2023 09:43:46 -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 j4-20020a17090a588400b0026b3773043dsm1525248pji.22.2023.09.08.09.43.46 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Sep 2023 09:43:46 -0700 (PDT) In-Reply-To: <3b3f90e8-a318-4b63-915e-6477701de897@mailo.com> X-Mailer: Apple Mail (2.3731.700.6) Received-SPF: pass client-ip=2607:f8b0:4864:20::62e; envelope-from=casouri@gmail.com; helo=mail-pl1-x62e.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:310342 Archived-At: > On Sep 8, 2023, at 4:53 AM, Augustin Ch=C3=A9neau (BTuin) = wrote: >=20 > Le 06/09/2023 =C3=A0 06:07, Yuan Fu a =C3=A9crit : >> I added local parser support to master. If everything goes right, you = just need to add a :local t flag in treesit-range-rules. Check out the = modified bision-ts-mode.el that I hacked up for an example. BTW, it=E2=80=99= s vital that you define treesit-language-at-point-function for a = multi-language mode. >> Yuan >=20 > Thanks a lot! >=20 > I did some tests and it's working pretty well. Awesome! > Do you think it's a good idea to add a prefix to bison feature names = in font-lock settings to avoid conflicts with C names (as I did)? I should add some way to distinguish between languages in feature name = list. The tricky part is to make it backward compatible and not too = confusing and still convenient to use. > I have a few issues though: >=20 > - I first defined `treesit-language-at-point-function` using > `treesit-node-at`. However, `treesit-node-at` itself uses > `treesit-language-at-point-function` which causes an infinite = recursion. > So I instead used `treesit-local-parsers-at` to check if a local = parser is used. Is it a good solution? No no, you should use the host langauge=E2=80=99s parser (bison) and see = if point is in an undelimited_code_block, and return c or bison = accordingly. I=E2=80=99m highlight this in the docstring, thanks. For now, you can use something like (mapcar (lambda (rule) (list (nth 0 rule) (nth 1 rule) (intern (format "js-%s" (nth 2 rule))) (nth 3 rule))) js--treesit-font-lock-settings) to add prefix to c-ts-mode=E2=80=99s font-lock rules=E2=80=99 features. >=20 > - When I try to indent C code by using c-ts-mode indent rules, I get = the following error: >=20 > Debugger entered--Lisp error: (wrong-type-argument treesit-node-p = #) > treesit-node-parser(#) > treesit--indent-1() > treesit-indent-region(1075 1176) > indent-region(1075 1176) > indent-for-tab-command(nil) > funcall-interactively(indent-for-tab-command nil) > call-interactively(indent-for-tab-command nil nil) > command-execute(indent-for-tab-command) >=20 > There seems to be a mistake in `treesit--indent-1` in the `cond` at = the line `(local-parsers (car local-parsers))`, since a parser is = returned while it should be a node. Thanks, I fixed that on master. And c-ts-mode=E2=80=99s feature list is = a separate variable now. Yuan=