Recently, I’ve discovered a number of posts on Reddit — like
tree-sitter-hl-mode does not do
or How to use Emacs 29
— and decided to share my simple
tree-sitter setup that
seems to be working on my Emacs 28.2 like a charm.
Step 1. OS: Installing the
First of all, I’ve downloaded the latest pre-build binary archive for my
system from this GitHub
in my case that is tree-sitter-linux-x64.gz because I’m on Pop!_OS
20.10. Then I’ve unpack the archive, put the standalone binary in my
$HOME/bin that is in my
$PATH and therefore is accessible from
anywhere, and changed its mode to executable by
chmod +x tree-sitter.
Step 2. Emacs
Step 2.1. Emacs: Installing
Then I’ve installed
tree-sitter (the parsing system) and
(the grammar bundle) Emacs packages using
Step 2.2. Emacs: Configuring
I’ve added the following lines to my
;;;; `TREE-SITTER' ;; 2022-12-04 (require 'tree-sitter) (require 'tree-sitter-langs) (global-tree-sitter-mode) (add-hook 'python-mode-hook #'tree-sitter-hl-mode)
That’s it. Quite simple, isn’t it?
Please pay attention to the last line. It seems that the tree-sitter
highlighting mode provided by
tree-sitter-hl-mode is not activated when
you load a file into the buffer even if the global tree sitter mode is on.
Adding the hook for the particular source code mode solves this problem.
Now I have a pretty looking Python code.
tree-sitter and its internals can be found at https://tree-sitter.github.io/tree-sitter/.