Some background....
Ignore IFDEF / REGION ... => Then all folding is hierarchically structured/nested.
That means if you have
if a then begin // fold start
if b then begin // nested fold start
The nested fold for "b" will always end before the fold for "a" ends.
Or it ends on the same line.
But it can not overlap. It is never possible that "b" folds any lines that are not also folded by "a".
There is
no way that
- "b" folds lines 11 to 17
- "a" folds lines 10 to 15
The
nest level is not determined by the keywords. It does not matter if you fold at a "begin", or a "procedure" or "implementation" or "class" ....
- Every time a fold starts (the gutter has a [+]) the
nest level goes up by one (or more, if several folds start on that line).
- Every time a fold ends the
nest level goes down by one.
And the "fold to level n" simply counts how many surrounding/outer blocks exist.
IFDEF / REGION and region work different.
An IFDEF or REGION can partly overlap a begin block
if a then begin
...
{%REGION}
...
end;
...
{%ENDREGION}
If the REGION would increase/decrease the fold-level => then part of the begin/end would be at level 1, but part of that block would be at level 2 (because the "end" of the "begin..end" is in the REGION and therefore it would be at a higher level.
So IFDEF / REGION do not take part in the level counting. (There are also implementation details, which would make it incredible complicated to have them do level counting).
In theory they (can) have their own independent levels.
You could implement a command in the IDE that folds all regions, or only regions nested at n levels within other regions.
But someone would need to implement that.
(Adding it to the gutter menu is probably the easier task / yet still work that needs to be done by someone)