From b2f49a76933a156b35110e76fecd06f178a1f102 Mon Sep 17 00:00:00 2001 From: Basile Henry Date: Sat, 13 Jul 2019 18:13:18 +0100 Subject: [PATCH] Support single line where clauses --- data/examples/declaration/value/function/where-out.hs | 4 +--- src/Ormolu/Printer/Meat/Declaration/Value.hs | 8 +++++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data/examples/declaration/value/function/where-out.hs b/data/examples/declaration/value/function/where-out.hs index b569fde..5b9511c 100644 --- a/data/examples/declaration/value/function/where-out.hs +++ b/data/examples/declaration/value/function/where-out.hs @@ -1,7 +1,5 @@ foo :: Int -> Int -foo x = f x - where - f z = z +foo x = f x where f z = z bar :: Int -> Int bar x = f x diff --git a/src/Ormolu/Printer/Meat/Declaration/Value.hs b/src/Ormolu/Printer/Meat/Declaration/Value.hs index c1b6703..9c53eec 100644 --- a/src/Ormolu/Printer/Meat/Declaration/Value.hs +++ b/src/Ormolu/Printer/Meat/Declaration/Value.hs @@ -200,11 +200,13 @@ p_match' placer pretty style isInfix strictness m_pats m_grhss = do then RightArrow else EqualSign newlineSep (located' (p_grhs' pretty groupStyle)) grhssGRHSs + let whereLocation = combineSrcSpans patGrhssSpan $ getLoc grhssLocalBinds unless (GHC.isEmptyLocalBindsPR (unLoc grhssLocalBinds)) - (inciLocalBinds $ do - newline - line (txt "where") + (inciLocalBinds . switchLayout whereLocation $ do + breakpoint + txt "where" + breakpoint inci (located grhssLocalBinds p_hsLocalBinds) ) case style of