5 ms·
BTW: While Emacs 29.1 comes with "treesitter" built-in, you still need to manually build and install any treesitter language plugin implementing the actual lan
by G3rn0ti 3y ago
BTW:
While Emacs 29.1 comes with "treesitter" built-in, you still need to manually build and install any treesitter language plugin implementing the actual language specific parser. This can be fiddly and frustrating doing it yourself.
I had a quick success with using this convenience script: https://github.com/casouri/tree-sitter-module/ https://github.com/casouri/tree-sitter-module/. It provides fully-automated builds for the most popular languages (including typescript, c and c++).
This is how it works for "typescript":
1. Clone the repository: https://github.com/casouri/tree-sitter-module/ https://github.com/casouri/tree-sitter-module/
2. Install "build-essentials" (providing a c/c++ compiler if you're on Linux).
3. run "./build typescript" from within the repo
4. Copy the resulting shared library from "dist/libtree-sitter-typescript.so" into your "~/.emacs.d/tree-sitter/".
5. Open a random typescript file and try "M-x typescript-ts-mode" which should not give you any error but instead nice syntax highlighting.
You might find there is a treesitter plugin for your language available and it is even supported by "tree-sitter-module" but there is still no major mode, yet. Happened to me for Perl 5.
- nanna 3y agoTechnically in Emacs 29.1 tree-sitter is still only an optional build option, which a given package maintainer may have 'built in' to your package. It isn't actually a default. If you build it from source you need to pass the --with-tree-sitter flag to ./configure. See: https://www.masteringemacs.org/article/how-to-get-started-tree-sitter https://www.masteringemacs.org/article/how-to-get-started-tr... What I read from this is that tree-sitter isn't considered quite ready by the Emacs maintainers, perhaps because of the restricted number of actual treesitter modes, or maybe because the treesitter support itself is not quite considered there yet?
- 3836293648 3y agoIt's more external dependency. Libjansson (json serialisation) isn't default either and neither is libgccjit (native elisp comp).
- G3rn0ti 3y agoI was lazy. I installed Emacs from Alex Murray's snap: sudo snap install emacs It works w/o problems as it is using snapcraft's "classic" runtime. It comes with both native compilation and tresitter support.
- yougane 3y agoOr you can just "M-x treesit-install-language-grammar" then follow the prompts.
- G3rn0ti 3y agoI tried that but unsuccessfully. Did not get an error but also no grammar for Typescript or C/C++. Perhaps mileage varies with the language. Edit: I can confirm it works nicely for "javascript". Cool!
- imaltont 3y agoI have done typescript successfully. It has another install folder than the default, as the repo has tree-sitter for both tsx and typescript. C/C++ could be a similar situation. The installer should prompt you for it during the setup.
- treeblah 3y agoI found this snippet in one of Mickey's earlier tree-sitter posts that works great. It does require searching through the tree-sitter repo to make sure your paths are correct: (setq treesit-language-source-alist '((typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src") (tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src"))) (mapc #'treesit-install-language-grammar (mapcar #'car treesit-language-source-alist))
- nanna 3y agoFor the record, it's in Mickey's How to Get Started with Tree-Sitter post: https://www.masteringemacs.org/article/how-to-get-started-tree-sitter#compiling-and-installing-with-the-builtin-method-in-emacs https://www.masteringemacs.org/article/how-to-get-started-tr...