]> git.phdru.name Git - dotfiles.git/blobdiff - lib/python/pdbrc.py
pdb: Improve completion
[dotfiles.git] / lib / python / pdbrc.py
index 97bd40115cc971d9f286757e6e961333a1e67dc0..b4a9afb13ef820dca76b59d371404d5f71ccea74 100644 (file)
@@ -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