Author Topic: CodeFormatting aStyle - how do line breaks after fixed amount of characters  (Read 4360 times)

Offline Kaspatoo

  • Single posting newcomer
  • *
  • Posts: 5
Hi,

I am using Clodeblock 16.01 on Ubuntu 14.04 LTS x64.

For a special printable view of my prof I need to make my Code to have no lines with more thant 80 characters.

When right clicking of the code and chosing "Format use AStyle" its doing well except for some few hundred lines (out of thousands).

I still activated the "Enable line breaking" Checkbox und
Settings ->Editor -> Source formatter -> Formatting
and set the value from 200 to 50 or 80.
But nothing happend.

Also when rerunning "Format use AStyle" its still the same output as before, there still are lines with more thant 80 characters.

I also tried using the other checkbos "break logical condionals..." with not other result.
(after reopening the settings, this second checkbox always is greyed out until I uncheck and recheck the first checkbos ("Enable line breaking"))

Is there an other way to configure Astyle that way?
Or to get the option "Enable line breaking" working?


Sample of such a line not beeing wrapped:
Code
std::pair <std::multimap<int, std::tuple<int, double>>::iterator, std::multimap<int, std::tuple<int, double>>::iterator>
                revXTRangeBoundsIter;

Thanks in advance.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Hi, i tested this on windows and the line breaking works for me:

Set line length to 80, mark all text and left click->Format use astyle

i have found out, that you have to select all text to work, it does not work if you select only a part of the text...

You have to consider a view things:
1) AStyle can only break a line if there is a possibility to break (a empty space, or a apostrophe) : it can't break long names for example
2) It does not break comments
3) If you have deep contexts (like multiple if) it also can't break, because the indentation is stronger, so at the end there is no space left to break

Quote
I also tried using the other checkbos "break logical condionals..." with not other result.
This works also as expected:
From this code:
Code
        if(hellsadfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfo && teasdfasdfasdfasdfasdfasdfasdfasdfasdfst && blaasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfbla)
        {
            asdlalsdk;
        }
if disabled:
Code
        if(hellsadfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfo
                && teasdfasdfasdfasdfasdfasdfasdfasdfasdfst
                && blaasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfbla)
        {
            asdlalsdk;
        }
if enabled:
Code
        if(hellsadfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfo &&
                teasdfasdfasdfasdfasdfasdfasdfasdfasdfst &&
                blaasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfbla)
        {
            asdlalsdk;
        }

Quote
(after reopening the settings, this second checkbox always is greyed out until I uncheck and recheck the first checkbos ("Enable line breaking"))
i can confirm this and this is a bug...

Code
std::pair <std::multimap<int, std::tuple<int, double>>::iterator, std::multimap<int, std::tuple<int, double>>::iterator>
                revXTRangeBoundsIter;
i can confirm that this line is not wrapped correctly. The AStyle plugin uses the possibilities of AStyle (https://sourceforge.net/projects/astyle/) so it could be possible that template wrapping is not implemented in the core lib, because it was designed for C ?



Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Can you try the astyle executable on your file and report if this works?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353

Offline Kaspatoo

  • Single posting newcomer
  • *
  • Posts: 5
Hi,

thanks for further analysis.
Currently I manually broke ever Line being greater than 80.

"
Can you try the astyle executable on your file and report if this works?
"

I am not that familar with it.
Where do I find this file and how do I have provide parameters? May you show me a sample call?
Thanks in advance.

Offline Kaspatoo

  • Single posting newcomer
  • *
  • Posts: 5
Code
            if(countEdgesToBeDeleted != 0)
            {
                shortcutsPerAdjNodeRatio = (double)
                                           countShortcutsToBeCreated / countEdgesToBeDeleted;
            }
            calculatedRank = shortcutsPerAdjNodeRatio;
        }

        return calculatedRank;
    }

There, even when selecting all first the line " countShortcutsToBeCreated / countEdgesToBeDeleted;" is vertically evened with the equal-sign of the line before.
There are much more of such lines beeing evened with an equal sign.

Else I cannot see a difference between using format astyle and first selecting all.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
as i noted at top cb uses astyle for code formatting. So if astyle does not work codeblocks does not work.
I have tested your code with the latest astyle executable and i can confirm that astyle does not handle this correctly....
So this is a astyle bug and has to be reported to the astyle bug tracker...

can you do this please?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
The link to the bug reporting:
https://sourceforge.net/p/astyle/bugs/?source=navbar

also it would be better if you test astyle directly download link:
https://sourceforge.net/projects/astyle/files/astyle/astyle%202.06/

it is very easy to use, just read the help file...