Author Topic: How to configure the Source Formatter for GNU Bracket Style  (Read 4223 times)

Offline 93NickCousar

  • Single posting newcomer
  • *
  • Posts: 6
How to configure the Source Formatter for GNU Bracket Style
« 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: How to configure the Source Formatter for GNU Bracket Style
« Reply #1 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?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline 93NickCousar

  • Single posting newcomer
  • *
  • Posts: 6
Re: How to configure the Source Formatter for GNU Bracket Style
« Reply #2 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.

application screenshot

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: How to configure the Source Formatter for GNU Bracket Style
« Reply #3 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline tigerbeard

  • Almost regular
  • **
  • Posts: 186
Re: How to configure the Source Formatter for GNU Bracket Style
« Reply #4 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

Offline 93NickCousar

  • Single posting newcomer
  • *
  • Posts: 6
Re: How to configure the Source Formatter for GNU Bracket Style
« Reply #5 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.