Hi fellow Caml-wranglers,
I ran across an unexpected behavior while trying do disable wrapping in Format
. From what I understand the wrapping in Format
is dependent on the value of margin
, thus setting it to a large value (like Format.pp_infinity
) should disable wrapping.
Format.printf "@[<hov>This is a long text that I want to print aaa bbb@ ccc ddd eee @[<hov>fff gg hh iii jjjj@] kkk lll mmm n o@]";;
This will wrap at the space hint. So
Format.set_margin 100000;
Format.printf "@[<hov>This is a long text that I want to print aaa bbb@ ccc ddd eee @[<hov>fff gg hh iii jjjj@] kkk lll mmm n o@]";;
this makes it all print out in one line. So far so good. But if I try the same with Format.asprintf
:
Format.set_margin 100000;
Format.asprintf "@[<hov 2>This is a long text that I want to print aaa bbb@ ccc ddd eee @[<hov>fff gg hh iii jjjj@] kkk lll mmm n o@]";;
I get a \n
in my string, thus it is wrapping, despite the margin
setting.
On the other hand, if I specifically set the margin in the format string, it works properly:
Format.asprintf "%a@[<hov 2>This is a long text that I want to print aaa bbb@ ccc ddd eee @[<hov>fff gg hh iii jjjj@] kkk lll mmm n o@]" Format.pp_set_margin Int.max_int;;
What is going on and how can I disable the wrapping manually without having to annotate every format string?