开发者

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

开发者 https://www.devze.com 2022-12-29 23:24 出处:网络
I would like to align all C++ class member names ( do not confuse with member types ) in one column.

I would like to align all C++ class member names ( do not confuse with member types ) in one column.

Lets look at the example of what we have at entrance:

class Foo
{
public:
    开发者_如何学Govoid   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 ?


Select the region with the method declarations

M-x align-regexp

Enter the string [^ ]+\((\|;\) and press Enter

Edited to add the ; in the matching, which aligns the member variable as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消