我正在尝试配置uncrustify(源代码美化器)以避免在先前打开的括号下对齐.例如,我希望代码看起来像这样(来自文件
indent_paren.c):
void f(void)
{
while (one &&
two)
{
continue;
}
}
Run Code Online (Sandbox Code Playgroud)
当我在上面的代码上运行uncrustify时,该行two)
缩进以与上面的行对齐(:
void f(void)
{
while (one &&
two)
{
continue;
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用从源代码编译的最新版本的uncrustify(0.59),以及此测试的以下配置设置(在文件中indent_paren.cfg):
indent_with_tabs = 0
indent_columns = 4
indent_paren_nl = false
indent_bool_paren = false
Run Code Online (Sandbox Code Playgroud)
我正在按如下方式调用uncrustify:
uncrustify -c indent_paren.cfg indent_paren.c
Run Code Online (Sandbox Code Playgroud)
我发现版本0.56(从Ubuntu 11.04的存储库安装)具有相同的行为.我使用了错误的配置设置,还是其他错误?谢谢你的帮助.
经过进一步的实验和探索未解决的源代码,我发现该indent_continue选项主要是我想要的.默认情况下,indent_continue为零,并且连续的行在上面的行中的左括号下面缩进.设置indent_continue为非零值会覆盖此行为,从而导致延续线基于当前"级别"缩进.因此,在uncrustify.cfg中使用以下设置时,我的原始示例将根据需要缩进:
indent_with_tabs = 0
indent_columns = 4
indent_continue = 4
Run Code Online (Sandbox Code Playgroud)
但是,因为嵌套括号的"级别"会增加,所以对于以下情况,缩进比所需的更多:
void g(void)
{
/* Nested parentheses cause undesired additional indent. */
TRACE(("The varargs need extra parentheses %d %d\n",
(firstArgIsLong +
withMultipleTerms),
secondArg));
}
Run Code Online (Sandbox Code Playgroud)
上面的设置会产生如下缩进:不需要的额外缩进级别:
void g(void)
{
/* Nested parentheses cause undesired additional indent. */
TRACE(("The varargs need extra parentheses %d %d\n",
(firstArgIsLong +
withMultipleTerms),
secondArg));
}
Run Code Online (Sandbox Code Playgroud)
看看unrusifictify来源,似乎这种行为是不可调整的. indent_continue在大多数情况下给出了期望的结果,并且它似乎是目前最接近unrustiftify的.
| 归档时间: |
|
| 查看次数: |
1359 次 |
| 最近记录: |