on master help sign in
Align multi-line lambda arguments nicer
de279d8Utku Demir
data/examples/declaration/value/function/lambda-multi-line1-out.hs+4−3
@@ -9,6 +9,7 @@ bar x = \y ->
9 else 12
9 else 12
10
10
11foo =
11foo =
12− prop "is inverse to closure" $ \(f :: StaticPtr (Int -> Int))
12+ prop "is inverse to closure"
13+ $ \(f :: StaticPtr (Int -> Int))
13− (x :: Int) ->
14+ (x :: Int) ->
14− (unclosure . closure) f x == deRefStaticPtr f x
15+ (unclosure . closure) f x == deRefStaticPtr f x
data/examples/declaration/value/function/lambda-multi-line1.hs+2−3
@@ -10,6 +10,5 @@ bar x = \y ->
10
10
11foo =
11foo =
12 prop "is inverse to closure" $ \(f :: StaticPtr (Int -> Int))
12 prop "is inverse to closure" $ \(f :: StaticPtr (Int -> Int))
13− (x :: Int) ->
13+ (x :: Int) ->
14− (unclosure . closure) f x == deRefStaticPtr f x
14+ (unclosure . closure) f x == deRefStaticPtr f x
15−
data/examples/declaration/value/function/lambda-multi-line2.hs−1
@@ -10,4 +10,3 @@ tricky2 =
10 flip all (zip ws gs) $
10 flip all (zip ws gs) $
11 \(wt, gt) ->
11 \(wt, gt) ->
12 canUnify poly_given_ok wt gt || go False wt gt
12 canUnify poly_given_ok wt gt || go False wt gt
13−
src/Ormolu/Printer/Meat/Declaration/Value.hs+8−2
@@ -17,6 +17,7 @@ import Data.Bool (bool)
17import Data.Char (isPunctuation, isSymbol)
17import Data.Char (isPunctuation, isSymbol)
18import Data.Data hiding (Infix, Prefix)
18import Data.Data hiding (Infix, Prefix)
19import Data.List (intersperse, sortOn)
19import Data.List (intersperse, sortOn)
20+import Data.List.NonEmpty (NonEmpty ((:|)))
20import Data.Text (Text)
21import Data.Text (Text)
21import GHC
22import GHC
22import Ormolu.Printer.Combinators
23import Ormolu.Printer.Combinators
@@ -182,7 +183,7 @@ p_match' placer pretty style isInfix strictness m_pats m_grhss = do
182 SplicePat _ _ -> True
183 SplicePat _ _ -> True
183 _ -> False
184 _ -> False
184 txt (if needsSpace then "\\ " else "\\")
185 txt (if needsSpace then "\\ " else "\\")
185− stdCase
186+ sitcc stdCase
186 LambdaCase -> stdCase
187 LambdaCase -> stdCase
187 return inci'
188 return inci'
188 let
189 let
@@ -946,7 +947,12 @@ cmdTopPlacement = \case
946
947
947exprPlacement :: HsExpr GhcPs -> Placement
948exprPlacement :: HsExpr GhcPs -> Placement
948exprPlacement = \case
949exprPlacement = \case
950+ -- Only hang lambdas with single line parameter lists
951+ HsLam NoExt mg -> case mg of
952+ MG _ (L _ [L _ (Match NoExt _ (x:xs) _)]) _
953+ | isOneLineSpan (combineSrcSpans' $ fmap getLoc (x :| xs))
949− HsLam NoExt _ -> Hanging
954+ -> Hanging
955+ _ -> Normal
950 HsLamCase NoExt _ -> Hanging
956 HsLamCase NoExt _ -> Hanging
951 HsCase NoExt _ _ -> Hanging
957 HsCase NoExt _ _ -> Hanging
952 HsDo NoExt DoExpr _ -> Hanging
958 HsDo NoExt DoExpr _ -> Hanging