Sign in Join

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

Mailing lists / lazarus / 2023-02

Folding ?

7 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

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

Michael Van Canneyt

Hi,

Is it possible to enable/disable code folding on a per-language basis ?

I would like to enable it only for HTML/XML and disable for all other languegs.

(I'd add JSON, but there is no language JSON in the IDE ;),

Currently it seems you can only do this by enabling code folding globally, and then disable it for all constructs in all languages except the ones you want... But it can be that I missed the option somewhere...

Michael.

Reply by email

Martin Frb
to Michael Van Canneyt
Michael Van Canneyt wrote
Hi, Is it possible to enable/disable code folding on a per-language basis? ?

No, or only in the way you described below. Or by changing the source in each highlighter, and make the pretend they don't fold.

In any case, there also remains the "fold selected lines" folding.

Show quoted text 6 lines
Currently it seems you can only do this by enabling code folding globally, and then disable it for all constructs in all languages except the ones you want... But it can be that I missed the option somewhere...

Reply by email

Michael Van Canneyt
to Martin Frb
Martin Frb wrote 7 lines
On 19/02/2023 12:28, Michael Van Canneyt via lazarus wrote: > > Hi, > > Is it possible to enable/disable code folding on a per-language basis? ? No, or only in the way you described below. Or by changing the source in each highlighter, and make the pretend they don't fold.

That seems a strange way.
Since folding can be globally switched on and off, it should also be possible to switch it on/off on a language basis.

In any case, there also remains the "fold selected lines" folding.

That would defeat the purpose.
I use the folding to see if the HTML tags are closed properly without having to select them.

Michael.

Reply by email

Martin Frb
to Michael Van Canneyt
Michael Van Canneyt wrote 16 lines
On Sun, 19 Feb 2023, Martin Frb via lazarus wrote: > On 19/02/2023 12:28, Michael Van Canneyt via lazarus wrote: >> >> Hi, >> >> Is it possible to enable/disable code folding on a per-language >> basis? ? > No, or only in the way you described below. Or by changing the source > in each highlighter, and make the pretend they don't fold. That seems a strange way. Since folding can be globally switched on and off, it should also be possible to switch it on/off on a language basis.

Well, it just hasn't been implemented. There is no reason not to add it, if someone wants to do it.

To entertain my lack of imagination: What is the issue, if e.g. Pascal shows fold indicators, and you just don't use them?

Show quoted text 7 lines
> > In any case, there also remains the "fold selected lines" folding. That would defeat the purpose. I use the folding to see if the HTML tags are closed properly without having to select them.

You don't have to select them.

If you do select text, the gutter will show an additional fold (actually "hide") symbol, allowing you to collapse whatever text is selected.

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.

Reply by email

Michael Van Canneyt
to Martin Frb
Martin Frb wrote 22 lines
On 19/02/2023 19:06, Michael Van Canneyt wrote: > > > On Sun, 19 Feb 2023, Martin Frb via lazarus wrote: > >> On 19/02/2023 12:28, Michael Van Canneyt via lazarus wrote: >>> >>> Hi, >>> >>> Is it possible to enable/disable code folding on a per-language basis? ? >> No, or only in the way you described below. Or by changing the source in >> each highlighter, and make the pretend they don't fold. > > That seems a strange way. Since folding can be globally switched on and > off, it should also be > possible to switch it on/off on a language basis. Well, it just hasn't been implemented. There is no reason not to add it, if someone wants to do it. To entertain my lack of imagination: What is the issue, if e.g. Pascal shows fold indicators, and you just don't use them?

For starters, some people think adding

{%region /fold}

to the code is a good idea. I think not.

Secondly, I sometimes inadvertently click on the fold markers.

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.

(strictly my personal opinion)

Show quoted text 14 lines
>> In any case, there also remains the "fold selected lines" folding. > > That would defeat the purpose. I use the folding to see if the HTML tags > are closed properly without having > to select them. You don't have to select them. If you do select text, the gutter will show an additional fold (actually "hide") symbol, allowing you to collapse whatever text is selected. 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.

Michael.

Reply by email

Martin Frb
to Michael Van Canneyt
Michael Van Canneyt wrote 6 lines
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 patterns.
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.

Show quoted text 6 lines
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).

Show quoted text 10 lines
> 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 options"
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.

Reply by email

Martin Frb
to Martin Frb
Martin Frb wrote 6 lines
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...)

There seems to be a bug. That needs an IDE restart (after changing the option) for the line to be painted...

Reply by email