问题描述
我想这样格式化代码:
-
a)最大行宽120
a) line width maximum 120
b)-如果调用了函数的长度,则每行缩进的函数调用参数为> 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)-如果函数调用位于if,for,while等内,则参数的格式应为 b)
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);
}
现在,我想得到结果:
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);
}
我在Uncrustify 0.63中使用了以下选项:
I've used the following options in Uncrustify 0.63:
ls_func_split_full = true
ls_func_split_full = true
ls_code_width = false
ls_code_width = false
nl_func_leave_one_liners = true
nl_func_leave_one_liners = true
indent_func_call_param = true
indent_func_call_param = true
nl_func_def_start =添加
nl_func_def_start = add
nl_func_def_start_single =删除
nl_func_def_start_single = remove
align_oc_msg_colon_first = false
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);
}
任何人都有函数调用位于if / for / while内的情况并需要像这样拆分参数?
Have anyone a situation where the function call is inside a if/for/while and needs to have the parameters split like this?
推荐答案
使用以下设置:
nl_func_call_start_multi_line = true
nl_func_call_args_multi_line = true
code_width = 120
-
code_width
:尝试将代码宽度限制为 N 列 -
nl_func_call_start_multi_line
:如果<$ c $,是否在函数调用中的(
之后添加换行符c>(和)
不在同一行。 -
nl_func_call_args_multi_line
:如果(
和<$ c $,则在函数调用中的每个,
之后是否添加换行符c>)在不同的行中。 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.
(可选):
nl_func_call_end_multi_line = true
-
nl_func_call_end_multi_line
:是否在之前添加换行符)
如果(
和)
在不同的行中。 nl_func_call_end_multi_line
: Whether to add newline before)
in a function call if(
and)
are in different lines.
这篇关于取消拆分函数调用参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!