[Lazarus] Folding ?

Martin Frb lazarus at mfriebe.de
Sun Feb 19 21:49:23 CET 2023

On 19/02/2023 21:12, Michael Van Canneyt wrote:
> On Sun, 19 Feb 2023, Martin Frb wrote:
>> To entertain my lack of imagination: What is the issue, if e.g. 
>> Pascal shows fold indicators, and you just don't use them?
> Secondly, I sometimes inadvertently click on the fold markers.
Ok, good reason.

That the thing, a lot of features are tested against my own usage 
patterns / experience. Simply because I don't know other people usage 
I could imagine the accidental clicks to happen when trying to select 
text with the mouse (or set the caret). Neither of those 2 I usually do 
by mouse.

> The above 2 reasons are why I disabled it. Also, I think that if you need
> folding in Pascal, your code is not very well structured. As a general 
> rule,
> I think a procedure may not occupy more than 50 lines. If you adhere to
> that, folding is simply not needed.
Actually there used to be another reason for folding (but that has been 
mitigated a decade ago).

And that other reason is why back then I spent the time to make it work...
=> Fold (several consecutive) entire procedures.

I occasionally find it useful while writing code in one procedure, to 
have another procedure in view for reference. (E.g. refactoring, moving 
code around)
If that was in the same unit (and back then one unit could only be open 
in one SourceEdit window), then I just folded all the procedures in between.
Now, I just open the unit in 2 windows, and have them side by side.

And in code that does have $IFDEF, it's sometimes nice to hide that.
As well as comments, including single line comments (hence hide/fold).

>> Btw, folding may not be the best way to check for correct html nesting.
>> IIRC, the highlighter tries to find a matching-name closing tag, even 
>> if that means to skip other tags.
> No doubt. But there are other uses: in large html structures (HTML can be
> very verbose in some CSS frameworks, there is no way around it) , it 
> helps to be able to see the larger structure.
> Ideally, the fold indicators are also not visible in HTML/XML, but I 
> can simply right-click a div and ask to collapse/expand that div.

That could also be added.
There are keyboard shortcuts to fold at word at cursor (if that word is 
starting a fold).

Adding that to the menu should not be to hard.
And neither should it be hard to add an option to hide the fold outline.
But as usual it needs to be done.

I don't mind feature requests for those. But it's likely some time 
before I would get to it.

Hiding the fold-outline gutter (global / for all languages) is probably 
easy. So if folding by key works for you , and you don't mind that the 
keys work for pascal code too => that I can probably squeeze in.

Or, if it is just against accidental clicks => go to "Mouse advanced 
Remove all (or at least left button) mouse actions for the fold-tree, 
and fold nodes. Then nothing happens if you click there.
Or change the clicks, so they only work with a modifier key (as protection)

On "Editor > Display" you can also change the "Gutter Separator index" 
from 3 to 4 => then the separator (a gray line /color can be changed) 
will be between the fold-tree and the text (and with that another 1 or 2 
pixels distance / not much, but)
(the preview in the options seems to be not showing the effect...)

Btw, If the caret is at a html tag, the matching tag is highlighted, so 
you can see those without needing the gutter outline.

More information about the lazarus mailing list