Custom folding outside of the lexer

84 views
Skip to first unread message

Paul K

unread,
Jul 10, 2014, 1:28:59 AM7/10/14
to scintilla...@googlegroups.com
Neil:

I'm trying to add custom folding after lexing is already done and can't figure out the sequence of steps to achieve that. It seems to be possible (at least according to the documentation), but I can't figure out why the following is not working:

e:SetFoldLevel(3, e:GetFoldLevel(3) + 1 + wxstc.wxSTC_FOLDLEVELHEADERFLAG)
e:SetFoldLevel(4, e:GetFoldLevel(4) + 1)
e:SetFoldLevel(5, e:GetFoldLevel(5) + 1)
e:SetFoldLevel(6, e:GetFoldLevel(6) + 1)

I'd like to start my fold on line 3 and end on line 6. Just in case, the text I'm applying it to looks like this:

if true then
  if false then
  end
  --#start
  print '1'
  print '2'
  --#end
end

The folding is shown for the "if" statements (Lua lexer), but I also want to add another fold level for the lines marked by --#start and --#end. Is it possible and if so, what am I doing wrong?

Paul.

Neil Hodgson

unread,
Jul 10, 2014, 6:56:08 PM7/10/14
to scintilla...@googlegroups.com
Paul K:

> I'm trying to add custom folding after lexing is already done and can't figure out the sequence of steps to achieve that. It seems to be possible (at least according to the documentation), but I can't figure out why the following is not working:

Implementing folding completely in your own code should work but I don’t expect trying to modify the results of a built in folder will work since your changes will be overwritten when the folder is next called. Its not something I have ever tried.

Neil

Paul K

unread,
Jul 10, 2014, 8:14:42 PM7/10/14
to scintilla...@googlegroups.com, nyama...@me.com
Neil:

> Implementing folding completely in your own code should work but I don’t expect trying to modify the results of a built in folder will work since your changes will be overwritten when the folder is next called. Its not something I have ever tried. 

I realize that and expect that code to be executed in something like UPDATEUI handler, but I couldn't get folding markers to show up, so I wasn't sure if the logic is correct. I tried it in UPDATEUI handler and it does execute (at least once), but I don't see any folding indicators updated:

e:Connect(wxstc.wxEVT_STC_UPDATEUI, function ()
    if e:GetFoldLevel(3) < wxstc.wxSTC_FOLDLEVELHEADERFLAG then -- will use check for bit mask
      e:SetFoldLevel(3, e:GetFoldLevel(3) + 1 + wxstc.wxSTC_FOLDLEVELHEADERFLAG)
      e:SetFoldLevel(4, e:GetFoldLevel(4) + 1)
      e:SetFoldLevel(5, e:GetFoldLevel(5) + 1)
      e:SetFoldLevel(6, e:GetFoldLevel(6) + 1)
    end
  end)

Is there something I'm doing incorrectly?

Paul.

Neil Hodgson

unread,
Jul 10, 2014, 9:43:39 PM7/10/14
to scintilla...@googlegroups.com
Paul K:

> I realize that and expect that code to be executed in something like UPDATEUI handler, but I couldn't get folding markers to show up, so I wasn't sure if the logic is correct. I tried it in UPDATEUI handler and it does execute (at least once), but I don't see any folding indicators updated:
> …
> Is there something I'm doing incorrectly?

I can’t see anything but its not something I have looked into so the sequencing may be wrong. At this point I’d run it in a debugger or add some traces to see what the sequence of fold setting calls is.

Neil

Reply all
Reply to author
Forward
0 new messages