Recent

Author Topic: Source Editor Collapsed Procs  (Read 292 times)

J-G

  • Hero Member
  • *****
  • Posts: 1101
Source Editor Collapsed Procs
« on: July 10, 2026, 06:44:36 pm »
 A minor irritation which I've put up with for too long !

Once any project I'm working on has more than (say)  1000 lines, it is my habit to collapse the procedures that I consider finished using the little squares at the start of each 'Procedure' (or 'Begin') line in the Source Editor. - those containing the + or -.

However once I close a project down, on re-opening it, only the first few Procs come back in that state - in my current project it seems to be the first 32 Procs - beyond that they are all fully expanded so I have to go through the whole source code re-collapsing each.  >:(

Am I missing a short-cut method which would collapse all procs or is '32' a significant figure?
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

paweld

  • Hero Member
  • *****
  • Posts: 1678
Re: Source Editor Collapsed Procs
« Reply #1 on: July 10, 2026, 07:23:44 pm »
I recommend updating Lazarus to the latest version. I used to have those kinds of problems too, but I haven't experienced them lately.
Best regards / Pozdrawiam
paweld

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12540
  • Debugger - SynEdit - and more
    • wiki
Re: Source Editor Collapsed Procs
« Reply #2 on: July 10, 2026, 07:33:18 pm »
The name of the feature is "code folding".

There is no limit/setting how many folds are saved/restored. It should always restore all of them.

One exception: any folds made from selection (rather than keywords) are not restored, but should not affect restoring any folds on the keywords.

Also, of course modifying a source file while the IDE is closed (e.g. updating from git/svn/...) would mean the IDE could not find the code on which it wants to restore code.



As mentioned by paweld: There have been bug fixes in the past. Including such where fold-restoring was early aborted.

You can search the git commit log for files in the SynEdit folder for commits with "fold" in the log-message.

cdbc

  • Hero Member
  • *****
  • Posts: 2869
    • http://www.cdbc.dk
Re: Source Editor Collapsed Procs
« Reply #3 on: July 10, 2026, 07:38:32 pm »
Hi J-G
I use this in my code:
Code: Pascal  [Select][+][-]
  1. {$Region 'BoilerPlate' -fold}
  2.   /// code goes here ///
  3. {$EndRegion 'BoilerPlate'}
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

J-G

  • Hero Member
  • *****
  • Posts: 1101
Re: Source Editor Collapsed Procs
« Reply #4 on: July 10, 2026, 11:08:50 pm »
Ah  -  'Code Folding'  -  there had to be a name for it  ::)

@paweld  -  It may well be the best solution, but one I'm unlikely to take - the amount of coding I do is so small and now that the Triangle Program has gone to the user (Grandson) (for evaluation !)  I have no idea when the next project might begin.

@Benny  -  That's an interesting option  - - - -  though something that I might term a half-way-house.   -  Yes it 'works' such that the code between the two markers is 'folded' when the program is re-opened.  but - - -  I had folded the procs within the $Region  and (as you'll no doubt expect)  once I 'unfolded' the region, the procs were all unfolded. I could 'boiler-plate' many sections of course - and this may well be useful in a new project . . .  we'll have to see.

@ Martin  -  the chance of me updating any code via GitHub is vanishingly small - a few years ago I was persuaded to install 'TortoiseSVN' but I only ever used it once to share some files with  @Lainz (IIRC)

I may well simply 'live with what I have'  -  it was getting to be a pain re-folding 9000 lines  :o
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12540
  • Debugger - SynEdit - and more
    • wiki
Re: Source Editor Collapsed Procs
« Reply #5 on: July 10, 2026, 11:18:30 pm »
I don't recall what errors there were... 32 as a count isn't part of it.

IIRC one issue arose when the distance between 2 folds, or the length of a fold was within specific ranges. The En/Decoding for streaming the fold-info had a bug, and it would get it wrong.

There are keycombos to fold at a certain level.

E.g.
[ + ] procedure // level 1
[ + ] begin// level 2
          if then
[ + ]      begin// level 3

Of course, if unit sections "interface" fold too, then all levels are one higher.

And var/type/class/... all have levels too, which are in the same ranges as the begin/end or whatever.

But you can fold ALL at "level n" (and nested below) per key.  Depending on your config what can fold, it may help.
Check the keymap settings for "fold".

J-G

  • Hero Member
  • *****
  • Posts: 1101
Re: Source Editor Collapsed Procs
« Reply #6 on: July 11, 2026, 10:31:59 am »
Hi J-G
I use this in my code:
Code: Pascal  [Select][+][-]
  1. {$Region 'BoilerPlate' -fold}
  2.   /// code goes here ///
  3. {$EndRegion 'BoilerPlate'}
Regards Benny
After 'sleeping on it' I do see that this method could be more useful than I originally thought !

It has long been my habit to deliniate sections of my code using a comment line - often with useful clues as to what the section is doing, such as :

//- - - - - - - - -   Saving Routines  - - - - - - - - - \\


This morning I've started to replace those comments with :
{$Region 'BoilerPlate' -fold}    //  Initialize   
{$EndRegion 'BoilerPlate'}
{$Region 'BoilerPlate' -fold}    //  Presets 
{$EndRegion 'BoilerPlate'}

and since these regions do remain 'folded' when the project is re-opened, it does save me a great deal of time trying to find the section that needs attention.

I just have to spend the 'one off' time to go through the project.  I'm sure it will be well worth the effort. ;D

Many thanks for the tip.


FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

cdbc

  • Hero Member
  • *****
  • Posts: 2869
    • http://www.cdbc.dk
Re: Source Editor Collapsed Procs
« Reply #7 on: July 11, 2026, 10:41:33 am »
Hi J-G
No worries mate  :D
Cool, then here's another tip for you, instead of:
Code: Pascal  [Select][+][-]
  1. {$Region 'BoilerPlate' -fold} //  Initialize
  2.   /// code goes here ///
  3. {$EndRegion 'BoilerPlate'}
I'd do this:
Code: Pascal  [Select][+][-]
  1. {$Region 'Initialize' -fold}
  2.   /// code goes here ///        
  3. {$EndRegion 'Initialize'}
  4. {$Region 'Presets' -fold}    
  5.   /// code goes here ///  
  6. {$EndRegion 'Presets'}
..."BoilerPlate" was just an example  ;D
Regards Benny
« Last Edit: July 11, 2026, 10:45:34 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

J-G

  • Hero Member
  • *****
  • Posts: 1101
Re: Source Editor Collapsed Procs
« Reply #8 on: July 11, 2026, 11:17:14 am »
Ah!!!  -  I did wonder why 'BoilerPlate'  but I am familiar with that tern in respect of Word Processing.  It was the major reason that Word Perfect was (and still is !!) superior to MS Word. 

WP came from the practical background of the legal profession where the concept of sections of pre-prepared text - BoilerPlates - could be selected for inclusion (or not) in a contract. MS Word came from a purely theoretical 'want' to provide a word processing facility.

It makes even more sense now !
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018