Need help with emacs-tree-sitter?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

ubolonton
419 Stars 31 Forks MIT License 589 Commits 25 Opened issues

Description

Tree-sitter in Emacs

Services available

!
?

Need anything else?

Contributors list

# 91,689
Clojure
Shell
tree-si...
increme...
475 commits
# 299,617
Emacs
C
increme...
tree-si...
44 commits
# 11,540
Emacs
emacs-l...
magit
Lisp
5 commits
# 18,703
Emacs
elisp
python3
luajit
5 commits
# 180,050
Emacs
Angular
Dart
ESLint
4 commits
# 33,887
Emacs
ivy
elisp
flychec...
2 commits
# 17,503
Emacs
emacs-l...
keymap
Lisp
1 commit
# 234,766
PureScr...
deoplet...
Neovim
racket-...
1 commit
# 484,017
Haskell
Shell
HTML
increme...
1 commit
# 62,222
Emacs
Vim
spacema...
flychec...
1 commit
# 197,152
emacs-c...
Emacs
emacs-l...
PHP
1 commit
# 394,509
Discord
discord...
Rust
C
1 commit
# 275,718
Clojure
shell-s...
Clojure...
repl
1 commit
# 43,552
ls
React
vim-scr...
viml
1 commit

emacs-tree-sitter

Documentation Build Status

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.

Installation

See the installation section in the documentation.

If you want to hack on

emacs-tree-sitter
itself, see the next section instead.

Setup for Development

  • Clone this repo with the
    --recursive
    flag.
  • Add 3 of its directories to
    load-path
    :
    core/
    ,
    lisp/
    and
    langs/
    .
  • Install cask.
  • Run
    ./bin/setup
    (
    .\bin\setup
    on Windows).

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.

Building grammars from source

  • Install tree-sitter CLI tool (if you don't use NodeJS, you can download the binary directly from GitHub): ```bash

    For yarn user

    yarn global add tree-sitter-cli

    For npm user

    npm install -g tree-sitter-cli ```

  • Run: ```bash

    macOS/Linux: make ensure/

    make ensure/rust

    powershell
    
    

    Windows: .\bin\ensure-lang

    .\bin\ensure-lang rust ```

  • You can modify

    tree-sitter-langs-repos
    if the language you need is not declared there.

Working on the dynamic module

  • Install the Rust toolchain.
  • Install
    clang
    , to generate the raw Rust binding for
    emacs-module.h
    .
  • Build:
    bash
    # macOS/Linux
    make build
    
    powershell
    # Windows
    .\bin\build
    
  • Test:
    bash
    # macOS/Linux
    make test
    
    powershell
    # Windows
    .\bin\test
    
  • Continuously rebuild and test on change (requires cargo-watch):
    bash
    # macOS/Linux
    make watch
    
    powershell
    # 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
).

Overall Plan

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.

Alternative

Binding through C instead of Rust: https://github.com/karlotness/tree-sitter.el

Contribution

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.

For language-specific issues/features, please check out tree-sitter-langs instead.

Show respect and empathy towards others. Both technical empathy and general empathy are highly valued.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.