Merge branch 'master' of github.com:scopatz/xonsh

This commit is contained in:
Anthony Scopatz 2016-02-21 16:26:02 -05:00
commit b60908fcd4
4 changed files with 36 additions and 2 deletions

View file

@ -86,6 +86,16 @@ def test_indent_with_empty_line():
' some_command for_sub_process_mode\n')
yield check_parse, code
def test_command_in_func():
code = ('def f():\n'
' echo hello\n')
yield check_parse, code
def test_command_in_func_with_comment():
code = ('def f():\n'
' echo hello # comment\n')
yield check_parse, code
if __name__ == '__main__':

View file

@ -104,6 +104,22 @@ def test_subproc_toks_ls_str_comment():
obs = subproc_toks(s + com, lexer=LEXER, returnline=True)
assert_equal(exp, obs)
def test_subproc_toks_indent_ls_comment():
ind = ' '
s = 'ls -l'
com = ' # lets list'
exp = '{0}$[{1}]{2}'.format(ind, s, com)
obs = subproc_toks(ind + s + com, lexer=LEXER, returnline=True)
assert_equal(exp, obs)
def test_subproc_toks_indent_ls_str():
ind = ' '
s = 'ls "wakka"'
com = ' # lets list'
exp = '{0}$[{1}]{2}'.format(ind, s, com)
obs = subproc_toks(ind + s + com, lexer=LEXER, returnline=True)
assert_equal(exp, obs)
def test_subproc_toks_ls_l_semi_ls_first():
lsdl = 'ls -l'
ls = 'ls'

View file

@ -72,7 +72,8 @@ class TabShouldInsertIndentFilter(Filter):
def can_compile(src):
"""Returns whether the code can be compiled, i.e. it is valid xonsh."""
src = src if src.endswith('\n') else '{}\n'.format(src)
src = src if src.endswith('\n') else src + '\n'
src = src.lstrip()
try:
builtins.__xonsh_execer__.compile(src, mode='single', glbs=None,
locs=builtins.__xonsh_ctx__)

View file

@ -125,7 +125,14 @@ def subproc_toks(line, mincol=-1, maxcol=None, lexer=None, returnline=False):
tok.type = 'NEWLINE'
tok.value = '\n'
tok.lineno -= 1
tok.lexpos = len(line)
if len(toks) >= 2:
prev_tok_end = toks[-2].lexpos + len(toks[-2].value)
else:
prev_tok_end = len(line)
if '#' in line[prev_tok_end:]:
tok.lexpos = prev_tok_end # prevents wrapping comments
else:
tok.lexpos = len(line)
break
else:
if len(toks) == 0: