Mohammad Efazati
Mohammad Efazati

Reputation: 4910

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?

Upvotes: 46

Views: 14030

Answers (2)

Greg
Greg

Reputation: 2024

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>

Upvotes: 51

Eric O. Lebigot
Eric O. Lebigot

Reputation: 94475

You can get code folding (and more) with CEDET. With CEDET, you should consider putting the following setting in your emacs configuration file:

(global-semantic-folding-mode t)

CEDET handles Python and other languages.

Other ideas about how you can make emacs even more convenient when programming can be found on StackOverflow.

Upvotes: 6

Related Questions