tree-sitter-langs
tree-sitter-langs copied to clipboard
Hacky support for treesit in Emacs core
CC @casouri
I wanted to use tree-sitter-langs packaged grammars and queries with treesit in Emacs core.
I'm not expecting these bunch of hacks to be accepted, it's more of a talking point on compatibility/collaboration between elisp-tree-sitter and treesit.
Points:
- elisp-tree-sitter maps capture name
Xto facetree-sitter-hl-face:X, while treesit expectsXto be a face by itself. I tried to replaceXwithtree-sitter-hl-face:X, but seems like colons end identifier names in tree-sitter's query language. What I ended up doing is replacingXwith the parent face oftree-sitter-hl-face:X .match?and.eq?predicates in elisp-tree-sitter are renamed to#matchand#euqalin treesit, and#matchhas its arguments swapped in relation to.match?- treesit expects grammars to be files in the format
libtree-sitter-X, so it can't find tree-sitter-lang's grammars, so I symlinked each grammar file with itself prefixed withlibtree-sitter-.
@ymarco question: does the treesit integration in core support multi-language documents?
I haven't delved much into that, it would be doable with functions like treesit-set-ranges in the API. Yuan wrote a texinfo node about it in the feature/tree-sitter branch (see Parsing Text in Multiple Languages and treesit-parser-set-included-ranges), but I think it'd be better to ask him on emacs-devel what an actual mode using these would look like.
@kiennq I just saw your fork on reddit, what does it do? I couldn't make sense of the commit history...
@ymarco My fork is similar to your commit with additional to:
- doesn't take dependencies on
emacs-tree-sitter, the only dependency is the builtintreesit. The recipe for it is(treesit-langs :repo "kiennq/tree-sitter-langs" :fetcher github :files ("tree-sitter-langs-build.el" "treesit-*.el" "queries")) - Add some more parsers with their highlight queries (taken from the parser's repo or neovim's tree-sitter repo)