This project is read-only.

How to define own code folding scopes?

Topics: User Forum
Apr 30, 2013 at 9:44 PM
I'm trying use ScintillaNet for a different language. I don't know if its possible and I want to implement my own code folding rules to Scintilla but couldnt figure out how.
For example:
name: Template
file(0-69): sprite\template1\0.bmp  w: 79  h: 79  row: 10  col: 7
file(70-139): sprite\template1\1.bmp  w: 79  h: 79  row: 10  col: 7
walking_frame_rate 3
walking_speed 4.000000
walking_speedz 2.000000
running_frame_rate 3
running_speed 8.000000
running_speedz 1.300000
jump_height -16.299999
jump_distance 8.000000
jump_distancez 3.000000

<frame> 0 standing
   pic: 0  state: 0  wait: 3  next: 1  dvx: 0  dvy: 0  centerx: 39  centery: 79  hit_a: 0  hit_d: 0  hit_j: 0
      kind: 0  x: 21  y: 18  w: 43  h: 62

<frame> 1 standing
   pic: 1  state: 0  wait: 3  next: 2  dvx: 0  dvy: 0  centerx: 38  centery: 79  hit_a: 0  hit_d: 0  hit_j: 0
I have a similar code like this and I want to fold lines between frame and frame_end, bmp_begin and bmp_end, bdy and bdy_end tags. I'm using "gap" LexerName which suits best for the syntax.

Thanks in Advance!..

Maybe remind you english is not my first language...
May 1, 2013 at 8:15 AM
I may be mistaken, but as far as I know, you can't control the folding rules. Folding is determined by the lexer you choose, and you can't change the way it folds. There may be a way to do it if you don't use a built in lexer, but I've never tried, so I wouldn't know which direction to point you.
May 1, 2013 at 8:29 AM
In general ahouse101 is correct. In order to get full control over folding you can't use a lexer. You will be constantly fighting it. However some lexers do give you some options to control folding. These are set with lexer properties. What the property names and values are (if they even exist) for the gap lexer I don't know. You probably need to look at the gap lexer's source code in the Scintilla project.
May 3, 2013 at 1:38 PM
Edited May 3, 2013 at 1:53 PM
You could always set the "folding.enabled" property to "0" (if a lexer supports folding, it also supports that property) and do the folding yourself via calls to INativeScintilla.SetFoldLevel(CurrentLine, mFoldDepth | mCurrentLineFlags), which is how I do it for CustomLexer's in the WPF branch.

I just looked at the gap lexer, and it appears I was wrong, not all lexers support the "folding.enabled" property, the gap lexer being one of the ones that doesn't, so Chris is right, you would probably be fighting the lexer every step of the way.