Installation

tree-sitter requires Emacs 25.1 or above, built with dynamic module support. Some Emacs distributions have this disabled by default. To check whether your Emacs has dynamic module support enabled, try evaluating one of these:

(functionp 'module-load) ; should be t

module-file-suffix ; should be non-nil

Upon byte compilation and first load, the package tree-sitter (tsc) will try to obtain the dynamic module using 2 mechanisms:

  • Downloading a pre-compiled binary from GitHub. This only works for macOS/Linux/Windows on x86_64 machines, and macOS on Apple Silicon.
  • Compiling the binary from the Rust source. This requires the Rust toolchain.

This behavior can be customized by setting the variable tsc-dyn-get-from, before tree-sitter (tsc) is byte-compiled/loaded. Its default value is (:github :compilation). For example, you should set it to (:compilation) if you don’t want to download binaries from GitHub.

Installing from MELPA

  • Run M-x package-refresh-contents.

  • Install tree-sitter and tree-sitter-langs packages.

  • Load the framework and the language bundle:

    (require 'tree-sitter)
    (require 'tree-sitter-langs)
    

Installing with straight.el

  • Run (straight-pull-package "melpa") to update MELPA recipes, if necessary.

  • Install tree-sitter and tree-sitter-langs packages.

    (straight-use-package 'tree-sitter)
    (straight-use-package 'tree-sitter-langs)
    
  • Load the framework and the language bundle:

    (require 'tree-sitter)
    (require 'tree-sitter-langs)
    

Installing from Source

  • Clone the source repository:

    git clone https://github.com/emacs-tree-sitter/elisp-tree-sitter
    
  • Add its core, lisp and langs directories to load-path:

    (add-to-list 'load-path "/path-to/emacs-tree-sitter/core")
    (add-to-list 'load-path "/path-to/emacs-tree-sitter/lisp")
    (add-to-list 'load-path "/path-to/emacs-tree-sitter/langs")
    
  • Load the libraries in your config:

    (require 'tree-sitter)
    (require 'tree-sitter-hl)
    (require 'tree-sitter-langs)
    (require 'tree-sitter-debug)
    (require 'tree-sitter-query)