Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang-format: how to prevent all function arguments on next line?

I have a C++ function call that I've manually and intentionally formatted like this:

DoSomethingForAPurposeThatCausesALongFunctionName(
    arg_0,
    arg_1,
    arg_2);

clang-format wants to re-format it like this:

DoSomethingForAPurposeThatCausesALongFunctionName(
    arg_0, arg_1, arg_2)

I do not want this. AllowAllParametersOfDeclarationOnNextLine appears to control this behavior for function declarations, but what about function calls? Is there a corresponding setting?

My .clang-format looks like this:

BasedOnStyle: Google
BinPackArguments: false
BinPackParameters: false
AllowAllParametersOfDeclarationOnNextLine: false
AlignAfterOpenBracket: AlwaysBreak
like image 503
jacobsa Avatar asked Nov 19 '22 23:11

jacobsa


1 Answers

I'm also interested in preventing multiple arguments on the same line, but below the fun( line. In my case, I don't mind if the first argument is still on the same line as fun(. I just want them to either be all on the fun( line or all stacked.

I was able to achieve this by increasing PenaltyBreakBeforeFirstCallParameter to 100. Presumably you may need a different value depending on your other penalty settings.

This yields:

fun(my_long_argument_0,
    my_long_argument_1,
    my_long_argument_2);

In your case, assuming DoSomethingForAPurposeThatCausesALongFunctionName(arg_0, is too long for one line, it would yield:

DoSomethingForAPurposeThatCausesALongFunctionName(
    arg_0,
    arg_1,
    arg_2);
like image 112
Nicolas Avatar answered Dec 28 '22 09:12

Nicolas