forked from aniani/vim
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Problem: Vim9: cannot use heredoc in :def function for :python, :lua, etc. Solution: Concatenate the heredoc lines and pass them in the ISN_EXEC_SPLIT instruction.
This commit is contained in:
@@ -121,6 +121,23 @@ def Test_disassemble_exec_expr()
|
||||
res)
|
||||
enddef
|
||||
|
||||
if has('python3')
|
||||
def s:PyHeredoc()
|
||||
python3 << EOF
|
||||
print('hello')
|
||||
EOF
|
||||
enddef
|
||||
|
||||
def Test_disassemble_python_heredoc()
|
||||
var res = execute('disass s:PyHeredoc')
|
||||
assert_match('<SNR>\d*_PyHeredoc.*' ..
|
||||
" python3 << EOF^@ print('hello')^@EOF\\_s*" ..
|
||||
'\d EXEC_SPLIT python3 << EOF^@ print(''hello'')^@EOF\_s*' ..
|
||||
'\d RETURN 0',
|
||||
res)
|
||||
enddef
|
||||
endif
|
||||
|
||||
def s:Substitute()
|
||||
var expr = "abc"
|
||||
:%s/a/\=expr/&g#c
|
||||
|
@@ -2758,5 +2758,33 @@ def Test_closing_brace_at_start_of_line()
|
||||
call CheckDefAndScriptSuccess(lines)
|
||||
enddef
|
||||
|
||||
if has('python3')
|
||||
def Test_python3_heredoc()
|
||||
py3 << trim EOF
|
||||
import vim
|
||||
vim.vars['didit'] = 'yes'
|
||||
EOF
|
||||
assert_equal('yes', g:didit)
|
||||
|
||||
python3 << trim EOF
|
||||
import vim
|
||||
vim.vars['didit'] = 'again'
|
||||
EOF
|
||||
assert_equal('again', g:didit)
|
||||
enddef
|
||||
endif
|
||||
|
||||
" This messes up syntax highlight, keep near the end.
|
||||
if has('lua')
|
||||
def Test_lua_heredoc()
|
||||
g:d = {}
|
||||
lua << trim EOF
|
||||
x = vim.eval('g:d')
|
||||
x['key'] = 'val'
|
||||
EOF
|
||||
assert_equal('val', g:d.key)
|
||||
enddef
|
||||
endif
|
||||
|
||||
|
||||
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
|
||||
|
Reference in New Issue
Block a user