Monday, December 24, 2007

Emacs code folding with python

I tried out several packages. outline-mode, allout, ecb, and hide-show. hide-show was the only package that I can work with for 'code-folding'. By the way, it is surprising that ECB didn't have code folding mode, even for major languages like C/C++.

Using hide-show is very easy. No need to install extra package.
M-x hs-minor-mode will activate it.

The basic functions are:

And, maybe this will be useful:

It has a short cut, too. I am not used to it, at this time. Shortcut makes sense, but I call this by M-x. Maybe when I'm tired of function name, I will use their short cut key because I generally avoid my own short cut.


Jesse Aldridge said...

Useful. Thanks for posting!

This post is the #1 google result for "python code folding emacs"

Ryan said...

hs-hide-all is also a helpful one to know. It sure cleans up the screen quick. ;-) I wish I'd known about this a while ago. I'd tried using folding mode before, but it was just a mess.

jdb said...

The shortest most useful tips. You'd be in my city, you won a free beer.

Neilen said...

Using emacs 23.1 I find that hide-show mode does absolutely nothing in a python buffer for me! I do M-x hs-hide-all and nothing happens. Do I need to do some further configuration?

Raymond said...

@Neilen To be honest, I have neglected hide-show mode. I settled in ECB. hide-show is good for flat view, but with ECB, I realized that hide-show like summary is unnecessary, because there is dedicate window for class layout (including methods. My favorite layout is 'leftright2'. )

Neilen said...

Interestingly, I stumbled across hide-show mode again, as well as this blog post :) Now, in emacs 23.2.1 as shipped with Ubuntu 11.04 it seems to work as avertised. Weird keybindings too (C-c @ C-c to toggle)