Rectangular text in Emacs

Sometimes I have a text file similar to this in Emacs:

some text     123     17
other text    1       0
still more    12      8
last one      1234    123

I would like to right - match numbers (using spaces), changing them to something like this:

some text      123     17
other text       1      0
still more      12      8
last one      1234    123

How can this be done in Emacs?

+5
source share
1 answer

align-regexpcan do it. Mark the area and then use:

C-u M-x align-regexp RET \(\s-+[0-9]*\)[0-9] RET -1 RET 4 RET y

This should be the easiest approach.

( Edit: Actually, you don’t even need to highlight this final figure, it \(\s-+[0-9]+\)works just as well for regular expression.)

See the interactive hints and C-h f align-regexp RETand the variable align-rules-listfor what is actually happening.

, , , align-regexp justify:

`justify'   
It is possible with `regexp' and `group' to identify a
character group that contains more than just whitespace
characters.  By default, any non-whitespace characters in
that group will also be deleted while aligning the
alignment character.  However, if the `justify' attribute
is set to a non-nil value, only the initial whitespace
characters within that group will be deleted.  This has
the effect of right-justifying the characters that remain,
and can be used for outdenting or just plain old right-
justification.

(, org, ses, table-capture/release), elisp.

. , , , ( untabify , ), (.. , ).

C-M-% \([0-9]+\)\([[:space:]]+\) RET \,(format (concat "%" (number-to-string (1- (length \&))) "d ") (string-to-number \1)) RET

+8

All Articles