on master help sign in
Improve handling of newlines
d7d4592mrkkrp
data/examples/declaration/instance/single-parameter-out.hs+3−2
@@ -6,5 +6,6 @@ instance Enum Int where
6
6
7 fromEnum x = x
7 fromEnum x = x
8
8
9− toEnum = \x ->
9+ toEnum =
10+ \x ->
10− x
11+ x
data/examples/declaration/value/function/arrow/proc-cases-out.hs+12−11
@@ -2,14 +2,15 @@
2
2
3foo f = proc a -> case a of Left b -> f -< b
3foo f = proc a -> case a of Left b -> f -< b
4
4
5+bar f g h j =
5−bar f g h j = proc a -> case a of
6+ proc a -> case a of
6− Left
7+ Left
7− ( (a, b)
8+ ( (a, b)
8− , (c, d)
9+ , (c, d)
9− ) -> f (a <> c) -< b <> d
10+ ) -> f (a <> c) -< b <> d
10− Right
11+ Right
11− (Left a) ->
12+ (Left a) ->
12− h -< a
13+ h -< a
13− Right
14+ Right
14− (Right b) ->
15+ (Right b) ->
15− j -< b
16+ j -< b
data/examples/declaration/value/function/arrow/proc-forms-out.hs+26−22
@@ -2,30 +2,34 @@
2
2
3foo0 f g x y = proc _ -> (|f (g -< (x, y))|)
3foo0 f g x y = proc _ -> (|f (g -< (x, y))|)
4
4
5−foo1 f g h x = proc (y, z) ->
5+foo1 f g h x =
6+ proc (y, z) ->
6− (|test (h f . (h g) -< (y x) . y z) ((h g) . h f -< y z . (y x))|)
7+ (|test (h f . (h g) -< (y x) . y z) ((h g) . h f -< y z . (y x))|)
7
8
8−foo2 f g h x = proc (y, z) ->
9+foo2 f g h x =
10+ proc (y, z) ->
9− (| test
11+ (| test
10− ( h f .
12+ ( h f .
11− h g -<
13+ h g -<
12− y x .
14+ y x .
13− y z
15+ y z
14− )
16+ )
15− ( h g .
17+ ( h g .
16− h f -<
18+ h f -<
17− y z .
19+ y z .
18− y x
20+ y x
19− )
21+ )
20− |)
22+ |)
21
23
22bar0 f g x y = proc _ -> f -< x &&& g -< y
24bar0 f g x y = proc _ -> f -< x &&& g -< y
23
25
24−bar1 f g h x = proc (y, z) ->
26+bar1 f g h x =
27+ proc (y, z) ->
25− h f . (h g) -< (y x) . y z ||| (h g) . h f -< y z . (y x)
28+ h f . (h g) -< (y x) . y z ||| (h g) . h f -< y z . (y x)
26
29
27−bar2 f g h x = proc (y, z) ->
30+bar2 f g h x =
28− (h f . h g) -<
31+ proc (y, z) ->
32+ (h f . h g) -<
29− (y x) . y z |||
33+ (y x) . y z |||
30− (h g . h f) -<
34+ (h g . h f) -<
31− y z . (y x)
35+ y z . (y x)
data/examples/declaration/value/function/arrow/proc-lambdas-out.hs+5−2
@@ -2,5 +2,8 @@
2
2
3foo = proc a -> \f b -> a -< f b -- Foo
3foo = proc a -> \f b -> a -< f b -- Foo
4
4
5+bar =
6+ proc x -> \f g h ->
7+ \() ->
5−bar = proc x -> \f g h -> \() -> \(Left (x, y)) -> -- Tuple value
8+ \(Left (x, y)) -> -- Tuple value
6− f (g (h x)) -< y
9+ f (g (h x)) -< y
data/examples/declaration/value/function/case-multi-line-out.hs+15−13
@@ -4,12 +4,13 @@ foo x = case x of
4 _ -> 12
4 _ -> 12
5
5
6bar :: Int -> Int
6bar :: Int -> Int
7+bar x =
7−bar x = case x of
8+ case x of
8− 5 ->
9+ 5 ->
9− if x > 5
10+ if x > 5
10− then 10
11+ then 10
11− else 12
12+ else 12
12− _ -> 12
13+ _ -> 12
13
14
14baz :: Int -> Int
15baz :: Int -> Int
15baz x = case x of
16baz x = case x of
@@ -21,10 +22,11 @@ quux x = case x of
21 x -> x
22 x -> x
22
23
23withGuards :: Int -> Int
24withGuards :: Int -> Int
24−withGuards x = case x of
25+withGuards x =
25− x
26+ case x of
26− | x > 10 ->
27+ x
28+ | x > 10 ->
27− foo +
29+ foo +
28− bar
30+ bar
29− x | x > 5 -> 10
31+ x | x > 5 -> 10
30− _ -> 20
32+ _ -> 20
data/examples/declaration/value/function/do-out.hs+10−9
@@ -4,15 +4,16 @@ bar = do
4 foo
4 foo
5 bar
5 bar
6
6
7−baz = mdo
7+baz =
8+ mdo
8− bar a
9+ bar a
9− a <- foo
10+ a <- foo
10− b <-
11+ b <-
11− bar
12+ bar
12− 1
13+ 1
13− 2
14+ 2
14− 3
15+ 3
15− return (a + b)
16+ return (a + b)
16
17
17baz = do
18baz = do
18 a <- foo
19 a <- foo
data/examples/declaration/value/function/lambda-single-line-out.hs+2−1
@@ -2,7 +2,8 @@ foo :: a -> a -> a
2foo x = \y -> x
2foo x = \y -> x
3
3
4bar :: a -> a -> a
4bar :: a -> a -> a
5−bar x = \y -> x
5+bar x =
6+ \y -> x
6
7
7baz :: a -> a -> a
8baz :: a -> a -> a
8baz = \ ~x ~y -> x
9baz = \ ~x ~y -> x
src/Ormolu/Printer/Meat/Declaration/Value.hs+15−8
@@ -142,14 +142,13 @@ p_match' placer pretty style isInfix m_pats m_grhss = do
142 return inci'
142 return inci'
143
143
144 let
144 let
145− -- Calculate a 'SrcSpan' that captures the end of the name\/pattern part
145+ -- Calculate position of end of patterns. This is useful when we decide
146− -- of the match. This is used to tell if we need to have the body on a
146+ -- about putting certain constructions in hanging positions.
147− -- newline.
148− endOfPatsSpan = srcLocSpan . srcSpanEnd <$> case NE.nonEmpty m_pats of
147+ endOfPats = case NE.nonEmpty m_pats of
149 Nothing -> case style of
148 Nothing -> case style of
150− Function name -> Just $ getLoc name
149+ Function name -> (Just . srcSpanEnd . getLoc) name
151 _ -> Nothing
150 _ -> Nothing
152− Just pats -> Just . getLoc $ NE.last pats
151+ Just pats -> (Just . srcSpanEnd . getLoc . NE.last) pats
153 isCase = \case
152 isCase = \case
154 Case -> True
153 Case -> True
155 LambdaCase -> True
154 LambdaCase -> True
@@ -166,8 +165,16 @@ p_match' placer pretty style isInfix m_pats m_grhss = do
166 _ -> txt " ->"
165 _ -> txt " ->"
167 let grhssSpan = combineSrcSpans' $
166 let grhssSpan = combineSrcSpans' $
168 getGRHSSpan . unLoc <$> NE.fromList grhssGRHSs
167 getGRHSSpan . unLoc <$> NE.fromList grhssGRHSs
169− patGrhssSpan = maybe grhssSpan (combineSrcSpans grhssSpan) endOfPatsSpan
168+ patGrhssSpan = maybe grhssSpan
169+ (combineSrcSpans grhssSpan . srcLocSpan) endOfPats
170+ placement =
171+ case endOfPats of
170− placement = blockPlacement placer grhssGRHSs
172+ Nothing -> blockPlacement placer grhssGRHSs
173+ Just spn ->
174+ if isOneLineSpan
175+ (mkSrcSpan spn (srcSpanStart grhssSpan))
176+ then blockPlacement placer grhssGRHSs
177+ else Normal
171 inciLocalBinds = case placement of
178 inciLocalBinds = case placement of
172 Normal -> id
179 Normal -> id
173 Hanging -> inci
180 Hanging -> inci