In all emacs python modes that I have used, pressing TAB
(bound to indent-for-tab-command
) will "intelligently" indent to the current block level. Repeatedly pressing TAB
will then out-dent one level at a time, in case you want to close a block. If you select a region of text first, then TAB
should indent the whole region to the current block level (assuming that transient-mark-mode
is activated), but this doesn't work if there are intervening blank lines. Better to use C-c >
and C-c <
(bound to python-indent-shift-{right,left}
) if you need to indent/outdent whole regions of code.
But eflanigan00's comment is correct: it is good programming style to keep blocks of code short, especially if they are deeply indented. If you find you need to scroll back and forth a lot in order to follow a program's structure, then it's probably time to refactor into shorter functions.