English 中文(简体)
采用不按开放的括号进行统一
原标题:Using uncrustify without aligning under open parenthesis
  • 时间:2011-10-11 18:00:19
  •  标签:
  • uncrustify

I m trying to configure uncrustify (a source code beautifier) to avoid aligning beneath a previous open parenthesis. For example, I d like the code to look like this (from file indent_paren.c):

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

When I run uncrustify on the above code, the line two) indents to align with the ( from the line above:

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

I m using the latest version of uncrustify (0.59) compiled from source, with the following configuration settings for this test (in file indent_paren.cfg):

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

I m 援引以下术语:

uncrustify -c indent_paren.cfg indent_paren.c

I found the same behavior with version 0.56 (installed from the repository for Ubuntu 11.04). Am I using the wrong configuration settings, or is something else wrong here? Thanks for any help.

最佳回答

After further experimentation and spelunking in the uncrustify source code, I ve found that the indent_continue option does mostly what I want. By default, indent_continue is zero, and continued lines are indented to up beneath open parenthesis in the line above. Setting indent_continue to a non-zero value overrides this behavior, causing continuation lines to be indented based on the current "level". So my original example is indented as desired when using the following settings in uncrustify.cfg:

indent_with_tabs = 0
indent_columns   = 4
indent_continue  = 4

Because the "level" is incremented for nested parentheses, however, there is more indentation than desired for cases such as:

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

The above settings generate indentation as follows, with undesired extra levels of indentation:

void g(void)
{
    /* Nested parentheses cause undesired additional indent. */
    TRACE(("The varargs need extra parentheses %d %d
",
            (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.

问题回答

暂无回答




相关问题
Blank line after curly brace in function with uncrustify

I have configured xcode to use Uncrustify to beautify the code. I modified the Uncrustify configuration file and the resulting code is almost as desired. One thing I don t like is the removal of a ...

ctags multi-line C function prototypes

Is there a way for ctags to handle multiline function prototypes in C? I ve searched around and the --fields=+S is supposed to do multiline prototypes, but I can t get it to work: ctags -x --c-kinds=...

C++ / Uncrustify / Indenting base class specifications

How do I setup uncrustify so that this code: static const class Example : Int1 , Int2 , Int3 looks like this: static const class Example : Int1 , Int2 , Int3 I can not find any ...

Uncrustify spacing issue with macro inside method call

I am attempting to use Uncrustify on a project of mine, but I am running into some issues with spacing changes that it makes when a macro is used as the receiver of an Objective-C message. For example,...

How do I get uncrustify to indent BEGIN_MESSAGE_MAP regions?

I m trying to use uncrustify on a large inherited C++ codebase and I can t figure out how to get it to indent the following code segment like the example here. BEGIN_MSG_MAP(CMyDlg) MESSAGE_HANDLER(...

热门标签