开发者

Emacs C++-mode indenting for function declarations

The coding standards at my company have changed such that the function declaration

void foo开发者_运维知识库( int a, float* b);

must now be written as:

void
foo(int    a,
    float* b);

Where both the type of the variable and the name of the variable must be vertically aligned.

I'm using emacs 23.2 with c++-mode.

This mode lines up each variable type but won't let me indent the variable names to match.

Is there a build in setting to allow this?

If there isn't, what do I need to turn off to allow me to freely indent my variable names?


Perhaps what you want is M-i (tab-to-tab-stop).

This will move the cursor to the next tab stop. The tab stops may be configured by the variable tab-stop-list, which defaults to every eight columns. Note this will either insert spaces or actual TAB characters depending on the local variable indent-tabs-mode. (Be careful to not confuse this with tab-width, which influences how actual TAB characters are displayed.)

This will not always make the param names in the lowest possible column, e.g., you may end up with

void
foo(int     a,
    float*  b);   // two spaces there

but note that this is somewhat more maintainable-- when adding a new param with a longer type name you won't necessarily have to go fix up the rest, you'll only have to if you cross a tab column.


Select the lines with the arguments then M-x align

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