Ocaml-ts-mode - Emacs ocaml major mode using tree sitter

This weekend I got interested in emacs major modes based on treesitter, so I decided to implement ocaml-ts-mode. The code can be found here:

It was actually very easy thanks to the hard work others have done in creating the treesitter grammar.

It supports:

  • Syntax highlighting of .ml and .mli files.
  • Initial indentation support (this is probably currently broken in multiple places)
  • C-c C-a - Switch between .ml and .mli files for a module.

This is less feature rich than Tuareg mode, so I don’t know if it replaces it. If anything, maybe it could be integrated into tuareg mode.

I have no experience writing elisp so this probably has obvious mistakes. Contributions welcome!

Enjoy!

5 Likes

Whoops, in my excitement learning about treesitter I didn’t notice that there already is an ocaml-ts-mode. That one is probably the preferred one to use. I’ll probably direct any of my development towards it. But learning how to make a major mode was a fun experience.

3 Likes

I’m not sure which mode you’re referring to, but I don’t think that there’s any ocaml-ts-mode with active development and any meaningful adoption yet. Perhaps yours will be the first one!

This is the mode I guess : GitHub - dmitrig/ocaml-ts-mode: OCaml major mode using tree-sitter

Unfortunately it’s a WIP without any development in 6 months.
Any competent people to help?

I’ve been pushing a few changes here and there for my ocaml-ts-mode. Some known issues:

  1. paragraph fill does not work correctly.
  2. the language mode indentation totally doesn’t work
  3. does’t work with hideshow mode, which would be nice. Part of that is just Ocaml isn’t a language very friendly to hideshow mode.

Other than that for the most part it suits my needs but happy to take PRs. I want to fix the fill paragraph for sure at some point. I use ocamlformat which mostly alleviates issues (1) and (2).