Skip to content

Instantly share code, notes, and snippets.

@stevestreza
Forked from tonyarnold/clang-format
Created January 7, 2014 20:57
Show Gist options
  • Save stevestreza/8306795 to your computer and use it in GitHub Desktop.
Save stevestreza/8306795 to your computer and use it in GitHub Desktop.
---
BasedOnStyle: WebKit
AccessModifierOffset: -2
AlignEscapedNewlinesLeft: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackParameters: true
BreakBeforeBinaryOperators: false
BreakBeforeBraces: Attach
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: ForIndentation
...

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 `^```

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