我的函数调用看起来像这样(没有明显的原因):
func
(
a,
b,
c
)有没有办法让uncrustify将函数压缩成一行?我已经试了两天了不是断断续续...
我把它用在函数声明上,但不能用在函数调用上。
当我们这样做的时候,我也有一些函数看起来像这样:
func
(
a, // (IN) the A
b, // (IN) something b
c // (OUT) the resulting value
)有没有办法在不破坏代码的情况下处理这种情况?由于uncrustify保留评论,我认为这是不可能的。使用函数声明,它将其折叠为第一个注释。
发布于 2012-09-11 17:17:10
经过长时间的研究,我得出结论,uncrustify不能做到这一点。我把一个小的perl脚本拼凑在一起:
$filename = $ARGV[0];
{
open(FILE, "<", $filename) or die "Cant open $filename for reading\n";
local $/ = undef;
$lines = <FILE>;
close(FILE);
}
# squash comments in function calls and declarations
$lines =~ s/,[ \t]*\/\/[^\n\r]*/,/gm;
# squash last comment in function calls and declarations
$lines =~ s/[ \t]*\/\/[^\n\r]*\r\n[ \t]*\)/\)/gm;
# squash newlines at the start of a function call or declaration
$lines =~ s/\([ \t]*\r\n[ \t]*/\(/gm;
# squash newlines in function calls and declarations
$lines =~ s/,[ \t]*\r\n[ \t]*/, /gm;
# squash the last newline in a function call or declaration
$lines =~ s/[ \t]*\r\n[ \t]*\)/\)/gm;
{
open(FILE, ">", $filename) or die "Cant open $filename for writing\n";
print FILE $lines;
close(FILE);
}我将研究是否可以构建一个将该功能集成到uncustify中的补丁。
发布于 2012-09-05 15:53:19
在阅读文档时,我想到了这个:
# Add or remove newline between a function name and the opening '('
nl_func_paren = remove # ignore/add/remove/force
# Add or remove newline between a function name and the opening '(' in the definition
nl_func_def_paren = remove # ignore/add/remove/force
# Add or remove newline after '(' in a function declaration
nl_func_decl_start = remove # ignore/add/remove/force
# Add or remove newline after '(' in a function definition
nl_func_def_start = remove # ignore/add/remove/force
# Add or remove newline after each ',' in a function declaration
nl_func_decl_args = remove # ignore/add/remove/force
# Add or remove newline after each ',' in a function definition
nl_func_def_args = remove # ignore/add/remove/force
# Add or remove newline before the ')' in a function declaration
nl_func_decl_end = remove # ignore/add/remove/force
# Add or remove newline before the ')' in a function definition
nl_func_def_end = remove # ignore/add/remove/force正如你所预料的那样,这些评论--不过,有点毁了它。提供了一个选项,可以将单行注释(//)更改为块注释(/* ... */),这将使您更容易手动连接各行(例如在vim v%J中)
# Whether to change cpp-comments into c-comments
cmt_cpp_to_c = true # false/true我使用原型、声明和调用对其进行了测试:
呼叫不受影响。另请注意以下相关选项:
# Whether to fully split long function protos/calls at commas
ls_func_split_full = false # false/truehttps://stackoverflow.com/questions/12276328
复制相似问题