且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Emacs中,如何排列一系列初始化语句中的等号?

更新时间:2022-10-17 15:52:37

使用 Mx align-regexp (这里, Mx align-regexp RET = RET )。您还可以向变量 align-rules-list 添加对齐规则,以便将来 Mx align 会做的。有关详细信息,请参阅文档( C-h f align )。


I saw this somewhere, but cannot find it now. Is there a built-in function in emacs, or does someone have elisp, to line up all the equals signs in a series of inititialization statments in cc-mode?

Before:

int t=9;
Graphics g = new Graphics();
List<String> list = new List<String>();

After:

int          t    = 9;
Graphics     g    = new Graphics();
List<String> list = new List<String>();

Use M-x align-regexp (here, M-x align-regexp RET = RET). You can also add an "alignment rule" to the variable align-rules-list, so that in future M-x align will do it. See the documentation (C-h f align) for details.