Home page Home page Home page Home page
Pixel
Pixel Header R1 C1 Pixel
Pixel Header R2 C1 Pixel
Pixel Header R3 C1 Pixel
Pixel
By Sprezz | Tuesday, 7 January 2025 08:45 | 0 Comments

Some seven years ago, REVDEX documented the then newly introduced concept of #region to allow folding of code. We find this to be incredibly useful when working on large commuter programs as it allows easy navigation between code sections. There's no point in reproducing the linked article, so briefly, you can bracket sections of code between #region regionname and #endregion regionname and then fold that section of code.

Here's an example of one of our commuter routines with the various code sections "regioned".


I'm able to see at a glance what a large program does. If I want to look at the supportingRoutines I can just dropdown the "Find label..." combo and select that option


The editor then takes me to the line number where that region begins.

However, there is a minor caveat to be aware of when we're cutting and pasting collapsed regions.

In the following pseudo-code (with a nod to Jackson Structured Programming throwback for those as ancient as myself) we've simply placed an individual subroutine within a region. That's not normally a real life scenario. You use regions to group logically connected groups of code. Of course you may choose to do this if you wish to be able to collapse individual subroutines.


and collapse it to make cutting and pasting easier


Let's decide that we want to move the process region to after the wrapup region, so we select the "#region process"


and Ctrl-X to cut the region


then move to the end of the program and press return and Ctrl-V to paste the region


All looks sort of good. But let's expand everything again and see where we are



It has brought across the process region line but inserted it within the wrapup region.

So let's revisit and this time change the selection


Note that we have now selected to the beginning of the next line - you can see the cursor. Cut, move down and paste and the expansion now looks like this


the process region has been inserted within the wrapup region, not after.

To fix this what we have to do is expand the wrapup region before doing the paste, like so


and after pasting and expanding we now have what we originally wanted.


Well worth paying a little attention to detail. 

Pixel
Pixel Footer R1 C1 Pixel
Pixel
Pixel
Pixel