From f61fe5d53b739fd96ea5a4707859fc65952590cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Sun, 28 Jan 2018 13:06:59 +0000 Subject: [PATCH 1/4] Format functions with args with newlines --- Nix/Pretty.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Nix/Pretty.hs b/Nix/Pretty.hs index 3693147..8726ae6 100644 --- a/Nix/Pretty.hs +++ b/Nix/Pretty.hs @@ -80,16 +80,16 @@ prettyParams (ParamSet s mname) = prettyParamSet s <> case mname of Just name -> text "@" <> text (unpack name) prettyParamSet :: ParamSet NixDoc -> Doc -prettyParamSet params = lbrace <+> middle <+> rbrace +prettyParamSet params = encloseSep (lbrace <> space) (align rbrace) sep prettyArgs where + prettySetArg (n, maybeDef) = case maybeDef of + Nothing -> text (unpack n) + Just v -> text (unpack n) <+> text "?" <+> withoutParens v prettyArgs = case params of FixedParamSet args -> map prettySetArg (toList args) VariadicParamSet args -> map prettySetArg (toList args) ++ [text "..."] - middle = hcat $ punctuate (comma <> space) prettyArgs - prettySetArg (n, maybeDef) = case maybeDef of - Nothing -> text (unpack n) - Just v -> text (unpack n) <+> text "?" <+> withoutParens v + sep = align (comma <> space) prettyBind :: Binding NixDoc -> Doc prettyBind (NamedVar n v) = prettySelector n <+> equals <+> withoutParens v <> semi From f867c2ccbb68b896d0ab3a5c316474d2e218ebcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Sun, 28 Jan 2018 13:07:36 +0000 Subject: [PATCH 2/4] Indent first line after functions --- Nix/Pretty.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nix/Pretty.hs b/Nix/Pretty.hs index 8726ae6..d0523da 100644 --- a/Nix/Pretty.hs +++ b/Nix/Pretty.hs @@ -131,7 +131,7 @@ prettyNix = withoutParens . cata phi where phi (NRecSet xs) = simpleExpr $ group $ nest 2 (vsep $ recPrefix <> lbrace : map prettyBind xs) <$> rbrace phi (NAbs args body) = leastPrecedence $ - (prettyParams args <> colon) (nest 2 $ withoutParens body) + (prettyParams args <> colon) (indent 2 (withoutParens body)) phi (NBinary op r1 r2) = flip NixDoc opInfo $ hsep [ wrapParens (f NAssocLeft) r1 , text $ operatorName opInfo From 22097ebe1c46d5a0e6f5185cd61ab07aadd868b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Sun, 28 Jan 2018 13:08:09 +0000 Subject: [PATCH 3/4] dedent 'in' in 'let in' --- Nix/Pretty.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Nix/Pretty.hs b/Nix/Pretty.hs index d0523da..51a6d76 100644 --- a/Nix/Pretty.hs +++ b/Nix/Pretty.hs @@ -162,8 +162,8 @@ prettyNix = withoutParens . cata phi where | "../" `isPrefixOf` txt -> txt | otherwise -> "./" ++ txt phi (NSym name) = simpleExpr $ text (unpack name) - phi (NLet binds body) = leastPrecedence $ group $ nest 2 $ - vsep (text "let" : map prettyBind binds) <$> text "in" <+> withoutParens body + phi (NLet binds body) = leastPrecedence $ group $ text "let" <$> indent 2 ( + vsep (map prettyBind binds)) <$> text "in" <+> withoutParens body phi (NIf cond trueBody falseBody) = leastPrecedence $ group $ nest 2 $ (text "if" <+> withoutParens cond) <$> ( align (text "then" <+> withoutParens trueBody) From b391db0bf6cb5c1cc76543f1966e019bbc52b50a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Sun, 28 Jan 2018 13:08:43 +0000 Subject: [PATCH 4/4] assert and with should be followed with a newline --- Nix/Pretty.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Nix/Pretty.hs b/Nix/Pretty.hs index 51a6d76..c8c34d3 100644 --- a/Nix/Pretty.hs +++ b/Nix/Pretty.hs @@ -170,8 +170,8 @@ prettyNix = withoutParens . cata phi where <$> align (text "else" <+> withoutParens falseBody) ) phi (NWith scope body) = leastPrecedence $ - text "with" <+> withoutParens scope <> semi <+> withoutParens body + text "with" <+> withoutParens scope <> semi <$> align (withoutParens body) phi (NAssert cond body) = leastPrecedence $ - text "assert" <+> withoutParens cond <> semi <+> withoutParens body + text "assert" <+> withoutParens cond <> semi <$> align (withoutParens body) recPrefix = text "rec" <> space