r79049 - pyrepl/trunk/pyrepl/pyrepl

[email protected] Fri, 12 Nov 2010 23:29:43 +0100 (CET)
Newsgroups gmane.comp.python.pyrepl.checkins
Message-ID <[email protected]>
Author: antocuni
Date: Fri Nov 12 23:29:41 2010
New Revision: 79049

Modified:
   pyrepl/trunk/pyrepl/pyrepl/completing_reader.py
   pyrepl/trunk/pyrepl/pyrepl/readline.py
Log:
try to match more closely the behaviour of readline in case there is an unique
completion followed by a <TAB> (this semantic is e.g. exploited by
fancycompleter to automatically complete unique prefixes)



Modified: pyrepl/trunk/pyrepl/pyrepl/completing_reader.py
==============================================================================
--- pyrepl/trunk/pyrepl/pyrepl/completing_reader.py	(original)
+++ pyrepl/trunk/pyrepl/pyrepl/completing_reader.py	Fri Nov 12 23:29:41 2010
@@ -99,12 +99,19 @@
 # the considerations are:
 # (1) how many completions are possible
 # (2) whether the last command was a completion
+# (3) if we can assume that the completer is going to return the same set of
+#     completions: this is controlled by the ``assume_immutable_completions``
+#     variable on the reader, which is True by default to match the historical
+#     behaviour of pyrepl, but e.g. False in the ReadlineAlikeReader to match
+#     more closely readline's semantics (this is needed e.g. by
+#     fancycompleter)
 #
 # if there's no possible completion, beep at the user and point this out.
 # this is easy.
 #
 # if there's only one possible completion, stick it in.  if the last thing
-# user did was a completion, point out that he isn't getting anywhere.
+# user did was a completion, point out that he isn't getting anywhere, but
+# only if the ``assume_immutable_completions`` is True.
 #
 # now it gets complicated.
 # 
@@ -133,7 +140,8 @@
     def do(self):
         r = self.reader
         stem = r.get_stem()
-        if r.last_command_is(self.__class__):
+        if r.assume_immutable_completions and \
+                r.last_command_is(self.__class__):
             completions = r.cmpltn_menu_choices
         else:
             r.cmpltn_menu_choices = completions = \
@@ -141,7 +149,8 @@
         if len(completions) == 0:
             r.error("no matches")
         elif len(completions) == 1:
-            if len(completions[0]) == len(stem) and \
+            if r.assume_immutable_completions and \
+                   len(completions[0]) == len(stem) and \
                    r.last_command_is(self.__class__):
                 r.msg = "[ sole completion ]"
                 r.dirty = 1
@@ -187,7 +196,9 @@
       * cmpltn_menu, cmpltn_menu_vis, cmpltn_menu_end, cmpltn_choices:
       *
     """
-
+    # see the comment for the complete command
+    assume_immutable_completions = True
+    
     def collect_keymap(self):
         return super(CompletingReader, self).collect_keymap() + (
             (r'\t', 'complete'),)

Modified: pyrepl/trunk/pyrepl/pyrepl/readline.py
==============================================================================
--- pyrepl/trunk/pyrepl/pyrepl/readline.py	(original)
+++ pyrepl/trunk/pyrepl/pyrepl/readline.py	Fri Nov 12 23:29:41 2010
@@ -47,6 +47,8 @@
 
 class ReadlineAlikeReader(HistoricalReader, CompletingReader):
 
+    assume_immutable_completions = False
+
     def error(self, msg="none"):
         pass    # don't show error messages by default