【问题标题】:Using uncrustify without aligning under open parenthesis使用 uncrustify 而不在左括号下对齐
【发布时间】:2011-12-05 12:48:56
【问题描述】:

我正在尝试将 uncrustify(源代码美化器)配置为 避免在前一个左括号下对齐。为了 例如,我希望代码看起来像这样(来自文件 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 的存储库)。我是否使用了错误的配置 设置,还是这里有其他问题?感谢您的帮助。

【问题讨论】:

    标签: uncrustify


    【解决方案1】:

    经过进一步的实验和探索 源代码,我发现 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));
    }
    

    查看 uncrustify 来源,似乎这种行为 不可调节。 indent_continue 给出了想要的结果 在大多数情况下,它似乎是最接近 unrustify 的 这个时候可以来。

    【讨论】:

      猜你喜欢
      • 2020-01-30
      • 1970-01-01
      • 2016-08-26
      • 2020-01-15
      • 2016-11-16
      • 1970-01-01
      • 2013-12-18
      • 1970-01-01
      • 2020-08-19
      相关资源
      最近更新 更多