Rework begin match/if branch layout (review follow-up)
Reworks the previous fix (e3babbb1) per review. The earlier version
special-cased `ctx0=ifthenelse` in `fmt_beginend` to handle a comment
before a `begin match/if … end` branch body; it glued the body
(`begin if a then b`) and reindented it when a comment was added.
Why the comment case now goes through the plain begin/end path:
`fmt_beginend` cannot see the comment — `branch_pro` consumes it in
`Params` before the expression is formatted. `get_if_then_else`, however,
runs before consumption, so the decision belongs there. A special
`begin match/if … end` branch with a leading comment on its body no
longer takes the `begin <kw>` shortcut arm; it falls through to the
existing plain begin/end machinery (`has_cmts_before` predicate). That
keeps `begin` on its own line with the body (comment included) one indent
in, identically across all if-then-else modes, so adding a comment no
longer reindents the body.
Why expr_pro is dropped for special-bodied begin/end branches: the
fit-or-vertical / vertical branch `expr_pro` is `break_unless_newline
1000`, which enqueues width 1000 even as a no-op at BOL and poisons the
body's `match … with` / `if … then` header box, forcing it to split over
several lines. Such a body already breaks after `begin`, so it provides
its own break instead of the poisoning one. Simple-bodied `begin e end`
keeps the regular branch break (no header to poison). K&R additionally
dropped the extra body box that indented a comment-routed body by +2.
Why a ctx0 box wrap remains in fmt_beginend: the no-comment shortcut path
still needs `end` aligned with `begin`. In fit-or-vertical the branch box
is `hovbox 0` while the branch break indents `begin` one level in, so the
body and `end` are wrapped together. This is scoped to `ctx0=ifthenelse`
because wrapping unconditionally reindents application arguments
(`map x begin fun … end`, exp_grouping.ml); the scope is structural
(alignment), not comment-handling logic.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>