作为一名测试工程师,我经常有一些像下面这样的意大利面条式代码:
int *const cpe = &n; assert(42 == *cpe);
int *const cpf = &cn; assert(42 == *cpf);
int *const cpg = pcn; assert(42 == *cpg);
int *const cph = cpcn; assert(42 == *cph);
Run Code Online (Sandbox Code Playgroud)
为了美观,我想将它们在由“ ; ”定义的列中对齐,如下所示:
int *const cpe = &n; assert(42 == *cpe);
int *const cpf = &cn; assert(42 == *cpf);
int *const cpg = pcn; assert(42 == *cpg);
int *const cph = cpcn; assert(42 == *cph);
Run Code Online (Sandbox Code Playgroud)
emacs 中有没有办法做到这一点?(我知道,M-x align但它并没有像期望的那样做一个整洁的工作。)希望该方法也应该与“,”一起使用。
(add-to-list 'align-rules-list
'(c-assignment1
(regexp . "[=;]\\(\\s-*\\)")
(mode . '(c-mode))
(repeat . t)))
Run Code Online (Sandbox Code Playgroud)
M-x align
如果您编写此代码,也很简单。