@@ -347,11 +347,11 @@ mergeSpacings Hardspace (Newlines x) = Newlines x
347
347
mergeSpacings _ (Newlines x) = Newlines (x + 1 )
348
348
mergeSpacings _ y = y
349
349
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 =
352
352
(<> " \n " )
353
353
. Text. strip
354
- . layoutGreedy width
354
+ . layoutGreedy width indentWidth
355
355
. fixup
356
356
. pretty
357
357
-- In strict mode, set the line number of all tokens to zero
@@ -480,8 +480,8 @@ indent n = Text.replicate n " "
480
480
type St = (Int , NonEmpty (Int , Int ))
481
481
482
482
-- 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 ))
485
485
where
486
486
-- Simple helpers around `put` with a tuple state
487
487
putL = modify . first . const
@@ -496,7 +496,7 @@ layoutGreedy tw doc = Text.concat $ evalState (go [Group RegularG doc] []) (0, s
496
496
case textNL `compare` nl of
497
497
-- Push the textNL onto the stack, but only increase the actual indentation (`ci`)
498
498
-- 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'
500
500
-- Need to go down one or more levels
501
501
-- Just pop from the stack and recurse until the indent matches again
502
502
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
623
623
_ -> grp
624
624
(nl, off) = nextIndent grp'
625
625
626
- indentWillIncrease = if fst (nextIndent rest) > lineNL then 2 else 0
626
+ indentWillIncrease = if fst (nextIndent rest) > lineNL then iw else 0
627
627
where
628
628
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 )
630
630
in fits indentWillIncrease (tw - firstLineWidth rest) grp'
631
631
<&> \ t -> runState (putText nl off t) (cc, ci)
632
632
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
634
634
where
635
635
lineNL = snd $ NonEmpty. head ci
636
636
in fits (indentWillIncrease - cc) (tw - cc - firstLineWidth rest) grp
0 commit comments