Author Topic: About AStyle plugin, Here is a new problem  (Read 18524 times)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
About AStyle plugin, Here is a new problem
« on: January 13, 2010, 07:57:15 am »
AStyle version: 1.23
and the arguments is:
Code
--style=allman --indent=spaces --indent-cases --indent-preprocessor --pad-oper --unpad-paren --keep-one-line-statements --keep-one-line-blocks --convert-tabs --suffix=none
If use this arguments, it's can be format this code FROM:
Code
int main()
{
    for(int i=0;i<10;++i)
    {
        cout << i << endl;
    }
    return 0;
}
TO:
Code
int main()
{
for (int i = 0; i < 10; ++i)
{
cout << i << endl;
}
return 0;
}

NOTICE:
for{HERE is a space}(int i = 0; i < 10; ++i)

But, if i setting AStyle Plugin like below picture show, it's only format the code TO:
Code
int main()
{
for(int i = 0; i < 10; ++i)
{
cout << i << endl;
}
return 0;
}

IN for and (, NOT space in there.

[attachment deleted by admin]

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: About AStyle plugin, Here is a new problem
« Reply #1 on: January 13, 2010, 08:02:36 am »
I'am sorry! It's seems works now. SVN6080
if i selected the option on cursor position.


[attachment deleted by admin]
« Last Edit: January 13, 2010, 08:17:57 am by Loaden »

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: About AStyle plugin, Here is a new problem
« Reply #2 on: January 24, 2010, 04:41:59 pm »
Still have problems, if this option is enabled, the following code to have a problem.
Code
#include <windows.h>

int main()
{
    for (int i = 0; i < 10; ++i)
    {
        cout << i << endl;
    }

    ::MessageBox (0, 0, 0, 0);
    return 0;
}
Code
::MessageBox(0, 0, 0, 0);
formated to
Code
::MessageBox (0, 0, 0, 0); 

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: About AStyle plugin, Here is a new problem
« Reply #3 on: January 24, 2010, 04:45:59 pm »
Code
::MessageBox(0, 0, 0, 0);
formated to
Code
::MessageBox (0, 0, 0, 0); 

Well if you have enabled the option "Insert space padding around parenthesis on the outside" as shown in the screenshot of the previous post that's exactly what has to happen...?!
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: About AStyle plugin, Here is a new problem
« Reply #4 on: January 24, 2010, 05:25:02 pm »
Code
::MessageBox(0, 0, 0, 0);
formated to
Code
::MessageBox (0, 0, 0, 0); 

Well if you have enabled the option "Insert space padding around parenthesis on the outside" as shown in the screenshot of the previous post that's exactly what has to happen...?!
It's seems lost this option.

http://astyle.sourceforge.net/astyle.html#_unpad-paren

--unpad-paren / -U / --unpad=paren (depreciated)
Remove extra space padding around parenthesis on the inside and outside.  Any end of line comments will remain in the original column, if possible. This option can be used in combination with the paren padding options pad‑paren‑out and pad‑paren‑in above. Only padding that has not been requested by other options will be removed.

For example, if a source has parens padded on both the inside and outside, and you want inside only. You need to use unpad-paren to remove the outside padding, and pad‑paren‑in to retain the inside padding. Using only pad‑paren‑in would not remove the outside padding.

if ( isFoo( a, b ) )
    bar ( a, b );
becomes (with no padding option requested):

if (isFoo(a, b))
    bar(a, b);
« Last Edit: January 24, 2010, 05:41:02 pm by Loaden »

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: About AStyle plugin, Here is a new problem
« Reply #5 on: January 24, 2010, 05:47:53 pm »
example, this code:
Code
#include <windows.h>

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

int main()
{
    for (int i = 0; i < 10; ++i)
    {
        cout << i << endl;
    }

    ::MessageBox (0, 0, 0, 0);
    return 0;
}
How to format it to:
Code
#include <windows.h>

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

int main()
{
    for (int i = 0; i < 10; ++i)
    {
        cout << i << endl;
    }

    ::MessageBox(0, 0, 0, 0);
    return 0;
}
but not:
Code
#include <windows.h>

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

int main()
{
    for(int i = 0; i < 10; ++i)
    {
        cout << i << endl;
    }

    ::MessageBox(0, 0, 0, 0);
    return 0;
}



[attachment deleted by admin]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: About AStyle plugin, Here is a new problem
« Reply #6 on: January 24, 2010, 06:42:03 pm »
example, this code:
[...]
How to format it to:
[...]
but not:
[...]
That's simply not possible with the set of options given.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: About AStyle plugin, Here is a new problem
« Reply #7 on: January 25, 2010, 01:11:01 am »
example, this code:
[...]
How to format it to:
[...]
but not:
[...]
That's simply not possible with the set of options given.
Do not, AStyle can do that!
Launching tool 'AStyle': D:\LoveDEV\tool\AStyle.exe --style=allman --indent=spaces --indent-cases --indent-preprocessor --pad-oper --unpad-paren --keep-one-line-statements --keep-one-line-blocks --convert-tabs --suffix=none D:\Projects\fsefe\main.cpp (in D:\Projects\fsefe)
stdout> formatted  D:\Projects\fsefe\main.cpp
Tool execution terminated with status 0

Current code:
Code
#include <windows.h>

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

int main()
{
    for(int i = 0; i < 10; ++i)
    {
        cout << i << endl;
    }

    ::MessageBox            (0, 0, 0, 0);
    return 0;
}
Can formatted to :
Code
#include <windows.h>

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

int main()
{
    for (int i = 0; i < 10; ++i)
    {
        cout << i << endl;
    }

    ::MessageBox(0, 0, 0, 0);
    return 0;
}

[attachment deleted by admin]
« Last Edit: January 25, 2010, 01:31:33 am by Loaden »

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: About AStyle plugin, Here is a new problem
« Reply #8 on: January 25, 2010, 01:18:59 am »
And I found a bug: If you run this tool, The CB Editor did not prompt the file has been modified.


[attachment deleted by admin]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: About AStyle plugin, Here is a new problem
« Reply #9 on: January 25, 2010, 06:26:27 am »
That's simply not possible with the set of options given.
Do not, AStyle can do that!
Look: I meant it's not possible with the options given by C::B. You can enhance the plugin if you like and add the appropriate options. It's pretty easy.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: About AStyle plugin, Here is a new problem
« Reply #10 on: January 25, 2010, 06:58:36 am »
That's simply not possible with the set of options given.
Do not, AStyle can do that!
Look: I meant it's not possible with the options given by C::B. You can enhance the plugin if you like and add the appropriate options. It's pretty easy.
But in SVN5731, it's work fine...
OK, I will try it.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: About AStyle plugin, Here is a new problem
« Reply #11 on: January 25, 2010, 09:18:29 am »
Certainly there are problems, I have read the code, my options and CB option is the same. However, the code is not formatted the same.

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: About AStyle plugin, Here is a new problem
« Reply #12 on: January 25, 2010, 12:20:48 pm »
As another example, thic code:
Code
void test() {}
void func(int i) {}

int main()
{
    test();
    func(1);
    if(int i=0;i<10;++i) test();
    return 0;
}
if use run Astyle plugin, it's became to:
Code
void test() {}
void func (int i) {}

int main()
{
    test();
    func (1);
    if (int i = 0; i < 10; ++i) test();
    return 0;
}
Notice:
Code
    test();
    func (1);
« Last Edit: January 25, 2010, 12:43:32 pm by Loaden »

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: About AStyle plugin, Here is a new problem
« Reply #13 on: March 27, 2010, 02:12:15 pm »
AStyle 1.24 release, I think the reason is:

Code
 --pad-header / -H
Insert space padding after paren headers only (e.g. 'if', 'for', 'while'...). Any end of line comments will remain in the original column, if possible. This can be used with unpad-paren to remove unwanted spaces.

if(isFoo(a, b))
    bar(a, b);

becomes:

if (isFoo(a, b))
    bar(a, b);
http://astyle.sourceforge.net/astyle.html
And the : --pad-header will fix this problem. :lol:

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014