@@ -59,6 +59,7 @@ data Placement
59 | Hanging -- ^ Expressions that have hanging form
59 | Hanging -- ^ Expressions that have hanging form
60 -- should use it and avoid bumping one level
60 -- should use it and avoid bumping one level
61 -- of indentation
61 -- of indentation
63p_valDecl :: HsBindLR GhcPs GhcPs -> R ()
64p_valDecl :: HsBindLR GhcPs GhcPs -> R ()
64p_valDecl = \case
65p_valDecl = \case
@@ -512,11 +513,34 @@ p_hsExpr = \case
512 txt "\\case"
513 txt "\\case"
513 breakpoint
514 breakpoint
514 inci (p_matchGroup LambdaCase mgroup)
515 inci (p_matchGroup LambdaCase mgroup)
515− HsApp NoExt f x -> sitcc $ do
516+ HsApp NoExt f x -> do
516− located f p_hsExpr
517+ -- We hang only the last function argument. In order to do
517− -- Second argument can be a `do` or `case` block with `-XBlockArguments`.
518+ -- this, we only call 'placeHanging' on the topmost 'HsApp',
519+ -- and then use 'p_withoutHanging' for the descendants.
520+ let p_withoutHanging (HsApp NoExt f' x') = do
522+ (L _ (HsApp _ _ _)) -> located f' p_withoutHanging
523+ _ -> located f' p_hsExpr
525+ inci $ located x' p_hsExpr
526+ p_withoutHanging e = p_hsExpr e
527+ -- Only use the hanging placement if the function spans
530+ if isOneLineSpan (getLoc f)
518− placeHanging (exprPlacement (unLoc x)) $
531+ then exprPlacement (unLoc x)
533+ -- We only sit when the last expression is not hanging.
534+ -- This is to allow:
537+ sit' = if placement == Normal
541+ useBraces $ located f p_withoutHanging
542+ placeHanging placement $
519− located x p_hsExpr
543+ located x p_hsExpr
520 HsAppType a e -> do
544 HsAppType a e -> do
521 located e p_hsExpr
545 located e p_hsExpr
522 breakpoint
546 breakpoint
@@ -1091,6 +1115,8 @@ exprPlacement = \case
1091 -- whole block hanging; so that we can use the common @f = foo $ do@
1115 -- whole block hanging; so that we can use the common @f = foo $ do@
1092 -- style.
1116 -- style.
1093 OpApp NoExt _ _ y -> exprPlacement (unLoc y)
1117 OpApp NoExt _ _ y -> exprPlacement (unLoc y)
1118+ -- Same thing for function applications (usually with -XBlockArguments)
1119+ HsApp NoExt _ y -> exprPlacement (unLoc y)
1094 HsProc NoExt (L s _) _ ->
1120 HsProc NoExt (L s _) _ ->
1095 -- Indentation breaks if pattern is longer than one line and left
1121 -- Indentation breaks if pattern is longer than one line and left
1096 -- hanging. Consequently, only apply hanging when it is safe.
1122 -- hanging. Consequently, only apply hanging when it is safe.