reddit / emacs

Building tree-sitter languages for Emacs

NoisyFrequency · 2022-12-30 23:42
NoisyFrequency · 2022-12-30 23:43
Hi everyone, I've had to search around a bit for this information and how to use the new tree-sitter feature in the upcoming Emacs release so I thought others might find the info useful =)
AndreaSomePostfix · 2022-12-31 00:49
maybe this other blog could interest you as well? https://wwwtech.de/articles/2022/dec/emacs-29-install-tree-sitter-parser-modules-with-a-minor-mode
kiennq · 2022-12-31 01:44
You can find the pre-built parser binaries from here https://github.com/kiennq/treesit-langs ss well
takutekato · 2022-12-31 05:21
For our info, upstream has provided `treesit-install-language-grammar`: https://git.savannah.gnu.org/cgit/emacs.git/commit/?h=emacs-29&id=0248fc9e1ac6aa0b802a334ace77c9cf0709e2c3 Although we have to modify `treesit-language-source-alist` so the mentioned command knows where to install.
NoisyFrequency · 2022-12-31 07:21
I had seen it but I don't use straight so I rolled my own for a quick fix, thanks!
NoisyFrequency · 2022-12-31 07:22
Oh cool! Thank you =)
NoisyFrequency · 2022-12-31 07:23
That's pretty much what I was missing, thanks for the info!
NoisyFrequency · 2022-12-31 15:02
I've updated my blog post to reflect this new functionality, you can find it used here: (use-package treesit :commands (treesit-install-language-grammar nf/treesit-install-all-languages) :init (setq treesit-language-source-alist '((bash . ("https://github.com/tree-sitter/tree-sitter-bash")) (c . ("https://github.com/tree-sitter/tree-sitter-c")) (cpp . ("https://github.com/tree-sitter/tree-sitter-cpp")) (css . ("https://github.com/tree-sitter/tree-sitter-css")) (go . ("https://github.com/tree-sitter/tree-sitter-go")) (html . ("https://github.com/tree-sitter/tree-sitter-html")) (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript")) (json . ("https://github.com/tree-sitter/tree-sitter-json")) (lua . ("https://github.com/Azganoth/tree-sitter-lua")) (make . ("https://github.com/alemuller/tree-sitter-make")) (ocaml . ("https://github.com/tree-sitter/tree-sitter-ocaml" "ocaml/src" "ocaml")) (python . ("https://github.com/tree-sitter/tree-sitter-python")) (php . ("https://github.com/tree-sitter/tree-sitter-php")) (typescript . ("https://github.com/tree-sitter/tree-sitter-typescript" "typescript/src" "typescript")) (ruby . ("https://github.com/tree-sitter/tree-sitter-ruby")) (rust . ("https://github.com/tree-sitter/tree-sitter-rust")) (sql . ("https://github.com/m-novikov/tree-sitter-sql")) (toml . ("https://github.com/tree-sitter/tree-sitter-toml")) (zig . ("https://github.com/GrayJack/tree-sitter-zig")))) :config (defun nf/treesit-install-all-languages () "Install all languages specified by `treesit-language-source-alist'." (interactive) (let ((languages (mapcar 'car treesit-language-source-alist))) (dolist (lang languages) (treesit-install-language-grammar lang) (message "`%s' parser was installed." lang) (sit-for 0.75)))))