From: Andrew De Angelis <bobodeangelis@gmail.com>
To: emacs-devel@gnu.org
Subject: treesit: how to get it to parse multiple languages
Date: Sun, 3 Nov 2024 13:28:57 -0500 [thread overview]
Message-ID: <CAP5CrM3i+s8zUSQ58csd-aux1r=+YHDpzpcSt5R7CKUQcRWCTQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2131 bytes --]
Hello everyone and thanks for all your work!
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!
Best,
Andrew
[-- Attachment #2: Type: text/html, Size: 2902 bytes --]
next reply other threads:[~2024-11-03 18:28 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-03 18:28 Andrew De Angelis [this message]
2024-11-04 12:02 ` treesit: how to get it to parse multiple languages Eli Zaretskii
2024-11-05 6:46 ` Yuan Fu
2024-11-10 14:35 ` Andrew De Angelis
2024-11-10 22:47 ` Peter Oliver
2024-11-11 19:28 ` Juri Linkov
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='CAP5CrM3i+s8zUSQ58csd-aux1r=+YHDpzpcSt5R7CKUQcRWCTQ@mail.gmail.com' \
--to=bobodeangelis@gmail.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.