Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Jewest on March 08, 2018, 10:28:00 am

Title: AStyle formatting help needed
Post by: Jewest on March 08, 2018, 10:28:00 am
Dear All,

I have found the astyle formatter and I love it.
There is only on thing that I can not make the formatter do in version 17.12, what I have made working in version 12.11.

What I want:

Quote
if(statment1 == 1) statment1++;
or
Quote
if(statment1 == 1)
statment1++;
transform in:
Quote
if(statment1 == 1)
{
  statment1++;
}
What do I have so far?
Quote
if(statment1 == 1)
{statment1++;}
But I want the break in to new lines in one single step.

Anyone got a suggestion?

thank you in advance,

Jewest
Title: Re: AStyle formatting help needed
Post by: oBFusCATed on March 08, 2018, 07:56:16 pm
Can you setup the command line version to do it?
Astyle is not a project we develop, it is an external tool we just integrate in the IDE.
Title: Re: AStyle formatting help needed
Post by: Jewest on March 09, 2018, 09:20:03 am
I understand, I had version 12.11 doing what is doing what is supposed todo.
is there are way to debug this? can I see the output to the astyle formatter?
I have a feeling that its the parameter sequence that C::B is sending to aStyle.
Title: Re: AStyle formatting help needed
Post by: oBFusCATed on March 09, 2018, 10:16:35 am
As far as I know you can install a command line astyle. You need to use the same version.
Otherwise debugging could be done by building cb with debug symbols/no optimizations and using gdb to step through the code...
Title: Re: AStyle formatting help needed
Post by: Jewest on March 09, 2018, 03:28:36 pm
I did some digging around.

Source file:
Code
void main()
{
    if(def ==1) def=3;
    else def=12;

while(def<12) def--;
}



int Foo(bool isBar)
{
    if (isBar)
    {
        bar();
        return 1;
    }
    else
        return 0;
}


switch (foo)
{
case 1:
    a += 1;
    break;

case 2:
{
    a += 2;
    break;
}
}

command with aStyle 3.1  command used:  astyle -A1 --indent=spaces=2 -f -j < benchmark.cpp > test.cpp

results in:
 
Code
void main()
{
  if(def ==1)
  {
    def=3;
  }
  else
  {
    def=12;
  }

  while(def<12)
  {
    def--;
  }
}



int Foo(bool isBar)
{
  if (isBar)
  {
    bar();
    return 1;
  }
  else
  {
    return 0;
  }
}


switch (foo)
{
case 1:
  a += 1;
  break;

case 2:
{
  a += 2;
  break;
}
}


I see "--add-one-line-braces / -J"  in the option window of C::B but apparently I am overlooking the "--add-braces / -j" that I need.
Any suggestions which option to enable on the screen?
Title: Re: AStyle formatting help needed
Post by: Jewest on May 02, 2018, 10:32:59 am
At the moment I have created the following workaround:

Add a new tool in the tools menu
With the following settings:
astyle
-A1 --indent=spaces=2 -f -j $(ACTIVE_EDITOR_FILENAME)

This does the job for me at the moment.
(Detecting the change on disk is slow, but acceptable)
Title: Re: AStyle formatting help needed
Post by: BlueHazzard on May 02, 2018, 07:55:10 pm
Ticket on SF would be nice so this won't get lost...