Setting up Emacs for OCaml Development: Neocaml Edition
A few years ago I wrote about setting up Emacs for OCaml development. Back then the recommended stack was tuareg-mode + merlin-mode, with Merlin providing the bulk of the IDE experience. A lot has changed since then – the OCaml tooling has evolved considerably, and I’ve been working on some new tools myself. Time for an update.

In recent years, the OCaml ecosystem has seen significant advancements in tooling and development environments, particularly for those using Emacs as their editor. A few years ago, the recommended setup for OCaml development in Emacs involved tuareg-mode and merlin-mode, with Merlin serving as the primary source of IDE functionality. However, the OCaml community has evolved, and new tools have emerged, offering enhanced features and improved workflows. This article provides an updated guide to setting up Emacs for OCaml development, focusing on the Neocaml tool, which is designed to streamline the development process and provide a more integrated experience.
Neocaml is a modern tool that aims to simplify OCaml development within Emacs. It was created to address some of the limitations of the older tuareg-mode and merlin-mode setups, offering a more user-friendly and efficient environment for OCaml programmers. Neocaml is built on top of the OCaml compiler itself, leveraging its capabilities to provide real-time feedback and improved code navigation. This tool is part of a broader trend in the OCaml community towards more robust and integrated development environments, reflecting the growing maturity and popularity of the language.
To begin setting up Emacs for OCaml development with Neocaml, you'll need to ensure that you have the latest version of Emacs installed. You can download the latest release from the official Emacs website or use your system's package manager if available. Once you have Emacs installed, the next step is to install the necessary packages. Neocaml is available through the Emacs Package Manager (ELPA), which makes it easy to install and manage packages within your Emacs configuration.
To install Neocaml, open Emacs and run the following command in the Emacs minibuffer:
```elisp
M-x package-install RET neocaml RET
```
This will install the Neocaml package and its dependencies. After the installation is complete, you'll need to configure Emacs to use Neocaml as the primary OCaml development tool. Neocaml integrates with the built-in OCaml mode in Emacs, so you can start by adding the following lines to your `.emacs` or `init.el` file:
```elisp
(require 'neocaml)
(setq neocaml-ocaml-executable "ocaml")
(setq neocaml-topfind-executable "opam env")
```
These settings tell Emacs to use the `ocaml` compiler and the `opam env` command for resolving dependencies. If you have a different OCaml compiler or Opam environment set up, you can adjust these variables accordingly.
With Neocaml installed and configured, you can now start using its features within Emacs. One of the key benefits of Neocaml is its ability to provide real-time feedback as you type. This is achieved through a feature called "live parsing," which analyzes your code as you write it, highlighting any syntax errors or potential issues. Neocaml also offers enhanced code navigation, allowing you to jump to the definition of a function or module with a single keystroke. This makes it easier to understand and maintain larger OCaml projects.
Another significant improvement provided by Neocaml is its integration with the OCaml compiler's type inference system. By leveraging the compiler's capabilities, Neocaml can provide more accurate and detailed type information directly within Emacs. This means that you can see the inferred types of variables, functions, and expressions as you work, which can help you write more robust and maintainable code.
In addition to these core features, Neocaml also includes support for linting and code formatting. It integrates with the OCaml community's popular linter, ocamlformat, to ensure that your code adheres to standard formatting conventions. This not only makes your code more readable but also helps maintain consistency across projects.
As you start using Neocaml in your OCaml development workflow, you may also want to explore additional packages and configurations that can further enhance your experience. For example, the `ocaml-indent` package provides smart indentation for OCaml code, while the `ocaml-mode` package offers additional syntax highlighting and support for OCaml-specific language features.
In conclusion, the OCaml tooling landscape has evolved significantly in recent years, with Neocaml emerging as a powerful and user-friendly option for Emacs-based development. By leveraging the latest advancements in OCaml compiler technology and integrating them seamlessly into Emacs, Neocaml provides a more efficient and integrated development experience for OCaml programmers. Whether you're a seasoned OCaml developer or just starting out, adopting Neocaml can help you take advantage of the language's capabilities and streamline your workflow. As the OCaml community continues to innovate, tools like Neocaml are poised to shape the future of OCaml development, making it even more attractive for both academic and industrial use.










