Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format(line wrapping) constructor initializer list in Eclipse CDT

I tried to find a solution for now ~30min and couldn't find any. I am trying to set up the code 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?

like image 245
DragonTux Avatar asked Aug 04 '10 19:08

DragonTux


2 Answers

@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
like image 78
Luca Davanzo Avatar answered Sep 28 '22 07:09

Luca Davanzo


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.

like image 30
Tod Avatar answered Sep 28 '22 06:09

Tod