Forum > Options

Code folding tree — highlighting current foldable block

(1/2) > >>

furious programming:
I have it set in the IDE settings to always color the folding tree in gray (same color for different tree states), see the first attachment. I would like the tree to be colored white, but only for the code block that caret is inside (and all nested blocks), see the second attachment. Can this be set somehow? I looked for suitable options, but found nothing.

By the way, I think it would be nice if, in addition to the folding tree itself, you could also define the color of the line numbers for the active block — see the third attachment. But for now, it would be enough for me if the folding tree could be highlighted.

Martin_fr:
No, there is on such option at current.

You probably know: https://wiki.lazarus.freepascal.org/New_IDE_features_since#Outline_for_Pascal_Sources
But it is all blocks, all the time.
You can configure the colors, use dotted lines, only use the lines, and don't change the keyword, ....

You can add a feature request for the gutter.

The fold gutter has it's own unit => so code is easy to find. In case you want to look yourself.


Unfortunately that means, line numbers are in a separate unit, in their own class. And they have no idea folding even exists. So that is a bit harder to add.

furious programming:

--- Quote from: Martin_fr on February 12, 2024, 10:05:38 pm ---You probably know: https://wiki.lazarus.freepascal.org/New_IDE_features_since#Outline_for_Pascal_Sources
But it is all blocks, all the time.

--- End quote ---

Yes, I know this, but — as you wrote — it is intended for all blocks.


--- Quote ---You can add a feature request for the gutter.

--- End quote ---

I briefly looked through the SynEdit code, but there is so much of it that it would take a million years to find anything appropriate, so I just have to create a feature request. I'm not familiar with the code for this control, and it's quite complex, so it's best if someone who knows its implementation will take care of it.

As for me, I need something that will somehow help me point out the block where the caret is located. I think that highlighting the block in a different style for the folding tree will be sufficient. I think it would be good to be able to choose (checkbox) whether the highlighting should apply only to the current block (in which the caret is located) or also to all nested blocks. See the first and second attachment. I would probably use highlighting only the current block (second attachment) to better understand what level of nesting the instructions I am modifying are at.

Martin_fr:
Units SynGutterCodeFolding and SynGutterLineNumber,

Both can access SynEdit.CaretY => so you know where the caret is. (doesn't handle multi caret)

Also they get SynEdit.Highlighter

If 
  SynEdit.Highlighter is TSynCustomFoldHighlighter
then

try getting FoldBlockMinLevel (atype = 0) for the current caret line

Then go up/down, and as long as the FoldBlockMinLevel does not go below what it was in the caret line....


May need some fine tuning. But generally that should do...

atype 1/2 are ifdef and region (if avail / FoldTypeCount > 1)
in the pas hl

FoldBlockEndLevel
  level at the end of the line => e.g. if a line has BEGIN then that is included, but also if it has END.
  So  a line with END will have a count lower than you want, but  FoldBlockEndLevel is also the level at the START of the next line. So use that.

FoldBlockMinLevel
       end else begin
  The FoldBlockMinLevel shows you that the line closed stuff, even if it then opens them again.

So with using both of them you should be able to get it right.



Martin_fr:
Done in 3.99.

Small "curiosity"...


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type tfoo = class  private  a: integer;  publicend;...procedure bar;  var    a: integer;  begin  ... 
The "private" and the "var" block are closed by the "public" and "begin".

Technically the spaces at the start of the line, are part of those 2 blocks. But in order to have a nice fold-tree in the gutter, the blocks ends are moved to the line before the closing keyword (because that closing keyword (usually) opens a new block, and having close and open overlap into the same line does not look pretty.

As a result those leading spaces are not part of the "private" / "var" block. But also not of the next block. They are attributed to the enclosing block (class/procedure) and highlighted accordingly.

This does not happen if there are non-spaces on the closing line before the "public" and "begin".

Of course the attribution could be improved. This was simply the easiest way. And for now, this is "by design".


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure foo;begin  ...  if a then begin    ...  end else begin    ...  end;  ...end;Here the highlighted block works correct.
- up to and including the "end", the block above is highlighted
- on the "else" it is in neither of the "then" nor "else"s begin/end. => the procedures begin/end is active
- after and on the "begin", the block below is highlighted


Navigation

[0] Message Index

[#] Next page

Go to full version