Use Tree-sitter as backend to source code indentation. Provide an `indent-line-function` using the emacs-tree-sitter package
 
 
 
Go to file
FelipeLema 4ef246db3e Merge pull request 'Enable arbitrary major-mode selection' (#18) from knobo/tree-sitter-indent.el:use-any-mode into main
Reviewed-on: #18
2022-04-11 16:39:15 +02:00
.gitignore keep sandboxed emacs user directory hidden 2020-12-14 18:39:41 -03:00
LICENSE Initial commit 2020-08-18 20:31:36 +02:00
Makefile exclude flycheck's temporary files 2020-12-21 17:01:40 -03:00
README.md setup tree-sitter-indent as a mode (fix #7) 2020-12-21 17:03:54 -03:00
code_of_conduct.md add code of conduct 2020-10-19 14:41:52 -03:00
emacs-sandbox.sh package-lint does not play nice with `straight.el` 2020-12-14 18:37:39 -03:00
setup-tests.el Removed fork reference and added main csharp-mode repository as 2021-03-22 17:26:10 -03:00
tree-sitter-indent-tests.el Removed fork reference and added main csharp-mode repository as 2021-03-22 17:26:10 -03:00
tree-sitter-indent.el Enable arbitrary major-mode selection 2022-03-28 21:12:37 +02:00

README.md

tree-sitter-indent.el

Use Tree-sitter as backend to source code indentation.

Provide an indent-line-function that resolves the indentation by looking at the syntax tree using the emacs-tree-sitter package.

Installation

First, install emacs-tree-sitter. I recommend using straight.el

(straight-use-package
 '(tree-sitter :host github
               :repo "ubolonton/emacs-tree-sitter"
               :files ("lisp/*.el")))

(straight-use-package
 '(tree-sitter-langs :host github
                     :repo "ubolonton/emacs-tree-sitter"
                     :files ("langs/*.el" "langs/queries")))

;; Load the language bundle

(require 'tree-sitter-langs)

Then, install tree-sitter-indent. Recommended way is using straight.el (no (M)ELPA package currently available).

(straight-use-package
 '(tree-sitter-indent :type git
                      :repo "https://codeberg.org/FelipeLema/tree-sitter-indent.el.git"
                      :branch "main"
                      :files ("tree-sitter-indent.el")))

Usage

So far, only rust language can be indented. Add the following to your init.el

;; install tree-sitter
;; …

;; install tree-sitter-indent
;; …

(tree-sitter-require 'rust)
(require 'tree-sitter-indent)

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

Adding languages or fixing current

Currently, julia is work-in-progress as the Tree-sitter implementation is not done. Rust was actually the second language being worked on, which involved a more mature development, so you may want to check those commits.

The best way to work through a language is to add the targets you want to get ("I want this code to be indented like this") as a unit test. And then add code as needed.

PRs are welcome.

Running tests

To run tests, execute the following

make

This will byte-compile elisp files and run tests. Byte-compiler warnings will be treated as errors, so make sure to cover them.

Internally, make will fetch all dependencies using straight.el and run.

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.