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 have used the first two for some time and find that they are very useful. The pycomplete enhancement also seems useful but I have not been using it long.
I have successfully used these extensions on both Emacs-21 and Emacs-22.
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.
To use these extensions, py-mode-ext.el is placed in my emacs load path. See below for the code that I inserted into my .emacs file.
When the user invokes py-execute-prog or py-call-pdb, the following sequence occurs.
py-mode-ext.el also includes several functions for moving up and down the trace back stack when a error occurs. The following commands are implemented.
You may invoke these functions with the following key sequences:
The easist way to navigation an error trace when executing a program is to use mouse-3. [mouse-3] is defined to invoke 'py-current-line-exception. Just go to the *Python Output* window, select the traceback line you want to visit with mouse-1 and push the mouse-3 button. This is the variation that I use most often.
Since I have been using the traceback navigation above and pyp to easily insert debugging statements, I have not used the debugger very often.
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 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
os.path.is
then ESC-Tab opens a window 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 I found an early version which was rather limited. Looking around the
net, I found reference to an extension patch. When I applied the
patch, I agreed 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 pycomplete.py 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 for the code I use in my .emacs to activate the
extensions.
To set up GUD, the emacs debugger
for use with my python mode extensions, set the emacs option
gud-pdbpcommand-name to point to the file "pdb.py".
In my .emacs I have the statement:
To use pyp just move pyp.el to the emacs load path and see the
.emacs code below for attaching it to a function key.
Installation of pycomplete is slightly more complicated because 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.
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. For some time, I was unable to find a website for
pymacs. Recently, I found a site devoted to Pymacs; it
provides downloads and documentation. This site has documentation
labeled Pymacs version 0.23 but the latest packaged version on the
site is version 0.22.
Fortunately, pymacs is easier to install than to find. Instructions
are in the package and are pretty standard with nothing to
compile. setup.py does everything without having to compiling
anything. When I tried testing pycomlete under emacs-22, I found that
merely moving pymacs.el from the distribution directory to the Emacs
load path is sufficient.
Installation of pycomplete consists of merely moving pycomplete.el
to the emacs load path and pycomplete.py to the PYTHONPATH. Again look
at the .emacs code below.
I have the following code in my .emacs to enable these extensions.
You may contact me at:
Download
Installaton
(gud-pdb-command-name "~/pdb.py")
Of course, I find that pdb.py is now located in
/usr/lib/python2.5 and that location could be used in the .emacs
statement above. The setting can be made via the Options menu.
.Emacs code.
(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)))