Interactive OCaml development with utop in Emacs

I made a blog post about REPL driven development with utop in Emacs a few months ago. Please let me know if you found it useful or have anything to add! I’m a bit new to OCaml so any feedback helps.

There was a similar post about REPL driven development last year and my post addresses a lot of those points. I wish I’d seen that post before I wrote this since there’s a ton of useful information in the comments.

4 Likes

I recommend to add a video/GIFWebP animation/asciinema recording, so it will be easier to see with your own eyes.

1 Like

thanks for this post! This made me try again the utop mode for emacs (I normally use the “basic” ocaml REPL emacs mode), and reminds me of why I didn’t end up using it: do you know how to enable Merlin completion (and type analysis) + syntax highlighting in the utop buffer? (it works well in the plain ocaml REPL mode)

utop has pretty great support for completion inside a terminal but I’ve found it to be hit-or-miss inside Emacs (maybe my config is messed up). My usual workflow is to write code in my main OCaml buffer, highlight it, and send it over to the REPL to be evaluated, so I never really cared about things like eldoc (for Merlin type hints) support in Emacs’ utop mode itself. If I’m testing out a function in the REPL, I don’t really mind typing out the whole thing without any completion support and the usual C-n and C-p shortcuts work just fine. I don’t think I ever tried the plain OCaml REPL inside Emacs before so it’s good to know that an alternative exists!

That’s a good idea, thanks for the suggestion. I use Emacs in the regular GUI mode so I’m not sure if there’s an easy way to record it (knowing the Emacs community, I bet there’s some kind of asciinema-mode). Maybe it’s finally time to try out terminal Emacs…

Every example of workflow/using of Emacs/Ocaml is useful. So thanks.

Suggestion when you do the video. There are ways of see the key bindings one use. Either by printing in a overlay or in a small window in Emacs with key binding AND function.

I am currently looking for the second one, which probably works great with asciinema. For ordinary graphical videos, I guess both works.