@@ -29,6 +29,7 @@ module Dodo
29
29
, foldWithSeparator
30
30
, foldWith
31
31
, locally
32
+ , withLocalOptions
32
33
, print
33
34
, Printer (..)
34
35
, plainText
@@ -49,6 +50,7 @@ import Data.String as String
49
50
import Data.String.Regex as Regex
50
51
import Data.String.Regex.Flags (global )
51
52
import Data.String.Regex.Unsafe (unsafeRegex )
53
+ import Data.Tuple (Tuple (..))
52
54
import Dodo.Internal (Doc (..), Position , LocalOptions , bothNotEmpty , isEmpty , notEmpty )
53
55
import Dodo.Internal (Doc , Position , bothNotEmpty , isEmpty , notEmpty ) as Exports
54
56
import Dodo.Internal.Buffer (Buffer )
@@ -197,7 +199,13 @@ foldWith f = foldr (bothNotEmpty f) mempty
197
199
-- | *EXPERIMENTAL:* modifies printing state and options locally for a document.
198
200
-- | This may change or be removed at any time.
199
201
locally :: forall a . (LocalOptions -> LocalOptions ) -> Doc a -> Doc a
200
- locally = Local
202
+ locally k doc = Local \options -> Tuple (k options) doc
203
+
204
+ -- | *EXPERIMENTAL:* modifies printing state and options locally for a document.
205
+ -- | This may change or be removed at any time. Differs from `locally` in that the
206
+ -- | document can be responsive to options.
207
+ withLocalOptions :: forall a . (LocalOptions -> Tuple LocalOptions (Doc a )) -> Doc a
208
+ withLocalOptions = Local
201
209
202
210
-- | Custom printers can be used to render richer documents than just plain
203
211
-- | text.
@@ -453,7 +461,7 @@ print (Printer printer) opts = flip go initState <<< pure <<< Doc
453
461
{ annotations = ann : state.annotations
454
462
, buffer = Buffer .modify (printer.enterAnnotation ann state.annotations) state.buffer
455
463
}
456
- Local k doc1 -> do
464
+ Local k -> do
457
465
let
458
466
prevOptions =
459
467
{ indent: state.position.indent
@@ -463,7 +471,7 @@ print (Printer printer) opts = flip go initState <<< pure <<< Doc
463
471
, pageWidth: state.options.pageWidth
464
472
, ribbonRatio: state.options.ribbonRatio
465
473
}
466
- localOptions = k prevOptions
474
+ Tuple localOptions doc1 = k prevOptions
467
475
go (Doc doc1 : LeaveLocal prevOptions: stk) $ storeOptions state.position.indent localOptions state
468
476
Empty ->
469
477
go stk state
0 commit comments