@@ -347,11 +347,11 @@ mergeSpacings Hardspace (Newlines x) = Newlines x
347347mergeSpacings _ (Newlines x) = Newlines (x + 1 )
348348mergeSpacings _ y = y
349349
350- layout :: (Pretty a , LanguageElement a ) => Int -> Bool -> a -> Text
351- layout width strict =
350+ layout :: (Pretty a , LanguageElement a ) => Int -> Int -> Bool -> a -> Text
351+ layout width indentWidth strict =
352352 (<> " \n " )
353353 . Text. strip
354- . layoutGreedy width
354+ . layoutGreedy width indentWidth
355355 . fixup
356356 . pretty
357357 -- In strict mode, set the line number of all tokens to zero
@@ -480,8 +480,8 @@ indent n = Text.replicate n " "
480480type St = (Int , NonEmpty (Int , Int ))
481481
482482-- tw Target Width
483- layoutGreedy :: Int -> Doc -> Text
484- layoutGreedy tw doc = Text. concat $ evalState (go [Group RegularG doc] [] ) (0 , singleton (0 , 0 ))
483+ layoutGreedy :: Int -> Int -> Doc -> Text
484+ layoutGreedy tw iw doc = Text. concat $ evalState (go [Group RegularG doc] [] ) (0 , singleton (0 , 0 ))
485485 where
486486 -- Simple helpers around `put` with a tuple state
487487 putL = modify . first . const
@@ -496,7 +496,7 @@ layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, s
496496 case textNL `compare` nl of
497497 -- Push the textNL onto the stack, but only increase the actual indentation (`ci`)
498498 -- if this is the first one of a line. All subsequent nestings within the line effectively get "swallowed"
499- GT -> putR ((if cc == 0 then ci + 2 else ci, textNL) <| indents) >> go'
499+ GT -> putR ((if cc == 0 then ci + iw else ci, textNL) <| indents) >> go'
500500 -- Need to go down one or more levels
501501 -- Just pop from the stack and recurse until the indent matches again
502502 LT -> putR (NonEmpty. fromList indents') >> putText textNL textOffset t
@@ -623,14 +623,14 @@ layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, s
623623 _ -> grp
624624 (nl, off) = nextIndent grp'
625625
626- indentWillIncrease = if fst (nextIndent rest) > lineNL then 2 else 0
626+ indentWillIncrease = if fst (nextIndent rest) > lineNL then iw else 0
627627 where
628628 lastLineNL = snd $ NonEmpty. head ci
629- lineNL = lastLineNL + (if nl > lastLineNL then 2 else 0 )
629+ lineNL = lastLineNL + (if nl > lastLineNL then iw else 0 )
630630 in fits indentWillIncrease (tw - firstLineWidth rest) grp'
631631 <&> \ t -> runState (putText nl off t) (cc, ci)
632632 else
633- let indentWillIncrease = if fst (nextIndent rest) > lineNL then 2 else 0
633+ let indentWillIncrease = if fst (nextIndent rest) > lineNL then iw else 0
634634 where
635635 lineNL = snd $ NonEmpty. head ci
636636 in fits (indentWillIncrease - cc) (tw - cc - firstLineWidth rest) grp
0 commit comments