-1

Following on from How can I align function parameter names in clang-format?, I'd like to be able to do the opposite. In other words, this:

void ReallyLongFunctionNameWithLotsOfParams(Type param1, Type param2, Type param3,
    Type param4, Type param5, Type param6, Type param7, Type param8, Type param9) {
    ...function body
}

Instead of this:

void ReallyLongFunctionNameWithLotsOfParams(Type param1, Type param2, Type param3,
                                            Type param4, Type param5, Type param6,
                                            Type param7, Type param8, Type param9) {
    ...function body
}

Is the former possible? The latter looks incredibly ugly to me and simply inversing @AhmedFasih's instructions in his answer to the linked question does nothing, at least not for me:

with BinPackArguments and BinPackParameters both false, and AlignConsecutiveAssignments and AlignConsecutiveDeclarations both set to true (documentation of these parameters).

I'm using VS Code v1.50.1 (system setup), commit d2e414d9e4239a252d1ab117bd7067f125afd80a which uses clang-format v10.0.1.

Update: I just realised my comment was a little harsh, and that I should provide some context here to encourage clicking through to the linked page. Apologies for any offence taken by anyone in this short time. I should also provide my .clang-format as suggested by sweenish, so here it is:

BasedOnStyle:                           Google
AccessModifierOffset:                   -4
AlignConsecutiveDeclarations:           false
AllowShortIfStatementsOnASingleLine:    false
BinPackArguments:                       true
BinPackParameters:                      true
BraceWrapping:
    AfterClass:                         false
    AfterControlStatement:              false
    AfterEnum:                          false
    AfterFunction:                      false
    AfterNamespace:                     false
    AfterObjCDeclaration:               false
    AfterStruct:                        false
    AfterUnion:                         false
    BeforeCatch:                        false
    BeforeElse:                         false
    IndentBraces:                       false
BreakBeforeBraces:                      Custom
ColumnLimit:                            0
IndentCaseLabels:                       true
IndentWidth:                            4
PointerAlignment:                       Left
TabWidth:                               4
UseTab:                                 Always
Kenny83
  • 769
  • 12
  • 38
  • `BinPackArguments` and `BinPackParameters`. I recommend looking at the documentation. https://clang.llvm.org/docs/ClangFormatStyleOptions.html – sweenish Nov 08 '20 at 15:49
  • I have searched the documentation and tried both those options. Which I stated above by linking another question and saying that "inversing @AhmedFasih's instructions in his answer to the linked question does nothing, at least not for me". Does **anyone** click through links on this site?! – Kenny83 Nov 08 '20 at 15:57

1 Answers1

1

Add the following setting, AlignAfterOpenBracket: DontAlign, to your .clang-format file.

If you want to control the size of the indent (for example, using 8 instead of 4), you would also need to provide a value to ContinuationIndentWidth.

sweenish
  • 4,793
  • 3
  • 12
  • 23
  • P.S. I never clicked through the link because it is irrelevant to your question. Especially after you provided all the necessary information that actually allowed for your question to be answered. SO guidelines at [ask] exist for a very good reason. – sweenish Nov 08 '20 at 17:57
  • OK fair enough, I just wanted to avoid getting the quick, irrelevant answer that I **did** get from you LOL :P The other question incorrectly (for my case) suggests `BinPackArguments` and `BinPackParameters` just like you did. But I should have made that clearer. – Kenny83 Nov 08 '20 at 18:26
  • And your answer doesn't quite suit my needs *exactly*, but it's pretty damn close. +12 :-) – Kenny83 Nov 08 '20 at 18:31
  • Those two arguments are still necessary; they are part of the solution. – sweenish Nov 08 '20 at 22:41
  • Those two args don't seem to change anything for me, but I'll take your word for it. Thanks :-) – Kenny83 Nov 10 '20 at 15:07