0

Using clang-format, I want the result somewhat like this:

  value = new MyClass(variable1, variable2, mystring + "test",
                      another_variable);

But I don't want the result below:

  value =
      new MyClass(variable1, variable2, mystring + "test", another_variable);

How can I do?

Xiaoyu Chen
  • 295
  • 1
  • 4
  • 12

1 Answers1

0

You could try the following parameters in your .clang-format file (How do I specify a clang-format file?):

AlignOperands: true
PenaltyBreakAssignment: 21
PenaltyBreakBeforeFirstCallParameter: 1
  • AlignOperands: you want to align the operands after a break line (as you align another_variable below)
  • PenaltyBreakAssignment: 21 because is the shortest value suitable for your case (you have available a playground here)
  • PenaltyBreakBeforeFirstCallParameter: as documentation describes: The penalty for breaking a function call after call(., so it should be greater than 0.

You can learn more on what a penalty is on clang-format: In clang-format, what do the penalties do?

Another related and insightful answer: Clang-format: How to avoid new line breaks


PS: consider using smart pointers in C++ ;)

horro
  • 1,262
  • 3
  • 20
  • 37