Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indent multiline bracketed expr with minimal amount of space #1116

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Fix Haddock comments on infix constructors
[Issue 758](https://github.com/tweag/ormolu/issues/758)
* Multiline bracketed expressions indent closing bracket by just 1 space instead of a full indentation

## Ormolu 0.7.5.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bar f x =
( y,
z,
w
)
)
->
f -- The value
-<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bar f g h j =
Left
( (a, b),
(c, d)
) -> f (a <> c) -< b <> d
) -> f (a <> c) -< b <> d
Right
(Left a) ->
h -< a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ foo
( (a, b),
(c, d),
(e, f)
)
)
-> do
-- Begin do
(x, y) <- -- GHC parser fails if layed out over multiple lines
Expand All @@ -29,7 +29,7 @@ foo
Left
( z,
w
) -> \u ->
) -> \u ->
-- Procs can have lambdas
let v =
u -- Actually never used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ foo x = proc (y, z) -> do
(|
bar
(bindA -< y)
|)
|)

foo1 x = proc (y, z) -> do
(|
bar
(bindA -< y)
|)
|)
z
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
foo = do
( bar
baz
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ warningFor var place = do
( if includeGlobals || isLocal var
then warningForLocals
else warningForGlobals
)
)
var
place
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ scientifically h = do
something
( I.satisfy (\w -> w == 'e' || w == 'E')
*> fmap (h . Sci.scientific signedCoeff . (e +)) (signed decimal)
)
)
<|> return (h $ Sci.scientific signedCoeff e)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ barbaz x y z w =
a = do
[ c
| c <- d
]
]

trans =
[ x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ foo
( Bar
x
y
)
)
z = x
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:<|> getNodeInfoR
:<|> getNextUpdateR
:<|> restartNodeR
)
)
:<|> ( getUtxoR
:<|> getConfirmedProposalsR
) = client nodeV1Api
) = client nodeV1Api
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ readerBench doc name =
runPure $ case (getReader name, getWriter name) of
( Right (TextReader r, rexts),
Right (TextWriter w, wexts)
) -> undefined
) -> undefined

f xs = case xs of
[ a,
b
] -> a + b
] -> a + b

g xs = case xs of
( a
: bs
) -> a + b
) -> a + b
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ multiline :: Int
multiline
( n
+ 1
) = n
) = n

n :: Int
(n + 1) = 3
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ z_multiline = True
where
(#
| | _x
#) =
#) =
(#
| | True
#)
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ multiline
Foo
bar
baz
) = True
) = True
6 changes: 5 additions & 1 deletion src/Ormolu/Printer/Combinators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,11 @@ brackets_ needBreaks open close style m = sitcc (vlayout singleLine multiLine)
then newline >> inci m
else space >> sitcc m
newline
inciIf (style == S) (txt close)
inciIfS (txt close)

-- ideally this would be 0, but some contexts require at least one space,
-- e.g. case patterns or top-level patterns
inciIfS = if style == S then inciBy 1 else id

----------------------------------------------------------------------------
-- Literals
Expand Down
2 changes: 2 additions & 0 deletions src/Ormolu/Printer/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Ormolu.Printer.Internal
askModuleFixityMap,
askDebug,
inci,
inciBy,
sitcc,
Layout (..),
enterLayout,
Expand Down Expand Up @@ -396,6 +397,7 @@ askModuleFixityMap = R (asks rcModuleFixityMap)
askDebug :: R Bool
askDebug = R (asks rcDebug)

-- | Like 'inci', but indents by exactly the given number of steps.
inciBy :: Int -> R () -> R ()
inciBy step (R m) = R (local modRC m)
where
Expand Down
2 changes: 1 addition & 1 deletion src/Ormolu/Printer/Meat/Declaration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ declSeries (L _ x) (L _ y) =
case (x, y) of
( SigD _ (TypeSig _ _ _),
SigD _ (TypeSig _ _ _)
) -> True
) -> True
_ -> False

intersects :: (Ord a) => [a] -> [a] -> Bool
Expand Down