In a different topics I wrote about about my recent work on neocaml, and I thought it might be a good idea to post something separately as well. Check out the project’s GitHub repo and the short blog post.
Contributions and feedback are most welcome, and I hope neocaml
will be useful to some of you either a tool or as a source of inspiration.
9 Likes
We can always “cheat” a bit with the indentation, by delegating it to another Emacs package like ocp-indent.el
Note that this “cheat” has another virtue: not every programmer uses the same editor, a problem that ocp-indent
solves (also being able to reindent from the cli is occasionally useful).
1 Like
I’ve never used a TS-based editor package, but I’m a gynormous Emacs user. Is there someplace I could read about what TS brings to editing programming languages ? I’m genuinely curious.
The official docs summarize it well:
Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited. Tree-sitter aims to be:
- General enough to parse any programming language
- Fast enough to parse on every keystroke in a text editor
- Robust enough to provide useful results even in the presence of syntax errors
- Dependency-free so that the runtime library (which is written in pure C11) can be embedded in any application
In practice this means you get font-locking that’s not based on regular expressions, and indentation and navigation commands that leverage the AST provided by the TreeSitter parsers. So, font-locking becomes faster and more precise and potentially indentation & navigation (depending on how they were implemented before).
This article gives more details about the benefits in Emacs.
4 Likes
You might be tempted by the ocaml-eglot package!
2 Likes
Yeah, that’s on my radar already and it looks quite promising.
1 Like
If I Googled “Emacs OCaml package” and a link popped up for a project called “Neocaml”, I’d likely ignore that link under the assumption Neocaml is a Neovim plugin for OCaml and I’m getting this result because Google thinks of Emacs and Neovim as closely related
One downside of tree-sitter is that each search query you write in elisp gets compiled into an executable query and for some queries this can take a lot of time even by Emacs standards (a few seconds). The query is cached in memory but it cannot be serialized and stored to disk so you pay the compilation cost for all the font lock / indentation queries every time you start the major mode, which for me is once or twice a day. I started running Emacs in server mode so I have to restart it less frequently but a 5 second up front cost to edit text is pretty objectionable imo. (Typst tree sitter mode to be specific, might be a problem with that particular mode, not sure)
Yeah, I thought about this as well, but as it’s mostly an experimental package at this point I don’t think the name matters that much. Also - we can’t have neovim monopolize the word “neo”, right? 
1 Like
That’s a fair point. The support for TreeSitter in Emacs is still very young and there’s a lot of room for improvement for sure. For me the trade-off is fine, as I often run Emacs sessions for months, but for people using Emacs mostly from the terminal (the way vim is commonly used) this will probably an issue. With my use-case generally I don’t care about any startup optimizations as I start Emacs so rarely.