Great undocumented feature: foldable code with $REGION directive

From: Marcelo Carvalho (mc_nospam_at_arquivo.com.br)
Date: 12/04/04


Date: 4 Dec 2004 07:54:20 -0800

Hi,

   Having my first contact with C# IDE on D2005, I noticed a different
rectangle, that was “hiding” a piece of auto-generated code. It was the
#REGION directive. Than I saw the same kind of region in the Delphi.Net
IDE, as the {$REGION} directive. Immediately I tried it in the Win32
IDE and… it worked!

   The syntax is:

        …
        {$REGION ‘Any title you want’}
        …
        // Any piece of code
        …
        {$ENDREGION}
        …

   After typing it, when you place the cursor back on the {$REGION}
line, a small [+] appears near the line numbers - and you have a
foldable piece of code! Closing it provides a nice rectangle hiding all
code between the directives, showing the title you typed.

   This resource allow you to organize code easily, and is a great
complement for the similar foldable methods and procedures. You can
fold logical pieces of code, group code to turn complex structured
blocks easy to read, group procedures and functions by categories,
group variable declarations, and so on. You can even see all your unit
folded code in one single screen!

   The regions CAN be nested, and they keep the indentation of the
{$REGION} directive when folded. You can also customize it’s colors
when folded and unfolded.

   Of course there’s space for enhancements: The main one, as pointed
by Nick Hodges, would have some “Make selected code a region” as a
right click… Also I'd like to be have a parameter so set color for
individual regions (to categorize them), and have a shortcut do fold
all regions and methods...

   I was wondering why such great resource is undocumented, not even
being showed in the Borcons demos – it would be a success there, I’m
sure. My first thought is that maybe because it is derived from some C#
or VB resource… Observing many people being surprised when I mentioned
it I decided to share it here.

      [][][][]

         Marcelo.



Relevant Pages

  • Re: Great undocumented feature: foldable code with $REGION directive
    ... > IDE and. ... > code between the directives, ... Also I'd like to be have a parameter so set color for ... > I was wondering why such great resource is undocumented, ...
    (borland.public.delphi.non-technical)
  • Re: Managing project groups
    ... To make it easy for you to view all the directives, go to Project Options, change ... then open the project source and press Ctrl-O. ... The IDE will ...
    (borland.public.delphi.non-technical)
  • Re: Comment Blocks in VB
    ... Don't use #'s because they are reserved for directives ... Me personally have created my own toolbar within the IDE with the ... comment/uncomment buttons on. ...
    (microsoft.public.dotnet.languages.vb)