reddit / emacs

regarding feature/tree-sitter branch

fromadarkcontinent · 2022-09-05 02:59
Hi guys currently I noticed that Emacs has a feature branch for tree-sitter. I have installed `libtreesitter-devel`, configured that branch with the --tree-sitter option and compiled it. Now I when I open files the files are highlighted but I don't see any difference on the highlighting. Is there something I should do to use tree-sitter for the highlighting.
lebensterben · 2022-09-05 03:01
I have not used this new feature, but ... why do you expect any difference? If tree-sitter highlighted the code differently then it's a bug.
tryptych · 2022-09-05 03:52
I do see a difference (when using the \`tree-sitter\` package, not the feature branch). I assume that because it has richer semantic knowledge than just regexps it can provide more information? It's particularly noticeable for me in python files.
lebensterben · 2022-09-05 03:58
can you show me a screenshot?
tryptych · 2022-09-05 04:11
https://imgur.com/a/swB55GX
lebensterben · 2022-09-05 05:10
thx!
jimehgeek · 2022-09-05 07:55
I could be very wrong cause I’ve paid little attention to the tree-sitter branch. But, my understanding is that the goal is to make tree-sitter a built-in alternative to the current regex based syntax highlighting system used by major modes. So via the feature branch alone, I’m not sure you would see any difference unless the major mode you’re using has been updated to use it. However, if you want to use tree-sitter today, there is the [tree-sitter](https://github.com/emacs-tree-sitter/elisp-tree-sitter) package which enables tree-sitter syntax highlighting in a number of popular major modes. I’ve been using it for about six months now in all major modes it supports. It does generally highlight things a bit differently as it has much more details available about the syntax tree. If you dislike some of the highlighting differences, there’s a bunch of tree-sitter faces you can customize to make things more to your liking.
MonsieurPi · 2022-09-05 09:20
If I'm not mistaken, tree-sitter will replace the regexp used by font-lock with its own keywords so if the language you use it with already had good regexps you shouldn't notice any difference but tree-sitter will be the one providing font-lock the keywords. Now you need to make sure that your language has a parser for tree-sitter, you can check it with tree-sitter-debug (not sure about the exact command) that will open a buffer with how the current buffer is parsed by tree-sitter
eli-zaretskii · 2022-09-05 16:01
Did you read the documentation of the tree-sitter supported features on this branch? They are disabled by default, so you need to enable them first. It's also possible you will need some setup for a specific language you want to use.
eleven_cupfuls · 2022-09-05 23:40
This is correct. There are three pieces: Tree-sitter the library; code that connects the Tree-sitter library to Emacs's font locking; and finally a binary that represents the grammar for the language you're interested in highlighting. Those grammars are collected in the [tree-sitter-langs repo](https://github.com/emacs-tree-sitter/tree-sitter-langs), or you can build them yourself. I assume they're not bundled with Emacs yet, even on the feature branch. I don't know how the Emacs tree-sitter branch expects them to be registered and associated with a language mode, though.
fromadarkcontinent · 2022-09-06 03:20
Thanks I'll do so.