7

我正在尝试配置 uncrustify (源代码美化器)以避免在先前的左括号下方对齐。例如,我希望代码看起来像这样(来自 file indent_paren.c):

void f(void)
{
    while (one &&
        two)
    {
        continue;
    }
}

当我在上面的代码上运行 uncrustify 时,该行two) 缩进以与上面的行对齐(

void f(void)
{
    while (one &&
           two)
    {
        continue;
    }
}

我正在使用从源代码编译的最新版本的 uncrustify (0.59),该测试的配置设置如下(在文件中indent_paren.cfg):

indent_with_tabs = 0
indent_columns   = 4
indent_paren_nl  = false
indent_bool_paren = false

我调用 uncrustify 如下:

uncrustify -c indent_paren.cfg indent_paren.c

我发现版本 0.56(从 Ubuntu 11.04 的存储库安装)具有相同的行为。我使用了错误的配置设置,还是这里有其他问题?谢谢你的帮助。

4

1 回答 1

9

在对 unrustify 源代码进行进一步实验和探索之后,我发现该indent_continue选项主要满足我的需求。默认情况下,indent_continue为零,并且续行在上一行的左括号下方向上缩进。设置indent_continue为非零值会覆盖此行为,导致续行根据当前“级别”缩进。因此,在 uncrustify.cfg 中使用以下设置时,我的原始示例会根据需要缩进:

indent_with_tabs = 0
indent_columns   = 4
indent_continue  = 4

但是,因为嵌套括号的“级别”会增加,所以缩进比预期的要多,例如:

void g(void)
{
    /* Nested parentheses cause undesired additional indent. */
    TRACE(("The varargs need extra parentheses %d %d\n",
        (firstArgIsLong + 
        withMultipleTerms),
        secondArg));
}

上述设置会产生如下缩进,并带有不需要的额外缩进级别:

void g(void)
{
    /* Nested parentheses cause undesired additional indent. */
    TRACE(("The varargs need extra parentheses %d %d\n",
            (firstArgIsLong +
                withMultipleTerms),
            secondArg));
}

Looking at the uncrustify source, it appears that this behavior is not adjustable. indent_continue gives the desired results in most cases, and it seems to be the closest that uncrustify can come at this time.

于 2011-10-13T11:32:54.187 回答