Skip to content

Commit

Permalink
Experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
piegamesde committed Aug 17, 2024
1 parent 24b529e commit c002c55
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
16 changes: 16 additions & 0 deletions src/Nixfmt/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,22 @@ prettyApp indentFunction pre hasPost f a =
where
-- If the brackets are on different lines, keep them like that
sur = if sourceLine paropen /= sourceLine parclose then hardline else line
-- Same for sets. Limit is two items
absorbInner (Term (Set krec paropen@Ann{trailComment = post'} binders parclose)) =
-- \| length (unItems binders) <= 2 && all isSimpleBinding binders =
pretty (fmap (,hardspace) krec)
<> pretty (paropen{trailComment = Nothing})
<> surroundWith sep (nest $ pretty post' <> prettyItems binders)
<> pretty parclose
where
isSimpleBinding (Assignment sels (LoneAnn _) rhs (LoneAnn _)) =
all isSimpleSelector sels && isSimple rhs
isSimpleBinding _ = False
-- If the braces are on different lines, keep them like that
sep =
if sourceLine paropen /= sourceLine parclose
then line
else line
absorbInner expr = pretty expr

-- Render the last argument of a function call
Expand Down
14 changes: 4 additions & 10 deletions test/diff/apply/out.nix
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,10 @@
# multiline
} argument;

name3 =
function arg
{
asdf = 1;
# multiline
}
{
qwer = 12345;
}
argument;
name3 = function arg {
asdf = 1;
# multiline
} { qwer = 12345; } argument;
}
{
name4 = function arg { asdf = 1; } {
Expand Down

0 comments on commit c002c55

Please sign in to comment.