align-regexp可以做到这一点。标记区域,然后使用:
C-uM-x align-regexp RET \(\s-+[0-9]*\)[0-9] RET -1 RET 4 RET y
这应该是最简单的方法。
(编辑:事实上,你甚至不需要分离出最后一个数字;\(\s-+[0-9]+\)对于正则表达式也同样有效。)
查看交互式提示和C-hf align-regexp RET变量align-rules-list以了解实际执行的操作。
值得注意的部分是,通过为组指定负数,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、表格捕获/发布),或者您可以使用 elisp 替换模式来处理。
例如,如果文件已经使用空格进行对齐(如果没有,您可以使用untabify删除制表符)并且所有行的长度相同(即尾随空格是如果最后一列的长度不同,则在某些行上需要)。
C-M-% \([0-9]+\)\([[:space:]]+\) RET \,(format (concat "%" (number-to-string (1- (length \&))) "d ") (string-to-number \1)) RET