Skip to content
Browse files

Fix completion of '%tim' in the Qt console.

  • Loading branch information...
1 parent 637c65e commit e362fa9e08c53af241fbcab795573dcfdee0e443 @takluyver committed Jun 16, 2012
View
3 IPython/core/inputsplitter.py
@@ -96,6 +96,9 @@
ESC_QUOTE2 = ';' # Quote all args as a single string, call
ESC_PAREN = '/' # Call first argument with rest of line as arguments
+ESCAPE_RE = re.compile("^[" + ESC_SHELL + ESC_HELP + ESC_MAGIC + ESC_QUOTE + \
+ ESC_QUOTE2 + ESC_PAREN + "]+")
+
#-----------------------------------------------------------------------------
# Utilities
#-----------------------------------------------------------------------------
View
10 IPython/frontend/qt/console/console_widget.py
@@ -16,6 +16,7 @@
# Local imports
from IPython.config.configurable import LoggingConfigurable
+from IPython.core.inputsplitter import ESCAPE_RE
from IPython.frontend.qt.rich_text import HtmlExporter
from IPython.frontend.qt.util import MetaQObjectHasTraits, get_font
from IPython.utils.text import columnize
@@ -875,7 +876,7 @@ def _clear_temporary_buffer(self):
self._control.setUndoRedoEnabled(False)
self._control.setUndoRedoEnabled(True)
- def _complete_with_items(self, cursor, items):
+ def _complete_with_items(self, cursor, items, strip_escape_prefix=False):
""" Performs completion with 'items' at the specified cursor location.
"""
self._cancel_completion()
@@ -887,7 +888,12 @@ def _complete_with_items(self, cursor, items):
elif len(items) > 1:
current_pos = self._control.textCursor().position()
- prefix = commonprefix(items)
+ # If required, clean up escape characters like %
+ if strip_escape_prefix:
+ prefix_items = [ESCAPE_RE.sub("", match) for match in items]
+ else:
+ prefix_items = items
+ prefix = commonprefix(prefix_items)
if prefix:
cursor.setPosition(current_pos, QtGui.QTextCursor.KeepAnchor)
cursor.insertText(prefix)
View
14 IPython/frontend/qt/console/ipython_widget.py
@@ -20,7 +20,7 @@
# Local imports
from IPython.core.inputsplitter import IPythonInputSplitter, \
- transform_ipy_prompt
+ transform_ipy_prompt, ESCAPE_RE
from IPython.utils.traitlets import Bool, Unicode
from frontend_widget import FrontendWidget
import styles
@@ -158,10 +158,20 @@ def _handle_complete_reply(self, rep):
chop_length = sum(map(len, parts[:sep_count])) + sep_count
matches = [ match[chop_length:] for match in matches ]
offset -= chop_length
+
+ # If the completed text starts with an escape sequence (e.g. %),
+ # we'll ignore that for generating the common prefix to fill in. So
+ # we move the offset so it's filled from after the escape sequence.
+ strip_escape_prefix = False
+ if len(matches) > 1:
+ m = ESCAPE_RE.match(text)
+ if m:
+ strip_escape_prefix = True
+ offset -= len(m.group(0))
# Move the cursor to the start of the match and complete.
cursor.movePosition(QtGui.QTextCursor.Left, n=offset)
- self._complete_with_items(cursor, matches)
+ self._complete_with_items(cursor, matches, strip_escape_prefix)
def _handle_execute_reply(self, msg):
""" Reimplemented to support prompt requests.

0 comments on commit e362fa9

Please sign in to comment.
Something went wrong with that request. Please try again.