code folding, a unique problem to python?

J

John Salerno

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? :)
 
F

Fredrik Lundh

John said:
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?

since the Python syntax *has* real block delimiters (look up INDENT and
DEDENT in the language reference), it's an editor issue.

</F>
 
L

Laszlo Nagy

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
 
T

Tim Chase

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?

Yes, it is an editor thing. In Vim, it's as simple as

:set foldmethod=indent

and presto! I'm sure other quality editors provide similar
options. ;)
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? :)

Most editors are "just too simple and concise for [their] own
good". :)

-tkc
 
D

Diez B. Roggisch

John said:
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? :)

Eric3, the Qt-based and in python written IDE can do that. So I'd say
it's an UE-problem - nad it has to be: to perform folding, one has to
find out what constitutes a block. Obviously this CAN be done with
python-code - do it CAN be done in editor code.

Diez
 
J

John Salerno

Fredrik said:
since the Python syntax *has* real block delimiters (look up INDENT and
DEDENT in the language reference), it's an editor issue.

</F>

Interesting. This might help me then, assuming UE can use characters
other than strings to delimit blocks.

Thanks!
 
J

John Salerno

Diez said:
Eric3, the Qt-based and in python written IDE can do that. So I'd say
it's an UE-problem - nad it has to be: to perform folding, one has to
find out what constitutes a block. Obviously this CAN be done with
python-code - do it CAN be done in editor code.

::lowers head in embarassment:: I wanted to try out Eric3, but I
couldn't figure out how to install it! Is there a binary file? All I
found was a zipped file with a bunch of stuff I didn't recognize in it.
There was even a file called eric3.py which I thought might be it, but
running it did nothing.
 
J

Jarek Zgoda

John Salerno napisa³(a):
::lowers head in embarassment:: I wanted to try out Eric3, but I
couldn't figure out how to install it! Is there a binary file? All I
found was a zipped file with a bunch of stuff I didn't recognize in it.
There was even a file called eric3.py which I thought might be it, but
running it did nothing.

You'll need PyQt to run that one. And QScintilla too.
 
P

Paul McGuire

John Salerno said:
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? :)
 
P

Paul McGuire

John Salerno said:
But my question is more general: is it possible to implement code
folding with Python given that it has no real block delimiters?

SciTE can fold Python.
 
J

Jarek Zgoda

Paul McGuire napisa³(a):
SciTE can fold Python.

All other good editors can too. So general answer to this question is
"yes". Because Python *has* real block delimiters...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top