on master help sign in
Align multi-line lambda arguments nicer
commitde279d80122b287374d4ed87c7b630db1f157642 authorUtku Demir <me@utdemir.com> dateMon 19 Aug 2019, 16:01 (7 years ago) parentb2c26b7
4 files changed+14−9
data/examples/declaration/value/function/lambda-multi-line1-out.hs+4−3 data/examples/declaration/value/function/lambda-multi-line1.hs+2−3 data/examples/declaration/value/function/lambda-multi-line2.hs−1 src/Ormolu/Printer/Meat/Declaration/Value.hs+8−2
data/examples/declaration/value/function/lambda-multi-line1-out.hs+4−3
@@ -9,6 +9,7 @@ bar x = \y ->
99 else 12
1010
1111foo =
12− prop "is inverse to closure" $ \(f :: StaticPtr (Int -> Int))
13− (x :: Int) ->
14− (unclosure . closure) f x == deRefStaticPtr f x
12+ prop "is inverse to closure"
13+ $ \(f :: StaticPtr (Int -> Int))
14+ (x :: Int) ->
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 ->
1010
1111foo =
1212 prop "is inverse to closure" $ \(f :: StaticPtr (Int -> Int))
13− (x :: Int) ->
14− (unclosure . closure) f x == deRefStaticPtr f x
15−
13+ (x :: Int) ->
14+ (unclosure . closure) f x == deRefStaticPtr f x
data/examples/declaration/value/function/lambda-multi-line2.hs−1
@@ -10,4 +10,3 @@ tricky2 =
1010 flip all (zip ws gs) $
1111 \(wt, gt) ->
1212 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)
1717import Data.Char (isPunctuation, isSymbol)
1818import Data.Data hiding (Infix, Prefix)
1919import Data.List (intersperse, sortOn)
20+import Data.List.NonEmpty (NonEmpty ((:|)))
2021import Data.Text (Text)
2122import GHC
2223import Ormolu.Printer.Combinators
@@ -182,7 +183,7 @@ p_match' placer pretty style isInfix strictness m_pats m_grhss = do
182183 SplicePat _ _ -> True
183184 _ -> False
184185 txt (if needsSpace then "\\ " else "\\")
185− stdCase
186+ sitcc stdCase
186187 LambdaCase -> stdCase
187188 return inci'
188189 let
@@ -946,7 +947,12 @@ cmdTopPlacement = \case
946947
947948exprPlacement :: HsExpr GhcPs -> Placement
948949exprPlacement = \case
949− HsLam NoExt _ -> Hanging
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))
954+ -> Hanging
955+ _ -> Normal
950956 HsLamCase NoExt _ -> Hanging
951957 HsCase NoExt _ _ -> Hanging
952958 HsDo NoExt DoExpr _ -> Hanging