ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

do not break before match when that's the first body item of a function

Open samoht opened this issue 7 years ago • 4 comments

Currently the following code:

let f x = match x.v with
  |  Foo asdasdassdasdasdadasasddaasdas ->
      foosadadadasdsa asdadadadsa dadasdsadasdasdas
  | Bar -> sdasdas

is formatted into:

let f x =
  match x.y with
  | Foo asdasdassdasdasdadasasddaasdas ->
      foosadadadasdsa asdadadadsa dadasdsadasdasdas
  | Bar -> sdasdas

would it be possible to keep the let f x = match x.y with on the same line?

samoht avatar Aug 28 '18 08:08 samoht

Note that this sort of style, where the nesting of formatting boxes will need to be quite different from the nesting structure of the parsetree (because the indentation of the expression is not relative to the beginning of the expression) is involved and fragile in the current implementation. This is the sort of thing that introducing an intermediate structure between the parsetree and the formatting boxes would make easier.

jberdine avatar Aug 28 '18 11:08 jberdine

Easier after #406

jberdine avatar Sep 08 '18 14:09 jberdine

Given what's been said above, I'm not sure "Good first issue" is the right tag.

trefis avatar Jun 05 '19 09:06 trefis

Sorry for the very late answer, out of curiosity is that a really common style in the ocaml community? I've never seen it anywhere (I mean yes for function ofc, I can conceive it for fun but never seen it with match)

gpetiot avatar Nov 04 '21 21:11 gpetiot