开发者

Format(line wrapping) constructor initializer list in Eclipse CDT

开发者 https://www.devze.com 2023-01-10 18:32 出处:网络
I tried to find a solution for now ~30min and couldn\'t find any. I am trying to set up the c开发者_运维百科ode style in CDT so it gives me:

I tried to find a solution for now ~30min and couldn't find any. I am trying to set up the c开发者_运维百科ode style in CDT so it gives me:

MyClass::MyClass() :    
var1(1), 
var2(2), 
var3(3){

}

instead of

MyClass::MyClass() :    
var1(1), var2(2), var3(3){

}

but I couldn't find an option to do so.

The only 'initializer list' option I could find is actually for arrays and therefore not useful for me.

My question is: Am I missing the right spot? Is there a plug-in out there which does better formatting of C++ code than CDT?


@Eric provides manual solution, but to make this setting auomatic, you need to edit eclipse preferences.

Click on:
Window -> Preferences

Go to:
C/C++ -> Code Style -> Formatter

Here, as first thing you have to create a new profile.

Select tab:
Line Wrapping

Go to:
Function declarations -> Constructor initializer list

On the bottom, you have to set:

  • Line wrapping policy: Wrap all elements, every element on a new line.
  • check "Force split, even if line is shorter than maximum"
  • Indentation policy: indent on column


Well, I can't tell you exactly how to do this but if you don't mind a little extra white space I can get you close. Enter a blank line between each line. That is:

MyClass::MyClass() :    
var1(1), 

var2(2), 

var3(3){
}

Now when you reformat, this layout will stick. I know it's not exactly what you want but I thought I would post just in case you didn't know about this work-around.


Try this. I dont have the CDT package so I cannot test this, but the formatting does something similar in Java.

If you put a comment at the end of a line, it will keep the newline

MyClass::MyClass() : //
var1(1), //
var2(2), //
var3(3){ //

}
0

精彩评论

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