##// END OF EJS Templates
Remove workaround for prompt_toolkit completions with trailing space...
Thomas Kluyver -
Show More
@@ -39,11 +39,6 b' from IPython.utils.process import arg_split'
39 from IPython.utils.py3compat import cast_unicode_py2
39 from IPython.utils.py3compat import cast_unicode_py2
40 from traitlets import Bool, Enum, observe
40 from traitlets import Bool, Enum, observe
41
41
42 from functools import wraps
43
44 #-----------------------------------------------------------------------------
45 # Globals
46 #-----------------------------------------------------------------------------
47
42
48 # Public API
43 # Public API
49 __all__ = ['Completer','IPCompleter']
44 __all__ = ['Completer','IPCompleter']
@@ -54,48 +49,6 b' else:'
54 PROTECTABLES = ' ()[]{}?=\\|;:\'#*"^&'
49 PROTECTABLES = ' ()[]{}?=\\|;:\'#*"^&'
55
50
56
51
57 #-----------------------------------------------------------------------------
58 # Work around BUG decorators.
59 #-----------------------------------------------------------------------------
60
61 def _strip_single_trailing_space(complete):
62 """
63 This is a workaround for a weird IPython/Prompt_toolkit behavior,
64 that can be removed once we rely on a slightly more recent prompt_toolkit
65 version (likely > 1.0.3). So this can likely be removed in IPython 6.0
66
67 cf https://github.com/ipython/ipython/issues/9658
68 and https://github.com/jonathanslenders/python-prompt-toolkit/pull/328
69
70 The bug is due to the fact that in PTK the completer will reinvoke itself
71 after trying to completer to the longuest common prefix of all the
72 completions, unless only one completion is available.
73
74 This logic is faulty if the completion ends with space, which can happen in
75 case like::
76
77 from foo import im<ta>
78
79 which only matching completion is `import `. Note the leading space at the
80 end. So leaving a space at the end is a reasonable request, but for now
81 we'll strip it.
82 """
83
84 @wraps(complete)
85 def comp(*args, **kwargs):
86 text, matches = complete(*args, **kwargs)
87 if len(matches) == 1:
88 return text, [matches[0].rstrip()]
89 return text, matches
90
91 return comp
92
93
94
95 #-----------------------------------------------------------------------------
96 # Main functions and classes
97 #-----------------------------------------------------------------------------
98
99 def has_open_quotes(s):
52 def has_open_quotes(s):
100 """Return whether a string has open quotes.
53 """Return whether a string has open quotes.
101
54
@@ -1134,7 +1087,6 b' class IPCompleter(Completer):'
1134
1087
1135 return None
1088 return None
1136
1089
1137 @_strip_single_trailing_space
1138 def complete(self, text=None, line_buffer=None, cursor_pos=None):
1090 def complete(self, text=None, line_buffer=None, cursor_pos=None):
1139 """Find completions for the given text and line context.
1091 """Find completions for the given text and line context.
1140
1092
@@ -205,7 +205,7 b' install_requires = ['
205 'pickleshare',
205 'pickleshare',
206 'simplegeneric>0.8',
206 'simplegeneric>0.8',
207 'traitlets>=4.2',
207 'traitlets>=4.2',
208 'prompt_toolkit>=1.0.3,<2.0.0',
208 'prompt_toolkit>=1.0.4,<2.0.0',
209 'pygments',
209 'pygments',
210 ]
210 ]
211
211
General Comments 0
You need to be logged in to leave comments. Login now