From 255e87419a654e525d5634832bdac10e1f57f7f8 Mon Sep 17 00:00:00 2001 From: Jorgen Stenarson Date: Thu, 15 Jul 2010 23:52:43 +0200 Subject: [PATCH] Tab-completion problem in Python2.6 fixed. In python 2.6 tabcompletion autoappends ( to callables. There is now an example in startup.py on how to disable this. There was also a bug in the completion code that prevented a full list of completions from being printed in some cases. --- pyreadline/configuration/startup.py | 8 ++++++++ pyreadline/modes/basemode.py | 8 +++++--- pyreadline/test/emacs_test.py | 18 +++++++++++------- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pyreadline/configuration/startup.py b/pyreadline/configuration/startup.py index c425398..acda5e9 100644 --- a/pyreadline/configuration/startup.py +++ b/pyreadline/configuration/startup.py @@ -15,6 +15,14 @@ except ImportError: else: #import tab completion functionality import rlcompleter + + #Override completer from rlcompleter to disable automatic ( on callable + completer_obj = rlcompleter.Completer() + def nop(val, word): + return word + completer_obj._callable_postfix = nop + readline.set_completer(completer_obj.complete) + #activate tab completion readline.parse_and_bind("tab: complete") readline.read_history_file() diff --git a/pyreadline/modes/basemode.py b/pyreadline/modes/basemode.py index 632a8c1..5ee6bf9 100644 --- a/pyreadline/modes/basemode.py +++ b/pyreadline/modes/basemode.py @@ -196,13 +196,15 @@ class BaseMode(object): while 1: try: r = ensure_unicode(self.completer(text, i)) - except: + except IndexError: break i += 1 - if r and r not in completions: + if r is None: + break + elif r and r not in completions: completions.append(r) else: - break + pass log(u'text completions=<%s>' % map(ensure_unicode, completions)) if (self.complete_filesystem == "on") and not completions: # get the filename to complete diff --git a/pyreadline/test/emacs_test.py b/pyreadline/test/emacs_test.py index 81d4e9d..8554f18 100644 --- a/pyreadline/test/emacs_test.py +++ b/pyreadline/test/emacs_test.py @@ -344,19 +344,23 @@ class TestsHistory (unittest.TestCase): def test_complete (self): import rlcompleter - logger.sock_silent=False + logger.sock_silent = False - log("-"*50) - r=EmacsModeTest() - r.completer=rlcompleter.Completer().complete - r._bind_key("tab",r.complete) + log("-" * 50) + r = EmacsModeTest() + completerobj = rlcompleter.Completer() + def _nop(val, word): + return word + completerobj._callable_postfix = _nop + r.completer = completerobj.complete + r._bind_key("tab", r.complete) r.input(u'"exi(ksdjksjd)"') r.input(u'Control-a') r.input(u'Right') r.input(u'Right') r.input(u'Right') r.input(u'Tab') - self.assert_line(r,"exit(ksdjksjd)",4) + self.assert_line(r, u"exit(ksdjksjd)", 4) r.input(u'Escape') r.input(u'"exi"') @@ -365,7 +369,7 @@ class TestsHistory (unittest.TestCase): r.input(u'Right') r.input(u'Right') r.input(u'Tab') - self.assert_line(r,"exit",4) + self.assert_line(r, u"exit", 4)