Reputation: 3709
(This question applies to any language -- Python and Haskell are examples -- that lets you organize code via indentation instead of parentheses. Such languages are more readable and take less time to write, at least according to people like myself.)
The code I'm reading has some big indented passages that don't fit on one screen, or sometimes ten screens (I use a big font), and it'd be much easier to see what was going on if I could go to some line and press a keyboard shortcut to hide everything that follows until the next line that starts at the same position or farther left.
I've found a number of code-folding packages for Emacs, but all seem to suffer at least one of these problems:
{{{ ... }}}
) to know whereUpvotes: 2
Views: 578
Reputation: 17412
For Python, use elpy
- the Emacs Python Development Environment. It has a built-in module for code folding:
Elpy offers code folding by enhancing the builtin folding minor mode Hideshow.
When opening a python buffer, Elpy will indicate foldable things with an arrow in the left fringe. Clicking on an arrow will fold the corresponding code blocks. Folded code blocks can be unfolded by clicking on the … button at the end of the line.
If you don’t want to use your mouse, you can achieve the same thing with the function
C-c @ C-c (elpy-folding-toggle-at-point) Toggle folding for the thing at point, it can be a docstring, a comment or a code block.
Upvotes: 1