Emacs + python

Steffen Ries steffen.ries at sympatico.ca
Fri Sep 24 13:48:48 CEST 2004


Marcio Rosa da Silva <mrsilva at fastmail.fm> writes:

> Chris Green wrote:
> > The trick that I like most about emacs+python right now is inserting
> > import pdb; pdb.set_trace() and then running the python script from a
> > *shell* buffer. It just happens to load the exact same code that would
> > occur from running pdb.py directly so code lines can be synced up.
> 
> I am trying for a long time a way to run pdb from emacs and have the
> code synchronized.
> 
> I searched google for emacs+python+debug or emacs+pdb but the
> instructions would say: "M-x pdb" but then emacs asked the command
> line to run the debug and I tried "pdb" "pydb" "pydb filename" but
> nothing worked.
> 
> When I tryed "M-x pdb" then "pydb" I need to use "file <filename>"
> (and the completion doesn't work here for the filename), then the
> debugger worked, but no sync with the source code :-(
> 
>  From the help of GUD, I tried "M-x pdb <RET> FILE <RET>" also without
> success.

You can either start pdb as "python <path-to-python-libs/pdb.py" or to
make your life easier install an executable that does that. I'm using
the following script in /usr/local/bin/pdb for this purpose:

--8<--
#! /bin/sh
lib=`python -c "import sys; print '%s/lib/python%s' % (sys.prefix, sys.version[:3])"`
 
python -u $lib/pdb.py "$@"
--8<--

with this script you start pdb as "M-x pdb <RET> pdb yourscript.py
script arguments...<RET>"

> Anyone can help me with this? I really don't know how to make it
> work. I have seen in the python-emacs-mode that there are some code to
> synchronize the code, but I could not make it work in this way (I
> don't know enough elisp) :-(
> 
> But anyway, thanks Chris for the tip. This one worked for me :-) It is
> possible to set breakpoints using the source buffer instead of using
> the line number?

C-x <SPC> in the source buffer.

hth,
/steffen
-- 
steffen.ries at sympatico.ca	<> Gravity is a myth -- the Earth sucks!



More information about the Python-list mailing list