My little research suggests that the simplest way to get code folding for Python in Emacs (24.4) is (see the comment of @scytale on this answer):
(add-hook 'python-mode-hook 'outline-minor-mode)
This works almost great. The problem is the scope of folding. Consider the following example:
if foo == bar:
do 1
do 2
else:
do 3
do 4
do 5
do 6
If point
in in either of the first three lines then folding looks like:
if foo == bar:...
else:
do 3
do 4
do 5
do 6
So far so good. However, if the point is in lines 4-6 then folded view is:
if foo == bar:
do 1
do 2
else:...
Note that do 5
and do 6
are folded as well. Is there a way to limit the folding only to the right block?