3

我有看起来像这样的函数调用(没有明显的原因):

func
(
    a,
    b,
    c
)

有没有办法让 unrustify 将函数折叠成一行?试了两天没断断续续。。。

我让它适用于函数声明,但我不让它适用于函数调用。

虽然我们在这里,但我也有看起来像这样的功能:

func
(
    a, // (IN) the A
    b, // (IN) something b
    c  // (OUT) the resulting value
)

有没有办法在不破坏代码的情况下处理这种情况?由于 uncrustify 保留评论,我认为这是不可能的。使用函数声明,它会将其折叠到第一个注释。

4

2 回答 2

2

阅读文档,我想出了这个:

# 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/true
于 2012-09-05T07:53:18.543 回答
0

经过一些 LOOONG 研究后,我得出结论,uncrustify 无法做到这一点。对于我的 porposses,我一起编写了一个小的 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-11T09:17:09.757 回答