Merge branch 'paste-mode' of https://github.com/Carreau/xonsh into Carreau-paste-mode

This commit is contained in:
Anthony Scopatz 2016-08-12 00:22:14 -04:00
commit bddd7e43ab

View file

@ -11,11 +11,10 @@ from xonsh.aliases import xonsh_exit
from xonsh.tools import ON_WINDOWS
env = builtins.__xonsh_env__
indent_ = env.get('INDENT')
DEDENT_TOKENS = frozenset(['raise', 'return', 'pass', 'break', 'continue'])
def carriage_return(b, cli):
def carriage_return(b, cli, *, autoindent=True):
"""
Preliminary parser to determine if 'Enter' key should send command to
the xonsh parser for execution or should insert a newline for continued
@ -29,35 +28,37 @@ def carriage_return(b, cli):
- Any text exists below cursor position (relevant when editing previous
multiline blocks)
"""
doc = b.document
at_end_of_line = _is_blank(doc.current_line_after_cursor)
current_line_blank = _is_blank(doc.current_line)
at_end_of_line = _is_blank(b.document.current_line_after_cursor)
current_line_blank = _is_blank(b.document.current_line)
indent = env.get('INDENT') if autoindent else ''
# indent after a colon
if (b.document.current_line_before_cursor.strip().endswith(':') and
if (doc.current_line_before_cursor.strip().endswith(':') and
at_end_of_line):
b.newline()
b.insert_text(indent_, fire_event=False)
b.newline(copy_margin=autoindent)
b.insert_text(indent, fire_event=False)
# if current line isn't blank, check dedent tokens
elif (not current_line_blank and
b.document.current_line.split(maxsplit=1)[0] in DEDENT_TOKENS and
b.document.line_count > 1):
b.newline(copy_margin=True)
_ = b.delete_before_cursor(count=len(indent_))
elif (not b.document.on_first_line and
doc.current_line.split(maxsplit=1)[0] in DEDENT_TOKENS and
doc.line_count > 1):
b.newline(copy_margin=autoindent)
b.delete_before_cursor(count=len(indent))
elif (not doc.on_first_line and
not current_line_blank):
b.newline(copy_margin=True)
elif (b.document.char_before_cursor == '\\' and
b.newline(copy_margin=autoindent)
elif (doc.char_before_cursor == '\\' and
not (not builtins.__xonsh_env__.get('FORCE_POSIX_PATHS')
and ON_WINDOWS)):
b.newline()
elif (b.document.find_next_word_beginning() is not None and
b.newline(copy_margin=autoindent)
elif (doc.find_next_word_beginning() is not None and
(any(not _is_blank(i)
for i
in b.document.lines_from_current[1:]))):
b.newline(copy_margin=True)
elif not current_line_blank and not can_compile(b.document.text):
b.newline()
in doc.lines_from_current[1:]))):
b.newline(copy_margin=autoindent)
elif not current_line_blank and not can_compile(doc.text):
b.newline(copy_margin=autoindent)
else:
b.accept_action.validate_and_handle(cli, b)