Syntax Highlighting

Syntax highlighting is provided by the minor mode tree-sitter-hl-mode. It overrides the regex-based highlighting provided by font-lock-mode, using the syntax tree provided by tree-sitter-mode. It is based on tree queries, a system for pattern-matching on Tree-sitter’s syntax trees.

It can be toggled in a buffer by the command tree-sitter-hl-mode, or enabled through major mode hooks:

(add-hook 'rust-mode-hook #'tree-sitter-hl-mode)

To enable it whenever possible (assuming the language major modes were already installed):

(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)

The package tree-sitter-langs provides syntax highlighting queries for some languages:

  • C
  • C++
  • CSS
  • Go
  • HTML
  • Java
  • JavaScript
  • PHP
  • Python
  • Ruby
  • Rust
  • TypeScript

Most of the highlighting queries in the bundle are very basic, as they are copies of those included in the grammar repositories. Queries for languages written in bold have received additional work to leverage more of the querying system’s expressiveness.

Contributions to highlighting queries are welcome.