| 1 | # GTK coding style |
| 2 | # |
| 3 | # https://gitlab.gnome.org/GNOME/gtk/-/blob/main/docs/CODING-STYLE.md |
| 4 | # |
| 5 | # Configuration based on: |
| 6 | # - https://github.com/uncrustify/uncrustify/blob/master/etc/gnu-indent.cfg |
| 7 | # - https://gitlab.gnome.org/GNOME/mutter/-/blob/main/tools/uncrustify.cfg |
| 8 | # - https://gitlba.gnome.org/GNOME/nautilus/-/blob/main/data/uncrustify.cfg |
| 9 | # |
| 10 | # Run `uncrustify --show-config` to see documentation for these options. |
| 11 | |
| 12 | utf8_force = true |
| 13 | newlines = lf |
| 14 | |
| 15 | input_tab_size = 8 |
| 16 | output_tab_size = 8 |
| 17 | |
| 18 | indent_columns = 2 |
| 19 | indent_with_tabs = 0 # Spaces only |
| 20 | |
| 21 | indent_brace = 2 |
| 22 | |
| 23 | indent_ternary_operator = 1 # When the `if_false` is a continuation, indent it under `if_false` |
| 24 | indent_switch_case = 2 |
| 25 | indent_switch_body = 2 |
| 26 | indent_case_brace = 0 |
| 27 | |
| 28 | nl_after_semicolon = true |
| 29 | nl_start_of_file = remove |
| 30 | nl_end_of_file = force |
| 31 | nl_end_of_file_min = 1 |
| 32 | |
| 33 | nl_func_decl_args = force |
| 34 | nl_func_def_args = force |
| 35 | nl_func_decl_end = remove |
| 36 | nl_func_type_name = force |
| 37 | nl_func_decl_args = force |
| 38 | nl_func_def_args = force |
| 39 | nl_func_decl_end = remove |
| 40 | nl_func_call_end = remove |
| 41 | nl_func_call_empty = remove |
| 42 | nl_func_var_def_blk = 1 |
| 43 | |
| 44 | # Newlines for other statements (if, switch,..) |
| 45 | nl_enum_brace = add |
| 46 | nl_union_brace = add |
| 47 | nl_struct_brace = add |
| 48 | nl_class_brace = add |
| 49 | nl_do_brace = add |
| 50 | nl_if_brace = add |
| 51 | nl_for_brace = add |
| 52 | nl_else_brace = add |
| 53 | nl_elseif_brace = add |
| 54 | nl_while_brace = add |
| 55 | nl_switch_brace = add |
| 56 | nl_squeeze_ifdef = true |
| 57 | nl_fcall_brace = force |
| 58 | nl_fdef_brace = force |
| 59 | nl_brace_else = force |
| 60 | nl_assign_brace = remove |
| 61 | nl_brace_while = remove |
| 62 | nl_case_colon_brace = remove |
| 63 | nl_after_brace_open = true |
| 64 | nl_before_case = 1 |
| 65 | |
| 66 | sp_arith = force # foo = 1 + (2 / 4); |
| 67 | sp_arith_additive = force |
| 68 | sp_bool = force |
| 69 | sp_compare = force # (foo > 1) |
| 70 | sp_assign = force # foo = 2; |
| 71 | sp_after_assign = force |
| 72 | sp_before_assign = force |
| 73 | sp_after_comma = force |
| 74 | sp_after_cast = ignore |
| 75 | sp_not = ignore # if (!foo) |
| 76 | sp_after_byref = remove # & for indirections must be together with the variable |
| 77 | sp_before_semi = remove |
| 78 | sp_incdec = remove # (i++) |
| 79 | |
| 80 | sp_inside_braces = force # { 1 } |
| 81 | sp_inside_braces_struct = force # { 1 } |
| 82 | sp_inside_braces_enum = force # { 1 } |
| 83 | sp_inside_paren = remove |
| 84 | sp_inside_fparen = remove |
| 85 | sp_inside_sparen = remove |
| 86 | sp_inside_for = remove |
| 87 | |
| 88 | sp_between_ptr_star = remove # char **foo; |
| 89 | sp_before_ptr_star_func = force |
| 90 | sp_after_ptr_star = remove |
| 91 | sp_after_ptr_star_func = force |
| 92 | sp_ptr_star_paren = force # typedef GNode* (* ForeachFunc) (...); |
| 93 | |
| 94 | # class Foo:public |
| 95 | sp_before_class_colon = remove |
| 96 | sp_after_class_colon = add |
| 97 | |
| 98 | sp_inside_paren = remove # "( 1 )" vs "(1)" |
| 99 | sp_inside_fparen = remove # "( 1 )" vs "(1)" - functions |
| 100 | sp_inside_sparen = remove # "( 1 )" vs "(1)" - if/for/etc |
| 101 | sp_before_sparen = force # "if (" vs "if(" - if/for/etc |
| 102 | sp_paren_paren = remove # ((foo)) |
| 103 | |
| 104 | # Enforce the right spacing inside/around/after ( ) in typedefs and |
| 105 | # function calls |
| 106 | sp_inside_tparen = remove |
| 107 | sp_after_tparen_close = force |
| 108 | sp_func_call_paren = force |
| 109 | sp_func_def_paren = force |
| 110 | sp_func_proto_paren = force |
| 111 | sp_func_proto_paren_empty = force |
| 112 | |
| 113 | # Remove space between glib/gettext i18n function shortcuts and ( |
| 114 | set func_call_user _ C_ I_ N_ NC_ P_ Q_ |
| 115 | sp_func_call_user_paren = remove |
| 116 | |
| 117 | # We align parameters in function definitions, like this: |
| 118 | # |
| 119 | # int64_t meta_string_to_date (const char *date_string, |
| 120 | # int *offset_p, |
| 121 | # GError **error) |
| 122 | # |
| 123 | align_func_params = true |
| 124 | |
| 125 | # A '*' in a variable definition is considered 'dangling', rather than |
| 126 | # being part of the variable type. This produces the following style of |
| 127 | # alignment: |
| 128 | # |
| 129 | # meta_string_to_date (const gchar *date_string, |
| 130 | # gint *offset_p, |
| 131 | # GError **error) |
| 132 | # |
| 133 | align_var_def_star_style = 2 |
| 134 | |
| 135 | # int foo_bar (const int a) |
| 136 | # MyType *bar_foo (const int b) |
| 137 | align_func_proto_span = 4 |
| 138 | |
| 139 | # Disable auto-alignment of macros, we often manually align the \ with |
| 140 | # spaces which uncrustify doesn't support. |
| 141 | align_nl_cont = false |
| 142 | |
| 143 | # Add stars at the beginning of each line in multiline comments |
| 144 | cmt_star_cont = true |
| 145 | # Ignore spacing in multiline comments. |
| 146 | cmt_indent_multi = false |
| 147 | |
| 148 | # Code modifications |
| 149 | # Enforce the use of braces for do, for, while and function blocks |
| 150 | mod_full_brace_do = force |
| 151 | mod_full_brace_function = force |
| 152 | mod_full_brace_while = force |
| 153 | mod_full_brace_for = remove |
| 154 | mod_full_brace_if = remove |
| 155 | # Add braces to all blocks if any block needs braces and remove braces if they can be removed from all blocks |
| 156 | mod_full_brace_if_chain = 1 |
| 157 | # Remove braces on single-line 'using ()' statement |
| 158 | mod_full_brace_using = remove |
| 159 | # Prevent removal of braces from 'if'/'for'/'while'/etc. blocks which span multiple lines. |
| 160 | mod_full_brace_nl_block_rem_mlcond = true |
| 161 | |
| 162 | # Remove blanks |
| 163 | eat_blanks_before_close_brace = true |
| 164 | eat_blanks_after_open_brace = true |