Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: 93NickCousar on September 23, 2018, 12:45:24 am

Title: How to configure the Source Formatter for GNU Bracket Style
Post by: 93NickCousar on September 23, 2018, 12:45:24 am
I'm using version 17.12 of C::B, which I believe is the most current version and I am having trouble formatting my brackets.

Code written in the GNU bracket style is supposed to look like this:
Code
int Foo(bool isBar)
{
  if (isBar)
    {
      bar();
      return 1;
    }
  else
    return 0;
}

But instead, my code auto-formats to this:
Code
int Foo(bool isBar)
{
    if (isBar)
    {
        bar();
        return 1;
    }
    else
        return 0;
}
 

I've tried tweaking dozens of settings in the Configure Editor menu and the Source Formatter, but can't figure out how to get this to work.
Title: Re: How to configure the Source Formatter for GNU Bracket Style
Post by: oBFusCATed on September 23, 2018, 01:06:58 am
Are you using the "Format use Astyle" context menu command? Or do you expect the format to be preserved during normal editing?
Title: Re: How to configure the Source Formatter for GNU Bracket Style
Post by: 93NickCousar on September 23, 2018, 02:06:17 am
I'm not sure I understand your question. What is the "Format use AStyle" context menu? What I did was go into setting>editor>Source Formatter and selected GNU from the panel on the left. I guess what I am trying to do is configure my editor so that it formats to the selected style in real time, as I am typing out the code. Is that a possibility in Code::Blocks? Also, I don't know if this is relevant, but the plugin menu says I have Source code formatter (AStyle) 2.05.1 enabled.

(https://i.postimg.cc/vTBMqqXT/Screenshot_15.png) (https://postimages.org/)application screenshot (https://postimages.org/app)
Title: Re: How to configure the Source Formatter for GNU Bracket Style
Post by: oBFusCATed on September 23, 2018, 10:13:55 am
What is the "Format use AStyle" context menu?
Right click in an editor and you'll see it.

I don't think codeblocks supports this formatting during editing unfortunately.
Title: Re: How to configure the Source Formatter for GNU Bracket Style
Post by: tigerbeard on September 24, 2018, 10:52:36 pm
I am using that all the time while editing, but its only almost-realtime by pressing Alt-A (Windows only, just saw that in Linux that did not work).

This shortcut key actually formats your whole code in the current window, i.e. the whole file according to what style you have selected. It works quite well once I got used to pressing Alt-A all the time (a bit like pressing Ctrl-S all the time)

For exampe
 if(i==1) a=1;
else a=2;

looks like that after pressing Alt-A
 if (i==1)
    { a=1; }
 else
    { a=2; }
With your GNU style it would be a bit different.


Not sure if that answers the question, though
Title: Re: How to configure the Source Formatter for GNU Bracket Style
Post by: 93NickCousar on September 25, 2018, 09:19:34 pm
@tigerbeard That does answer my question. C::B is free after all, so I guess the alt-a is good enough.