C++ 如何在emacs C++;“模式”改为“模式”&引用;或&引用;?
作为一名测试工程师,我经常会有一些意大利面代码,如下所示:C++ 如何在emacs C++;“模式”改为“模式”&引用;或&引用;?,c++,emacs,C++,Emacs,作为一名测试工程师,我经常会有一些意大利面代码,如下所示: 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); int *const cpe = &n; assert
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);
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);
为了美观起见,我想在“;”定义的列中对齐它们,如下所示:
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);
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);
emacs中有没有办法做到这一点?(我知道M-x align,但它并没有像预期的那样出色。)
希望该方法也能与“,”一起使用。在这种特殊情况下,您可以在区域处于活动状态时在
assert
上对齐:
M-x align-regexp assert RET
一般来说,这里的答案类似于第一部分:
将转向
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);
进入
同样的技术也可用于在逗号上对齐。只需更换带有,
的正则表达式中的code>
(add-to-list 'align-rules-list
'(c-assignment1
(regexp . "[=;]\\(\\s-*\\)")
(mode . '(c-mode))
(repeat . t)))
简单地M-x对齐
也可以,如果您编写此代码。似乎是一种很好的通用技术。请给我一点时间来使用和验证它。@user3701346,当您想在匹配的内容之前调整空白时,最容易使用它,例如在本例中使用assert
。像上面的一般解决方案一样,在匹配之后,如果要调整空格,则更为棘手代码>。这仅仅是因为align regexp
的默认交互行为自动将模式前面的空格视为要修改的内容。很好的解决方案,我以前从未自定义过align rules list
。