Menu

#665 split_fcn_params fails to properly split function calls with very long first argument

Future
closed
None
5
2016-09-25
2016-02-19
zakkak
No

split_fcn_params fails to properly split function calls with very long first argument.

In the folllowing example (attached as input.c)

int main(int argc, char *argv[])
{
    int a, b, c;

    printf("This is a very long string that goes beyond the code_width, and it should not be split", a, b, c);

    return 0;
}

with configuration (attached as test.cfg):

# True:  indent continued function call parameters one indent level
# False: align parameters under the open paren
indent_func_call_param                    = false    # false/true

# Try to limit code width to N number of columns
code_width                                = 80       # number

# Whether to fully split long function protos/calls at commas
ls_func_split_full                        = false    # false/true

uncrustify produces

int main(int argc, char *argv[])
{
    int a, b, c;

    printf(
            "This is a very long string that goes beyond the code_width, and it should not be split", a, b,
            c);

    return 0;
}

while it should produce

int main(int argc, char *argv[])
{
    int a, b, c;

    printf("This is a very long string that goes beyond the code_width, and it should not be split",
            a, b, c);

    return 0;
}

Note that adding a new line after the fparen open when indent_func_call_param is set to false is meaning less.
Also note that it only puts c in a new line, which is not the best we can do.

Using 0.62 (and tested with master as well)

2 Attachments

Discussion

  • Guy Maurel

    Guy Maurel - 2016-03-15

    If having a very long function name such as:
    very_long_function_name_printf("This is a very long string that goes beyond the code_width, and it should not be split", a, b, c);

    and set the option:
    ls_func_split_full = true

    you'll get what you wanted to have:
    very_long_function_name_printf(
    "This is a very long string that goes beyond the code_width, and it should not be split",
    a,
    b,
    c);

     
  • zakkak

    zakkak - 2016-03-15

    But I do not want a, b, and c to appear in different lines, since they fit in a single one.

     
  • Guy Maurel

    Guy Maurel - 2016-03-17

    Yes, you can use the option:
    ls_code_width=true

    and get:
    very_long_function_name_printf(
    "This is a very long string that goes beyond the code_width, and it should not be split",
    a, b, c);

     
  • zakkak

    zakkak - 2016-03-17

    This indeed fixes somewhat (It still does not make sence to place the string bellow the function name) the behavior for this example.

        printf(
                "This is a very long string that goes beyond the code_width, and
     it should not be split",
                a, b, c);
    

    However, I do not see any groups in that example, so it should be irrelevant if I am not mistaken, which makes me skeptical.

    Additionally, as a side-effect I expect this change to break the grouping in some other instances of the code.

     
  • Guy Maurel

    Guy Maurel - 2016-03-22

    Could you push an example for this problem?

     
  • Guy Maurel

    Guy Maurel - 2016-03-22
    • status: open --> need-info
    • assigned_to: Guy Maurel
     
  • zakkak

    zakkak - 2016-04-12

    I am attaching input.c extended with a long conditional.

    break_group.cfg sets ls_code_width to true and produces break_group.c.

    keep_group.cfg sets ls_code_width to false and produces keep_group.c.

    expected.c contains the code formated as I would expect keep_group.cfg to format it.

     
  • Guy Maurel

    Guy Maurel - 2016-09-25
    • status: need-info --> closed
     
  • Guy Maurel

    Guy Maurel - 2016-09-25
     
MongoDB Logo MongoDB