code folding, a unique problem to python?

Laszlo Nagy gandalf at designaproduct.biz
Thu Jun 15 12:13:17 EDT 2006


John Salerno írta:
> Specifically, I'm using UltraEdit and perhaps there's no way perfect way 
> to implement code folding with it, given how it uses its syntax 
> highlighting file to do so (i.e., you have to specify an "Opening" and 
> "Closing" character in which to enfold code, such as braces).
>
> But my question is more general: is it possible to implement code 
> folding with Python given that it has no real block delimiters? Or is 
> this still a matter of which particular editor/IDE you use? For my part 
> I've tried (as was suggested elsewhere) to use 'def' as an opening and 
> closing keyword, but this of course will enfold everything between two 
> defs, even if you have more code between your function definitons (such 
> as a new class definition).
>
> So maybe I'm stuck in UE, but I'm curious if there is some general way 
> to do this, or is Python just too simple and concise for its own good? :)
>   

There are many editors that do this. For Python, folding is based on 
IDENT and DEDENT tokens. You can look for their definition in the Python 
Language Reference.

For example, SPE can do this. See this screenshot:

http://stani.be/python/spe/screenshots/spe-linux-blender.png


Best,

  Laszlo




More information about the Python-list mailing list