c++ - 如何将 emacs C++ 模式下的代码对齐到 ";"或 ","?

标签 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(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 但它并没有像期望的那样做得很好。) 希望该方法也适用于“,”。

最佳答案

(add-to-list 'align-rules-list
             '(c-assignment1
               (regexp . "[=;]\\(\\s-*\\)")
               (mode   . '(c-mode))
               (repeat . t)))

如果您编写这段代码,M-x align 也可以。

关于c++ - 如何将 emacs C++ 模式下的代码对齐到 ";"或 ","?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24471509/

相关文章:

regex - 在 emacs-lisp 中,如何正确使用 replace-regexp-in-string?

c++ - 模板类的非模板友元是否被实例化?

C++ operator= 重载

emacs - 如何将参数传递给 emacs lisp 中的映射?

bash - 如何让 Emacs 使用我的 .bashrc 文件?

xcode - 看起来像 Xcode 深色的 Emacs 颜色主题

c++ - 在 C++ 中存储字符串时,char* 和 char 有什么区别?

c++ - aws-sdk-cpp:如何通过代理访问S3?

c++ - 将字节数组反序列化为结构

emacs - 如何在退出递归编辑时抛出一个值(不使用setq)