Make _shorten_line_at_commas() do less mutation

This is done by splitting the line at offsets rather than accumulating
the tokens.
Generalize line shortening