Recent

Author Topic: Region fold all not working?  (Read 583 times)

chrnobel

  • Sr. Member
  • ****
  • Posts: 283
Region fold all not working?
« on: May 13, 2022, 07:20:41 pm »
Using Lazarus 2.2.0 I cannot get {region /fold} to work, when I try to fold all, using Alt-Shift 1.

All procedures etc. are folded as expected, but the region remains unfolded - however I am able to fold one region by right clicking on the -  next to {region /fold}.

The Alt-shift 1 key is bound to fold all.

And if I manually fold one region by mouse clicking, and then press the Alt-shift 1, the region (but not the procedures) actually opens again!
« Last Edit: May 13, 2022, 07:23:39 pm by chrnobel »

dsiders

  • Hero Member
  • *****
  • Posts: 634
Re: Region fold all not working?
« Reply #1 on: May 13, 2022, 09:11:17 pm »
Using Lazarus 2.2.0 I cannot get {region /fold} to work, when I try to fold all, using Alt-Shift 1.

All procedures etc. are folded as expected, but the region remains unfolded - however I am able to fold one region by right clicking on the -  next to {region /fold}.

The Alt-shift 1 key is bound to fold all.

And if I manually fold one region by mouse clicking, and then press the Alt-shift 1, the region (but not the procedures) actually opens again!

There is no "Fold all" key mapping. The default mapping for Alt+Shift+1 is "Fold to Level 1". Did you change it? Is your region directive at that level?

It works for me when the region is at the correct level. If does not fold if it is at the same level as the unit, interface, implementation, or end keywords.  You can use Alt+Shift+- and Alt+Shift+= for these regions though.

HTH
Lazarus 2.0.12, 2.2.0, 2.2.2, 2.3.0 (Git) / FPC 3.2.0, 3.2.2, 3.3.1 / x86 64-bit / Windows 8.1
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

chrnobel

  • Sr. Member
  • ****
  • Posts: 283
Re: Region fold all not working?
« Reply #2 on: May 13, 2022, 09:33:49 pm »
Did you change it?
It is a fresh installation of Lazarus, so no.

Quote
Is your region directive at that level?
I have no idea, where can I check which level a regions directive has?

dsiders

  • Hero Member
  • *****
  • Posts: 634
Re: Region fold all not working?
« Reply #3 on: May 13, 2022, 10:51:21 pm »
Did you change it?
It is a fresh installation of Lazarus, so no.

Quote
Is your region directive at that level?
I have no idea, where can I check which level a regions directive has?


I do not know... other than my observations.

Code: Pascal  [Select][+][-]
  1. unit testimagemain;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;
  9.  
  10. type
  11.   {$region 'Prior to level 1... Alt+Shift+1 does not fold. But Alt+Shift+- does.'}
  12.   { TForm1 }
  13.   TForm1 = class(TForm)
  14.     Image1: TImage;
  15.     Image2: TImage;
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     {$region 'TForm1 is at level 1... Alt+Shift+1 folds.'}
  19.     procedure FormCreate(Sender: TObject);
  20.     {$endregion}
  21.   private
  22.  
  23.   public
  24.  
  25.   end;
  26.   {$endregion}
  27.  
  28. ...
  29.  
  30.  
Lazarus 2.0.12, 2.2.0, 2.2.2, 2.3.0 (Git) / FPC 3.2.0, 3.2.2, 3.3.1 / x86 64-bit / Windows 8.1
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7876
  • Debugger - SynEdit - and more
    • wiki
Re: Region fold all not working?
« Reply #4 on: May 13, 2022, 10:59:17 pm »
regions don't have (that kind of) level.

The keyboard folding "fold to level n" (usually Alt-Shift-<num>) only works on Pascal-code.

For Pascal code levels depend on the config and code.
If you did set "unit" to be foldable, then that is likely the most outer level. "implementation (if configured) is then the 2nd level.

If you don't have those fold-able then "procedure" may be your first level, and then each nested begin inside opens a new level.


The fold gutter itself has a context menu that will (if applicable) offer "hide [all] comments [in selection]" and/or "fold inactive IFDEF"

But no such helper for regions exists. => they can only be folded individually. One by one.
 


You can inspect the code in unit SynGutterCodeFolding.

