首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Uncrustify折叠多行函数调用

Uncrustify折叠多行函数调用
EN

Stack Overflow用户
提问于 2012-09-05 15:16:18
回答 2查看 1.3K关注 0票数 3

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

代码语言:javascript
复制
func
(
    a,
    b,
    c
)

有没有办法让uncrustify将函数压缩成一行?我已经试了两天了不是断断续续...

我把它用在函数声明上,但不能用在函数调用上。

当我们这样做的时候,我也有一些函数看起来像这样:

代码语言:javascript
复制
func
(
    a, // (IN) the A
    b, // (IN) something b
    c  // (OUT) the resulting value
)

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-11 17:17:10

经过长时间的研究,我得出结论,uncrustify不能做到这一点。我把一个小的perl脚本拼凑在一起:

代码语言:javascript
复制
$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中的补丁。

票数 0
EN

Stack Overflow用户

发布于 2012-09-05 15:53:19

在阅读文档时,我想到了这个:

代码语言:javascript
复制
# 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中)

代码语言:javascript
复制
# Whether to change cpp-comments into c-comments
cmt_cpp_to_c                             = true    # false/true

我使用原型、声明和调用对其进行了测试:

  • 输入http://ideone.com/VPOTF
  • output http://ideone.com/z6jYY

呼叫不受影响。另请注意以下相关选项:

代码语言:javascript
复制
# Whether to fully split long function protos/calls at commas
ls_func_split_full                       = false    # false/true
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12276328

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档