On 3/5/07, Rob McMullen <[EMAIL PROTECTED]> wrote:
This is great, Stani!
Thanks, I was suprised myself as well. Scintilla has already a lot of
functionality, which is not always fully exploited.

Here's a shot of what it does to a C++ file.  Even though coming from
the python side we don't know how C++ is parsed, the folding seems to
give us a good idea of the structure.  We could do some pattern
matching on the items in the tree and deduce classes and relationships
from there, rather than writing an entire C++ lexer in python.  This
has huge potential.
Yes it seem to work quite well. I think indeed this is the best base
to fetch the documents hierarchy, maybe even for python. Things which
I had on my mind was:
- collect the styles of every line by splitting a line into words and
symbols and get the style of the first charachter of them
We could write a generic method which translates a list of styles of
the line into a 'style' for a tree item, which includes an icon
bitmap, text colour, ... This will pimp up the generic fold explorer
as if it was already a specific language class explorer. First we
should do as much generic as possible, as than the language specific
part will be reduced to a minimum. For the language specific part we
need clear guidelines so other people can easily write their own. Even
for the language specific class explorer, we could provide already
some tools. For example we should have a standard mechanism for fake
nodes: in python this is eg. if statements, try except, etc... Fake
nodes will be invisible in the explorer and the tree level of the
children is not increased, but is the same as the fake node.

For example:
def hello_world():
 pass
if linux:
 class Widget:
    def __init__(self):
      pass

Becomes in the tree:
def hello_world():
(if linux:)  #invisible
class Widget:
  def __init__(self):

I think by recognizing the fake nodes (with eg regular expression) we
can transform easily the fold explorer in the class explorer, but
still I think the fold explorer is still valuable on its own even if
there is also the class explorer implemented.

Labels are easy to implement, but are language specific. For a
language one can define a regular expression what defines a label (in
python most used is '#---label'). Than in getHierarchy we get:
if foldBits&stc.STC_FOLDLEVELHEADERFLAG:
 (...)
elif re.sub(label):
 (...)

We could define checkboxes with options what should appear in the
class explorer. For example todo could be inside or not (implemented
same as label). But for a seperate todo table, there is no need for
hierarchy. You just need a regular expression with finditer.

I did have to change setText to the following, because apparently the
C++ file I chose (Editor.cxx from the Scintilla source) has some
characters outside the 7-bit ascii code, and I got:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xdd in position
32785: ordinal not in range(128)

    def setText(self,text):
        styled = "\0".join(text) + "\0"
        self.Clear()
        self.AddStyledText(styled)
        self.Colourise(0, self.GetTextLength()) #make sure everything is lexed
        wx.CallAfter(self.explorer.update)

Is this not more generic?
   def open(self,fileName, language, encoding=DEFAULT_ENCODING, line=0):
       self.setLanguage(language)
       self.setText(open(fileName).read(),encoding)
       wx.CallAfter(self.GotoLine,line)

   def setText(self,text,encoding=DEFAULT_ENCODING):
       self.encoding   = encoding
       self.SetText(text.decode(encoding))
       self.Colourise(0, self.GetTextLength()) #make sure everything is lexed
       wx.CallAfter(self.explorer.update)

I wonder if there's a way to determine from the python side which
languages support folding and which don't?  HTML, for example, doesn't
produce any folding -- I had thought it might because of the nesting
of tags.
Me too. Josiah, any idea?

Realtime updating is also which belongs to the generic part. Therefore
we need to be able to diffs between a previous state and a current
state and to add a property expanded (True/False) to the nodes. Again
if we implement this in a generic way, we get everything for free for
all languages.

Another thing is that fold explorer will be a good tool for what I
will define local code blocks. For example now SPE compiles the whole
file to check for syntax errors which SPE underlines with a red
marker. With Scintilla we could get the visible lines on the screen,
fetch which codeblocks are involved from the fold explorer and than we
need only to compile these blocks to check for syntax errors. This
means for huge files only a very small proportion is shown on the
screen, so you could have realtime syntax checking there. Maybe with
subprocesses this could be done also for other languages as python.
This would be amazing.

Stani

--
http://pythonide.stani.be

Reply via email to