From: Yuan Fu <casouri@gmail.com>
To: "\"Augustin Chéneau (BTuin)\"" <btuin@mailo.com>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Questions about tree-sitter
Date: Fri, 8 Sep 2023 09:43:34 -0700 [thread overview]
Message-ID: <1F227B69-6195-4115-A7B6-BD2F7EA08E1F@gmail.com> (raw)
In-Reply-To: <3b3f90e8-a318-4b63-915e-6477701de897@mailo.com>
> On Sep 8, 2023, at 4:53 AM, Augustin Chéneau (BTuin) <btuin@mailo.com> wrote:
>
> Le 06/09/2023 à 06:07, Yuan Fu a écrit :
>> 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’s vital that you define treesit-language-at-point-function for a multi-language mode.
>> Yuan
>
> Thanks a lot!
>
> 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:
>
> - 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’s parser (bison) and see if point is in an undelimited_code_block, and return c or bison accordingly. I’m 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’s font-lock rules’ features.
>
> - When I try to indent C code by using c-ts-mode indent rules, I get the following error:
>
> Debugger entered--Lisp error: (wrong-type-argument treesit-node-p #<treesit-parser for c>)
> treesit-node-parser(#<treesit-parser for c>)
> 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)
>
> 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’s feature list is a separate variable now.
Yuan
next prev parent reply other threads:[~2023-09-08 16:43 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-29 21:26 Questions about tree-sitter Augustin Chéneau (BTuin)
2023-08-30 7:03 ` Yuan Fu
2023-08-30 11:28 ` Augustin Chéneau (BTuin)
2023-09-06 4:07 ` Yuan Fu
2023-09-08 11:53 ` Augustin Chéneau (BTuin)
2023-09-08 16:43 ` Yuan Fu [this message]
2023-09-09 16:39 ` Augustin Chéneau (BTuin)
2023-09-12 0:22 ` Yuan Fu
2023-09-13 12:43 ` Augustin Chéneau (BTuin)
2023-09-14 4:11 ` Yuan Fu
2023-09-18 17:04 ` Augustin Chéneau (BTuin)
2023-09-19 4:00 ` Yuan Fu
2023-09-01 2:39 ` Madhu
2023-09-01 6:53 ` Eli Zaretskii
2023-09-01 9:15 ` Madhu
2023-09-01 10:45 ` Dmitry Gutov
2023-09-01 10:58 ` Eli Zaretskii
2023-11-27 7:16 ` Madhu
2023-09-06 16:11 ` Lynn Winebarger
2023-09-07 23:42 ` Yuan Fu
2023-09-08 0:11 ` Lynn Winebarger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1F227B69-6195-4115-A7B6-BD2F7EA08E1F@gmail.com \
--to=casouri@gmail.com \
--cc=btuin@mailo.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.