-
Notifications
You must be signed in to change notification settings - Fork 42
Ocamlformat
Ocamlformat has not officially been adopted by the links project. This is simply a guide to introduce it.
Install Ocamlformat using opam install ocamlformat
Add the opam site-lisp
directory to your load path, then load the ocamlformat file.
(push "~/.opam/4.07.0/share/emacs/site-lisp/" load-path)
(require 'ocamlformat)
Just call ocamlformat <file-name>
to format a file.
It is possible to use the script tools/rules/ocamlformat_check.skip fix
to apply to all files.
Use the ocamlformat
command (invoke using Alt-q).
It is also possible to use ocamlformat-write-on-save
to have ocamlformat run automatically.
Ocamlformat has multiple ways to change settings:
- project wide (
.ocamlformat
file) - environmental variable
OCAMLFORMAT=option=val
- file wide
[@@@ocamlformat "option=val"]
- expression
[@@ocamlformat "option=val"]
To prevent a file from being run add the file directive to the top of the file:
[@@@ocamlformat "disable"]
Make sure that match cases aren't put on the same line:
break-cases=toplevel
Ensure that documentation comments (** ... *)
are formatted before the declaration:
doc-comments=before
It is worth reading the man page for ocamlformat using man ocamlformat
or ocamlformat --help
.