Author Topic: Suggestion: #if 0 comment coloring  (Read 8276 times)

Offline Edis Krad

  • Single posting newcomer
  • *
  • Posts: 6
Suggestion: #if 0 comment coloring
« on: February 08, 2007, 07:26:56 am »
Hiyas. First of all, thanks to the CodeBlocks developers for such a wonderful IDE!! Keep up the good work, guys :D

Anyways, when I'm debugging, I tend to comment out huge chunks of code by using #if 0 .... #endif for C/C++ languages. I find this much more practical than /* ... */ since the latter fails when there's already something commented with asterisks.

For example, while this works:

Code
#if 0 //commented out
/*This is a a huge chunk of code*/
void somefunction()
{
...
}
#endif //commented out

this fails

Code
/* commented out
/*This is a a huge chunk of code*/
void somefunction()   //these
{                     //lines
...                   //remain
}                     //uncommented
commented out */


What I'm suggesting is, if you deem it practical ( and it's not too much work :P ), instruct the editor to color everything between #if 0 and #endif as a comment as well for C / C++ languages.

Thanks!
« Last Edit: February 08, 2007, 07:28:42 am by Edis Krad »

wxLearner

  • Guest
Re: Suggestion: #if 0 comment coloring
« Reply #1 on: February 08, 2007, 10:06:54 am »
Hello,
did you try Code::Blocks' comment/uncomment feature? It's in the edit menu. Just select a block of code and press ctrl+shift+c to comment it or ctrl+shift+x to uncomment it.

Offline alextj

  • Single posting newcomer
  • *
  • Posts: 3
Re: Suggestion: #if 0 comment coloring
« Reply #2 on: April 29, 2011, 02:08:04 pm »
This topic is very old, but I still face a similar issue to the original poster.

Commenting out large blocks of code with #if 0/#endif is better than using ctrl+shift+c, because you can fold the #if/#endif code out of your way using Code::Blocks code folding.

Using ctrl+shift+c will add // in front of each line, which will leave this huge chunk of currently unneeded code in your way, not being able to fold it.

So it would be really nice to give #if 0 code a "commented" color. In any case it gives a better visual clue to the fact that the code is not being compiled - just like normal comments.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Suggestion: #if 0 comment coloring
« Reply #3 on: April 29, 2011, 02:23:49 pm »
Have you tried latest nightlies? There is similar feature.
The #ifdef 0 blocks are grayed out or something like that. I'm not sure if it is enabled by default.

BTW: There is the /* */ style of comments and they are foldable. I've can comment code with this style of comments with ctrl+shift+v (I don't remember if it is a custom patch which adds this functionality).
(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 alextj

  • Single posting newcomer
  • *
  • Posts: 3
Re: Suggestion: #if 0 comment coloring
« Reply #4 on: April 29, 2011, 03:16:11 pm »
Thanks for your quick answer oBFusCATed.

Have you tried latest nightlies? There is similar feature.
The #ifdef 0 blocks are grayed out or something like that. I'm not sure if it is enabled by default.
I didn't try latest nightlies. If the feature is in latest nightlies, does it mean that it might be in the official Code::Blocks release in a near future?

BTW: There is the /* */ style of comments and they are foldable. I've can comment code with this style of comments with ctrl+shift+v (I don't remember if it is a custom patch which adds this functionality).
I guess it is a custom patch, since it doesn't work in the latest version (10.05).
Of course using /* */ for commenting out large parts of code will fail, as the original poster have mentioned. But anyway, this would be a handy feature for quick inline commenting.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Suggestion: #if 0 comment coloring
« Reply #5 on: April 29, 2011, 07:05:09 pm »
I guess it is a custom patch, since it doesn't work in the latest version (10.05).
Of course using /* */ for commenting out large parts of code will fail, as the original poster have mentioned. But anyway, this would be a handy feature for quick inline commenting.

You can add (nearly) any keyboard shortcuts to "Edit -> STream comment" or "Edit -> Box comment" with the keybinder-plugin.
It's part of the contrib-plugins and the settings are in "Settings -> Editor... -> Keyboard shortcuts".

Offline alextj

  • Single posting newcomer
  • *
  • Posts: 3
Re: Suggestion: #if 0 comment coloring
« Reply #6 on: May 02, 2011, 09:20:09 am »
Ah! Thanks Jens, that's useful (and I guess this plugin has been mentioned 1000 times on this forum already... duh)  :o