Let's say a text file looks like so:
0.00 33.90 -93.9
0.00 43.90 -93.9
10.00 53.90 -93.9
10.00 63.90 -93.9
-100.00 10.00 -7.0
-100.00 9.00 -8.0
100.00 9.00 -9.0
100.00 63.00 -10.0
What would be the appropriate emacs command to line up the text so it appear like this:
0.00 33.90 -93.9
0.00 43.90 -93.9
10.00 53.90 -93.9
10.00 63.90 -93.9
-100.00 10.00 -7.0
-100.00 9.00 -8.0
100.00 9.00 -9.0
100.00 63.00 -10.0
The floats need to align vertically at the decimal point. I'm familiar with align-regexp
, but I don't know what align-rule-list
I should use.
The following function does not work perfectly but it should get you started. The justify
attribute is important to align at the decimal point. But, there is no optional justify
argument for align-regexp
. To see the meaning of the attributes consult the help of align-rules-list
.
(defun align-numbers (beg end)
(interactive "r")
(let (indent-tabs-mode
(align-rules-list '((temporary
(regexp . "\\( *[+-]?[0-9]*\\.\\)")
(group . 1)
(justify . t)
(repeat . t)
))))
(align beg end)))