There you could add such an entry to the context menu. But it will require some study of the existing code.

chrnobel

  • Sr. Member
  • ****
  • Posts: 283
Re: Region fold all not working?
« Reply #5 on: May 14, 2022, 12:59:39 pm »
For Pascal code levels depend on the config and code.
If you did set "unit" to be foldable, then that is likely the most outer level. "implementation (if configured) is then the 2nd level.

If you don't have those fold-able then "procedure" may be your first level, and then each nested begin inside opens a new level.
It is pure Pascal, so how do I see(set) if the unit is foldable?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7876
  • Debugger - SynEdit - and more
    • wiki
Re: Region fold all not working?
« Reply #6 on: May 14, 2022, 01:22:54 pm »
It is pure Pascal, so how do I see(set) if the unit is foldable?

Menu: Tools > Options > Editor > Code Folding
Set the checkbox for the "unit" entry.

The "Fold" / "Hide" radio buttons are available only for certain elements, such as comments.
- Fold: keep the first line visible
- Hide: do not even show the first line (the unfold symbol will then be on the line above)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7876
  • Debugger - SynEdit - and more
    • wiki
Re: Region fold all not working?
« Reply #7 on: May 14, 2022, 01:40:17 pm »
Some background....

Ignore IFDEF / REGION ... => Then all folding is hierarchically structured/nested.

That means if you have
Code: Pascal  [Select][+][-]
  1. if a then begin // fold start
  2.   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
Code: Pascal  [Select][+][-]
  1. if a then begin
  2.   ...
  3.   {%REGION}
  4.   ...
  5.   end;
  6. ...
  7. {%ENDREGION}
  8.  

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)


chrnobel

  • Sr. Member
  • ****
  • Posts: 283
Re: Region fold all not working?
« Reply #8 on: May 15, 2022, 06:38:21 pm »
I really don't get it.

I have tried to uncheck folding for everything, except region, but the result remains the same, the only way I can fold regions is by clicking the the - box at the left side, region by region.

And if i make unit foldable I can fold the entire unit, but still not the region (which should then be level 2, aka alt-shift-2).

And the editor nicely shows the beginning and end of the region.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7876
  • Debugger - SynEdit - and more
    • wiki
Re: Region fold all not working?
« Reply #9 on: May 15, 2022, 06:58:09 pm »
I have tried to uncheck folding for everything, except region, but the result remains the same, the only way I can fold regions is by clicking the the - box at the left side, region by region.

As, I told you:
regions don't have (that kind of) level.

The keyboard folding "fold to level n" (usually Alt-Shift-<num>) only works on Pascal-code.
The region-folds (and also the IFDEF folds) are not part of the "fold to level n".
There is no config to change that.

I agree that it would be nice to have some similar feature.
It just needs to be implemented by someone.

I did write "some similar feature" => because the current "fold to level n" are for various reason reserved to >>source-code-keyword<< folding.
But a new menu-entry or keyboard-combo "fold region to level n" or "fold all region in selection" or "fold all region" ... Well any of them would be welcome.

chrnobel

  • Sr. Member
  • ****
  • Posts: 283
Re: Region fold all not working?
« Reply #10 on: May 15, 2022, 07:41:16 pm »
The region-folds (and also the IFDEF folds) are not part of the "fold to level n".
There is no config to change that.
Ok, now I got it, thanks for the explanation  ;)

Quote
I agree that it would be nice to have some similar feature.

Indeed, it would be very useful.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 7876
  • Debugger - SynEdit - and more
    • wiki
Re: Region fold all not working?
« Reply #11 on: May 15, 2022, 08:30:54 pm »
One thing you can do, and while not ideal... it may help you

Record an "editor macro". Menu: View > Editor Macro => then the record button
(also search the wiki on how to use editor macros / make sure you save the recorded macro to the IDE list)

In the macro do:
ctrl-e  // search by typing
{
%
r
e
g
i
o
n
cursor-left
alt-shift- -  // fold at cursor (check if this is the correct combo for "fold at cursor")
cursor-down

end the macro

Assign this macro to a key.
Now you can play the macro repeatedly via the key. Each time it find and folds the next region.

Don't forget: move the macro to the IDE LIST


 

TinyPortal © 2005-2018