Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
73 lines (53 sloc) 2.33 KB


A simple tool to indent OCaml programs

Authors: Louis Gesbert (OCamlPro), Thomas Gazagnaire (OCamlPro), Jun Furuse

License: GPL v3.0


You need OCaml and ocp-build installed to compile ocp-indent.

make install

If you use opam and want it installed alongside ocaml, you may want to use ./configure --prefix $(opam config -var prefix).


  • ocp-indent or ocp-indent < outputs the file re-indented
  • From emacs, load emacs.el to have tuareg-mode automatically use ocp-indent. Warning: it is in a very early stage, intended for testing and debug only.
  • From emacs, you can also do a quick test with C-u M-| ocp-indent

These options should be mostly useful for binding in editors:

  • ocp-indent --lines <m>-<n> reindents only from line <m> to line <n>
  • ocp-indent --numeric only outputs the indentation values as integers, for the lines that should be reindented.


  • tests/passing contains tests that are properly indented and should be left unchanged by ocp-indent.
  • tests/failing contains tests for which ocp-indent currently returns the results in tests/failing-output, hence meld tests/failing{,-output} should give an overview of currently known bugs.
  • tests/ checks the current state against the reference state (checked into git).
  • tests/ --[git-]update updates the current reference state.
  • See tests/ --help for more

Please make sure tu run make && tests/ --git-update before any commit, so that the repo always reflects the state of the program.

Configuration options

A proper configuration engine is being written. For the time being you can use a few environment variables defined at the beginning of src/ of most use should be match_clause_indent (usually 2 or 4, default is 2) and type_indent.

Testing ocp-indent with emacs/vim

make install will copy elisp and vim scripts to <prefix>/share/typerex/ocp-indent/. Just load them in the editor of your choice to automatically use ocp-indent (obviously, replacing <prefix>):


echo '(load-file "<prefix>/share/typerex/ocp-indent/ocp-indent.el")' >>~/.emacs

will setup tuareg-mode to use ocp-indent.


echo 'autocmd FileType ocaml source <prefix>/share/typerex/ocp-indent/ocp-indent.vim' >>~/.vimrc
Jump to Line
Something went wrong with that request. Please try again.