如何在emacs的一列中对齐C++类成员名称?

Kot*_*lot 6 c++ emacs code-formatting indentation

我想在一列中对齐所有C++类成员名称(不要与成员类型混淆).

让我们看一下入口处的例子:

class Foo
{
public:
    void   method1( );
    int                  method2( ); 
    const Bar *        method3( ) const; 
protected:
    float    m_member;
};
Run Code Online (Sandbox Code Playgroud)

这就是我们最终想要拥有的东西:

class Foo
{
public:
    void           method1( );
    int            method2( ); 
    const Bar *    method3( ) const; 
protected:
    float          m_member;
};
Run Code Online (Sandbox Code Playgroud)

因此,最长的成员类型声明定义了类成员名称将对齐的列.我如何在emacs中执行此类转换?

小智 6

选择具有方法声明的区域

M-x align-regexp
Run Code Online (Sandbox Code Playgroud)

输入字符串[^ ]+\((\|;\) ,然后按Enter键

编辑添加;匹配,也对齐成员变量.