Page 1 of 1

Code Folding Query

Posted: Thu Jun 25, 2009 3:32 am
by gwgs
Is there a way to fold code to a specified level with one mouse click or keyboard function?
eg
fold all the def level code, but not the class level folding

from:

Code: Select all

class xyz:
    def abc(self):
          code
          code

    def def(self):
          code
          code
to:

Code: Select all

class xyz:
   def abc(self): ...
   def def(self): ...

Thanks in advance

Grant

Posted: Thu Jun 25, 2009 4:38 am
by jussij
Hi Grant,
Is there a way to fold code to a specified level with one mouse click or keyboard function?
There is no function or feature in Zeus that does this, but it should be fairly easy to implement as a Zeus script ;)

The pseudo code for the macro script would be something like the following:

Code: Select all

Save the current cursor details

Get the text for the current line

Calculate the whitespace indent level for the current line

For all the lines in the current document
   If line has the same indent level

        Move the cursor to this line

        Call the FoldingLineClose or FoldingLineOpen function to open/close the fold
   End If
End for

Restore the saved cursor details
NOTE: The FoldingLineClose and FoldingLineOpen are keyboard function that open and close the folds for the current line.

For more information on how to write such a script refer to the Zeus help and search for the Builtin Functions topic in the index.

Also there are lots of scripting examples in the zScript folder ;)

Cheers Jussi