Skip to content

Commit

Permalink
Add ocp-indent as a formatter
Browse files Browse the repository at this point in the history
ocp-indent allows indenting even partially compiling OCaml code, while
ocamlformat requires the code to compile correctly. Also, Doom Emacs
uses ocp-indent when ocamlformat's configuration file is not found, and
not having an ocp-indent formatter gives an error.
  • Loading branch information
punchagan committed Jun 27, 2024
1 parent 61766b5 commit 5f720d3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ The format is based on [Keep a Changelog].
called if provided. See [#204].

### Formatters
* [`ocp-indent`](https://github.com/OCamlPro/ocp-indent) for
[Ocaml](https://ocaml.org/) ([#306]).
* [`ocp-indent`](http://www.typerex.org/ocp-indent.html) for [Python](https://python.org) imports using ruff ([#279]).

### Bugs fixed
* The point alignment algorithm, which has been slightly wrong since
2019, has been fixed to more correctly use dynamic programming to
Expand Down
1 change: 1 addition & 0 deletions apheleia-formatters.el
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
(nixfmt . ("nixfmt"))
(ocamlformat . ("ocamlformat" "-" "--name" filepath
"--enable-outside-detected-project"))
(ocp-indent . ("ocp-indent"))
(ormolu . ("ormolu"))
(perltidy . ("perltidy" "--quiet" "--standard-error-output"
(apheleia-formatters-indent "-t" "-i")
Expand Down
5 changes: 5 additions & 0 deletions test/formatters/installers/ocp-indent.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apt-get install -y opam

opam init -n --disable-sandboxing --root /opt/ocp-indent
opam install ocp-indent -y --root /opt/ocp-indent
ln -s /opt/ocp-indent/default/bin/ocp-indent /usr/local/bin/
35 changes: 35 additions & 0 deletions test/formatters/samplecode/ocp-indent/in.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(* https://github.com/OCamlPro/ocp-indent/blob/master/tests/failing/list_of_funs.ml *)

let f x =
(fun x -> x [ (fun () -> 3) ;
(fun () -> 4) ])

let f x = (fun x -> x [ (fun () -> 3) ;
(fun () -> 4) ])

let f x =
x [ (fun () -> 3) ;
(fun () -> 4) ]

let f x =
[ (fun () -> 3) ;
(fun () -> 4) ]

let f x =
(fun x -> x [ (fun () ->
3) ;
(fun () -> 4) ])

let f x = (fun x -> x [ (fun () ->
3) ;
(fun () -> 4) ])

let f x =
x [ (fun () ->
3) ;
(fun () -> 4) ]

let f x =
[ (fun () ->
3) ;
(fun () -> 4) ]
35 changes: 35 additions & 0 deletions test/formatters/samplecode/ocp-indent/out.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(* https://github.com/OCamlPro/ocp-indent/blob/master/tests/failing/list_of_funs.ml *)

let f x =
(fun x -> x [ (fun () -> 3) ;
(fun () -> 4) ])

let f x = (fun x -> x [ (fun () -> 3) ;
(fun () -> 4) ])

let f x =
x [ (fun () -> 3) ;
(fun () -> 4) ]

let f x =
[ (fun () -> 3) ;
(fun () -> 4) ]

let f x =
(fun x -> x [ (fun () ->
3) ;
(fun () -> 4) ])

let f x = (fun x -> x [ (fun () ->
3) ;
(fun () -> 4) ])

let f x =
x [ (fun () ->
3) ;
(fun () -> 4) ]

let f x =
[ (fun () ->
3) ;
(fun () -> 4) ]

0 comments on commit 5f720d3

Please sign in to comment.