PythonWin/Scintilla aggressive folding...

Neil Hodgson neilh at scintilla.org
Tue Jul 25 21:49:50 EDT 2000


    [PythonWin / Scintilla folds away comments that belong to next
definition]

    Mark's comments are correct but I'd like to explain a little more.

    Scintilla uses a simple fold discovery algorithm that relies mostly on
indentation and only looks at a narrow window of lines. Often, comments are
not indented with the executable code so are treated by the folder as having
a 'neutral' indentation level which will bind to the indentation level of a
nearby piece of executable code. Blank lines also have neutral indentation
level as they are often sprinkled within a function. This allows a function
like

def z(y):
    x = 1
#  x = sin(y)

    return x*2

   to fold correctly. It has the downside of binding the top level comment
in your example to the preceding definition.

   This could be fixed by doing a much better job of parsing the Python code
or by doing some more tweaks such as detecting this particular common case.
The argument against a really good parser is the need for performance as the
folding structure is being continuously recalculated as editing occurs.

   Eventually I'll do some more work on the code folder but haven't yet
found a good alternative. It'd be great if someone else was interested in
working on this.

   Neil






More information about the Python-list mailing list