Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-11

user defined code folding regions using $REGION comments

6 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I added a new feature request for user defined code folding regions. I think such an addition to Lazarus editor would be very useful. I especially think the "folded by default" option would be very handy. That way the editor can hide certain code by default, while the rest of the unit is expanded. Very handy for things like "auto generated" code from a Form Designer or something else, which the developer normally doesn't need to tamper with.

http://bugs.freepascal.org/view.php?id=12718

Any thoughts on the above? Anybody code folding code experience willing to take up the challenge in implementing something like this?

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys
Graeme Geldenhuys wrote
Any thoughts on the above? Anybody code folding code experience willing to take up the challenge in implementing something like this?

Another use for user defined code folding regions.... I found this hint on some Delphi website.

--------------------------
Like you I don't use cold folding however I recently found a use for it.

Create a LiveTemplate something along these lines.

{$REGION 'Assert'}Assert(Condition, 'Message');{$ENDREGION}

Use it every time you write an assertion and fold it up straight away.

Your distracting full length Assert statement is reduced to a single word, Assert, and because the region starts and ends on the same line you don't have line numbers jumping unexpectedly.

I also change my editor colours so that the collapsed region label is less prominent than the regular code lines.
--------------------------------

That could be handy for hiding all kinds of debug code... I could see a use for this in my code.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Paul Ishenin
to Graeme Geldenhuys: I added a new feature request for user defined code folding regions. I think such an…
Graeme Geldenhuys wrote 12 lines
I added a new feature request for user defined code folding regions. I think such an addition to Lazarus editor would be very useful. I especially think the "folded by default" option would be very handy. That way the editor can hide certain code by default, while the rest of the unit is expanded. Very handy for things like "auto generated" code from a Form Designer or something else, which the developer normally doesn't need to tamper with. http://bugs.freepascal.org/view.php?id=12718 Any thoughts on the above? Anybody code folding code experience willing to take up the challenge in implementing something like this?

I answered you to the bug-tracker. But I will answer here to. Yes, this is known feature and once it will be implemented. Marin is working on synedit folding last few weeks and he made a big progress in bug fixing there. He also has plans to implement this feature: http://wiki.lazarus.freepascal.org/User:Martin

Best regards,
Paul Ishenin.

Reply by email

Martin Friebe
to Gerard N/A
Gerard N/A wrote 5 lines
I have a rough implementation that seems to work Ok (I'm cautious because the synedit highlighter is a scary piece of code). If there is interest, I can post a patch to the bug tracker or here.

Hi Gerard,

I saw the patch you uploaded to the bug system.

As indicated the user-token must not interfere with real compiler directives. This should still be easy to solve. Instead of looking for a directive named $REGION, you would look for a comment with special content.

The 2nd issue requires more work.

consider this:

 'for relesae builds' fold }
   If  IsRelease then begin
       a:= foo(b);
       writeln(a);
 'for relesae builds' fold }
   end;

This should work. The "begin" should still match the "end"

FoldedView has *some* (but completely untested) preparation for this.

The big task is, that this kind of fold info can not be stared in a single combined list of the current type (FoldMinLevel / FoldEndLevel )

- The Highlighter needs to keep/calculate the info independent of the current FoldLevel

- Current folds, have some info at *every* line in SynEditTextBuffer. User folds are likely to be less in count. So I would suggest *not* to add info to every line.
SynEditTextBuffer could have a TAVLTree storing info about each known userfold.
- SynEdit.ScanFrom => would need to update the additional fold info

- TFoldedView would have to obey the additional FoldInfo

If you have a different idea, how the problem could be solved, please feel free to explain, and we can discuss it.

Best Regards
Martin

Reply by email

Marc Weustink
to Martin Friebe
Martin Friebe wrote 27 lines
Gerard N/A wrote: > I have a rough implementation that seems to work Ok (I'm cautious > because the synedit highlighter is a scary piece of code). > If there is interest, I can post a patch to the bug tracker or here. > > Hi Gerard, I saw the patch you uploaded to the bug system. As indicated the user-token must not interfere with real compiler directives. This should still be easy to solve. Instead of looking for a directive named $REGION, you would look for a comment with special content. The 2nd issue requires more work. consider this: 'for relesae builds' fold } If IsRelease then begin a:= foo(b); writeln(a); 'for relesae builds' fold } end;

For IDE "directives" we use {%somedirective}

Better use them in this case too.

Marc

Reply by email