Permalink
Browse files

New option to force the indentation of function definition to start o…

…n the first column even if this function is defined inside a #if/#endif directive.
  • Loading branch information...
1 parent 053c278 commit d1c00e872cdeded1f4e676df6aa78e7d17f410a1 @rdan committed Feb 12, 2012
View
@@ -398,6 +398,7 @@ void indent_text(void)
bool token_used;
int sql_col = 0;
int sql_orig_col = 0;
+ bool in_func_def = false;
memset(&frm, 0, sizeof(frm));
cpd.frame_count = 0;
@@ -419,6 +420,35 @@ void indent_text(void)
parent_token_indent = token_indent(pc->parent_type);
}
+ /* Handle "force indentation of function definition to start in column 1" */
+ if (cpd.settings[UO_indent_func_def_force_col1].b)
+ {
+ if (!in_func_def)
+ {
+ next = chunk_get_next_ncnl(pc);
+ if ((pc->parent_type == CT_FUNC_DEF) ||
+ ((pc->type == CT_COMMENT) &&
+ (next->parent_type == CT_FUNC_DEF)))
+ {
+ in_func_def = true;
+ indent_pse_push(frm, pc);
+ frm.pse[frm.pse_tos].indent_tmp = 1;
+ frm.pse[frm.pse_tos].indent = 1;
+ frm.pse[frm.pse_tos].indent_tab = 1;
+ }
+ }
+ else
+ {
+ prev = chunk_get_prev(pc);
+ if ((prev->type == CT_BRACE_CLOSE) &&
+ (prev->parent_type == CT_FUNC_DEF))
+ {
+ in_func_def = false;
+ indent_pse_pop(frm, pc);
+ }
+ }
+ }
+
/* Clean up after a #define, etc */
if (!in_preproc)
{
View
@@ -530,6 +530,9 @@ void register_options(void)
unc_add_option("indent_var_def_cont", UO_indent_var_def_cont, AT_BOOL,
"Indent continued variable declarations instead of aligning.");
+ unc_add_option("indent_func_def_force_col1", UO_indent_func_def_force_col1, AT_BOOL,
+ "True: force indentation of function definition to start in column 1\n"
+ "False: use the default behavior");
unc_add_option("indent_func_call_param", UO_indent_func_call_param, AT_BOOL,
"True: indent continued function call parameters one indent level\n"
"False: align parameters under the open paren");
View
@@ -145,6 +145,7 @@ enum uncrustify_options
UO_indent_col1_comment, // indent comments in column 1
+ UO_indent_func_def_force_col1,// force indentation of function definition to start in column 1
UO_indent_func_call_param, // indent continued function calls to indent_columns
UO_indent_func_proto_param, // same, but for function protos
UO_indent_func_def_param, // same, but for function defs
View
@@ -96,6 +96,7 @@
00161 indent_func_call_param.cfg c/fcn_indent.c
00162 indent_func_def_param.cfg c/fcn_indent.c
00163 indent_func_proto_param.cfg c/fcn_indent.c
+00164 rdan.cfg c/fcn_indent_func_def_col1.c
00170 empty.cfg c/beautifier-off.c
View
@@ -90,6 +90,10 @@ indent_else_if = false # false/true
# Amount to indent variable declarations after a open brace. neg=relative, pos=absolute
indent_var_def_blk = 0 # number
+# True: force indentation of function definition to start in column 1
+# False: use the default behavior
+indent_func_def_force_col1 = true # false/true
+
# True: indent continued function call parameters one indent level
# False: align parameters under the open paren
indent_func_call_param = false # false/true
@@ -143,7 +147,7 @@ indent_case_shift = 0 # number
indent_case_brace = 0 # number
# Whether to indent comments found in first column
-indent_col1_comment = false # false/true
+indent_col1_comment = true # false/true
# How to indent goto labels
# >0 : absolute column where 1 is the leftmost column
@@ -1234,7 +1238,7 @@ pp_indent = add # ignore/add/remove/force
pp_indent_at_level = true # false/true
# If pp_indent_at_level=false, specifies the number of columns to indent per level. Default=1.
-pp_indent_count = 1 # number
+pp_indent_count = 3 # number
# Add or remove space after # based on pp_level of #if blocks
pp_space = remove # ignore/add/remove/force
@@ -0,0 +1,54 @@
+#if A
+/* dfsdsdfd */
+int X;
+#endif
+
+#if A
+void func1_1(void);
+#endif
+
+#if A
+#if A
+int X1;
+void func1_1(void)
+{
+#if A
+/* ttiti */
+if B
+{
+#if A
+/* dsfdf */
+a=5;
+#endif
+}
+#endif
+}
+int Y1;
+
+ void func1_2(void)
+ {
+ }
+ int Z1;
+#endif
+#endif
+
+#if A
+#if A
+int X2;
+/* fsdsfd */
+void func2_1(void)
+{
+#if A
+/* ttiti */
+if B
+{
+#if A
+/* dsfdf */
+a=5;
+#endif
+}
+#endif
+}
+ int Y2;
+#endif
+#endif
@@ -0,0 +1,58 @@
+#if A
+ /* dfsdsdfd */
+ int X;
+#endif
+
+#if A
+ void func1_1(void);
+
+#endif
+
+#if A
+ #if A
+ int X1;
+void func1_1(void)
+{
+ #if A
+ /* ttiti */
+ if B
+ {
+ #if A
+ /* dsfdf */
+ a = 5;
+ #endif
+ }
+ #endif
+}
+
+ int Y1;
+
+void func1_2(void)
+{
+}
+
+ int Z1;
+ #endif
+#endif
+
+#if A
+ #if A
+ int X2;
+/* fsdsfd */
+void func2_1(void)
+{
+ #if A
+ /* ttiti */
+ if B
+ {
+ #if A
+ /* dsfdf */
+ a = 5;
+ #endif
+ }
+ #endif
+}
+
+ int Y2;
+ #endif
+#endif

0 comments on commit d1c00e8

Please sign in to comment.