##// END OF EJS Templates
Do not emit single completions trailing with space....
Matthias Bussonnier -
Show More
@@ -77,6 +77,8 b' from IPython.utils.process import arg_split'
77 from IPython.utils.py3compat import builtin_mod, string_types, PY3, cast_unicode_py2
77 from IPython.utils.py3compat import builtin_mod, string_types, PY3, cast_unicode_py2
78 from traitlets import Bool, Enum, observe
78 from traitlets import Bool, Enum, observe
79
79
80 from functools import wraps
81
80 #-----------------------------------------------------------------------------
82 #-----------------------------------------------------------------------------
81 # Globals
83 # Globals
82 #-----------------------------------------------------------------------------
84 #-----------------------------------------------------------------------------
@@ -91,6 +93,44 b' else:'
91
93
92
94
93 #-----------------------------------------------------------------------------
95 #-----------------------------------------------------------------------------
96 # Work around BUG decorators.
97 #-----------------------------------------------------------------------------
98
99 def _strip_single_trailing_space(complete):
100 """
101 This is a workaround for a weird IPython/Prompt_toolkit behavior,
102 that can be removed once we rely on a slightly more recent prompt_toolkit
103 version (likely > 1.0.3). So this can likely be removed in IPython 6.0
104
105 cf https://github.com/ipython/ipython/issues/9658
106 and https://github.com/jonathanslenders/python-prompt-toolkit/pull/328
107
108 The bug is due to the fact that in PTK the completer will reinvoke itself
109 after trying to completer to the longuest common prefix of all the
110 completions, unless only one completion is available.
111
112 This logic is faulty if the completion ends with space, which can happen in
113 case like::
114
115 from foo import im<ta>
116
117 which only matching completion is `import `. Note the leading space at the
118 end. So leaving a space at the end is a reasonable request, but for now
119 we'll strip it.
120 """
121
122 @wraps(complete)
123 def comp(*args, **kwargs):
124 text, matches = complete(*args, **kwargs)
125 if len(matches) == 1:
126 return text, [matches[0].rstrip()]
127 return text, matches
128
129 return comp
130
131
132
133 #-----------------------------------------------------------------------------
94 # Main functions and classes
134 # Main functions and classes
95 #-----------------------------------------------------------------------------
135 #-----------------------------------------------------------------------------
96
136
@@ -1121,6 +1161,7 b' class IPCompleter(Completer):'
1121
1161
1122 return None
1162 return None
1123
1163
1164 @_strip_single_trailing_space
1124 def complete(self, text=None, line_buffer=None, cursor_pos=None):
1165 def complete(self, text=None, line_buffer=None, cursor_pos=None):
1125 """Find completions for the given text and line context.
1166 """Find completions for the given text and line context.
1126
1167
General Comments 0
You need to be logged in to leave comments. Login now