Problem:
expand_msg() derives its start row from the pager buffer even when the
target is the cmd or dialog buffer, so the copied lines are appended
instead of replacing, and the copied extmarks are placed at pager rows in
a smaller buffer: "Invalid 'end_col': out of range", thrown inside a UI
event handler.
Solution:
Offset only when appending to a visible pager, and read the line count
after msg_clear(), whose autocmds may write to the pager. Copy marks with
`strict = false`, since the rows and columns are recomputed for a
different buffer and should clamp rather than raise.
AI-assisted