fourmolu icon indicating copy to clipboard operation
fourmolu copied to clipboard

Fewer newlines

Open expipiplus1 opened this issue 4 years ago • 1 comments

Although it's probably more diff-friendly, I think it looks super weird to have code like

x =
    y

-- or

y 
  | x -> _
  | foo -> _

In both of these cases y or | can be shifted up a line with no horizontal movement.

The implementation is reasonably simple with a caveat. When inserting a newline with no pending comments, check rcIndent against scColumn and if the column has already reached the required indent, don't insert a newline (and maybe push some spaces to reach rcIndent as further lines may require alignment).

The caveat is that this interacts quite poorly with the alignment branch, as scColumn is indeterminate until the expression is rendered fully...

expipiplus1 avatar Jun 14 '21 02:06 expipiplus1

The caveat is that this interacts quite poorly with the alignment branch, as scColumn is indeterminate until the expression is rendered fully...

Perhaps an easy solution to this is to whenever we want access to scColumn deny the current line from taking part in alignment. This would make any column-dependent layout take precedence over alignment. Tricky to implement though as there could be several nested alignment contexts.

expipiplus1 avatar Jun 14 '21 06:06 expipiplus1