4 ms·
What's the "explain it like I'm 5 years old" (ELI5) for tree-sitter? Why should I, an emacs user but not lisp hacker, care about it?
by antipaul 4y ago
What's the "explain it like I'm 5 years old" (ELI5) for tree-sitter? Why should I, an emacs user but not lisp hacker, care about it?
- chriswarbo 4y agotree-sitter creates parsers, e.g. for programming languages, config formats, etc. Emacs modes can use those parsers on buffer contents, e.g. for syntax colouring/highlighting, finding matching delimiters (e.g. moving the cursor over an `if`, and having all the corresponding clauses (e.g. else/elif/fi) highlighted), for contextual editing (e.g. escaping " when inside a string), etc. This can be remarkably tricky to get right; e.g. consider languages which can splice expressions inside strings (which can themselves contain strings, containing spliced expressions, etc.) Using tree-sitter should make this easier and more robust (i.e. less time spent implementing parsers; more time spent implementing features!). I think it would also allow grammars to be re-used across different tools, which should improve support for obscure/niche languages.
- 2pEXgD0fZ5cF 4y agoDoes this mean that every emacs language package would automatically make use of this once it is built in. Or will this rather enable the possibility to write/rewrite programming language modes so they make use of tree-sitter because they can assume it is available in the default emacs install from then on?
- omnicognate 4y agoIt needs to be explicitly used. As far as I'm aware it doesn't slot in behind an existing API and magically make things better.
- 2pEXgD0fZ5cF 4y agoGot it. Are there any beginner guides yet on how to write an emacs (language) package while making use of it?
- mdaniel 4y agoUnknown if this qualifies as "beginner guide" but the in-tree document is titled "STARTER GUIDE ON WRITING MAJOR MODE WITH TREE-SITTER": https://git.savannah.gnu.org/cgit/emacs.git/tree/admin/notes/tree-sitter/starter-guide https://git.savannah.gnu.org/cgit/emacs.git/tree/admin/notes...
- 2pEXgD0fZ5cF 4y agoI hindsight I should have left out the "beginner" part. Thanks ofr pointing me in the right direction, exactly what I was looking for.
- lawn 4y agoAnother useful feature is that it makes it easier to support mixing languages in the same file. Think highlighting for html/JS/CSS in a single file or fully featured highlighting inside markdown code snippets.
- giraffe_lady 4y agoYou know how emacs typically has the worst syntax highlighting of all mainstream editors for a given language? This makes it better.