问题
I want to format the code like this:
a) line width maximum 120
b)- function call parameters one per line with indent if the length of the function is called is > 120 else function call in one line
c)- it the function call is inside a if, for, while, etc... the parameters should be formatted as written at b)
I have the code (it is just a fictive):
void a_function()
{
if(verify_if_the_conditions_are_meet(first_parameter, second_parameter, third_parameter, fourth_parameter, fifth_parameter, sixth_parameter ))
{
call_a_function_with_many_parameters(first_parameter, second_parameter, third_parameter, fourth_parameter, fifth_parameter, sixth_parameter);
}
save(first_parameter, second_parameter, third_parameter, fourth_parameter, fifth_parameter, sixth_parameter);
}
And now, I want to have the result:
void a_function()
{
if(verify_if_the_conditions_are_meet(
first_parameter,
second_parameter,
third_parameter,
fourth_parameter,
fifth_parameter,
sixth_parameter ))
{
call_a_function_with_many_parameters(
first_parameter,
second_parameter,
third_parameter,
fourth_parameter,
fifth_parameter,
sixth_parameter);
}
save(first_parameter, second_parameter, third_parameter, fourth_parameter, fifth_parameter, sixth_parameter);
}
I've used the following options in Uncrustify 0.63:
code_width = 120
ls_func_split_full = true
ls_code_width = false
nl_func_leave_one_liners = true
indent_func_call_param = true
nl_func_def_start = add
nl_func_def_start_single = remove
align_oc_msg_colon_first = false
With this settings I get just like this:
void a_function()
{
if(verify_if_the_conditions_are_meet(first_parameter, second_parameter, third_parameter, fourth_parameter,
fifth_parameter, sixth_parameter ))
{
call_a_function_with_many_parameters(
first_parameter,
second_parameter,
third_parameter,
fourth_parameter,
fifth_parameter,
sixth_parameter);
}
save(first_parameter, second_parameter, third_parameter, fourth_parameter, fifth_parameter, sixth_parameter);
}
Have anyone a situation where the function call is inside a if/for/while and needs to have the parameters split like this?
回答1:
Use these settings:
nl_func_call_start_multi_line = true
nl_func_call_args_multi_line = true
code_width = 120
code_width
: Try to limit code width to N columnsnl_func_call_start_multi_line
: Whether to add newline after(
in a function call if(
and)
are in different lines.nl_func_call_args_multi_line
: Whether to add newline after each,
in a function call if(
and)
are in different lines.
Optionally with:
nl_func_call_end_multi_line = true
nl_func_call_end_multi_line
: Whether to add newline before)
in a function call if(
and)
are in different lines.
来源:https://stackoverflow.com/questions/38479039/uncrustify-split-function-call-parameters