Menu

#498 Continuation indenting with tabs doesn't always work as expected

open
nobody
None
2020-04-02
2018-03-18
DRC
No

My project (VirtualGL) uses tabs and only tabs, and I try to keep things simple by not aligning continuation lines for conditionals under the open parenthesis. Unfortunately I'm still struggling to figure out the golden set of parameters to reproduce these simple formatting rules using AStyle. Take the following block of code:

> if(!SomeVeryLongFunctionName(someType someVeryLongFunctionArg,
> > someType someOtherVeryLongFunctionArg))
> > do_something();

where > is a tab character, as in the AStyle docs. I thought that the combination of

--style=allman
--indent=tab=2
--indent=force-tab=2
--indent-after-parens

would achieve what I want, but unfortunately not. I also tried various combinations of --indent=force-tab-x=2, --min-conditional-indent, and --indent-continuation. If --indent-continuation=0, it gives me this:

> if(!SomeVeryLongFunctionName(someType someVeryLongFunctionArg,
> someType someOtherVeryLongFunctionArg))
> > do_something();

If --indent-continuation=1 (default), it gives me this:

> if(!SomeVeryLongFunctionName(someType someVeryLongFunctionArg,
> > > > someType someOtherVeryLongFunctionArg))
> > do_something();

Either I'm missing something, or something isn't working as advertised.

Discussion

  • DRC

    DRC - 2018-03-18

    Clarification: minimal reproduction steps:

    Create test.c with:

    void function(void)
    {
        if(!SomeVeryLongFunctionName(someType someVeryLongFunctionArg,
            someType someOtherVeryLongFunctionArg))
            do_something();
    }
    

    Attempt to reformat using

    astyle --style=allman --indent=tab=2 --indent=force-tab=2 --remove-braces --indent-after-parens test.c
    

    Expected result:

    void function(void)
    {
    > if(!SomeVeryLongFunctionName(someType someVeryLongFunctionArg,
    > > someType someOtherVeryLongFunctionArg))
    > > do_something();
    }
    

    Actual result:

    void function(void)
    {
    > if(!SomeVeryLongFunctionName(someType someVeryLongFunctionArg,
    > > > someType someOtherVeryLongFunctionArg))
    > > do_something();
    }
    
     
  • w-peuker

    w-peuker - 2018-03-19

    Just a sidenote. Though not what you expected, the actual result reads much clearer: the depending statement better stands out from the continued condition line.

     

    Last edit: w-peuker 2018-03-19
    • DRC

      DRC - 2018-03-19

      Perhaps so, but the core issue is that I currently cannot trust the behavior of the tool, because it isn't behaving in a deterministic manner. I need to understand what it's trying to do and why, or else I will not use it.

       
  • Jim Pattee

    Jim Pattee - 2018-03-20

    Add the option --indent-continuation=0.
    You don't need the option --indent=tab=2. It can be removed.

     
    • DRC

      DRC - 2018-03-20

      That doesn't work either. It produces this:

      void function(void)
      {
      > if(!SomeVeryLongFunctionName(someType someVeryLongFunctionArg,
      > someType someOtherVeryLongFunctionArg))
      > > do_something();
      }
      

      That is, the continuation of the function arguments are not indented at all. That's really the source of my consternation. --indent-continuation=0 doesn't indent the continued arguments, and --indent-continuation=1 indents them with two tabs instead of one. I need a way to indent them with just one tab.

       
  • Jim Pattee

    Jim Pattee - 2018-03-22

    It idents once for each open paren.
    If there were one paren, it would indent once. If two it indents twice.

    There seems to be a problem where it doubles the indent instead of adding one.
    I will check this before the next release.

     
  • Nik Schew

    Nik Schew - 2020-04-02

    I have the same problem with the double indent instead of adding one. Is there is fix or workaround availabe by now?

     
  • Jim Pattee

    Jim Pattee - 2020-04-02

    Sorry, but there have been no changes. You might try thr options max-continuation-indent and
    min-conditional-indent to see if that helps.

     

Log in to post a comment.