Wiki

Clone wiki

python-extras / Home

Introduction

This GNU Emacs package will improve your quality of life by adding much-needed features that speed up editing and interaction with Python and its REPL.

Installing

1. Grab the code (you want trunk)

2. Add this to your .emacs:

(add-to-list 'load-path "/path/to/python-extras.el")
(require 'python-extras)

And that's it. If everything worked out OK, you should be up and running. For all the changes to take effect you may have to kill and reopen existing buffers (or just restart emacs.)

Oh, and one more thing: if you're using XEmacs (it's time to switch!) or python-mode.el from Launchpad this package will not work!

Features

Add Parameter (C-c C-p)

Adds a parameter to the method body point is in. If point is not in a valid method body an error is raised. If the function succeeds in adding it, the modified line is displayed in your minibuffer.

Extract...

Extracts the string, s-expression or expression at point to the local block, def or class.

  • C-c C-e C-b for extract to block
  • C-c C-e C-d for extract to def
  • C-c C-e C-c for extract to class

Get Help/Dir at point (C-c C-d and C-c C-h)

These commands only work in the inferior python buffer

Grabs expression at point and invokes dir(expression) or help(expression) respectively.

Inferior Python syntax highlighting

The inferior python buffer will now highlight strings in with the string face. To avoid text "bleeding" multi-line strings are not highlighted.

Send and Switch (C-c C-s)

Sends the buffer to the python interpreter (and launches it if it is missing) and then keeps focus in the buffer you were editing. It will also, if point is not at the end of the buffer, move the point there.

Intelligent Region Shifting (C-S-<up arrow>, C-S-<down arrow>)

Intelligently shifts blocks of Python code around (requires transient-mark-mode to be on) reindenting as necessary when entering and leaving blocks.

Better indentation handling (<tab>)

Python's old "Do What I Mean" indentation worked fine for single lines but not more than one. The new-and-improved version will indent a region to the innermost block.

Updated