Re:Let's write a treesitter major mode for Emacs
by nanna on Thursday September 14, 2023 @06:13AM
(#37507032)
Technically 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-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?
Re:Let's write a treesitter major mode for Emacs
by 3836293648 on Thursday September 14, 2023 @06:49AM
(#37507279)
It's more external dependency. Libjansson (json serialisation) isn't default either and neither is libgccjit (native elisp comp).
Re:Let's write a treesitter major mode for Emacs
by G3rn0ti on Thursday September 14, 2023 @06:55AM
(#37507316)
I 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.
Re:Let's write a treesitter major mode for Emacs
by yougane on Thursday September 14, 2023 @08:50AM
(#37508277)
Or you can just "M-x treesit-install-language-grammar" then follow the prompts.
Re:Let's write a treesitter major mode for Emacs
by G3rn0ti on Thursday September 14, 2023 @08:59AM
(#37508383)
I 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!
Re:Let's write a treesitter major mode for Emacs
by imaltont on Thursday September 14, 2023 @11:02AM
(#37509972)
I 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.
Re:Let's write a treesitter major mode for Emacs
by treeblah on Thursday September 14, 2023 @11:30AM
(#37510313)
I 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))
Re:Let's write a treesitter major mode for Emacs
by nanna on Friday September 15, 2023 @04:33AM
(#37520133)
For the record, it's in Mickey's How to Get Started with Tree-Sitter post:
https://www.masteringemacs.org/article/how-to-get-started-tr...
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/. 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/
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.