Feb 26, 2011

Folding C++ Code Regions in Eclipse

Normally, I don't use the code folding features of Visual Studio very often. Typically if my class is large enough to benefit from code folding it probably needs refactored into smaller classes. However some classes like my mediator and dispatch classes can benefit from code folding to make navigation and overview simpler. In those cases I miss region code folding when I move to Eclipse. While VS and ReSharper make code folding look very snazzy, you can get very functional (if not as pretty) regional code folding in Eclipse without any plugins. Just use the #if directive. Specifically, do this
#if (1) //Anything you want here to identify the region
… The C++ Code
#endif

If you find this article helpful check out my Eclipse Guided Tour course on Pluralsight. I’m currently working on part 2 which should be released in December of  2013.

 
You need to make sure you have code folding for pragmas enabled in the Windows->Preferences dialog as shown below.

SNAGHTML5a1cd4

Readers' Most Popular Posts