Skip to content

Hacky support for treesit in Emacs core#99

Open
ymarco wants to merge 8 commits intoemacs-tree-sitter:masterfrom
ymarco:master
Open

Hacky support for treesit in Emacs core#99
ymarco wants to merge 8 commits intoemacs-tree-sitter:masterfrom
ymarco:master

Conversation

@ymarco
Copy link
Contributor

@ymarco ymarco commented May 15, 2022

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 X to face tree-sitter-hl-face:X, while
    treesit expects X to be a face by itself. I tried to replace X with
    tree-sitter-hl-face:X, but seems like colons end identifier names in
    tree-sitter's query language. What I ended up doing is replacing X with the
    parent face of tree-sitter-hl-face:X
  • .match? and .eq? predicates in elisp-tree-sitter are renamed to #match and #euqal
    in treesit, and #match has 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 with libtree-sitter-.

@jsmestad
Copy link
Collaborator

@ymarco question: does the treesit integration in core support multi-language documents?

@ymarco
Copy link
Contributor Author

ymarco commented Sep 30, 2022

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.

@ymarco
Copy link
Contributor Author

ymarco commented Oct 10, 2022

@kiennq I just saw your fork on reddit, what does it do? I couldn't make sense of the commit history...

@kiennq
Copy link

kiennq commented Oct 18, 2022

@ymarco My fork is similar to your commit with additional to:

  • doesn't take dependencies on emacs-tree-sitter, the only dependency is the builtin treesit. 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants