ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Combination of options that matches ocp-indent's `strict_with=always` ?

Open dbuenzli opened this issue 4 years ago • 3 comments

This is more a question than a feature request.

Is there a combination of options that allow to match ocp-indent's strict_with=always option ?

This option basically maximizes the space for your scarce 80 columns by always having | unindented – it also more consistent since | never get indented.

I managed to unindent function by setting function-indent = 0 but I didn't find how to:

  1. Unindent type declarations
  2. Have a way to bring the first, toplevel match, on the same line as arguments when there is space[^1]:
(* Assumes long definitions that do not get collapsed on a line *)

type t = 
| A … 
| B …

let f = function
| A -> …
| B -> …

let f v arg = match v with 
| A -> …
| B -> …

[^1]: I don't know if that's supported but I think it would be nice. If I add a new argument to a function after the one that is being matched with function, then I replace the function by match v with. But with the current ocamlformat this will reformat my whole function body.

dbuenzli avatar Nov 25 '21 14:11 dbuenzli

There was an attempt at supporting ocp-indent options in ocamlformat as you can see, but it's far from perfect, mostly due to the fact that as opposed to ocp-indent, we don't just reindent the code we print the whole AST. To have match _ with floating after = would be painful as we have to fit the formatting we want into what is possible with Format.

We also made the choice to deprecate ocp-indent options' support for the next release, in the long run we still hope to see people adopt one of the main styles that emerged within the community, instead of each project having its own style.

In the mean time you can still use these options of course, for type declarations you can use --type-decl-indent 0.

gpetiot avatar Dec 03 '21 12:12 gpetiot

To have match _ with floating after = would be painful as we have to fit the formatting we want into what is possible with Format.

:-(

adopt one of the main styles that emerged within the community,

Is there one "main style" that truly tries to get you most of your 80 columns ?

I think all these indents when you have a strong initial indicator like | on the line are mostly useless and a waste of the scarce horizontal space.

dbuenzli avatar Dec 03 '21 12:12 dbuenzli

Is there one "main style" that truly tries to get you most of your 80 columns ?

No, but here is a short description of the styles:

  • the default one is deemed to be the more beginner-friendly by the ocaml-platform/mirage community,
  • the janestreet one is the style used by JaneStreet,
  • and ocamlformat focuses on legibility (in the sense of making it as hard as possible for quick visual parsing to give the wrong interpretation, see the readme for more details).

The issue is that everyone has its own taste, habits and constraints, but as a maintainer (it's mostly me) it is not feasible anymore to keep this many options, it makes the code of ocamlformat much more difficult to evolve, preventing refactoring and simplifications, and testing easily misses bugs and inconsistencies when testing the combination of options.

gpetiot avatar Dec 06 '21 10:12 gpetiot