ocp-indent [OPTION]… [FILE]…
Indent OCaml source files according to the official conventions, with a small number of tunable parameters.
Outputs the indented version of each FILE given in the command line to standard output, unless invoked with the `--inplace' option (see Options below). If no FILE is provided, reads from standard input.
Parameters can be defined on the command-line via the --config option, or as a configuration definition in one of the following, searched in order: a file named `.ocp-indent' in the current directory or its parents (which allows for per-project indentation settings), the file `$XDG_CONFIG_HOME/ocp/ocp-indent.conf', the file `$HOME/.ocp/ocp-indent.conf', or the environment variable $OCP_INDENT_CONFIG.
A configuration definition is a list of bindings in the form NAME=VALUE or of PRESET, separated by commas or newlines
- base=INT (default=2)
Indentation used when none of the following options applies.
let foo = ..bar
- type=INT (default=2)
Indentation for type definitions.
type t = ..int
- in=INT (default=0)
Indentation after `let ... in', unless followed by another `let'.
let foo = () in ..bar
- with=INT (default=0)
Indentation after `match ... with', `try ... with' or `function'.
match foo with ..| _ -> bar
- match_clause=INT (default=2)
Indentation for clauses inside a pattern-match (after arrows).
match foo with | _ -> ..bar
- ppx_stritem_ext=INT (default=2)
Indentation for items inside a [%%id ... ] extension node).
[%% id.id ..let x = 3 ]
- max_indent=<INT|none> (default=4)
When nesting expressions on the same line, their indentations are stacked in some cases so that they remain correct if you close them one per line. However, this can lead to large indentations in complex code, so this parameter sets a maximum indentation. Note that it only affects indentation after function arrows and opening parens at the ends of lines.
let f = g (h (i (fun x -> ....x) ) )
- strict_with=<always|never|auto> (default=never)
If `never', match bars are indented, superseding `with', whenever `match with' doesn't start its line. If `auto', there are exceptions for constructs like `begin match with'. If `always', `with' is always strictly respected, and additionally applies to variant types definition, for consistency.
Example with `strict_with=never,with=0': begin match foo with ..| _ -> bar end
- strict_else=<always|never|auto> (default=always)
If `always', indent after the `else' keyword normally, like after `then'. If `auto', indent after `else' unless in a few "unclosable" cases (`let .... in', `match', etc.). If `never', the `else' keyword won't indent when followed by a newline.
Example with `strict_else=auto': if cond then foo else let x = bar in baz
- strict_comments=BOOL (default=false)
In-comment indentation is normally preserved, as long as it respects the left margin or the comments starts with a newline. Setting this to `true' forces alignment within comments. Lines starting with `*' are always aligned
- align_ops=BOOL (default=true)
Toggles preference of column-alignment over line indentation for most of the common operators and after mid-line opening parentheses.
Example with `align_ops=true': let f x = x + y Example with `align_ops=false': let f x = x + y
- align_params=<always|never|auto> (default=auto)
If `never', function parameters are indented one level from the line of the function. If `always', they are aligned from the column of the function. if `auto', alignment is chosen over indentation in a few cases, e.g. after match arrows
Example with `align_params=never': match foo with | _ -> some_fun ..parameter Example with `align_params=always' or `auto': match foo with | _ -> some_fun ..parameter
Available presets are `normal', the default, `apprentice' which may make some aspects of the syntax more obvious for beginners, and `JaneStreet'.
- -c CONFIG, --config=CONFIG
Configure the indentation parameters. See section Configuration for more information.
- -d, --debug
Enable debug output to stderr.
- --help[=FMT] (default=auto)
Show this help in format FMT. The value FMT must be one of auto, pager, groff or plain. With auto, the format is pager or plain whenever the TERM env var is dumb or undefined.
- -i, --inplace
Re-indent files in-place.
Return indent for empty lines, too. Especially usefull with --numeric.
- -l RANGE, --lines=RANGE (absent=-)
Only re-indent the lines in RANGE (eg. 10-12), adapting to the current indentation of surrounding lines. Lines start at 1.
Instead of re-indenting the file, output one integer per line representing the indentation value. When specified together with --lines, only print as many values as lines in the range.
- -o FILE, --output=FILE
Output to FILE. The default is to print to stdout.
Print the current parameters to stdout and exit. (See section Configuration for more information.)
Extend the handled syntax for OCaml syntax extensions.
Show version information.
Bugs are tracked on github at https://github.com/OCamlPro/ocp-indent/issues. The tests directory of the source distribution is a good snapshot of the current status, and can be checked online at http://htmlpreview.github.io/?https://github.com/OCamlPro/ocp-indent/blob/master/tests/failing.html
Louis Gesbert and Thomas Gazagnaire from OCamlPro, from an original prototype by Jun Furuse.
Copyright (C) 2013 OCamlPro.
ocp-indent is free software, released under the terms of the GNU General Public License version 3, the text of which can be found in the file `LICENSE' distributed with the sources.