Python Mode for Emacs
Type C-c? when in python-mode for extensive help. Also see the Emacs OO-Browser support for Python.
Indentation
Primarily for entering new code:
- TAB
Indents line appropriately.
- LFD
Inserts newline, then indent.
- DEL
Reduces indentation, or delete single character. Primarily for reindenting existing code.
- C-c:
Guesses py-indent-offset from content; changes locally.
- C-u C-c:
Same, but changes globally.
- C-c TAB
Reindent region to match its context.
- C-c <
Shifts region left by py-indent-offset.
- C-c >
Shifts region right by py-indent-offset.
Processing Regions of Code
- C-c C-b
Marks block of lines.
- M-C-h
Marks smallest enclosing def.
- C-u M-C-h
Marks smallest enclosing class.
- C-c #
Comments out region of code.
- C-u C-c #
Uncomment region of code.
Moving the Point
- C-c C-p
Moves to statement preceding point.
- C-c C-n
Moves to statement following point.
- C-c C-u
Moves up to start of current block.
- M-C-a
Moves to start of def.
- C-u M-C-a
Moves to start of class.
- M-C-e
Moves to end of def.
- C-u M-C-e
Moves to end of class.
Executing Python Code
- C-c C-c
Sends the entire buffer to the Python interpreter.
- C-c |
Sends the current region.
- C-c !
Starts a Python interpreter window; this will be used by subsequent
C-c C-corC-c| commands.
Variables
py-indent-offsetIndentation increment.
py-block-comment-prefixComment string used by py-comment-region.
py-python-commandShell command to invoke Python interpreter.
py-scroll-process-buffer‘t’ means always scroll Python process buffer.
py-temp-directoryDirectory used for temp files (if needed). ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access