1f4a2713aSLionel Sambuc========================== 2f4a2713aSLionel SambucClang-Format Style Options 3f4a2713aSLionel Sambuc========================== 4f4a2713aSLionel Sambuc 5f4a2713aSLionel Sambuc:doc:`ClangFormatStyleOptions` describes configurable formatting style options 6f4a2713aSLionel Sambucsupported by :doc:`LibFormat` and :doc:`ClangFormat`. 7f4a2713aSLionel Sambuc 8f4a2713aSLionel SambucWhen using :program:`clang-format` command line utility or 9f4a2713aSLionel Sambuc``clang::format::reformat(...)`` functions from code, one can either use one of 10f4a2713aSLionel Sambucthe predefined styles (LLVM, Google, Chromium, Mozilla, WebKit) or create a 11f4a2713aSLionel Sambuccustom style by configuring specific style options. 12f4a2713aSLionel Sambuc 13f4a2713aSLionel Sambuc 14f4a2713aSLionel SambucConfiguring Style with clang-format 15f4a2713aSLionel Sambuc=================================== 16f4a2713aSLionel Sambuc 17f4a2713aSLionel Sambuc:program:`clang-format` supports two ways to provide custom style options: 18f4a2713aSLionel Sambucdirectly specify style configuration in the ``-style=`` command line option or 19f4a2713aSLionel Sambucuse ``-style=file`` and put style configuration in the ``.clang-format`` or 20f4a2713aSLionel Sambuc``_clang-format`` file in the project directory. 21f4a2713aSLionel Sambuc 22f4a2713aSLionel SambucWhen using ``-style=file``, :program:`clang-format` for each input file will 23f4a2713aSLionel Sambuctry to find the ``.clang-format`` file located in the closest parent directory 24f4a2713aSLionel Sambucof the input file. When the standard input is used, the search is started from 25f4a2713aSLionel Sambucthe current directory. 26f4a2713aSLionel Sambuc 27f4a2713aSLionel SambucThe ``.clang-format`` file uses YAML format: 28f4a2713aSLionel Sambuc 29f4a2713aSLionel Sambuc.. code-block:: yaml 30f4a2713aSLionel Sambuc 31f4a2713aSLionel Sambuc key1: value1 32f4a2713aSLionel Sambuc key2: value2 33f4a2713aSLionel Sambuc # A comment. 34f4a2713aSLionel Sambuc ... 35f4a2713aSLionel Sambuc 36*0a6a1f1dSLionel SambucThe configuration file can consist of several sections each having different 37*0a6a1f1dSLionel Sambuc``Language:`` parameter denoting the programming language this section of the 38*0a6a1f1dSLionel Sambucconfiguration is targeted at. See the description of the **Language** option 39*0a6a1f1dSLionel Sambucbelow for the list of supported languages. The first section may have no 40*0a6a1f1dSLionel Sambuclanguage set, it will set the default style options for all lanugages. 41*0a6a1f1dSLionel SambucConfiguration sections for specific language will override options set in the 42*0a6a1f1dSLionel Sambucdefault section. 43*0a6a1f1dSLionel Sambuc 44*0a6a1f1dSLionel SambucWhen :program:`clang-format` formats a file, it auto-detects the language using 45*0a6a1f1dSLionel Sambucthe file name. When formatting standard input or a file that doesn't have the 46*0a6a1f1dSLionel Sambucextension corresponding to its language, ``-assume-filename=`` option can be 47*0a6a1f1dSLionel Sambucused to override the file name :program:`clang-format` uses to detect the 48*0a6a1f1dSLionel Sambuclanguage. 49*0a6a1f1dSLionel Sambuc 50*0a6a1f1dSLionel SambucAn example of a configuration file for multiple languages: 51*0a6a1f1dSLionel Sambuc 52*0a6a1f1dSLionel Sambuc.. code-block:: yaml 53*0a6a1f1dSLionel Sambuc 54*0a6a1f1dSLionel Sambuc --- 55*0a6a1f1dSLionel Sambuc # We'll use defaults from the LLVM style, but with 4 columns indentation. 56*0a6a1f1dSLionel Sambuc BasedOnStyle: LLVM 57*0a6a1f1dSLionel Sambuc IndentWidth: 4 58*0a6a1f1dSLionel Sambuc --- 59*0a6a1f1dSLionel Sambuc Language: Cpp 60*0a6a1f1dSLionel Sambuc # Force pointers to the type for C++. 61*0a6a1f1dSLionel Sambuc DerivePointerAlignment: false 62*0a6a1f1dSLionel Sambuc PointerAlignment: Left 63*0a6a1f1dSLionel Sambuc --- 64*0a6a1f1dSLionel Sambuc Language: JavaScript 65*0a6a1f1dSLionel Sambuc # Use 100 columns for JS. 66*0a6a1f1dSLionel Sambuc ColumnLimit: 100 67*0a6a1f1dSLionel Sambuc --- 68*0a6a1f1dSLionel Sambuc Language: Proto 69*0a6a1f1dSLionel Sambuc # Don't format .proto files. 70*0a6a1f1dSLionel Sambuc DisableFormat: true 71*0a6a1f1dSLionel Sambuc ... 72*0a6a1f1dSLionel Sambuc 73f4a2713aSLionel SambucAn easy way to get a valid ``.clang-format`` file containing all configuration 74f4a2713aSLionel Sambucoptions of a certain predefined style is: 75f4a2713aSLionel Sambuc 76f4a2713aSLionel Sambuc.. code-block:: console 77f4a2713aSLionel Sambuc 78f4a2713aSLionel Sambuc clang-format -style=llvm -dump-config > .clang-format 79f4a2713aSLionel Sambuc 80f4a2713aSLionel SambucWhen specifying configuration in the ``-style=`` option, the same configuration 81f4a2713aSLionel Sambucis applied for all input files. The format of the configuration is: 82f4a2713aSLionel Sambuc 83f4a2713aSLionel Sambuc.. code-block:: console 84f4a2713aSLionel Sambuc 85f4a2713aSLionel Sambuc -style='{key1: value1, key2: value2, ...}' 86f4a2713aSLionel Sambuc 87f4a2713aSLionel Sambuc 88*0a6a1f1dSLionel SambucDisabling Formatting on a Piece of Code 89*0a6a1f1dSLionel Sambuc======================================= 90*0a6a1f1dSLionel Sambuc 91*0a6a1f1dSLionel SambucClang-format understands also special comments that switch formatting in a 92*0a6a1f1dSLionel Sambucdelimited range. The code between a comment ``// clang-format off`` or 93*0a6a1f1dSLionel Sambuc``/* clang-format off */`` up to a comment ``// clang-format on`` or 94*0a6a1f1dSLionel Sambuc``/* clang-format on */`` will not be formatted. The comments themselves 95*0a6a1f1dSLionel Sambucwill be formatted (aligned) normally. 96*0a6a1f1dSLionel Sambuc 97*0a6a1f1dSLionel Sambuc.. code-block:: c++ 98*0a6a1f1dSLionel Sambuc 99*0a6a1f1dSLionel Sambuc int formatted_code; 100*0a6a1f1dSLionel Sambuc // clang-format off 101*0a6a1f1dSLionel Sambuc void unformatted_code ; 102*0a6a1f1dSLionel Sambuc // clang-format on 103*0a6a1f1dSLionel Sambuc void formatted_code_again; 104*0a6a1f1dSLionel Sambuc 105*0a6a1f1dSLionel Sambuc 106f4a2713aSLionel SambucConfiguring Style in Code 107f4a2713aSLionel Sambuc========================= 108f4a2713aSLionel Sambuc 109f4a2713aSLionel SambucWhen using ``clang::format::reformat(...)`` functions, the format is specified 110f4a2713aSLionel Sambucby supplying the `clang::format::FormatStyle 111f4a2713aSLionel Sambuc<http://clang.llvm.org/doxygen/structclang_1_1format_1_1FormatStyle.html>`_ 112f4a2713aSLionel Sambucstructure. 113f4a2713aSLionel Sambuc 114f4a2713aSLionel Sambuc 115f4a2713aSLionel SambucConfigurable Format Style Options 116f4a2713aSLionel Sambuc================================= 117f4a2713aSLionel Sambuc 118f4a2713aSLionel SambucThis section lists the supported style options. Value type is specified for 119f4a2713aSLionel Sambuceach option. For enumeration types possible values are specified both as a C++ 120f4a2713aSLionel Sambucenumeration member (with a prefix, e.g. ``LS_Auto``), and as a value usable in 121f4a2713aSLionel Sambucthe configuration (without a prefix: ``Auto``). 122f4a2713aSLionel Sambuc 123f4a2713aSLionel Sambuc 124f4a2713aSLionel Sambuc**BasedOnStyle** (``string``) 125f4a2713aSLionel Sambuc The style used for all options not specifically set in the configuration. 126f4a2713aSLionel Sambuc 127f4a2713aSLionel Sambuc This option is supported only in the :program:`clang-format` configuration 128f4a2713aSLionel Sambuc (both within ``-style='{...}'`` and the ``.clang-format`` file). 129f4a2713aSLionel Sambuc 130f4a2713aSLionel Sambuc Possible values: 131f4a2713aSLionel Sambuc 132f4a2713aSLionel Sambuc * ``LLVM`` 133f4a2713aSLionel Sambuc A style complying with the `LLVM coding standards 134f4a2713aSLionel Sambuc <http://llvm.org/docs/CodingStandards.html>`_ 135f4a2713aSLionel Sambuc * ``Google`` 136f4a2713aSLionel Sambuc A style complying with `Google's C++ style guide 137f4a2713aSLionel Sambuc <http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml>`_ 138f4a2713aSLionel Sambuc * ``Chromium`` 139f4a2713aSLionel Sambuc A style complying with `Chromium's style guide 140f4a2713aSLionel Sambuc <http://www.chromium.org/developers/coding-style>`_ 141f4a2713aSLionel Sambuc * ``Mozilla`` 142f4a2713aSLionel Sambuc A style complying with `Mozilla's style guide 143f4a2713aSLionel Sambuc <https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style>`_ 144f4a2713aSLionel Sambuc * ``WebKit`` 145f4a2713aSLionel Sambuc A style complying with `WebKit's style guide 146f4a2713aSLionel Sambuc <http://www.webkit.org/coding/coding-style.html>`_ 147f4a2713aSLionel Sambuc 148f4a2713aSLionel Sambuc.. START_FORMAT_STYLE_OPTIONS 149f4a2713aSLionel Sambuc 150f4a2713aSLionel Sambuc**AccessModifierOffset** (``int``) 151f4a2713aSLionel Sambuc The extra indent or outdent of access modifiers, e.g. ``public:``. 152f4a2713aSLionel Sambuc 153*0a6a1f1dSLionel Sambuc**AlignAfterOpenBracket** (``bool``) 154*0a6a1f1dSLionel Sambuc If ``true``, horizontally aligns arguments after an open bracket. 155*0a6a1f1dSLionel Sambuc 156*0a6a1f1dSLionel Sambuc This applies to round brackets (parentheses), angle brackets and square 157*0a6a1f1dSLionel Sambuc brackets. This will result in formattings like 158*0a6a1f1dSLionel Sambuc \code 159*0a6a1f1dSLionel Sambuc someLongFunction(argument1, 160*0a6a1f1dSLionel Sambuc argument2); 161*0a6a1f1dSLionel Sambuc \endcode 162*0a6a1f1dSLionel Sambuc 163f4a2713aSLionel Sambuc**AlignEscapedNewlinesLeft** (``bool``) 164f4a2713aSLionel Sambuc If ``true``, aligns escaped newlines as far left as possible. 165f4a2713aSLionel Sambuc Otherwise puts them into the right-most column. 166f4a2713aSLionel Sambuc 167*0a6a1f1dSLionel Sambuc**AlignOperands** (``bool``) 168*0a6a1f1dSLionel Sambuc If ``true``, horizontally align operands of binary and ternary 169*0a6a1f1dSLionel Sambuc expressions. 170*0a6a1f1dSLionel Sambuc 171f4a2713aSLionel Sambuc**AlignTrailingComments** (``bool``) 172f4a2713aSLionel Sambuc If ``true``, aligns trailing comments. 173f4a2713aSLionel Sambuc 174f4a2713aSLionel Sambuc**AllowAllParametersOfDeclarationOnNextLine** (``bool``) 175f4a2713aSLionel Sambuc Allow putting all parameters of a function declaration onto 176f4a2713aSLionel Sambuc the next line even if ``BinPackParameters`` is ``false``. 177f4a2713aSLionel Sambuc 178*0a6a1f1dSLionel Sambuc**AllowShortBlocksOnASingleLine** (``bool``) 179*0a6a1f1dSLionel Sambuc Allows contracting simple braced statements to a single line. 180*0a6a1f1dSLionel Sambuc 181*0a6a1f1dSLionel Sambuc E.g., this allows ``if (a) { return; }`` to be put on a single line. 182*0a6a1f1dSLionel Sambuc 183*0a6a1f1dSLionel Sambuc**AllowShortCaseLabelsOnASingleLine** (``bool``) 184*0a6a1f1dSLionel Sambuc If ``true``, short case labels will be contracted to a single line. 185*0a6a1f1dSLionel Sambuc 186*0a6a1f1dSLionel Sambuc**AllowShortFunctionsOnASingleLine** (``ShortFunctionStyle``) 187*0a6a1f1dSLionel Sambuc Dependent on the value, ``int f() { return 0; }`` can be put 188*0a6a1f1dSLionel Sambuc on a single line. 189*0a6a1f1dSLionel Sambuc 190*0a6a1f1dSLionel Sambuc Possible values: 191*0a6a1f1dSLionel Sambuc 192*0a6a1f1dSLionel Sambuc * ``SFS_None`` (in configuration: ``None``) 193*0a6a1f1dSLionel Sambuc Never merge functions into a single line. 194*0a6a1f1dSLionel Sambuc * ``SFS_Inline`` (in configuration: ``Inline``) 195*0a6a1f1dSLionel Sambuc Only merge functions defined inside a class. 196*0a6a1f1dSLionel Sambuc * ``SFS_Empty`` (in configuration: ``Empty``) 197*0a6a1f1dSLionel Sambuc Only merge empty functions. 198*0a6a1f1dSLionel Sambuc * ``SFS_All`` (in configuration: ``All``) 199*0a6a1f1dSLionel Sambuc Merge all functions fitting on a single line. 200*0a6a1f1dSLionel Sambuc 201*0a6a1f1dSLionel Sambuc 202f4a2713aSLionel Sambuc**AllowShortIfStatementsOnASingleLine** (``bool``) 203f4a2713aSLionel Sambuc If ``true``, ``if (a) return;`` can be put on a single 204f4a2713aSLionel Sambuc line. 205f4a2713aSLionel Sambuc 206f4a2713aSLionel Sambuc**AllowShortLoopsOnASingleLine** (``bool``) 207f4a2713aSLionel Sambuc If ``true``, ``while (true) continue;`` can be put on a 208f4a2713aSLionel Sambuc single line. 209f4a2713aSLionel Sambuc 210*0a6a1f1dSLionel Sambuc**AlwaysBreakAfterDefinitionReturnType** (``bool``) 211*0a6a1f1dSLionel Sambuc If ``true``, always break after function definition return types. 212*0a6a1f1dSLionel Sambuc 213*0a6a1f1dSLionel Sambuc More truthfully called 'break before the identifier following the type 214*0a6a1f1dSLionel Sambuc in a function definition'. PenaltyReturnTypeOnItsOwnLine becomes 215*0a6a1f1dSLionel Sambuc irrelevant. 216*0a6a1f1dSLionel Sambuc 217f4a2713aSLionel Sambuc**AlwaysBreakBeforeMultilineStrings** (``bool``) 218f4a2713aSLionel Sambuc If ``true``, always break before multiline string literals. 219f4a2713aSLionel Sambuc 220f4a2713aSLionel Sambuc**AlwaysBreakTemplateDeclarations** (``bool``) 221f4a2713aSLionel Sambuc If ``true``, always break after the ``template<...>`` of a 222f4a2713aSLionel Sambuc template declaration. 223f4a2713aSLionel Sambuc 224*0a6a1f1dSLionel Sambuc**BinPackArguments** (``bool``) 225*0a6a1f1dSLionel Sambuc If ``false``, a function call's arguments will either be all on the 226*0a6a1f1dSLionel Sambuc same line or will have one line each. 227f4a2713aSLionel Sambuc 228*0a6a1f1dSLionel Sambuc**BinPackParameters** (``bool``) 229*0a6a1f1dSLionel Sambuc If ``false``, a function declaration's or function definition's 230*0a6a1f1dSLionel Sambuc parameters will either all be on the same line or will have one line each. 231*0a6a1f1dSLionel Sambuc 232*0a6a1f1dSLionel Sambuc**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) 233*0a6a1f1dSLionel Sambuc The way to wrap binary operators. 234*0a6a1f1dSLionel Sambuc 235*0a6a1f1dSLionel Sambuc Possible values: 236*0a6a1f1dSLionel Sambuc 237*0a6a1f1dSLionel Sambuc * ``BOS_None`` (in configuration: ``None``) 238*0a6a1f1dSLionel Sambuc Break after operators. 239*0a6a1f1dSLionel Sambuc * ``BOS_NonAssignment`` (in configuration: ``NonAssignment``) 240*0a6a1f1dSLionel Sambuc Break before operators that aren't assignments. 241*0a6a1f1dSLionel Sambuc * ``BOS_All`` (in configuration: ``All``) 242*0a6a1f1dSLionel Sambuc Break before operators. 243*0a6a1f1dSLionel Sambuc 244f4a2713aSLionel Sambuc 245f4a2713aSLionel Sambuc**BreakBeforeBraces** (``BraceBreakingStyle``) 246f4a2713aSLionel Sambuc The brace breaking style to use. 247f4a2713aSLionel Sambuc 248f4a2713aSLionel Sambuc Possible values: 249f4a2713aSLionel Sambuc 250f4a2713aSLionel Sambuc * ``BS_Attach`` (in configuration: ``Attach``) 251f4a2713aSLionel Sambuc Always attach braces to surrounding context. 252f4a2713aSLionel Sambuc * ``BS_Linux`` (in configuration: ``Linux``) 253f4a2713aSLionel Sambuc Like ``Attach``, but break before braces on function, namespace and 254f4a2713aSLionel Sambuc class definitions. 255f4a2713aSLionel Sambuc * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) 256*0a6a1f1dSLionel Sambuc Like ``Attach``, but break before function definitions, and 'else'. 257f4a2713aSLionel Sambuc * ``BS_Allman`` (in configuration: ``Allman``) 258f4a2713aSLionel Sambuc Always break before braces. 259*0a6a1f1dSLionel Sambuc * ``BS_GNU`` (in configuration: ``GNU``) 260*0a6a1f1dSLionel Sambuc Always break before braces and add an extra level of indentation to 261*0a6a1f1dSLionel Sambuc braces of control statements, not to those of class, function 262*0a6a1f1dSLionel Sambuc or other definitions. 263f4a2713aSLionel Sambuc 264f4a2713aSLionel Sambuc 265*0a6a1f1dSLionel Sambuc**BreakBeforeTernaryOperators** (``bool``) 266*0a6a1f1dSLionel Sambuc If ``true``, ternary operators will be placed after line breaks. 267*0a6a1f1dSLionel Sambuc 268f4a2713aSLionel Sambuc**BreakConstructorInitializersBeforeComma** (``bool``) 269f4a2713aSLionel Sambuc Always break constructor initializers before commas and align 270f4a2713aSLionel Sambuc the commas with the colon. 271f4a2713aSLionel Sambuc 272f4a2713aSLionel Sambuc**ColumnLimit** (``unsigned``) 273f4a2713aSLionel Sambuc The column limit. 274f4a2713aSLionel Sambuc 275f4a2713aSLionel Sambuc A column limit of ``0`` means that there is no column limit. In this case, 276f4a2713aSLionel Sambuc clang-format will respect the input's line breaking decisions within 277*0a6a1f1dSLionel Sambuc statements unless they contradict other rules. 278*0a6a1f1dSLionel Sambuc 279*0a6a1f1dSLionel Sambuc**CommentPragmas** (``std::string``) 280*0a6a1f1dSLionel Sambuc A regular expression that describes comments with special meaning, 281*0a6a1f1dSLionel Sambuc which should not be split into lines or otherwise changed. 282f4a2713aSLionel Sambuc 283f4a2713aSLionel Sambuc**ConstructorInitializerAllOnOneLineOrOnePerLine** (``bool``) 284f4a2713aSLionel Sambuc If the constructor initializers don't fit on a line, put each 285f4a2713aSLionel Sambuc initializer on its own line. 286f4a2713aSLionel Sambuc 287f4a2713aSLionel Sambuc**ConstructorInitializerIndentWidth** (``unsigned``) 288f4a2713aSLionel Sambuc The number of characters to use for indentation of constructor 289f4a2713aSLionel Sambuc initializer lists. 290f4a2713aSLionel Sambuc 291*0a6a1f1dSLionel Sambuc**ContinuationIndentWidth** (``unsigned``) 292*0a6a1f1dSLionel Sambuc Indent width for line continuations. 293*0a6a1f1dSLionel Sambuc 294f4a2713aSLionel Sambuc**Cpp11BracedListStyle** (``bool``) 295f4a2713aSLionel Sambuc If ``true``, format braced lists as best suited for C++11 braced 296f4a2713aSLionel Sambuc lists. 297f4a2713aSLionel Sambuc 298f4a2713aSLionel Sambuc Important differences: 299f4a2713aSLionel Sambuc - No spaces inside the braced list. 300f4a2713aSLionel Sambuc - No line break before the closing brace. 301f4a2713aSLionel Sambuc - Indentation with the continuation indent, not with the block indent. 302f4a2713aSLionel Sambuc 303f4a2713aSLionel Sambuc Fundamentally, C++11 braced lists are formatted exactly like function 304f4a2713aSLionel Sambuc calls would be formatted in their place. If the braced list follows a name 305f4a2713aSLionel Sambuc (e.g. a type or variable name), clang-format formats as if the ``{}`` were 306f4a2713aSLionel Sambuc the parentheses of a function call with that name. If there is no name, 307f4a2713aSLionel Sambuc a zero-length name is assumed. 308f4a2713aSLionel Sambuc 309*0a6a1f1dSLionel Sambuc**DerivePointerAlignment** (``bool``) 310*0a6a1f1dSLionel Sambuc If ``true``, analyze the formatted file for the most common 311*0a6a1f1dSLionel Sambuc alignment of & and \*. ``PointerAlignment`` is then used only as fallback. 312*0a6a1f1dSLionel Sambuc 313*0a6a1f1dSLionel Sambuc**DisableFormat** (``bool``) 314*0a6a1f1dSLionel Sambuc Disables formatting at all. 315f4a2713aSLionel Sambuc 316f4a2713aSLionel Sambuc**ExperimentalAutoDetectBinPacking** (``bool``) 317f4a2713aSLionel Sambuc If ``true``, clang-format detects whether function calls and 318f4a2713aSLionel Sambuc definitions are formatted with one parameter per line. 319f4a2713aSLionel Sambuc 320f4a2713aSLionel Sambuc Each call can be bin-packed, one-per-line or inconclusive. If it is 321f4a2713aSLionel Sambuc inconclusive, e.g. completely on one line, but a decision needs to be 322f4a2713aSLionel Sambuc made, clang-format analyzes whether there are other bin-packed cases in 323f4a2713aSLionel Sambuc the input file and act accordingly. 324f4a2713aSLionel Sambuc 325f4a2713aSLionel Sambuc NOTE: This is an experimental flag, that might go away or be renamed. Do 326f4a2713aSLionel Sambuc not use this in config files, etc. Use at your own risk. 327f4a2713aSLionel Sambuc 328*0a6a1f1dSLionel Sambuc**ForEachMacros** (``std::vector<std::string>``) 329*0a6a1f1dSLionel Sambuc A vector of macros that should be interpreted as foreach loops 330*0a6a1f1dSLionel Sambuc instead of as function calls. 331*0a6a1f1dSLionel Sambuc 332*0a6a1f1dSLionel Sambuc These are expected to be macros of the form: 333*0a6a1f1dSLionel Sambuc \code 334*0a6a1f1dSLionel Sambuc FOREACH(<variable-declaration>, ...) 335*0a6a1f1dSLionel Sambuc <loop-body> 336*0a6a1f1dSLionel Sambuc \endcode 337*0a6a1f1dSLionel Sambuc 338*0a6a1f1dSLionel Sambuc For example: BOOST_FOREACH. 339*0a6a1f1dSLionel Sambuc 340f4a2713aSLionel Sambuc**IndentCaseLabels** (``bool``) 341f4a2713aSLionel Sambuc Indent case labels one level from the switch statement. 342f4a2713aSLionel Sambuc 343f4a2713aSLionel Sambuc When ``false``, use the same indentation level as for the switch statement. 344f4a2713aSLionel Sambuc Switch statement body is always indented one level more than case labels. 345f4a2713aSLionel Sambuc 346f4a2713aSLionel Sambuc**IndentWidth** (``unsigned``) 347f4a2713aSLionel Sambuc The number of columns to use for indentation. 348f4a2713aSLionel Sambuc 349*0a6a1f1dSLionel Sambuc**IndentWrappedFunctionNames** (``bool``) 350*0a6a1f1dSLionel Sambuc Indent if a function definition or declaration is wrapped after the 351*0a6a1f1dSLionel Sambuc type. 352*0a6a1f1dSLionel Sambuc 353*0a6a1f1dSLionel Sambuc**KeepEmptyLinesAtTheStartOfBlocks** (``bool``) 354*0a6a1f1dSLionel Sambuc If true, empty lines at the start of blocks are kept. 355*0a6a1f1dSLionel Sambuc 356*0a6a1f1dSLionel Sambuc**Language** (``LanguageKind``) 357*0a6a1f1dSLionel Sambuc Language, this format style is targeted at. 358*0a6a1f1dSLionel Sambuc 359*0a6a1f1dSLionel Sambuc Possible values: 360*0a6a1f1dSLionel Sambuc 361*0a6a1f1dSLionel Sambuc * ``LK_None`` (in configuration: ``None``) 362*0a6a1f1dSLionel Sambuc Do not use. 363*0a6a1f1dSLionel Sambuc * ``LK_Cpp`` (in configuration: ``Cpp``) 364*0a6a1f1dSLionel Sambuc Should be used for C, C++, ObjectiveC, ObjectiveC++. 365*0a6a1f1dSLionel Sambuc * ``LK_Java`` (in configuration: ``Java``) 366*0a6a1f1dSLionel Sambuc Should be used for Java. 367*0a6a1f1dSLionel Sambuc * ``LK_JavaScript`` (in configuration: ``JavaScript``) 368*0a6a1f1dSLionel Sambuc Should be used for JavaScript. 369*0a6a1f1dSLionel Sambuc * ``LK_Proto`` (in configuration: ``Proto``) 370*0a6a1f1dSLionel Sambuc Should be used for Protocol Buffers 371*0a6a1f1dSLionel Sambuc (https://developers.google.com/protocol-buffers/). 372*0a6a1f1dSLionel Sambuc 373*0a6a1f1dSLionel Sambuc 374f4a2713aSLionel Sambuc**MaxEmptyLinesToKeep** (``unsigned``) 375f4a2713aSLionel Sambuc The maximum number of consecutive empty lines to keep. 376f4a2713aSLionel Sambuc 377f4a2713aSLionel Sambuc**NamespaceIndentation** (``NamespaceIndentationKind``) 378f4a2713aSLionel Sambuc The indentation used for namespaces. 379f4a2713aSLionel Sambuc 380f4a2713aSLionel Sambuc Possible values: 381f4a2713aSLionel Sambuc 382f4a2713aSLionel Sambuc * ``NI_None`` (in configuration: ``None``) 383f4a2713aSLionel Sambuc Don't indent in namespaces. 384f4a2713aSLionel Sambuc * ``NI_Inner`` (in configuration: ``Inner``) 385f4a2713aSLionel Sambuc Indent only in inner namespaces (nested in other namespaces). 386f4a2713aSLionel Sambuc * ``NI_All`` (in configuration: ``All``) 387f4a2713aSLionel Sambuc Indent in all namespaces. 388f4a2713aSLionel Sambuc 389f4a2713aSLionel Sambuc 390*0a6a1f1dSLionel Sambuc**ObjCBlockIndentWidth** (``unsigned``) 391*0a6a1f1dSLionel Sambuc The number of characters to use for indentation of ObjC blocks. 392*0a6a1f1dSLionel Sambuc 393*0a6a1f1dSLionel Sambuc**ObjCSpaceAfterProperty** (``bool``) 394*0a6a1f1dSLionel Sambuc Add a space after ``@property`` in Objective-C, i.e. use 395*0a6a1f1dSLionel Sambuc ``\@property (readonly)`` instead of ``\@property(readonly)``. 396*0a6a1f1dSLionel Sambuc 397f4a2713aSLionel Sambuc**ObjCSpaceBeforeProtocolList** (``bool``) 398f4a2713aSLionel Sambuc Add a space in front of an Objective-C protocol list, i.e. use 399f4a2713aSLionel Sambuc ``Foo <Protocol>`` instead of ``Foo<Protocol>``. 400f4a2713aSLionel Sambuc 401*0a6a1f1dSLionel Sambuc**PenaltyBreakBeforeFirstCallParameter** (``unsigned``) 402*0a6a1f1dSLionel Sambuc The penalty for breaking a function call after "call(". 403*0a6a1f1dSLionel Sambuc 404f4a2713aSLionel Sambuc**PenaltyBreakComment** (``unsigned``) 405f4a2713aSLionel Sambuc The penalty for each line break introduced inside a comment. 406f4a2713aSLionel Sambuc 407f4a2713aSLionel Sambuc**PenaltyBreakFirstLessLess** (``unsigned``) 408f4a2713aSLionel Sambuc The penalty for breaking before the first ``<<``. 409f4a2713aSLionel Sambuc 410f4a2713aSLionel Sambuc**PenaltyBreakString** (``unsigned``) 411f4a2713aSLionel Sambuc The penalty for each line break introduced inside a string literal. 412f4a2713aSLionel Sambuc 413f4a2713aSLionel Sambuc**PenaltyExcessCharacter** (``unsigned``) 414f4a2713aSLionel Sambuc The penalty for each character outside of the column limit. 415f4a2713aSLionel Sambuc 416f4a2713aSLionel Sambuc**PenaltyReturnTypeOnItsOwnLine** (``unsigned``) 417f4a2713aSLionel Sambuc Penalty for putting the return type of a function onto its own 418f4a2713aSLionel Sambuc line. 419f4a2713aSLionel Sambuc 420*0a6a1f1dSLionel Sambuc**PointerAlignment** (``PointerAlignmentStyle``) 421*0a6a1f1dSLionel Sambuc Pointer and reference alignment style. 422f4a2713aSLionel Sambuc 423*0a6a1f1dSLionel Sambuc Possible values: 424*0a6a1f1dSLionel Sambuc 425*0a6a1f1dSLionel Sambuc * ``PAS_Left`` (in configuration: ``Left``) 426*0a6a1f1dSLionel Sambuc Align pointer to the left. 427*0a6a1f1dSLionel Sambuc * ``PAS_Right`` (in configuration: ``Right``) 428*0a6a1f1dSLionel Sambuc Align pointer to the right. 429*0a6a1f1dSLionel Sambuc * ``PAS_Middle`` (in configuration: ``Middle``) 430*0a6a1f1dSLionel Sambuc Align pointer in the middle. 431*0a6a1f1dSLionel Sambuc 432*0a6a1f1dSLionel Sambuc 433*0a6a1f1dSLionel Sambuc**SpaceAfterCStyleCast** (``bool``) 434*0a6a1f1dSLionel Sambuc If ``true``, a space may be inserted after C style casts. 435f4a2713aSLionel Sambuc 436f4a2713aSLionel Sambuc**SpaceBeforeAssignmentOperators** (``bool``) 437f4a2713aSLionel Sambuc If ``false``, spaces will be removed before assignment operators. 438f4a2713aSLionel Sambuc 439*0a6a1f1dSLionel Sambuc**SpaceBeforeParens** (``SpaceBeforeParensOptions``) 440*0a6a1f1dSLionel Sambuc Defines in which cases to put a space before opening parentheses. 441*0a6a1f1dSLionel Sambuc 442*0a6a1f1dSLionel Sambuc Possible values: 443*0a6a1f1dSLionel Sambuc 444*0a6a1f1dSLionel Sambuc * ``SBPO_Never`` (in configuration: ``Never``) 445*0a6a1f1dSLionel Sambuc Never put a space before opening parentheses. 446*0a6a1f1dSLionel Sambuc * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``) 447*0a6a1f1dSLionel Sambuc Put a space before opening parentheses only after control statement 448*0a6a1f1dSLionel Sambuc keywords (``for/if/while...``). 449*0a6a1f1dSLionel Sambuc * ``SBPO_Always`` (in configuration: ``Always``) 450*0a6a1f1dSLionel Sambuc Always put a space before opening parentheses, except when it's 451*0a6a1f1dSLionel Sambuc prohibited by the syntax rules (in function-like macro definitions) or 452*0a6a1f1dSLionel Sambuc when determined by other style rules (after unary operators, opening 453*0a6a1f1dSLionel Sambuc parentheses, etc.) 454*0a6a1f1dSLionel Sambuc 455*0a6a1f1dSLionel Sambuc 456f4a2713aSLionel Sambuc**SpaceInEmptyParentheses** (``bool``) 457*0a6a1f1dSLionel Sambuc If ``true``, spaces may be inserted into '()'. 458f4a2713aSLionel Sambuc 459f4a2713aSLionel Sambuc**SpacesBeforeTrailingComments** (``unsigned``) 460*0a6a1f1dSLionel Sambuc The number of spaces before trailing line comments 461*0a6a1f1dSLionel Sambuc (``//`` - comments). 462*0a6a1f1dSLionel Sambuc 463*0a6a1f1dSLionel Sambuc This does not affect trailing block comments (``/**/`` - comments) as those 464*0a6a1f1dSLionel Sambuc commonly have different usage patterns and a number of special cases. 465*0a6a1f1dSLionel Sambuc 466*0a6a1f1dSLionel Sambuc**SpacesInAngles** (``bool``) 467*0a6a1f1dSLionel Sambuc If ``true``, spaces will be inserted after '<' and before '>' in 468*0a6a1f1dSLionel Sambuc template argument lists 469f4a2713aSLionel Sambuc 470f4a2713aSLionel Sambuc**SpacesInCStyleCastParentheses** (``bool``) 471*0a6a1f1dSLionel Sambuc If ``true``, spaces may be inserted into C style casts. 472*0a6a1f1dSLionel Sambuc 473*0a6a1f1dSLionel Sambuc**SpacesInContainerLiterals** (``bool``) 474*0a6a1f1dSLionel Sambuc If ``true``, spaces are inserted inside container literals (e.g. 475*0a6a1f1dSLionel Sambuc ObjC and Javascript array and dict literals). 476f4a2713aSLionel Sambuc 477f4a2713aSLionel Sambuc**SpacesInParentheses** (``bool``) 478*0a6a1f1dSLionel Sambuc If ``true``, spaces will be inserted after '(' and before ')'. 479*0a6a1f1dSLionel Sambuc 480*0a6a1f1dSLionel Sambuc**SpacesInSquareBrackets** (``bool``) 481*0a6a1f1dSLionel Sambuc If ``true``, spaces will be inserted after '[' and before ']'. 482f4a2713aSLionel Sambuc 483f4a2713aSLionel Sambuc**Standard** (``LanguageStandard``) 484f4a2713aSLionel Sambuc Format compatible with this standard, e.g. use 485f4a2713aSLionel Sambuc ``A<A<int> >`` instead of ``A<A<int>>`` for LS_Cpp03. 486f4a2713aSLionel Sambuc 487f4a2713aSLionel Sambuc Possible values: 488f4a2713aSLionel Sambuc 489f4a2713aSLionel Sambuc * ``LS_Cpp03`` (in configuration: ``Cpp03``) 490f4a2713aSLionel Sambuc Use C++03-compatible syntax. 491f4a2713aSLionel Sambuc * ``LS_Cpp11`` (in configuration: ``Cpp11``) 492f4a2713aSLionel Sambuc Use features of C++11 (e.g. ``A<A<int>>`` instead of 493f4a2713aSLionel Sambuc ``A<A<int> >``). 494f4a2713aSLionel Sambuc * ``LS_Auto`` (in configuration: ``Auto``) 495f4a2713aSLionel Sambuc Automatic detection based on the input. 496f4a2713aSLionel Sambuc 497f4a2713aSLionel Sambuc 498f4a2713aSLionel Sambuc**TabWidth** (``unsigned``) 499f4a2713aSLionel Sambuc The number of columns used for tab stops. 500f4a2713aSLionel Sambuc 501f4a2713aSLionel Sambuc**UseTab** (``UseTabStyle``) 502f4a2713aSLionel Sambuc The way to use tab characters in the resulting file. 503f4a2713aSLionel Sambuc 504f4a2713aSLionel Sambuc Possible values: 505f4a2713aSLionel Sambuc 506f4a2713aSLionel Sambuc * ``UT_Never`` (in configuration: ``Never``) 507f4a2713aSLionel Sambuc Never use tab. 508f4a2713aSLionel Sambuc * ``UT_ForIndentation`` (in configuration: ``ForIndentation``) 509f4a2713aSLionel Sambuc Use tabs only for indentation. 510f4a2713aSLionel Sambuc * ``UT_Always`` (in configuration: ``Always``) 511f4a2713aSLionel Sambuc Use tabs whenever we need to fill whitespace that spans at least from 512f4a2713aSLionel Sambuc one tab stop to the next one. 513f4a2713aSLionel Sambuc 514f4a2713aSLionel Sambuc 515f4a2713aSLionel Sambuc.. END_FORMAT_STYLE_OPTIONS 516f4a2713aSLionel Sambuc 517f4a2713aSLionel SambucExamples 518f4a2713aSLionel Sambuc======== 519f4a2713aSLionel Sambuc 520f4a2713aSLionel SambucA style similar to the `Linux Kernel style 521f4a2713aSLionel Sambuc<https://www.kernel.org/doc/Documentation/CodingStyle>`_: 522f4a2713aSLionel Sambuc 523f4a2713aSLionel Sambuc.. code-block:: yaml 524f4a2713aSLionel Sambuc 525f4a2713aSLionel Sambuc BasedOnStyle: LLVM 526f4a2713aSLionel Sambuc IndentWidth: 8 527f4a2713aSLionel Sambuc UseTab: Always 528f4a2713aSLionel Sambuc BreakBeforeBraces: Linux 529f4a2713aSLionel Sambuc AllowShortIfStatementsOnASingleLine: false 530f4a2713aSLionel Sambuc IndentCaseLabels: false 531f4a2713aSLionel Sambuc 532f4a2713aSLionel SambucThe result is (imagine that tabs are used for indentation here): 533f4a2713aSLionel Sambuc 534f4a2713aSLionel Sambuc.. code-block:: c++ 535f4a2713aSLionel Sambuc 536f4a2713aSLionel Sambuc void test() 537f4a2713aSLionel Sambuc { 538f4a2713aSLionel Sambuc switch (x) { 539f4a2713aSLionel Sambuc case 0: 540f4a2713aSLionel Sambuc case 1: 541f4a2713aSLionel Sambuc do_something(); 542f4a2713aSLionel Sambuc break; 543f4a2713aSLionel Sambuc case 2: 544f4a2713aSLionel Sambuc do_something_else(); 545f4a2713aSLionel Sambuc break; 546f4a2713aSLionel Sambuc default: 547f4a2713aSLionel Sambuc break; 548f4a2713aSLionel Sambuc } 549f4a2713aSLionel Sambuc if (condition) 550f4a2713aSLionel Sambuc do_something_completely_different(); 551f4a2713aSLionel Sambuc 552f4a2713aSLionel Sambuc if (x == y) { 553f4a2713aSLionel Sambuc q(); 554f4a2713aSLionel Sambuc } else if (x > y) { 555f4a2713aSLionel Sambuc w(); 556f4a2713aSLionel Sambuc } else { 557f4a2713aSLionel Sambuc r(); 558f4a2713aSLionel Sambuc } 559f4a2713aSLionel Sambuc } 560f4a2713aSLionel Sambuc 561f4a2713aSLionel SambucA style similar to the default Visual Studio formatting style: 562f4a2713aSLionel Sambuc 563f4a2713aSLionel Sambuc.. code-block:: yaml 564f4a2713aSLionel Sambuc 565f4a2713aSLionel Sambuc UseTab: Never 566f4a2713aSLionel Sambuc IndentWidth: 4 567f4a2713aSLionel Sambuc BreakBeforeBraces: Allman 568f4a2713aSLionel Sambuc AllowShortIfStatementsOnASingleLine: false 569f4a2713aSLionel Sambuc IndentCaseLabels: false 570f4a2713aSLionel Sambuc ColumnLimit: 0 571f4a2713aSLionel Sambuc 572f4a2713aSLionel SambucThe result is: 573f4a2713aSLionel Sambuc 574f4a2713aSLionel Sambuc.. code-block:: c++ 575f4a2713aSLionel Sambuc 576f4a2713aSLionel Sambuc void test() 577f4a2713aSLionel Sambuc { 578f4a2713aSLionel Sambuc switch (suffix) 579f4a2713aSLionel Sambuc { 580f4a2713aSLionel Sambuc case 0: 581f4a2713aSLionel Sambuc case 1: 582f4a2713aSLionel Sambuc do_something(); 583f4a2713aSLionel Sambuc break; 584f4a2713aSLionel Sambuc case 2: 585f4a2713aSLionel Sambuc do_something_else(); 586f4a2713aSLionel Sambuc break; 587f4a2713aSLionel Sambuc default: 588f4a2713aSLionel Sambuc break; 589f4a2713aSLionel Sambuc } 590f4a2713aSLionel Sambuc if (condition) 591f4a2713aSLionel Sambuc do_somthing_completely_different(); 592f4a2713aSLionel Sambuc 593f4a2713aSLionel Sambuc if (x == y) 594f4a2713aSLionel Sambuc { 595f4a2713aSLionel Sambuc q(); 596f4a2713aSLionel Sambuc } 597f4a2713aSLionel Sambuc else if (x > y) 598f4a2713aSLionel Sambuc { 599f4a2713aSLionel Sambuc w(); 600f4a2713aSLionel Sambuc } 601f4a2713aSLionel Sambuc else 602f4a2713aSLionel Sambuc { 603f4a2713aSLionel Sambuc r(); 604f4a2713aSLionel Sambuc } 605f4a2713aSLionel Sambuc } 606f4a2713aSLionel Sambuc 607