Menu

#590 align_left_shift in combination with code_width leads to unexpected results

Future
closed
None
5
2016-09-23
2014-07-28
hydrac
No

Reproducible with uncrustify 0.60 and 36a0f44c54e, using the following example code:

int main()
{
    std::ostringstream oss;
    oss << "Line " << "is" << "very" << "long" << "and" << "continued" << "on" << "the" << "next" << "line" << "but" << "the" << "next" << "line" << "is" << "not" << "indeted" << "as" << "expected";

    oss << "However," << "a" << "long" << "line" << "which" << "is" 
    << "already" << "wrapped" << "and" << "has" << "a" << "stream" << "operator" << "at" << "the" << "beginning" << "is" << "apparently" 
    << "aligned" << "as" << "expected.";

    std::string str = "This" + "line" + "is" + "also" + "very" + "long" + "and" + "continued" + "in" + "the" + "next" + "line," + "however" + "it" + "is" + "indented" + "as" + "expected";
}

With a configuration of:

indent_columns = 4
indent_continue = 12
code_width = 100
align_left_shift = true

the result is:

int main()
{
    std::ostringstream oss;
    oss << "Line " << "is" << "very" << "long" << "and" << "continued" << "on" << "the" << "next" <<
                "line" << "but" << "the" << "next" << "line" << "is" << "not" << "indeted" <<
                "as" << "expected";

    oss << "However," << "a" << "long" << "line" << "which" << "is"
        << "already" << "wrapped" << "and" << "has" << "a" << "stream" << "operator" << "at" <<
                "the" << "beginning" << "is" << "apparently"
        << "aligned" << "as" << "expected.";

    std::string str = "This" + "line" + "is" + "also" + "very" + "long" + "and" + "continued" +
                "in" + "the" + "next" + "line," + "however" + "it" + "is" + "indented" + "as" +
                "expected";
}

Here uncrustify does not wrap before the "<<", making
align_left_shift useless. It only aligns lines which were wrapped manually at the right places
before.


Using

indent_columns = 4
indent_continue = 12
indent_with_tabs = 0
code_width = 100
align_left_shift = false

the result is

int main()
{
    std::ostringstream oss;
    oss << "Line " << "is" << "very" << "long" << "and" << "continued" << "on" << "the" << "next" <<
    "line" << "but" << "the" << "next" << "line" << "is" << "not" << "indeted" <<
    "as" << "expected";

    oss << "However," << "a" << "long" << "line" << "which" << "is"
    << "already" << "wrapped" << "and" << "has" << "a" << "stream" << "operator" << "at" << "the" <<
    "beginning" << "is" << "apparently"
    << "aligned" << "as" << "expected.";

    std::string str = "This" + "line" + "is" + "also" + "very" + "long" + "and" + "continued" +
                "in" + "the" + "next" + "line," + "however" + "it" + "is" + "indented" + "as" +
                "expected";
}

Here I would actually expect the indent_continue setting to take effect (as it does on the + line and
also on the first example), however, no indentation is done for the continued stream line.

Discussion

  • Guy Maurel

    Guy Maurel - 2016-04-06

    Something such as:
    nl_before_left_shift = true

    would produces:
    oss << "However,"
    << "a"
    << "long"
    << "line"
    << "which"
    << "is"
    << "already"
    << "wrapped"
    << "and"
    << "has"
    << "a"
    << "stream"
    << "operator"
    << "at"
    << "the"
    << "beginning"
    << "is"
    << "apparently"
    << "aligned"
    << "as"
    << "expected.";

    which is not pretty at all.
    Please make any proposal!

     
  • Guy Maurel

    Guy Maurel - 2016-04-06
    • status: open --> need-info
     
  • hydrac

    hydrac - 2016-04-07

    It is not about wrapping before every << operator.
    The point rather is that if wrapping is necessary, wrapping is not done at the location providing the most elegant result.
    Maybe an option would be that if wrapping would leave a << operator at the end of the line, if align_left_shift
    is given, rather wrap before that operator.

    Desired result using align_left_shift = true:

    oss << "However," << "a" << "long" << "line" << "which" << "is"
        << "already" << "wrapped" << "and" << "has" << "a" << "stream" << "operator" << "at" 
        << "the" << "beginning" << "is" << "apparently"
        << "aligned" << "as" << "expected.";
    
     
  • Guy Maurel

    Guy Maurel - 2016-04-11

    What do you think about an option
    wrapping_before_operator = true/false

    which gives you a choose.

     
  • Guy Maurel

    Guy Maurel - 2016-04-11
    • assigned_to: Guy Maurel
     
  • Guy Maurel

    Guy Maurel - 2016-09-23
     
  • Guy Maurel

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