我正在尝试配置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版(从Ubuntu11.04的存储库安装)也有相同的行为。是我使用了错误的配置设置,还是这里出现了其他错误?谢谢你的帮助。
发布于 2011-10-13 19:32:54
在对uncrustify源代码进行进一步的实验和探索之后,我发现indent_continue选项基本上能做我想要的事情。默认情况下,indent_continue为零,并且在上面的行中,连续的行缩进到左括号下方。将indent_continue设置为非零值会覆盖此行为,导致连续行根据当前“级别”缩进。因此,当在uncrustify.cfg中使用以下设置时,我的原始示例会根据需要缩进:
indent_with_tabs = 0
indent_columns = 4
indent_continue = 4但是,因为嵌套括号的"level“是递增的,所以缩进比预期的要多,例如:
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在大多数情况下都能给出想要的结果,而且它似乎是此时uncrustify最接近的结果。
https://stackoverflow.com/questions/7730378
复制相似问题