Balan Narcis
Balan Narcis

Reputation: 139

[Clang Format]Make MACRO after if statement stay on same line

I'm looking for a configuration options(s) for .clang-format that will make clang-format keep a MACRO on the same line as an if statement.

Current:

enter image description here

What I want:

enter image description here

Here is my current .clang-format: https://pastebin.com/GYH79k7u

---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignOperands: false
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: false
BraceWrapping: 
  AfterCaseLabel: true
  AfterClass: true
  AfterControlStatement: true
  AfterEnum: true
  AfterFunction: true
  AfterNamespace: true
  AfterStruct: true
  AfterUnion: true
  AfterExternBlock: true
  BeforeCatch: true
  BeforeElse: true
  BeforeLambdaBody: true
  BeforeWhile: false
  IndentBraces: false
  SplitEmptyFunction: false
  SplitEmptyRecord: false
  SplitEmptyNamespace: false
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: false
...

Thank you!

Upvotes: 1

Views: 283

Answers (1)

Quuxplusone
Quuxplusone

Reputation: 27155

Clang-format 12 adds AttributeMacros, as in

AttributeMacros: ['_LIKELY', '_UNLIKELY']

The "clang-format 12.0.1" installed by Homebrew doesn't yet support this option, but clang-format 14.0.6 (the current Homebrew release) does. The result with your .clang-format file plus the above line seems to give exactly what you wanted:

if( GWorldServer->SendAsync( Buffer ) != RSuccess ) _UNLIKELY
{
    return RFail;
}

Upvotes: 1

Related Questions