简体   繁体   English

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

[英]How to align C++ class member names in one column in emacs?

I would like to align all C++ class member names ( do not confuse with member types ) in one column. 我想在一列中对齐所有C ++类成员名称 (不要与成员类型混淆)。

Lets look at the example of what we have at entrance: 让我们看一下入口处的例子:

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

and this is what we would like to have at the end: 这就是我们最终想要拥有的东西:

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

So the longest member type declaration defines the column to which class member names will be aligned. 因此,最长的成员类型声明定义了类成员名称将对齐的列。 How can i perform such transformation in emacs ? 我如何在emacs中执行此类转换?

Select the region with the method declarations 选择具有方法声明的区域

M-x align-regexp

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

Edited to add the ; 编辑添加; in the matching, which aligns the member variable as well. 在匹配中,它也对齐成员变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM