File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,44 @@ line like:
112112will enable you to have the indentation after ` in ` setup to 2 locally on this
113113file.
114114
115+ ## Autoformat files with ocp-indent in dune
116+
117+ ` dune fmt ` or ` dune build @fmt ` can be used to format dune files and ocaml files
118+ with ocamlformat. This can prove a convenient workflow for new projects and made
119+ it available to ` ocp-indent ` users as well.
120+
121+ First you need to disable the default formatting rules for OCaml source files
122+ by adding the following to your ` dune-project ` :
123+ ``` dune
124+ (formatting (enabled_for dune))
125+ ```
126+
127+ ` dune fmt ` won't try to format your OCaml files with ` ocamlformat ` from there.
128+
129+ The ` ocp-indent ` formatting rules need to be enabled on a per-directory basis by
130+ adding the following dune rules to the ` dune ` file:
131+
132+ ``` dune
133+ ;; Auto indent files with `dune build @fmt`
134+
135+ (subdir
136+ run
137+ (dynamic_include ../rules/dune.ocp-indent))
138+
139+ (subdir
140+ rules
141+ (rule
142+ (deps
143+ (glob_files ../*.{ml,mli}))
144+ (target dune.ocp-indent)
145+ (action
146+ (run ocp-indent-gen-rules -o %{target}))))
147+ ```
148+
149+ ` ocp-indent-gen-rules ` will generate promotion based formatting rules for each
150+ ` .ml ` and ` .mli ` files in this folder. You can simply use the same
151+ ` dune build @fmt ` /` dune promote ` workflow as with ocamlformat.
152+
115153
116154## How does it compare to tuareg ?
117155
You can’t perform that action at this time.
0 commit comments