Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Last active January 2, 2016 12:49
Show Gist options
  • Save tonyarnold/8306037 to your computer and use it in GitHub Desktop.
Save tonyarnold/8306037 to your computer and use it in GitHub Desktop.
---
BasedOnStyle: WebKit
AccessModifierOffset: -2
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: true
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Stroustrup
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerBinding: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: false
IndentFunctionDeclarationAfterType: false
IndentWidth: 4
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 60
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerBindsToType: false
SpaceAfterControlStatementKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
Standard: Auto
TabWidth: 4
UseTab: Never
...

My first sweep at a clang-format configuration. There are a couple of issues:

  • Braces for block function bodies are pushed to the next line
  • Method calls are being pushed across multiple lines (although parameters are being aligned)
  • Literal arrays and dictionaries are being spread out a bit too much for my liking

Regardless, the output is still very readable and consistent. My guess is that this will be integrated into the next major release of Xcode (pleasepleaseplease), so I'm just going to suck it up, have a spoonful of concrete and adapt to the whatever the output is.

Currently best used with ClangFormat-Xcode. Place the contents in a file named .clang-format at the root of your project, and select the "Edit > Clang Format > File" menu item in Xcode. Assign a keyboard shortcut for bonus points — I use `^```

@langford
Copy link

Method calls are being pushed across multiple lines (although parameters are being aligned)

Is still a deal breaker for me, I wish I'd noticed you'd gotten this done before I made one, and came on the same limitation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment