X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=lib%2Fpython%2Fpdbrc.py;h=b4a9afb13ef820dca76b59d371404d5f71ccea74;hb=9a66d4531e7d0d015b38be0b38f1c379a45fd03f;hp=0ebe7b513e5cf2cb8b4e0ee738e927ae148111ff;hpb=580013920401a783a31124a179d328fc68952d31;p=dotfiles.git diff --git a/lib/python/pdbrc.py b/lib/python/pdbrc.py index 0ebe7b5..b4a9afb 100644 --- a/lib/python/pdbrc.py +++ b/lib/python/pdbrc.py @@ -1,54 +1,77 @@ -import atexit -import os -import sys -import readline +# This is startup file for interactive python debugger pdb. +# Use it like this in ~/.pdbrc: +# import os +# x = execfile("pdbrc.py") +# See http://wiki.python.org/moin/PdbRcIdea -# Command line history: -histfile = os.path.expanduser("~/.pdb-history") +def init(): + import atexit + import os + import sys + import readline -try: - readline.read_history_file(histfile) -except IOError: - pass + # Command line history: + histfile = os.path.expanduser("~/.pdb_history") + try: + readline.read_history_file(histfile) + except IOError: + pass -def savehist(histfile=histfile): - import os - import readline - histfilesize = os.environ.get('HISTFILESIZE') \ - or os.environ.get('HISTSIZE') - if histfilesize: - try: - histfilesize = int(histfilesize) - except ValueError: - pass - else: - readline.set_history_length(histfilesize) - readline.write_history_file(histfile) + def savehist(histfile=histfile): + import os + import readline -atexit.register(savehist) + histfilesize = os.environ.get('HISTFILESIZE') \ + or os.environ.get('HISTSIZE') + if histfilesize: + try: + histfilesize = int(histfilesize) + except ValueError: + pass + else: + readline.set_history_length(histfilesize) + readline.write_history_file(histfile) + atexit.register(savehist) -def info(type, value, tb): - # return to debugger after fatal exception (Python cookbook 14.5): - import pdb - import sys - import traceback - if hasattr(sys, 'ps1') or not sys.stderr.isatty(): - sys.__excepthook__(type, value, tb) - traceback.print_exception(type, value, tb) - print - pdb.pm() + def info(type, value, tb): + # return to debugger after fatal exception (Python cookbook 14.5): + import pdb + import sys + import traceback -sys.excepthook = info + if hasattr(sys, 'ps1') or not sys.stderr.isatty(): + sys.__excepthook__(type, value, tb) + traceback.print_exception(type, value, tb) + print + pdb.pm() + sys.excepthook = info -# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182 +init() + +# https://github.com/giampaolo/sysconf/blob/master/home/.pdbrc.py import pdb import rlcompleter -pdb.Pdb.complete = rlcompleter.Completer().complete +#pdb.Pdb.complete = rlcompleter.Completer(locals()).complete + +# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182 +def complete(self, text, state, rlcompleter=rlcompleter): + """return the next possible completion for text, using the current frame's + local namespace + + This is called successively with state == 0, 1, 2, ... until it + returns None. The completion should begin with 'text'. + """ + # keep a completer class, and make sure that it uses the current local scope + if not hasattr(self, 'completer'): + self.completer = rlcompleter.Completer(self.curframe.f_locals) + else: + self.completer.namespace = self.curframe.f_locals + return self.completer.complete(text, state) # Cleanup any variables that could otherwise clutter up the namespace. -del atexit, info, os, pdb, readline, rlcompleter, savehist, sys +del pdb, rlcompleter