---
BasedOnStyle: GNU
Language: C
Standard: c++20

# use tabs with a width of 8
IndentWidth: 8
TabWidth: 8
UseTab: Always

# dirty hack: C doesn't have "requires", and we use it as variable
# a lot in the code and want it properly aligned
RequiresClausePosition: SingleLine

# maximum column width
ColumnLimit: 100

# brace breaking style like Linux
BreakBeforeBraces: Linux

# always break after an open bracket, if the parameters don’t fit on a single line
AlignAfterOpenBracket: Align

# align consecutive macros
AlignConsecutiveMacros: true

# horizontally align operands of binary and ternary expressions
AlignOperands: true

# align trailing comments
AlignTrailingComments: true

# left-align array of structures
AlignArrayOfStructures: Left

# don't allow putting all parameters of a function/declaration onto the next line
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false

# only merge empty blocks.
AllowShortBlocksOnASingleLine: Empty

# always break after the return type of top-level definitions
AlwaysBreakAfterReturnType: TopLevelDefinitions

AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false

# never pack parameters/arguments
BinPackParameters: false
BinPackArguments: false

# regroup include blocks
IncludeBlocks: Regroup

# never sort includes
SortIncludes: false

# space after casts
SpaceAfterCStyleCast: true

# we abuse this to make clang-format not touch g_auto* macros,
# as these should not have a space inserted before their open bracket.
# The G_DECLARE_* macros are listed here for a different reason: they are
# declarations, so the one-parameter-per-line rule that autoformat.py adds for
# headers would otherwise split every one of them across five lines.
WhitespaceSensitiveMacros: [
    'g_autoptr',
    'g_auto',
    'g_autolist',
    'g_autoslist',
    '_',
    '__attribute__',
    'G_DEFINE_QUARK',
    'G_DEFINE_AUTOPTR_CLEANUP_FUNC',
    'G_TYPE_CHECK_CLASS_CAST',
    'GET_PRIVATE',
    'G_OBJECT',
    # boilerplate macros whose argument list is a fixed
    # signature, not a parameter list to be wrapped.
    'G_DECLARE_FINAL_TYPE',
    'G_DECLARE_DERIVABLE_TYPE',
    'G_DECLARE_INTERFACE',
    'G_GNUC_PRINTF'
]

# some attribute macros
# NOTE: G_GNUC_PRINTF is deliberately *not* listed here. AttributeMacros wins
# over WhitespaceSensitiveMacros, and would let its (fmt, args) pair be split
# across two lines.
AttributeMacros: ['G_GNUC_NULL_TERMINATED', 'G_GNUC_CONST', 'G_GNUC_PURE']

# statement macros that are not followed by a semicolon
StatementMacros: [
    'G_DEFINE_TYPE',
    'G_DEFINE_TYPE_WITH_PRIVATE',
    'G_DEFINE_TYPE_WITH_CODE',
    'G_DEFINE_INTERFACE',
    'G_DEFINE_BOXED_TYPE',
    'G_BEGIN_DECLS',
    'G_END_DECLS',
    'AS_BEGIN_PRIVATE_DECLS',
    'AS_INTERNAL_VISIBLE'
]

# our loop helpers
ForEachMacros: ['AS_YAML_SEQUENCE_FOREACH', 'AS_YAML_MAPPING_FOREACH']

# avoid breaking around an assignment operator
PenaltyBreakAssignment: 250

# left-align newline escapes, e.g. in macros
AlignEscapedNewlines: Left

# don't indent case labels
IndentCaseLabels: false

# don't reflow comments, this can cause issues with documentation / GIR annotations
ReflowComments: false

# all enums should be on their own line
AllowShortEnumsOnASingleLine: false

# break after operators
BreakBeforeBinaryOperators: None
