This is an Emacs Lisp binding for tree-sitter, an incremental parsing library. It requires Emacs 25.1 or above, built with dynamic module support.
It aims to be the foundation for a new breed of Emacs packages that understand code structurally. For example:
- Faster, fine-grained code highlighting.
- More flexible code folding.
- Structural editing (like Paredit, or even better) for non-Lisp code.
- More informative indexing for imenu.
The author of tree-sitter articulated its merits a lot better in this Strange Loop talk.
See the installation section in the documentation.
If you want to hack on emacs-tree-sitter
itself, see the next section instead.
Clone this repo and add its lisp
and langs
directories to load-path
.
Install cask and run cask install
to install dev dependencies.
If you want to hack on the high-level features (in Lisp) only:
- Make changes to the
.el
files. - Add tests to
tree-sitter-tests.el
and run them with./bin/test
(.\bin\test
on Windows).
If you want to build additional (or all) grammars from source, or work on the core dynamic module, see the next 2 sections.
- Install tree-sitter CLI tool (if you don't use NodeJS, you can download the binary directly from GitHub):
# For yarn user yarn global add tree-sitter-cli # For npm user npm install -g tree-sitter-cli
- Run:
# macOS/Linux make ensure/rust
# Windows .\bin\ensure-lang rust
- You can modify
tree-sitter-langs-repos
if the language you need is not declared there.
- Install the Rust toolchain.
- Install
clang
, to generate the raw Rust binding foremacs-module.h
. - Build:
# macOS/Linux make build
# Windows .\bin\build
- Test:
# macOS/Linux make test
# Windows .\bin\test
- Continuously rebuild and test on change (requires cargo-watch):
# macOS/Linux make watch
# Windows .\bin\test watch
To test against a different version of Emacs, set the environment variable EMACS
(e.g. EMACS=/snap/bin/emacs make test
).
Targeting lib authors:
- Write a guide on using the tree-sitter APIs.
Targeting end users:
- Pick a language, make a "killer" minor mode that extends its major mode in multiple ways.
- Make minor modes for most common languages.
- Extract common patterns from the language minor modes into helper language-diagnostic minor modes.
- Get a language major mode to use tree-sitter for optional features.
Binding through C instead of Rust: https://github.com/karlotness/tree-sitter.el
Contributions are welcomed. Please take a look at the issue list for ideas, or create a new issue to describe any idea you have for improvement.
Show respect and empathy towards others. Both technical empathy and general empathy are highly valued.