Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Story on July 28, 2011, 03:51:56 am

Title: code folding switch statements
Post by: Story on July 28, 2011, 03:51:56 am
How can I fold an individual case of a switch statement? I don't see any option to do so.
I am using version 10.05 on Windows 7.
Title: Re: code folding switch statements
Post by: Freem on July 28, 2011, 10:32:15 am
I don't think it's possible.
If you really need it, you can always surround the bloc of code with '{' and '}'.
I have never seen it in other code, but one day I've tried it and it compile (ok, I didn't try it into a case statement. By the way, I really rarely use case statements, and they often just call a function, because the code if often reused later)

PS: And I don't think it could become, as there are is way to know the end of the bloc: break statements are not mandatory, so you can say that "case 1:" just imply to run something AND "case 2:".
This is why you probably never see fold in switch cases in an editor made to write C/C++ code.
(some can do, as notepad++ in certain conditions, because it fall on a indent style fold when it don't know the language.)
Title: Re: code folding switch statements
Post by: MortenMacFly on July 28, 2011, 03:12:35 pm
If you really need it, you can always surround the bloc of code with '{' and '}'.
To be precise, the following snippet does the trick:
Code
  switch (foo)
  {
    case bar1:
    { //{
      Func1();
      break;
    } //}
    case bar2:
    { //{
      Func2();
      break;
    } //}
  }