views:

163

answers:

3

From PDB

(Pdb) help l
l(ist) [first [,last]]
  List source code for the current file.
  Without arguments, list 11 lines around the current line
  or continue the previous listing.
  With one argument, list 11 lines starting at that line.
  With two arguments, list the given range;
  if the second argument is less than the first, it is a count.

The "continue the previous listing" feature is really nice, but how do you turn it off?

+2  A: 

I don't think there is a way to turn it off. It's annoyed me enough that once I went looking in the pdb source to see if there was an undocumented syntax, but I didn't find any.

There really needs to be a syntax that means, "List the lines near the current execution pointer."

Ned Batchelder
That is both great and horrible news. It's great because now I know this is not a stupid question, horrible because I really like something like this. Since we are going into the feature request category then I'm thinking the best will be to have a reverse operation. Lets call it "rlist" that will be a reverse pager on list. So doing (Pdb) l(Pdb) rwill get you to the same spot.
Jorge Vargas
+1  A: 

You could monkey patch it for the behavior you want. For example, here is a full script which adds a "reset_list" or "rl" command to pdb:

import pdb

def Pdb_reset_list(self, arg):
    self.lineno = None
    print >>self.stdout, "Reset list position."
pdb.Pdb.do_reset = Pdb_reset_list
pdb.Pdb.do_rl = Pdb_reset_list

a = 1
b = 2

pdb.set_trace()

print a, b

One could conceivably monkey patch the standard list command to not retain the lineno history.

edit: And here is such a patch:

import pdb
Pdb = pdb.Pdb

Pdb._do_list = Pdb.do_list
def pdb_list_wrapper(self, arg):
    if arg.strip().lower() in ('r', 'reset', 'c', 'current'):
        self.lineno = None
        arg = ''
    self._do_list(arg)
Pdb.do_list = Pdb.do_l = pdb_list_wrapper

a = 1
b = 2

pdb.set_trace()

print a, b
Mike Boers
Thank you I guess this is the way to go for now. Perhaps a patch proposal for python itself?
Jorge Vargas
+1  A: 

If you use epdb1 instead of pdb, you can use "l" to go forward like in pdb, but then "l." goes back to the current line number, and "l-" goes backwards through the file. You can also use until # to continue until a given line. Epdb offers a bunch of other niceties too.

Joseph Tate