Page 1 of 1

[Feature request] Adding regions

Posted: Mon Jan 26, 2009 8:35 pm
by kortyburns
Hi,

I would like CL to support regions, like VStudio, but in another way. I mean, with VS, writing

Code: Select all

#pragma region "this is a region"
...
#pragma endregion
Creates a region that can be folded. This is usefull when the same source code file is written in logical parts. Also, #pragma is a preprocessor directive and other compiler than M$, like gcc, don't like it until we disable warning for this directive ; that's why i would prefer a c comment tag to use to create a Region.

Would it be possible to create a region using a specific c comment tag, like

Code: Select all

/* Region Parse CAPMT */
... This block can be automaticaly folded in or out in the editor.
   /* Region Parse Elementary Stream */
   ... This is a subregion.
   /* EndRegion
/* EndRegion */
?

This would be displayed in the editor

Code: Select all

+Parse CAPMT
If '+' is clicked, then

Code: Select all

- /* Region Parse CAPMT */
   ... the code has been unfolded
   + Parse Elementary Stream 
   ...
/* EndRegion */
Creating a region is almost the same as creating a { } block, with a name.

Using these regions in source code is a good way to make a zoom in/ zoom out in the code. For example, you can choose to display or not all the error cases of a source file(parameters checks, errors values returned by functions, by choosing to unfold all "ERROR xxx" regions names).

Re: [Feature request] Adding regions

Posted: Mon Jan 26, 2009 10:29 pm
by sdolim
I think some other editors (vim?) allow something like this to mark regions:

Code: Select all

//{ 
...
//}
You can add descriptive words like "Parsing" after the '{' or '}'. This pattern is nice because it is easy to scan for and can't really be misspelled.

Of course, that doesn't stand out visually very nicely when you are scrolling through the editor. Maybe we could do something like this:

Code: Select all

//---------------------------------{ Parsing }--------------------------------

...

//---------------------------------{ Lexical }--------------------------------
Here, the regex for a region start would be

Code: Select all

^ *//-*{.*}-* *$
The region would go to the beginning of the next region, as in the example above. (I use spaces in this regex for example only: a real regex would match tabs too.)

There could also be a marker to end a region if you want to not start a new region. I suggest this:

Code: Select all

//---------------------------------{ Lexical }--------------------------------

...

//-----------------------------------------------------------------------------
Note the lack of a "{ Name }" in the middle of the end-region marker.

BTW, this kind of feature is not really part of the CodeFormatter's job: It's a Scintilla Lexer issue because of the folding (CodeFormatter just reindents and respaces code.)

Scott

Re: [Feature request] Adding regions

Posted: Mon Jan 26, 2009 10:35 pm
by eranif
sdolim wrote:I think some other editors (vim?) allow something like this to mark regions:
CODE: SELECT ALL
//{
...
//}
and so does codelite.
Adding

Code: Select all

//{
adds a fold point and

Code: Select all

//}

will close it.

this is a built in feature of scintilla

Eran

Re: [Feature request] Adding regions

Posted: Tue Jan 27, 2009 3:06 am
by sdolim
So my list of "some editors" includes CodeLite already...
Well, that makes it easy to satisfy this FR! :D

Re: [Feature request] Adding regions

Posted: Tue Jan 27, 2009 12:38 pm
by kortyburns
Haha excellent, thank you !