mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
Line continuation can't be a Lazy object.
This is because XONSH_INTERACTIVE changes state during startup. So if this object is accessed during early startup it will end up having the wrong value.
This commit is contained in:
parent
12c187fdb7
commit
9cf359a441
3 changed files with 10 additions and 9 deletions
|
@ -8,7 +8,7 @@ import builtins
|
|||
|
||||
from xonsh.tools import (XonshError, print_exception, DefaultNotGiven,
|
||||
check_for_partial_string, format_std_prepost,
|
||||
LINE_CONTINUATION)
|
||||
get_line_continuation)
|
||||
from xonsh.platform import HAS_PYGMENTS, ON_WINDOWS
|
||||
from xonsh.codecache import (should_use_cache, code_cache_name,
|
||||
code_cache_check, get_cache_filename,
|
||||
|
@ -429,7 +429,8 @@ class BaseShell(object):
|
|||
if usecache:
|
||||
self.reset_buffer()
|
||||
return src, code
|
||||
if src.endswith(str(LINE_CONTINUATION)+'\n'):
|
||||
lincont = get_line_continuation()
|
||||
if src.endswith(lincont+'\n'):
|
||||
self.need_more_lines = True
|
||||
return src, None
|
||||
try:
|
||||
|
|
|
@ -8,7 +8,7 @@ from prompt_toolkit.filters import (Condition, IsMultiline, HasSelection,
|
|||
from prompt_toolkit.keys import Keys
|
||||
|
||||
from xonsh.aliases import xonsh_exit
|
||||
from xonsh.tools import check_for_partial_string, LINE_CONTINUATION
|
||||
from xonsh.tools import check_for_partial_string, get_line_continuation
|
||||
from xonsh.shell import transform_command
|
||||
|
||||
env = builtins.__xonsh_env__
|
||||
|
@ -50,7 +50,7 @@ def carriage_return(b, cli, *, autoindent=True):
|
|||
b.delete_before_cursor(count=len(indent))
|
||||
elif (not doc.on_first_line and not current_line_blank):
|
||||
b.newline(copy_margin=autoindent)
|
||||
elif (doc.current_line.endswith(str(LINE_CONTINUATION))):
|
||||
elif (doc.current_line.endswith(get_line_continuation())):
|
||||
b.newline(copy_margin=autoindent)
|
||||
elif (doc.find_next_word_beginning() is not None and
|
||||
(any(not _is_blank(i) for i in doc.lines_from_current[1:]))):
|
||||
|
|
|
@ -405,13 +405,12 @@ def _have_open_triple_quotes(s):
|
|||
return open_triple
|
||||
|
||||
|
||||
@lazyobject
|
||||
def LINE_CONTINUATION():
|
||||
def get_line_continuation():
|
||||
""" The line contiuation characters used in subproc mode. In interactive
|
||||
mode on Windows the backslash must be preseeded by a space. This is because
|
||||
paths on windows may end in a backspace.
|
||||
"""
|
||||
if ON_WINDOWS and builtins.__xonsh_env__.get('XONSH_INTERACTIVE'):
|
||||
if ON_WINDOWS and builtins.__xonsh_env__.get('XONSH_INTERACTIVE', False):
|
||||
return ' \\'
|
||||
else:
|
||||
return '\\'
|
||||
|
@ -425,7 +424,7 @@ def get_logical_line(lines, idx):
|
|||
"""
|
||||
n = 1
|
||||
nlines = len(lines)
|
||||
linecont = str(LINE_CONTINUATION)
|
||||
linecont = get_line_continuation()
|
||||
while idx > 0 and lines[idx-1].endswith(linecont):
|
||||
idx -= 1
|
||||
start = idx
|
||||
|
@ -446,6 +445,7 @@ def replace_logical_line(lines, logical, idx, n):
|
|||
"""Replaces lines at idx that may end in line continuation with a logical
|
||||
line that spans n lines.
|
||||
"""
|
||||
lincont = get_line_continuation()
|
||||
if n == 1:
|
||||
lines[idx] = logical
|
||||
return
|
||||
|
@ -459,7 +459,7 @@ def replace_logical_line(lines, logical, idx, n):
|
|||
logical = ''
|
||||
else:
|
||||
# found space to split on
|
||||
lines[i] = logical[:b] + str(LINE_CONTINUATION)
|
||||
lines[i] = logical[:b] + linecont
|
||||
logical = logical[b:]
|
||||
lines[idx+n-1] = logical
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue