From: Oleg Broytman Date: Mon, 10 Jun 2019 10:11:23 +0000 (+0300) Subject: pdb: Improve completion X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=920e9b2291149c2adbb89eaaf2644575aaaa06f9;p=dotfiles.git pdb: Improve completion --- diff --git a/.pdbrc b/.pdbrc index 1bc8abf..f2ec6a5 100644 --- a/.pdbrc +++ b/.pdbrc @@ -8,4 +8,12 @@ # If pdbrc.py is missing, you get an error message (which doesn't hurt). import os +import sys + x = execfile(os.path.expanduser("~/lib/python/pdbrc.py")) + +# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182 +# replace the Pdb class's complete method with ours +sys._getframe(1).f_globals['Pdb'].complete = complete +# set use_rawinput to 1 as tab completion relies on rawinput being used +sys._getframe(1).f_locals['self'].use_rawinput = 1 diff --git a/lib/python/pdbrc.py b/lib/python/pdbrc.py index 97bd401..b4a9afb 100644 --- a/lib/python/pdbrc.py +++ b/lib/python/pdbrc.py @@ -53,11 +53,25 @@ def init(): init() -# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182 # https://github.com/giampaolo/sysconf/blob/master/home/.pdbrc.py import pdb import rlcompleter -pdb.Pdb.complete = rlcompleter.Completer(locals()).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 pdb, readline, rlcompleter +del pdb, rlcompleter