From 5f720d320830da430cbf7c4a1e8f36fb0af520a9 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Thu, 27 Jun 2024 16:20:30 +0530 Subject: [PATCH] Add ocp-indent as a formatter 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. --- CHANGELOG.md | 4 +++ apheleia-formatters.el | 1 + test/formatters/installers/ocp-indent.bash | 5 +++ test/formatters/samplecode/ocp-indent/in.ml | 35 ++++++++++++++++++++ test/formatters/samplecode/ocp-indent/out.ml | 35 ++++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 test/formatters/installers/ocp-indent.bash create mode 100644 test/formatters/samplecode/ocp-indent/in.ml create mode 100644 test/formatters/samplecode/ocp-indent/out.ml diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d7a553..ccc7922 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/apheleia-formatters.el b/apheleia-formatters.el index 6257e09..ebb8b3a 100644 --- a/apheleia-formatters.el +++ b/apheleia-formatters.el @@ -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") diff --git a/test/formatters/installers/ocp-indent.bash b/test/formatters/installers/ocp-indent.bash new file mode 100644 index 0000000..0e449f2 --- /dev/null +++ b/test/formatters/installers/ocp-indent.bash @@ -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/ diff --git a/test/formatters/samplecode/ocp-indent/in.ml b/test/formatters/samplecode/ocp-indent/in.ml new file mode 100644 index 0000000..d647068 --- /dev/null +++ b/test/formatters/samplecode/ocp-indent/in.ml @@ -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) ] diff --git a/test/formatters/samplecode/ocp-indent/out.ml b/test/formatters/samplecode/ocp-indent/out.ml new file mode 100644 index 0000000..dddb26b --- /dev/null +++ b/test/formatters/samplecode/ocp-indent/out.ml @@ -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) ]