Author Topic: "Allow one line code blocks in class definition" not working  (Read 5200 times)

evanratt

  • Senior Community Member
  • Posts: 300
  • Hero Points: 23
"Allow one line code blocks in class definition" not working
« on: April 25, 2013, 08:41:39 PM »
In Tools->Options->Languages->Application Languages->C/C++->Formatting->Edit...->Newlines->Statement Blocks: (whew!!)

The option to "Allow one line code blocks in class definition" doesn't seem to work for me. As soon as I type the opening brace in a function in my class definition, both opening and closing braces are entered, each one on a newline. I did notice when I first set up my formatting options that it looks like there may be conflicting options... Could the "Brace Style->Declaration Style->function/method blocks" setting, which is set to "Next Line", be stomping the Newline setting?

In general, I want the brace style to be "Next Line" for function/method blocks, *except* in the case of one-line methods in a class definition.

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: "Allow one line code blocks in class definition" not working
« Reply #1 on: April 25, 2013, 09:20:08 PM »
It is taking the "Next Line" setting for function method blocks.  The editing code isn't taking that particular setting into account.  Even if you have "Beautify with typing" enabled, this won't do what you want, because it's conservative in the way it's implemented.  It will never look at a method, and say "Hey, this is only one line of code, so lets pull it and the braces and the declaration up onto one line."  It's more along the lines of you telling the beautifier "I'm going to do this, don't screw it up for me."

It is irritating when typing one-liners, having to manually fix up the method.  One thing I've considered is having a command that could be bound to a key that can cycle through the styles in place:  one-line function/block, then then through the other brace styles, finally back the default brace style. 

evanratt

  • Senior Community Member
  • Posts: 300
  • Hero Points: 23
Re: "Allow one line code blocks in class definition" not working
« Reply #2 on: April 25, 2013, 09:58:41 PM »
I guess I'm only thinking of it from the "Beautify while typing" case, and I obviously don't know how the code is structured, but it seems like if it waited for the user to enter a new-line to apply the Brace Style, it could then look to see if a closing brace was or was not present on the same line, and behave accordingly.

As it is, does this mean that if I have the method brace style set to "Next Line", the "Allow one line code blocks in class definition" setting is never going to be used--it's always going to be overrided by the brace style?

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: "Allow one line code blocks in class definition" not working
« Reply #3 on: April 26, 2013, 01:17:24 PM »
Yes, the beautify would have to be delayed for that to work.  Let me try to do that, and see how it works in practice.  I doubt I'll have the time to test it enough to drop it in for the v18 release, but if I can get it to work without major changes, it could be in a dot release.  I'll update the thread either way.

evanratt

  • Senior Community Member
  • Posts: 300
  • Hero Points: 23
Re: "Allow one line code blocks in class definition" not working
« Reply #4 on: April 26, 2013, 02:21:09 PM »
Cool, thanks Patrick!

As an aside, I'm working in a code base with a significantly different coding style than I'm used to, so this is the first time I've really appreciated the Beautify While Typing feature. It's saving my sanity--great feature!