News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

About AStyle plugin, Here is a new problem

Started by Loaden, January 13, 2010, 07:57:15 AM

Previous topic - Next topic

Loaden

AStyle version: 1.23
and the arguments is:
--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:
int main()
{
    for(int i=0;i<10;++i)
    {
        cout << i << endl;
    }
    return 0;
}

TO:
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:
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]

Loaden

#1
I'am sorry! It's seems works now. SVN6080
if i selected the option on cursor position.


[attachment deleted by admin]

Loaden

Still have problems, if this option is enabled, the following code to have a problem.
#include <windows.h>

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

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

::MessageBox(0, 0, 0, 0); formated to ::MessageBox (0, 0, 0, 0);

MortenMacFly

Quote from: Loaden on January 24, 2010, 04:41:59 PM
::MessageBox(0, 0, 0, 0); formated to ::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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Loaden

#4
Quote from: MortenMacFly on January 24, 2010, 04:45:59 PM
Quote from: Loaden on January 24, 2010, 04:41:59 PM
::MessageBox(0, 0, 0, 0); formated to ::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);

Loaden

example, this 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:
#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:
#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]

MortenMacFly

Quote from: Loaden on January 24, 2010, 05:47:53 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Loaden

#7
Quote from: MortenMacFly on January 24, 2010, 06:42:03 PM
Quote from: Loaden on January 24, 2010, 05:47:53 PM
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:
#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 :
#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]

Loaden

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]

MortenMacFly

Quote from: Loaden on January 25, 2010, 01:11:01 AM
Quote from: MortenMacFly on January 24, 2010, 06:42:03 PM
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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

Loaden

Quote from: MortenMacFly on January 25, 2010, 06:26:27 AM
Quote from: Loaden on January 25, 2010, 01:11:01 AM
Quote from: MortenMacFly on January 24, 2010, 06:42:03 PM
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.

Loaden

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.

Loaden

#12
As another example, thic 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:
void test() {}
void func (int i) {}

int main()
{
   test();
   func (1);
   if (int i = 0; i < 10; ++i) test();
   return 0;
}

Notice:
    test();
   func (1);

Loaden

AStyle 1.24 release, I think the reason is:

--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: