mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 16:34:47 +01:00
Merge pull request #2308 from xonsh/linecont
Line continuations not always working on Win
This commit is contained in:
commit
a891b21ab3
4 changed files with 27 additions and 11 deletions
14
news/linecont.rst
Normal file
14
news/linecont.rst
Normal file
|
@ -0,0 +1,14 @@
|
|||
**Added:** None
|
||||
|
||||
**Changed:** None
|
||||
|
||||
**Deprecated:** None
|
||||
|
||||
**Removed:** None
|
||||
|
||||
**Fixed:**
|
||||
|
||||
* Correct line continuation would not work on Windows if the line continuations were used
|
||||
in the ``xonshrc`` file.
|
||||
|
||||
**Security:** None
|
|
@ -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:]))):
|
||||
|
|
|
@ -417,13 +417,13 @@ 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.
|
||||
mode on Windows the backslash must be preceded by a space. This is because
|
||||
paths on Windows may end in a backslash.
|
||||
"""
|
||||
if ON_WINDOWS and builtins.__xonsh_env__.get('XONSH_INTERACTIVE'):
|
||||
if (ON_WINDOWS and hasattr(builtins, '__xonsh_env__') and
|
||||
builtins.__xonsh_env__.get('XONSH_INTERACTIVE', False)):
|
||||
return ' \\'
|
||||
else:
|
||||
return '\\'
|
||||
|
@ -437,7 +437,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
|
||||
|
@ -458,6 +458,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.
|
||||
"""
|
||||
linecont = get_line_continuation()
|
||||
if n == 1:
|
||||
lines[idx] = logical
|
||||
return
|
||||
|
@ -471,7 +472,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