Menu

#90 Feature: wrap arguments vertically downward on long lines

None
open
2019-07-21
2015-05-03
No

This is a feature request:

When wrapping long lines it is often desirable to wrap them downward based on the first argument. For example (in C++):

std::vector<int> functionFoo(apples,
                             bananas,
                             pears,
                             strawberries,
                             mangos)
{
...
}

If the line is too long even with just one argument they all drop down and indent to the indent level:

std::vector<int> functionFooLongEnoughToMakeOneArgumentTooMany(
    apples,
    bananas,
    pears,
    strawberries,
    mangos)
{
...
}

It would be great if there was an option for this.

--wrap-arguments-vertically

We use this style in C++, Scala, and Python and find it to be very readable.

Thanks!

-Darin

Discussion

  • w-peuker

    w-peuker - 2015-05-04

    I'd like Artistic Style to support this formatting also for normal-length function names. I think that this is currently not possible, or am I overlooking the right options?

     
  • Jim Pattee

    Jim Pattee - 2015-05-04

    You can increase the line length used with max-instatement-indent=###.

    Does this fix the problem or are you talking about something else?

     
    • w-peuker

      w-peuker - 2015-05-05

      max-instatement-indent must be a value between 40 and 120. I'd like to have arguments, enumerators, initialisers uniquely aligned at one to three indent levels. I don't see the (maybe good) reason for having the first of it attached...

       

      Last edit: w-peuker 2015-05-05
  • Darin Velarde

    Darin Velarde - 2015-05-05

    JIm, is that aimed at me or w-peuker? By the way, AStyle is great! So thanks for that.

     
  • Jim Pattee

    Jim Pattee - 2015-05-05

    I guess I don't understand the problem.
    AStyle aligns vertically unless the line is too long.
    I need to see more examples of what you want.

     
  • Darin Velarde

    Darin Velarde - 2015-05-06

    Of course. Given the following code:

    std::vector<int> functionFoo(apples, bananas, pears, strawberries, mangos)
    {
    ...
    }
    

    Or this code:

    std::vector<int> functionFoo(apples, bananas, pears,
                                 strawberries, mangos)
    {
    ...
    }
    

    With this option, would yield the following (basically if any argument has to wrap, wrap them all):

    std::vector<int> functionFoo(apples,
                                 bananas,
                                 pears,
                                 strawberries,
                                 mangos)
    {
    ...
    }
    

    If the function name plus any argument's length is over the specified max width, then drop them all down below the function and indent to the indent size.

    std::vector<int> functionFoo(
        apples,
        bananas,
        pears,
        strawberries,
        mangos)
    {
    ...
    }
    

    This same methodology can be used when calling functions. I hope I'm understanding what you need. This could surely be a case of not knowing how to get astyle to do what I want it to. I tried the max-instatement-indent option with no luck, unfortunately.

    My full set of options used:

    --indent=spaces=2 --style=otbs --max-code-length=78 --break-closing-brackets --convert-tabs --add-brackets --max-instatement-indent=40
    
     
  • w-peuker

    w-peuker - 2015-05-06

    Interestingly, Darin and I seem to talk of the same thing. Artistic style is by default quite artistic in formatting wrapped arguments and indeed: the results look nice. The requested feature would add a simplistic option. What I dislike about the artistic formatting is that changing a function name has a bigger impact on diffs which makes reviewing changes slightly harder (because of the worse signal-to-noise ratio).

     
  • Jim Pattee

    Jim Pattee - 2018-01-29

    Ticket moved from /p/astyle/bugs/359/

     
  • Gilad Reich

    Gilad Reich - 2018-07-09

    Hello @JimPattee, I was looking for this too and found my self needing to register and asking if it's already implemented and I'm not aware of the right option for this?
    Would really appreciate hearing from you.
    Thanks a lot for the amazing work you did here! and of course the contributors to this project!

     
  • Jim Pattee

    Jim Pattee - 2018-07-10

    This has not been implemented.

     
    • Gilad Reich

      Gilad Reich - 2018-07-10

      Thanks for info Jim! Hopefully I'll have time at some point looking into this.

       

Log in to post a comment.