- Mark the region
column -x RET
column -x -c N for lines of (up to) N characters in length.
column is a BSD-derived shell command, which you quite likely have if you're on a Unix-like OS.
-x argument gives the "row-major" output that you wanted.
column -x -c 70 gives you the exact number of rows and columns that you showed in the question:
one, two, three, four,
five, six, seven, eight,
nine, ten, eleven, twelve,
thirteen, fourteen, fifteen, sixteen,
I don't see a way to specify the minimum spacing between columns, but the main problem with this is that the tab width used by
column might not match your
tab-width in Emacs, which might give you some wonky-looking output (even though it's formatted nicely for some other value).
However, once you have the basic arrangement of rows and columns, you can use
align-regexp to tidy up if necessary:
The pattern would be:
,\(\s-*\) (i.e. prefix a comma to the default pattern). The next two options are default, and then say "Yes" to "Repeat throughout the line".
n.b. I believe you're going to run into trouble with some of the other answers as soon as your data contains spaces, which is why I think using a tool (
column) already designed for this task is sensible, and why I recommend using the commas for alignment if you use
align-regexp, rather than spaces.
Note that when
indent-tabs-mode is non-nil,
align-regexp will insert tabs for alignment. You can either
untabify to convert them to spaces, or use https://stackoverflow.com/a/8129994/324105 to prevent it from happening.