:lang ocaml
This module adds OCaml support, powered by tuareg-mode.
- Code completion, documentation look-up, code navigation and refactoring (merlin)
- Type, documentation and function argument display on idle (merlin-eldoc)
- REPL (utop)
- Syntax-checking (
merlinwith flycheck-ocaml) - Auto-indentation (ocp-indent)
- Code formatting (ocamlformat)
- Dune file format (dune)
Table of Contents TOC
Module Flags
This module provides the +opam-site-lisp flag to compile editor support .el
files from opam's site-lisp directory.
By default all editor plugins are installed from MELPA/GitHub even if the
corresponding opam package isn't installed.
If this flag is enabled then you must have all of the packages listed in
package.el installed via opam.
To enable this, use:
(doom! :lang (ocaml +opam-site-lisp))
Prerequisites
It is highly recommended to install opam.
To get all the features you should also install these opam packages, however
they are not all required (features should be disabled gracefully when a tool is
missing):
opam install merlin utop ocp-indent dune ocamlformat
Features
- the following files should have syntax highlighting support:
.ml{i,p,y,}, .eliom{i,}, jbuild, dune, opam
merlin-modeis activated whenever a.merlinfile is found (including in a parent directory) andocamlmerlinexecutable is present- line-based auto-indentation is provided by
ocp-indentwhen installed
Configuration
- if
:completion companyis enabled then autocomplete is provided bymerlin - when
:tools flycheckis enabled thenflycheck-ocamlis activated to do on-the-fly syntax/type checking viamerlin, otherwise this is only done when the file is saved. - spell checking is activated in comments if
:tools flyspellis active - a REPL is provided if
utopis installed and:feature evalis active - if
:editor formatis enabled, theocamlformatexecutable is available and there is an.ocamlformatfile present thenformat-all-bufferis bound toocamlformat, otherwise toocp-indent - if
:editor multiple-cursorsis enabled then identifiers can be refactored withv Rand multiple cursors (this correctly matches identifier occurrences according to scope, it is not purely a textual match) - if
:emacs imenuis enabled then top level symbols (modules, type, functions, etc.) can be looked up usingSPC / i
Run make install to install all packages, and make doctor to diagnose missing tools.
Appendix
Commands
| command | key / ex command | description |
|---|---|---|
merlin-type-enclosing |
SPC m t |
display type under point |
tuareg-find-alternate-file |
SPC m a |
switch between .ml and .mli |
merlin-locate |
gd |
lookup definition |
merlin-occurences |
SPC c D |
lookup references |
merlin-document |
K |
lookup documentation |
merlin-imenu |
SPC / i |
symbol lookup in file |
merlin-iedit-occurrences |
v R |
visual refactor identifier under point (multiple cursors) |
utop |
SPC o r |
open utop as REPL |
utop-eval-region |
SPC c e |
evaluate selected region in utop |
Hacks
set-pretty-symbols!is called with the full tuareg prettify symbol list, this can cause columns to change as certain keywords are shortened (e.g.funbecomes λ.tuareg-opam-update-envis called the first timetuaregis loaded