Code Folding with user defined {$REGION} comments
Original Reporter info from Mantis: ggeldenhuys
-
Reporter name: Graeme Geldenhuys
Original Reporter info from Mantis: ggeldenhuys
- Reporter name: Graeme Geldenhuys
Description:
After Delphi 7, Borland introduced code folding. They also introduced an option for the developer to create there own code folding regions. This is accomplished with the { $REGION } and { $ENDREGION } comment tags. Please note the space in front of the $REGION and $ENDREGION. This prevents FPC from thinking it's compiler directive and gets treated as a standard comment - this also allows any other editor that doesn't support $REGION to simply ignore this.
Syntax used in Delphi and that I think will be very handy in Lazarus IDE.
{ $REGION 'comment' }
// you code goes here
{ $ENDREGION }
This is the basic syntax required. I also think it will be very handy if we can extend that syntax to include a default 'fold' option. For example: Say I want the editor to default show all code folding as collapsed (no folding by default), but a certain GUI initialization method I always want folded by default - because that code is normally auto generated and the developer 99.9% of the time doesn't need to scratch in there...
{ $REGION 'GUI initialization code' fold }
// GUI initialization code goes here
{ $ENDREGION }
The $REGION now has a comment 'GUI Initialization' and trigger 'fold' that says by default this region must be folded when this unit is displayed for the first time.
If the region is folded, the editor must also display the user defined comment in the editor line next to the code folded (gutter) + (plus) sign.
See the following CodeGear web page showing the Code Folding and $REGION feature in action. It's about halfway down the page.
http://dn.codegear.com/article/34323/
Mantis conversion info:
- Mantis ID: 12718
- OS: Ubuntu Linux
- OS Build: 7.10
- Platform: x86
- Version: 0.9.27 (SVN)
- Fixed in version: 0.9.27 (SVN)
- Fixed in revision: 19409 (#71fb77ec)
- Target version: 0.9.28
- LazTarget: 1.4