Using emacs for OCaml development



Is there a documented working and up-to-date instruction on how to setup emacs for OCaml development?

Everthing I’ve tried so far is more or less broken.

I started out with emacs prelude which uses emacs packages for tuereg, merlin, etc. The packages versions seems to be outdated and does not start clean on latest release of emacs.

Then I tried user-setup from opam.

Now things start but the interactive shell is not utop.


In my side, I followed the advise of @rgrinberg and use spacemacs with the OCaml layer. I’m not a big fan, but it stills work for me with an updated opam environement.

But I’m not a strong user of emacs, I used vim and neovim before.


Working (and up-to-date ) instructions for Spacemacs


I am using emacs 25.2.1 with tuareg, merlin, and utop and everithing work well
here are my setting in my init.el

 (and (require 'cl)
      (use-package tuareg
        :ensure t
        (add-hook 'tuareg-mode-hook #'electric-pair-local-mode)
        ;; (add-hook 'tuareg-mode-hook 'tuareg-imenu-set-imenu)
        (setq auto-mode-alist
              (append '(("\\.ml[ily]?$" . tuareg-mode)
                        ("\\.topml$" . tuareg-mode))

      ;; Merlin configuration

      (use-package merlin
        :ensure t
        (add-hook 'tuareg-mode-hook 'merlin-mode)
        (add-hook 'merlin-mode-hook #'company-mode)
        (setq merlin-error-after-save nil))
      ;; utop configuration

      (use-package utop
        :ensure t
        (autoload 'utop-minor-mode "utop" "Minor mode for utop" t)
        (add-hook 'tuareg-mode-hook 'utop-minor-mode)

By the way, i am using ‘use package’ to manage all my packages.

I point you to a greet series of tutorials that helped me a lot to understand how to configure emacs.

Best regards