Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python code-folding in emacs?

I have many classes and defs ...

I want to have + and - keys before class and def to collapse the class or open it ( toggle it ).

How i can do this?

like image 893
Mohammad Efazati Avatar asked Mar 09 '11 10:03

Mohammad Efazati


People also ask

How do I fold a python code in Vim?

It maps alt+1 to fold the first python indent level (class definitions and functions), alt+2 to fold the second level (class methods), and alt+0 to unfold everything. It makes sure it only folds one level and doesn't fold any of the nested sub levels. You can still use za to toggle folding for the current block.


1 Answers

Hideshow works out of the box and folds python code. It is built-in my version of emacs (24.3.1)

I have never needed more than these commands:

M-x hs-minor-mode M-x hs-hide-all M-x hs-show-all 

To toggle use C-c @ C-c which probably needs rebinding. You might also want to setup a hook in your .emacs file for hs-minor-mode to automatically be enabled when opening .py files.

I use it in combination the following to jump around.

M-x imenu <my_func_name> 
like image 187
Greg Avatar answered Sep 30 '22 21:09

Greg