I would think that your second example (with hv-boxes) should work. But it looks like @ \ n does not have the expected behavior.
Solution 1: forces a line break before the right bracket, i.e. replaces @ with @ \ n.
let () = Format.printf "@."; Format.printf "@[<hov 2>( ---@ \ n@ [<hov 2>( ---@ \ n@ [<hov 2>( ---@ \n)@]@\n)@]@\n)@]@\n"; Format.printf "@."
Result:
(
Problem: there will always be a line break, it will never print:
(--- (--- (---)))
even if he has a place for him. If this is a problem for you, see Solution 2.
Solution 2: Use longer lines :) If the break is caused by a long line, then the hv block breaks the line before the closing bracket.
let () = Format.printf "@."; Format.printf "@[<hv 2>(--------- ---------------------------------------------------------------@ ,@[<hv 2>( ---@ ,@[<hv 2>( ---@ ,)@]@,)@]@,)@]"; Format.printf "@."
Result:
(
However, the closing bracket does not match the open.
Solution 3: If you want the right bracket to be aligned with the left, you need two boxes.
let () = Format.printf "@."; Format.printf "@[<hv>@[<hv 2>(------------------------------------------------------------------------\ @[<hv>@[<hv 2>(------------------------------------------------------------------------\ @[<hv>@[<hv 2>(------------------------------------------------------------------------\ @]@,)@]@]@,)@]@]@,)@]"; Format.printf "@."
Result:
(
source share