diff --git a/data/examples/declaration/value/function/do-out.hs b/data/examples/declaration/value/function/do-out.hs index 278a671..cf54e5c 100644 --- a/data/examples/declaration/value/function/do-out.hs +++ b/data/examples/declaration/value/function/do-out.hs @@ -20,3 +20,9 @@ baz = do bar c let d = c + 2 return d + +quux = + something $ do + foo + bar + baz diff --git a/data/examples/declaration/value/function/do.hs b/data/examples/declaration/value/function/do.hs index 365bc3a..c08469e 100644 --- a/data/examples/declaration/value/function/do.hs +++ b/data/examples/declaration/value/function/do.hs @@ -16,3 +16,8 @@ baz = do bar c let d = c + 2 return d + +quux = something $ do + foo + bar + baz diff --git a/src/Ormolu/Printer/Meat/Declaration/Pat.hs b/src/Ormolu/Printer/Meat/Declaration/Pat.hs index c82c7e5..dab2b79 100644 --- a/src/Ormolu/Printer/Meat/Declaration/Pat.hs +++ b/src/Ormolu/Printer/Meat/Declaration/Pat.hs @@ -55,10 +55,8 @@ p_pat = \case Nothing -> txt ".." Just x -> located x p_hsRecField inci . braces . velt . withSep comma f $ case dotdot of - Nothing -> - Just <$> fields - Just n -> do - (Just <$> take n fields) ++ [Nothing] + Nothing -> Just <$> fields + Just n -> (Just <$> take n fields) ++ [Nothing] InfixCon x y -> do located x p_pat space diff --git a/src/Ormolu/Printer/Meat/Declaration/Value.hs b/src/Ormolu/Printer/Meat/Declaration/Value.hs index 9b6de32..c62a90a 100644 --- a/src/Ormolu/Printer/Meat/Declaration/Value.hs +++ b/src/Ormolu/Printer/Meat/Declaration/Value.hs @@ -231,7 +231,9 @@ p_hsExpr = \case located x p_hsExpr space located op p_hsExpr - breakpoint + if isPrefixBlockExpr (unL y) + then space + else breakpoint inci (located y p_hsExpr) NegApp NoExt e _ -> do txt "-" @@ -437,10 +439,14 @@ getGRHSSpan (XGRHS NoExt) = notImplemented "XGRHS" -- case expressions. isPrefixBlock :: [LGRHS GhcPs (LHsExpr GhcPs)] -> Bool -isPrefixBlock [(L _ (GRHS NoExt _ (L _ e)))] = - case e of - HsLam NoExt _ -> True - HsDo NoExt _ _ -> True - HsLamCase NoExt _ -> True - _ -> False +isPrefixBlock [(L _ (GRHS NoExt _ (L _ e)))] = isPrefixBlockExpr e isPrefixBlock _ = False + +-- | Similar to 'isPrefixBlock', but just for checking 'HsExpr' directly. + +isPrefixBlockExpr :: HsExpr GhcPs -> Bool +isPrefixBlockExpr = \case + HsLam NoExt _ -> True + HsDo NoExt _ _ -> True + HsLamCase NoExt _ -> True + _ -> False