uncrustify

Using uncrustify without aligning under open parenthesis


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 invoking uncrustify as follows:

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.


Solution

  • 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\n",
            (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\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.