Python EMACS Extensions

This package contains three extensions to python-mode which I find useful when programming python. They are:

They are packaged separately so that one may choose which to use.


I really like to run and debugging python programs from inside of emacs but I have wanted to see a couple of additional features added to python-mode.el This applies to executing the program as well as running with a symbolic debugger.

py-mode-ext.el is a short bit of emacs lisp which I assert accomplishes the above. I am new to writing elisp so I welcome comments and suggestions.

To use these extensions, py-mode-ext.el is placed in my emacs load path. See the code that I inserted into my .emacs file below.

When the user invokes py-execute-prog or py-call-pdb, the following sequence occurs.

  1. It first reads from the mini-buffer the name of the initial file to be executed by the interpreter. If no history exists, then the file behind the current buffer is suggested. The user may then substitute any file he wishes as the initial file to be executed by the interpreter. It will be save in a history list.

  2. Next, it reads from the mini-buffer the argument string to be passed to the program being interpreted. Again, if there is a history of arguments, the most recent will be selected. The user may over ride the suggestion. The argument string passed to the program will be saved in a history list.

  3. It next saves all the modified buffers based on queries.

  4. Finally, it invokes python on the initial file or it invokes pdb on the initial file.

When the user initiates the command for pychecker, it will check whether any buffers have been changed and ask whether you want any of those saved. Then it will run PyChecker against the file behind the current buffer.


pyp is a pair of functions which facilitate adding print statements to a python module. They are:

I attach ppy to F12 so I just have to enter the expression and hit return to get my debugging output. Using 'list-matching-lines' or grep with 'pyp' give me an easy way to remove the statements.


I have included an updated version of pycomplete.

This is a nifty emacs extension which helps one to insert attributes and functions into a python program. For instance, one can type

then hits and a window will open up showing all attributes and function in os.path which begin with "is". Also, functions are can be distinguished from simple attributes because they are followed by "()". Pick one with the mouse and hit and the completion will take place. It is required that there be an include statement for "os.path" in order for the completion to work. If it is not included one get a message the name is undefined.

I got an early version which was rather limited. Looking around the net, I found reference to an extension patch. When I applied the patch, I saw that it was better. So I removed some unnecessary code from the package and added the facility to distinguish functions and to end up in the python buffer after the completion. There are two pieces to the package - pycomplete.el which is loaded by emacs so must be in the emacs load path and which should go into an active site-packages directory or anywhere else in the PYTHONPATH.


This collection of extensions may be downloaded from Summary Page.


The python mode extensions are installed by placing "py-mode-ext.el" in the emacs load path specified in the emacs load path. See below the code I use in my .emacs to activate the extensions.

To use pyp just move pyp.el to the emacs load path and see the .emacs code below.

Installation of pycomplete is slightly more complicated. It requires pymacs which needs to have been installed. For Debian based systems you can probably use apt-get. Otherwise, get a tarball and install it from there. Look for "pymacs_0.22.orig.tar.gz". If you can't find it, I can send you a copy.

I think that pymacs is really great but at present it does not appear to be supported and the documentation is poor like many Open Source programs. The main documentation problem I found was a paucity of examples. For instance, I fussed around for a while before I discovered that the output of print statements show up in the *Pymacs* buffer. Pymacs seems to have neither a web site nor a maintainer. Damn shame!

Fortunately, pymacs is easier to install than to find. Instructions are in the package and are pretty standard with nothing to compile. does everything without compiling anything.

Installation of pycomplete consists of merely moving pycomplete.el to the emacs load path and to the PYTHONPATH. Again look at the .emacs code below.

.Emacs code.

I have the following code in my .emacs to enable these extensions.

(add-hook 'python-mode-hook
       	  '(lambda ()
             (load "py-mode-ext")  
             (load "pyp")
             (require 'pycomplete)
             (define-key py-mode-map [f12] 'pyp)
             (define-key py-mode-map "\C-c\C-c" 'py-execute-prog)
             (define-key py-mode-map "\C-c\C-g" 'py-call-pdb)
             (define-key py-mode-map "\C-c\C-w" 'pychecker)))

You may contact me at [rozen at mcn dot org] *