@@ -637,20 +637,22 @@ absorbRHS expr = case expr of
637
637
(Application f a) -> nest $ prettyApp False line False f a
638
638
(With {}) -> nest $ group' RegularG $ line <> pretty expr
639
639
-- Special case `//` and `++` and `+` operations to be more compact in some cases
640
+ -- The following code assumes all of these operators are parsed with right-handed associativity
641
+ -- (even though in Nix, addition technically is considered left-associative)
640
642
-- Case 1: LHS is absorbable term, unindent concatenations
641
643
-- https://github.com/NixOS/nixfmt/issues/228
642
644
(Operation (Term t) op@ (Ann {value}) _)
643
645
| isAbsorbableTerm t
644
- && matchFirstToken (\ Ann {preTrivia} -> preTrivia == [] ) t
645
- && elem value [ TUpdate , TConcat , TPlus ] ->
646
+ && matchFirstToken (not . hasPreTrivia ) t
647
+ && isUpdateConcatPlus value ->
646
648
hardspace <> prettyOp True expr op
647
649
-- Case 2a: LHS fits onto first line, RHS is an absorbable term
648
650
(Operation l (LoneAnn op) (Term t))
649
- | isAbsorbable t && isUpdateOrConcat op ->
651
+ | isAbsorbable t && isUpdateConcatPlus op ->
650
652
nest $ group' RegularG $ line <> pretty l <> line <> group' Transparent (pretty op <> hardspace <> group' Priority (prettyTermWide t))
651
653
-- Case 2b: LHS fits onto first line, RHS is a function application
652
654
(Operation l (LoneAnn op) (Application f a))
653
- | isUpdateOrConcat op
655
+ | isUpdateConcatPlus op
654
656
&& matchFirstToken (not . hasPreTrivia) f ->
655
657
nest $ line <> group l <> line <> prettyApp False (pretty op <> hardspace) False f a
656
658
-- Everything else:
@@ -659,9 +661,10 @@ absorbRHS expr = case expr of
659
661
-- Otherwise, start on new line, expand fully (including the semicolon)
660
662
_ -> nest $ line <> group expr
661
663
where
662
- isUpdateOrConcat TUpdate = True
663
- isUpdateOrConcat TConcat = True
664
- isUpdateOrConcat _ = False
664
+ isUpdateConcatPlus TUpdate = True
665
+ isUpdateConcatPlus TConcat = True
666
+ isUpdateConcatPlus TPlus = True
667
+ isUpdateConcatPlus _ = False
665
668
666
669
instance Pretty Expression where
667
670
pretty (Term t) = pretty t
0 commit comments