# Base style rules
BasedOnStyle: Google
ColumnLimit: 100
IndentWidth: 2
ContinuationIndentWidth: 4
UseTab: Never

# Function parameters & arguments layout
AlignAfterOpenBracket: BlockIndent                  
BinPackArguments: false                             
AllowAllParametersOfDeclarationOnNextLine: false   
AllowAllArgumentsOnNextLine: false                  

BinPackParameters: false              
AlwaysBreakAfterDefinitionReturnType: All   
PenaltyBreakAssignment: 500           

# Break return type on definitions, keep on declarations
BreakAfterReturnType: AllDefinitions                
PenaltyReturnTypeOnItsOwnLine: 1000000
SpaceBeforeParens: Always                           
IndentWrappedFunctionNames: false

# Brace placement rules
BreakBeforeBraces: Custom
BraceWrapping:
  AfterCaseLabel: false
  AfterControlStatement: Never
  AfterEnum: true
  AfterFunction: true
  AfterStruct: true
  BeforeElse: false
  BeforeWhile: true
  SplitEmptyFunction: false
  SplitEmptyRecord: false
  SplitEmptyNamespace: false

# Inline short code blocks
AllowShortFunctionsOnASingleLine: None              
AllowShortBlocksOnASingleLine: Never 
AllowShortIfStatementsOnASingleLine: AllIfsAndElse 
AllowShortLoopsOnASingleLine: true                 
AllowShortCaseLabelsOnASingleLine: true             
AllowShortEnumsOnASingleLine: true                  

# Include Rules 
# File Foo.c:
# #include "foo.h"
#
# #include "bar.h"
# #include "biz.h"
#
# #include <stdlib.h>
IncludeBlocks: Regroup
SortIncludes: CaseSensitive

# Categorize includes by priority
IncludeCategories:
  # Category 0 is automatically reserved by 
  # clang-format for the matching main header 
  # (e.g., foo.h in foo.c)
  
  # Category 1: Quotes/Local headers
  - Regex: '^"'
    Priority: 1

  # Category 2: Angle brackets/System headers
  - Regex: '^<'
    Priority: 2

# Auto-insert braces for control statements
InsertBraces: true                                  

# Preprocessor directives indentation
IndentPPDirectives: AfterHash                       
PPIndentWidth: 2                                    

# Whitespace cleanup
MaxEmptyLinesToKeep: 1                              
KeepEmptyLinesAtTheStartOfBlocks: false            
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true                
SpacesBeforeTrailingComments: 1                    
DerivePointerAlignment: false                       
Cpp11BracedListStyle: true                          
PointerAlignment: Right
PenaltyBreakBeforeFirstCallParameter: 1

# Consecutive block alignment
AlignConsecutiveMacros: Consecutive                

AlignConsecutiveAssignments:
  Enabled: true
  AcrossEmptyLines: true
  AcrossComments: true

AlignEscapedNewlines: Left                          
AlignOperands: Align                                

# Align Struct fields (not functions)
AlignConsecutiveDeclarations:
  Enabled: true
  AcrossEmptyLines: true
  AcrossComments: true
  AlignFunctionDeclarations: false

# Align bit fields
AlignConsecutiveBitFields:
  Enabled: true
  AcrossEmptyLines: true
  AcrossComments: true

AlignTrailingComments:
  Kind: Always

# Keep a line between different 
# function declarations and structs
SeparateDefinitionBlocks: Always

# Line wraps inside expressions
BreakBeforeBinaryOperators: NonAssignment           
BreakStringLiterals: true                           
ReflowComments: true                                
