Ormolu uses too much vertical space
I frequently work on a laptop with quite limited vertical space. There's only so much context I can/want to keep in my brain. I find the formatting used by Ormolu to frequently use much more vertical space than I would have myself.
I love that I can set Emacs to nicely format my code when I save my file. But if that means I later have to work that much harder read my code, the gain from uniform formatting is lost.
Some examples:
[ "if",
"else",
"of",
"upon",
"where",
"return",
"yield",
"break",
"continue",
"in",
"do",
"then",
"until",
"otherwise",
"catch"
]
Why aren't these on a single line (or two)?
pExpr =
choice
( [ EAttr <$> pAttr <*> pExpr,
EReturn <$> (pKeyword "return" *> optional pExpr),
EDef <$> pExpr <*> many pArr
] ::
[P Expr]
)
where
pArr =
reservedOp "=>"
*> ( eitherP
(reservedOp "{" *> pList <* reservedOp "}")
pAttr
)
Why is 'choice' on a new line? Same for 'reservedOp'? Why is '[P Expr]' on a new line?
I realise that these things are a matter of style. But to me vertical space is precious and mustn't be squandered, so this will be a deal breaker for me.
Re/ your first example — Ormolu preserves the multi-line-ness of most expressions, i.e. if it was one line in the input file it will be one line in the output file, and if it was 2+ lines in the input file, it will be formatted in a generic "multiline" fashion. For lists it means that every element goes on its own line.
Currently Ormolu never emits a list where some elements share a line and others don't, and it also never turns a multiline list into a single-line list.
Re/ choice being on its own line — there is a discussion at https://github.com/tweag/ormolu/issues/514.
Example 1 will stay on a single line if the input is on a single line. If you want multiple lines but also multiple list items on each line, break the list into multiple sublists concatenated together. There's always a tension between more automation and finer control. So sometimes workarounds like this are needed (though personally I'm happy to have long lists take up all the vertical space it needs).