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

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.


About Me

My photo
Tod Gentille (@todgentille) is now a Curriculum Director for Pluralsight. He's been programming professionally since well before you were born and was a software consultant for most of his career. He's also a father, husband, drummer, and windsurfer. He wants to be a guitar player but he just hasn't got the chops for it.