align-regexp 可以做到这一点。标记区域,然后使用:
CuMx align-regexp RET \(\s-+[0-9]*\)[0-9] RET -1 RET kbd> 4 RET y
这应该是最简单的方法了。
(编辑:事实上,您甚至不需要分离出最后一个数字;\(\s-+[0-9]+\) 也适用于正则表达式。)
查看交互式提示和 Chf 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