Emacs:对齐文本,但不是整行?
我使用过的唯一支持此功能的编辑器(不过我相信很多编辑器都支持)是 Sublime Text 2,但希望 emacs 也有一个妙招。我工作的一些类具有相当声明性的语法,如果源代码保持列化,那么它们看起来会更干净。当新行将列的长度增加一两个空格时,问题就出现了……然后您必须重新对齐每一行。
屏幕截图可能澄清了我的意思:
这里我添加了一行,其中一个如果它的列比其他列延伸得更远,那么我想再次重新对齐它。通常,我只是在箭头和空格键周围重复循环手指,直到我逐行重新对齐所有内容,但如果有一种方法可以只选择一个矩形区域并用力,那就太好了该区域的文本非空白部分要对齐。
这可能吗?
The only editor I've ever used that supports this (I'm sure lots do, however) is Sublime Text 2, but hopefully emacs has a trick up its sleeve too. Some classes I work on that have a fairly declarative syntax look cleaner if the source is kept columnized. The problem comes in when a new row increases the length of a column by a space or two... you then have to work through each row re-aligning it.
A screenshot probably clarifies what I'm getting at:
Here I've added a row in which one if its columns extends further than the other columns, so I'd like to realign it all again. Ordinarily I'd just repeat-cycle my fingers around the arrows and the space bar until I've re-aligned everything row-by-row, but it'd be good if there was a way to just select a rectangular area and force text non-whitespace parts of that area to fall into alignment.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
align-regexp
,而不是使用矩形。选择区域,然后执行:Cu Mxalign-regexp RET ,\(\s-*\) RET 1 RET 1 RET y
如果您经常这样做,请创建一个函数:
然后选择区域并MX my-align-after-commas
Rather than using rectangles, you could use
align-regexp
. Select the area then do:C-u M-x align-regexp RET ,\(\s-*\) RET 1 RET 1 RET y
If you do this a lot, make a function:
Then select the area and M-x my-align-after-commas
还有 columnize 库 可以将其转换
为:
您选择要对齐的区域然后是
Mx columnize-text
。有关此内容和其他内容的 EmacsWiki 页面:
http://www.emacswiki.org/emacs/CategoryAlignment
There's also the columnize library which can transform this:
into this:
You select the region you want to align and then
M-x columnize-text
.EmacsWiki page on this and others:
http://www.emacswiki.org/emacs/CategoryAlignment
Emacs 确实允许您选择矩形区域,并且它确实允许您编辑整个列。要删除矩形区域,请在一个角上设置标记,指向另一个角,然后
Mx Kill-rectangle
。您可以通过以相同的方式标记它来添加空白矩形,然后使用Mx open-rectangle
。这就是我知道如何做到这一点的方法;毫无疑问还有其他可能更好的方法。
Emacs does let you select rectangular areas, and it does let you edit whole columns. To delete a rectangular area, set the mark at one corner, point at the other, and then
M-x kill-rectangle
. You can add a rectangle of whitespace by marking it the same way, and thenM-x open-rectangle
.This is just the way that I know how to do this; there are doubtless other, possibly better ways.