0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.0578: heredoc for interfaces does not support "trim"

Problem:    Heredoc for interfaces does not support "trim".
Solution:   Update the script heredoc support to be same as the :let command.
            (Yegappan Lakshmanan, closes #5916)
This commit is contained in:
Bram Moolenaar
2020-04-14 20:15:49 +02:00
parent 7a1637f4c0
commit 6c2b7b8055
22 changed files with 2093 additions and 1926 deletions

View File

@@ -32,7 +32,7 @@ Examples:
:lua local curbuf = vim.buffer() curbuf[7] = "line #7"
<
:[range]lua << [endmarker]
:[range]lua << [trim] [{endmarker}]
{script}
{endmarker}
Execute Lua script {script}.
@@ -40,10 +40,9 @@ Examples:
feature wasn't compiled in. To avoid errors, see
|script-here|.
The {endmarker} must NOT be preceded by any white space.
If [endmarker] is omitted from after the "<<", a dot '.' must be used after
{script}, like for the |:append| and |:insert| commands.
{script}, like for the |:append| and |:insert| commands. Refer to
|:let-heredoc| for more information.
This form of the |:lua| command is mainly useful for including Lua code
in Vim scripts.

View File

@@ -39,7 +39,7 @@ To speed up the process, you might also want to use --disable-gracket and
:[range]mz[scheme] {stmt}
Execute MzScheme statement {stmt}.
:[range]mz[scheme] << [endmarker]
:[range]mz[scheme] << [trim] [{endmarker}]
{script}
{endmarker}
Execute inlined MzScheme script {script}.
@@ -47,12 +47,11 @@ To speed up the process, you might also want to use --disable-gracket and
feature wasn't compiled in. To avoid errors, see
|script-here|.
The {endmarker} below the {script} must NOT be
preceded by any white space.
If [endmarker] is omitted from after the "<<", a dot
'.' must be used after {script}, like for the
|:append| and |:insert| commands.
|:append| and |:insert| commands. Refer to
|:let-heredoc| for more information.
*:mzfile* *:mzf*
:[range]mzf[ile] {file} Execute the MzScheme script in {file}.

View File

@@ -55,7 +55,7 @@ The ActiveState one should work, Strawberry Perl is a good alternative.
working: >
:perl VIM::Msg("Hello")
:pe[rl] << [endmarker]
:pe[rl] << [trim] [{endmarker}]
{script}
{endmarker}
Execute Perl script {script}.

View File

@@ -34,7 +34,7 @@ Both can be available at the same time, but read |python-2-and-3|.
the `:python` command is working: >
:python print "Hello"
:[range]py[thon] << [endmarker]
:[range]py[thon] << [trim] [{endmarker}]
{script}
{endmarker}
Execute Python script {script}.
@@ -42,10 +42,9 @@ Both can be available at the same time, but read |python-2-and-3|.
feature wasn't compiled in. To avoid errors, see
|script-here|.
The {endmarker} below the {script} must NOT be preceded by any white space.
If [endmarker] is omitted from after the "<<", a dot '.' must be used after
{script}, like for the |:append| and |:insert| commands.
{script}, like for the |:append| and |:insert| commands. Refer to
|:let-heredoc| for more information.
This form of the |:python| command is mainly useful for including python code
in Vim scripts.
@@ -768,12 +767,12 @@ match the Python 2.x or Python 3 version Vim was compiled with.
*:py3* *:python3*
:[range]py3 {stmt}
:[range]py3 << [endmarker]
:[range]py3 << [trim] [{endmarker}]
{script}
{endmarker}
:[range]python3 {stmt}
:[range]python3 << [endmarker]
:[range]python3 << [trim] [{endmarker}]
{script}
{endmarker}
The `:py3` and `:python3` commands work similar to `:python`. A

View File

@@ -28,15 +28,15 @@ downloading Ruby there.
:rub[y] {cmd} Execute Ruby command {cmd}. A command to try it out: >
:ruby print "Hello"
:rub[y] << [endmarker]
:rub[y] << [trim] [{endmarker}]
{script}
{endmarker}
Execute Ruby script {script}.
The {endmarker} after {script} must NOT be preceded by
any white space.
If [endmarker] is omitted, it defaults to a dot '.'
like for the |:append| and |:insert| commands.
like for the |:append| and |:insert| commands. Refer
to |:let-heredoc| for more information.
This form of the |:ruby| command is mainly useful for
including ruby code in vim scripts.

View File

@@ -30,7 +30,7 @@ comments, ideas etc to <Ingo.Wilken@informatik.uni-oldenburg.de>
is working: >
:tcl puts "Hello"
:[range]tc[l] << [endmarker]
:[range]tc[l] << [trim] [{endmarker}]
{script}
{endmarker}
Execute Tcl script {script}.
@@ -38,10 +38,9 @@ comments, ideas etc to <Ingo.Wilken@informatik.uni-oldenburg.de>
wasn't compiled in. To avoid errors, see
|script-here|.
The {endmarker} after {script} must NOT be preceded by any white space.
If [endmarker] is omitted from after the "<<", a dot '.' must be used after
{script}, like for the |:append| and |:insert| commands.
{script}, like for the |:append| and |:insert| commands. Refer to
|:let-heredoc| for more information.
This form of the |:tcl| command is mainly useful for including tcl code in Vim
scripts.

View File

@@ -541,10 +541,15 @@ list_script_vars(int *first)
* The {marker} is a string. If the optional 'trim' word is supplied before the
* marker, then the leading indentation before the lines (matching the
* indentation in the 'cmd' line) is stripped.
*
* When getting lines for an embedded script (e.g. python, lua, perl, ruby,
* tcl, mzscheme), script_get is set to TRUE. In this case, if the marker is
* missing, then '.' is accepted as a marker.
*
* Returns a List with {lines} or NULL.
*/
list_T *
heredoc_get(exarg_T *eap, char_u *cmd)
heredoc_get(exarg_T *eap, char_u *cmd, int script_get)
{
char_u *theline;
char_u *marker;
@@ -553,6 +558,7 @@ heredoc_get(exarg_T *eap, char_u *cmd)
int marker_indent_len = 0;
int text_indent_len = 0;
char_u *text_indent = NULL;
char_u dot[] = ".";
if (eap->getline == NULL)
{
@@ -597,10 +603,17 @@ heredoc_get(exarg_T *eap, char_u *cmd)
}
}
else
{
// When getting lines for an embedded script, if the marker is missing,
// accept '.' as the marker.
if (script_get)
marker = dot;
else
{
emsg(_("E172: Missing marker"));
return NULL;
}
}
l = list_alloc();
if (l == NULL)
@@ -746,7 +759,7 @@ ex_let_const(exarg_T *eap, int is_const)
list_T *l;
// HERE document
l = heredoc_get(eap, expr + 3);
l = heredoc_get(eap, expr + 3, FALSE);
if (l != NULL)
{
rettv_list_set(&rettv, l);

View File

@@ -4408,44 +4408,37 @@ open_cmdwin(void)
* Returns a pointer to allocated memory with {script} or NULL.
*/
char_u *
script_get(exarg_T *eap, char_u *cmd)
script_get(exarg_T *eap UNUSED, char_u *cmd UNUSED)
{
char_u *theline;
char *end_pattern = NULL;
char dot[] = ".";
#ifdef FEAT_EVAL
list_T *l;
listitem_T *li;
char_u *s;
garray_T ga;
if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL)
return NULL;
cmd += 2;
l = heredoc_get(eap, cmd, TRUE);
if (l == NULL)
return NULL;
ga_init2(&ga, 1, 0x400);
if (cmd[2] != NUL)
end_pattern = (char *)skipwhite(cmd + 2);
else
end_pattern = dot;
for (;;)
FOR_ALL_LIST_ITEMS(l, li)
{
theline = eap->getline(
#ifdef FEAT_EVAL
eap->cstack->cs_looplevel > 0 ? -1 :
#endif
NUL, eap->cookie, 0, TRUE);
if (theline == NULL || STRCMP(end_pattern, theline) == 0)
{
vim_free(theline);
break;
}
ga_concat(&ga, theline);
s = tv_get_string(&li->li_tv);
ga_concat(&ga, s);
ga_append(&ga, '\n');
vim_free(theline);
}
ga_append(&ga, NUL);
list_free(l);
return (char_u *)ga.ga_data;
#else
return NULL;
#endif
}
#if defined(FEAT_EVAL) || defined(PROTO)

View File

@@ -13,7 +13,7 @@ list_T *eval_spell_expr(char_u *badword, char_u *expr);
int get_spellword(list_T *list, char_u **pp);
void prepare_vimvar(int idx, typval_T *save_tv);
void restore_vimvar(int idx, typval_T *save_tv);
list_T *heredoc_get(exarg_T *eap, char_u *cmd);
list_T *heredoc_get(exarg_T *eap, char_u *cmd, int script_get);
void ex_let(exarg_T *eap);
void ex_const(exarg_T *eap);
int ex_let_vars(char_u *arg_start, typval_T *tv, int copy, int semicolon, int var_count, int flags, char_u *op);

View File

@@ -37,7 +37,7 @@ STARTTEST
:fun d.f()
: return 1
:endfun
py << EOF
py << trim EOF
d=vim.bindeval('d')
d['1']='asd'
d.update() # Must not do anything, including throwing errors
@@ -208,7 +208,7 @@ EOF
:let l = [0, 1, 2, 3]
:py l=vim.bindeval('l')
:lockvar! l
py << EOF
py << trim EOF
def emsg(ei):
return ei[0].__name__ + ':' + repr(ei[1].args)
@@ -221,7 +221,7 @@ EOF
:unlockvar! l
:"
:" Function calls
py << EOF
py << trim EOF
import sys
def ee(expr, g=globals(), l=locals()):
try:
@@ -283,7 +283,7 @@ EOF
:endif
:let messages=[]
:delfunction DictNew
py <<EOF
py << trim EOF
d=vim.bindeval('{}')
m=vim.bindeval('messages')
def em(expr, g=globals(), l=locals()):
@@ -367,7 +367,7 @@ EOF
:" threading
:let l = [0]
:py l=vim.bindeval('l')
py <<EOF
py << trim EOF
import threading
import time
@@ -400,7 +400,7 @@ EOF
:" settrace
:let l = []
:py l=vim.bindeval('l')
py <<EOF
py << trim EOF
import sys
def traceit(frame, event, arg):
@@ -497,7 +497,7 @@ EOF
: put =' W: '.wvals
: put =' B: '.wvals
:endfun
py << EOF
py << trim EOF
def e(s, g=globals(), l=locals()):
try:
exec(s, g, l)
@@ -627,7 +627,7 @@ EOF
: autocmd BufFilePost * python cb.append(vim.eval('expand("<abuf>")') + ':BufFilePost:' + vim.eval('bufnr("%")'))
: autocmd BufFilePre * python cb.append(vim.eval('expand("<abuf>")') + ':BufFilePre:' + vim.eval('bufnr("%")'))
:augroup END
py << EOF
py << trim EOF
# Tests BufferAppend and BufferItem
cb.append(b[0])
# Tests BufferSlice and BufferAssSlice
@@ -687,7 +687,7 @@ EOF
:buffer #
:edit c
:buffer #
py << EOF
py << trim EOF
try:
from __builtin__ import next
except ImportError:
@@ -750,7 +750,7 @@ EOF
:vnew a.2
:vnew b.2
:vnew c.2
py << EOF
py << trim EOF
cb.append('Number of tabs: ' + str(len(vim.tabpages)))
cb.append('Current tab pages:')
def W(w):
@@ -793,7 +793,7 @@ if list(vim.windows) != list(vim.current.tabpage.windows):
EOF
:"
:" Test vim.current
py << EOF
py << trim EOF
def H(o):
return repr(o)
cb.append('Current tab page: ' + repr(vim.current.tabpage))
@@ -839,7 +839,7 @@ EOF
:only!
:"
:" Test types
py << EOF
py << trim EOF
for expr, attr in (
('vim.vars', 'Dictionary'),
('vim.options', 'Options'),
@@ -857,7 +857,7 @@ del attr
EOF
:"
:" Test __dir__() method
py << EOF
py << trim EOF
for name, o in (
('current', vim.current),
('buffer', vim.current.buffer),
@@ -904,7 +904,7 @@ EOF
:py Pt = vim.bindeval('Pt')
:unlet Pt
:py del Pt
py << EOF
py << trim EOF
def ecall(out_prefix, func, *args, **kwargs):
line = out_prefix + ': '
try:
@@ -1029,7 +1029,7 @@ EOF
:py ecall('psa2(self={"20": 1})', psa2, self={'20': 1})
:py ecall('psa3(self={"20": 1})', psa3, self={'20': 1})
:py ecall('psa4(self={"20": 1})', psa4, self={'20': 1})
py << EOF
py << trim EOF
def s(v):
if v is None:
return repr(v)
@@ -1126,7 +1126,7 @@ EOF
: $put =string(a:000)
: return a:000
:endfun
py << EOF
py << trim EOF
class DupDict(vim.Dictionary):
def __setitem__(self, key, value):
super(DupDict, self).__setitem__(key, value)
@@ -1156,7 +1156,7 @@ EOF
:$put =string(pyeval('dd') is# pyeval('dd'))
:$put =string(pyeval('df'))
:delfunction Put
py <<
py << trim
del DupDict
del DupList
del DupFun
@@ -1167,7 +1167,7 @@ del df
.
:"
:" Test chdir
py << EOF
py << trim EOF
import os
fnamemodify = vim.Function('fnamemodify')
cb.append(fnamemodify('.', ':p:h:t'))
@@ -1197,7 +1197,7 @@ EOF
:endfun
:fun D()
:endfun
py << EOF
py << trim EOF
d = vim.Dictionary()
ned = vim.Dictionary(foo='bar', baz='abcD')
dl = vim.Dictionary(a=1)
@@ -1583,7 +1583,7 @@ EOF
:delfunction F
:"
:" Test import
py << EOF
py << trim EOF
sys.path.insert(0, os.path.join(os.getcwd(), 'python_before'))
sys.path.append(os.path.join(os.getcwd(), 'python_after'))
vim.options['rtp'] = os.getcwd().replace(',', '\\,').replace('\\', '\\\\')
@@ -1623,7 +1623,7 @@ EOF
:fun Exe(e)
: execute a:e
:endfun
py << EOF
py << trim EOF
Exe = vim.bindeval('function("Exe")')
ee('vim.command("throw \'abcN\'")')
ee('Exe("throw \'def\'")')
@@ -1637,7 +1637,7 @@ EOF
:delfunction Exe
:"
:" Regression: interrupting vim.command propagates to next vim.command
py << EOF
py << trim EOF
def test_keyboard_interrupt():
try:
vim.command('while 1 | endwhile')
@@ -1669,7 +1669,7 @@ EOF
:py del test_keyboard_interrupt
:"
:" Cleanup
py << EOF
py << trim EOF
del cb
del ee
del emsg

View File

@@ -31,7 +31,7 @@ STARTTEST
:fun d.f()
: return 1
:endfun
py3 << EOF
py3 << trim EOF
d=vim.bindeval('d')
d['1']='asd'
d.update() # Must not do anything, including throwing errors
@@ -201,7 +201,7 @@ EOF
:let l = [0, 1, 2, 3]
:py3 l=vim.bindeval('l')
:lockvar! l
py3 << EOF
py3 << trim EOF
def emsg(ei):
return ei[0].__name__ + ':' + repr(ei[1].args)
@@ -214,7 +214,7 @@ EOF
:unlockvar! l
:"
:" Function calls
py3 << EOF
py3 << trim EOF
import sys
import re
@@ -301,7 +301,7 @@ EOF
:endif
:let messages=[]
:delfunction DictNew
py3 <<EOF
py3 << trim EOF
import sys
d=vim.bindeval('{}')
m=vim.bindeval('messages')
@@ -389,7 +389,7 @@ EOF
:" threading
:let l = [0]
:py3 l=vim.bindeval('l')
py3 <<EOF
py3 << trim EOF
import threading
import time
@@ -422,7 +422,7 @@ EOF
:" settrace
:let l = []
:py3 l=vim.bindeval('l')
py3 <<EOF
py3 << trim EOF
import sys
def traceit(frame, event, arg):
@@ -519,7 +519,7 @@ EOF
: put =' W: '.wvals
: put =' B: '.wvals
:endfun
py3 << EOF
py3 << trim EOF
def e(s, g=globals(), l=locals()):
try:
exec(s, g, l)
@@ -649,7 +649,7 @@ EOF
: autocmd BufFilePost * python3 cb.append(vim.eval('expand("<abuf>")') + ':BufFilePost:' + vim.eval('bufnr("%")'))
: autocmd BufFilePre * python3 cb.append(vim.eval('expand("<abuf>")') + ':BufFilePre:' + vim.eval('bufnr("%")'))
:augroup END
py3 << EOF
py3 << trim EOF
# Tests BufferAppend and BufferItem
cb.append(b[0])
# Tests BufferSlice and BufferAssSlice
@@ -705,7 +705,7 @@ EOF
:buffer #
:edit c
:buffer #
py3 << EOF
py3 << trim EOF
# Check GCing iterator that was not fully exhausted
i = iter(vim.buffers)
cb.append('i:' + str(next(i)))
@@ -764,7 +764,7 @@ EOF
:vnew a.2
:vnew b.2
:vnew c.2
py3 << EOF
py3 << trim EOF
cb.append('Number of tabs: ' + str(len(vim.tabpages)))
cb.append('Current tab pages:')
@@ -806,7 +806,7 @@ if list(vim.windows) != list(vim.current.tabpage.windows):
EOF
:"
:" Test vim.current
py3 << EOF
py3 << trim EOF
def H(o):
return repr(o)
cb.append('Current tab page: ' + repr(vim.current.tabpage))
@@ -852,7 +852,7 @@ EOF
:only!
:"
:" Test types
py3 << EOF
py3 << trim EOF
for expr, attr in (
('vim.vars', 'Dictionary'),
('vim.options', 'Options'),
@@ -870,7 +870,7 @@ del attr
EOF
:"
:" Test __dir__() method
py3 << EOF
py3 << trim EOF
for name, o in (
('current', vim.current),
('buffer', vim.current.buffer),
@@ -917,7 +917,7 @@ EOF
:py3 Pt = vim.bindeval('Pt')
:unlet Pt
:py3 del Pt
py3 << EOF
py3 << trim EOF
def ecall(out_prefix, func, *args, **kwargs):
line = out_prefix + ': '
try:
@@ -1042,7 +1042,7 @@ EOF
:py3 ecall('psa2(self={"20": 1})', psa2, self={'20': 1})
:py3 ecall('psa3(self={"20": 1})', psa3, self={'20': 1})
:py3 ecall('psa4(self={"20": 1})', psa4, self={'20': 1})
py3 << EOF
py3 << trim EOF
def s(v):
if v is None:
return repr(v)
@@ -1139,7 +1139,7 @@ EOF
: $put =string(a:000)
: return a:000
:endfun
py3 << EOF
py3 << trim EOF
class DupDict(vim.Dictionary):
def __setitem__(self, key, value):
super(DupDict, self).__setitem__(key, value)
@@ -1169,7 +1169,7 @@ EOF
:$put =string(py3eval('dd') is# py3eval('dd'))
:$put =string(py3eval('df'))
:delfunction Put
py3 << EOF
py3 << trim EOF
del DupDict
del DupList
del DupFun
@@ -1180,7 +1180,7 @@ del df
EOF
:"
:" Test chdir
py3 << EOF
py3 << trim EOF
import os
fnamemodify = vim.Function('fnamemodify')
cb.append(str(fnamemodify('.', ':p:h:t')))
@@ -1210,7 +1210,7 @@ EOF
:endfun
:fun D()
:endfun
py3 << EOF
py3 << trim EOF
d = vim.Dictionary()
ned = vim.Dictionary(foo='bar', baz='abcD')
dl = vim.Dictionary(a=1)
@@ -1596,7 +1596,7 @@ EOF
:delfunction F
:"
:" Test import
py3 << EOF
py3 << trim EOF
sys.path.insert(0, os.path.join(os.getcwd(), 'python_before'))
sys.path.append(os.path.join(os.getcwd(), 'python_after'))
vim.options['rtp'] = os.getcwd().replace(',', '\\,').replace('\\', '\\\\')
@@ -1636,7 +1636,7 @@ EOF
:fun Exe(e)
: execute a:e
:endfun
py3 << EOF
py3 << trim EOF
Exe = vim.bindeval('function("Exe")')
ee('vim.command("throw \'abcN\'")')
ee('Exe("throw \'def\'")')
@@ -1650,7 +1650,7 @@ EOF
:delfunction Exe
:"
:" Regression: interrupting vim.command propagates to next vim.command
py3 << EOF
py3 << trim EOF
def test_keyboard_interrupt():
try:
vim.command('while 1 | endwhile')
@@ -1682,7 +1682,7 @@ EOF
:py3 del test_keyboard_interrupt
:"
:" Cleanup
py3 << EOF
py3 << trim EOF
del cb
del ee
del emsg

View File

@@ -597,7 +597,7 @@ func Test_lua_set_cursor()
new
call setline(1, ['first line', 'second line'])
normal gg
lua << EOF
lua << trim EOF
w = vim.window()
w.line = 1
w.col = 5
@@ -608,3 +608,22 @@ EOF
normal j
call assert_equal([2, 5], [line('.'), col('.')])
endfunc
" Test for various heredoc syntax
func Test_lua_heredoc()
lua << END
vim.command('let s = "A"')
END
lua <<
vim.command('let s ..= "B"')
.
lua << trim END
vim.command('let s ..= "C"')
END
lua << trim
vim.command('let s ..= "D"')
.
call assert_equal('ABCD', s)
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -219,7 +219,7 @@ endfunc
func Test_stdio()
redir =>l:out
perl <<EOF
perl << trim EOF
VIM::Msg("&VIM::Msg");
print "STDOUT";
print STDERR "STDERR";
@@ -290,3 +290,22 @@ func Test_set_cursor()
normal j
call assert_equal([2, 6], [line('.'), col('.')])
endfunc
" Test for various heredoc syntax
func Test_perl_heredoc()
perl << END
VIM::DoCommand('let s = "A"')
END
perl <<
VIM::DoCommand('let s ..= "B"')
.
perl << trim END
VIM::DoCommand('let s ..= "C"')
END
perl << trim
VIM::DoCommand('let s ..= "D"')
.
call assert_equal('ABCD', s)
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -167,3 +167,22 @@ func Test_Catch_Exception_Message()
call assert_match( '^Vim(.*):RuntimeError: TEST$', v:exception )
endtry
endfunc
" Test for various heredoc syntax
func Test_python_heredoc()
python << END
s='A'
END
python <<
s+='B'
.
python << trim END
s+='C'
END
python << trim
s+='D'
.
call assert_equal('ABCD', pyxeval('s'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -295,9 +295,11 @@ func Test_python3_opt_reset_local_to_global()
" Set the global and buffer-local option values and then clear the
" buffer-local option value.
for opt in bopts
py3 pyopt = vim.bindeval("opt")
py3 vim.options[pyopt[0]] = pyopt[1]
py3 curbuf.options[pyopt[0]] = pyopt[2]
py3 << trim END
pyopt = vim.bindeval("opt")
vim.options[pyopt[0]] = pyopt[1]
curbuf.options[pyopt[0]] = pyopt[2]
END
exe "call assert_equal(opt[2], &" .. opt[0] .. ")"
exe "call assert_equal(opt[1], &g:" .. opt[0] .. ")"
exe "call assert_equal(opt[2], &l:" .. opt[0] .. ")"
@@ -315,9 +317,11 @@ func Test_python3_opt_reset_local_to_global()
\ ['sidescrolloff', 6, 12, -1],
\ ['statusline', '%<%f', '%<%F', '']]
for opt in wopts
py3 pyopt = vim.bindeval("opt")
py3 vim.options[pyopt[0]] = pyopt[1]
py3 curwin.options[pyopt[0]] = pyopt[2]
py3 << trim
pyopt = vim.bindeval("opt")
vim.options[pyopt[0]] = pyopt[1]
curwin.options[pyopt[0]] = pyopt[2]
.
exe "call assert_equal(opt[2], &" .. opt[0] .. ")"
exe "call assert_equal(opt[1], &g:" .. opt[0] .. ")"
exe "call assert_equal(opt[2], &l:" .. opt[0] .. ")"
@@ -331,4 +335,21 @@ func Test_python3_opt_reset_local_to_global()
close!
endfunc
" Test for various heredoc syntax
func Test_python3_heredoc()
python3 << END
s='A'
END
python3 <<
s+='B'
.
python3 << trim END
s+='C'
END
python3 << trim
s+='D'
.
call assert_equal('ABCD', pyxeval('s'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -15,7 +15,7 @@ endfunc
func Test_pyx()
redir => var
pyx << EOF
pyx << trim EOF
import sys
print(sys.version)
EOF
@@ -79,3 +79,22 @@ func Test_Catch_Exception_Message()
call assert_match( '^Vim(.*):RuntimeError: TEST$', v:exception )
endtry
endfunc
" Test for various heredoc syntaxes
func Test_pyx2_heredoc()
pyx << END
result='A'
END
pyx <<
result+='B'
.
pyx << trim END
result+='C'
END
pyx << trim
result+='D'
.
call assert_equal('ABCD', pyxeval('result'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -15,7 +15,7 @@ endfunc
func Test_pyx()
redir => var
pyx << EOF
pyx << trim EOF
import sys
print(sys.version)
EOF
@@ -79,3 +79,22 @@ func Test_Catch_Exception_Message()
call assert_match( '^Vim(.*):RuntimeError: TEST$', v:exception )
endtry
endfunc
" Test for various heredoc syntaxes
func Test_pyx3_heredoc()
pyx << END
result='A'
END
pyx <<
result+='B'
.
pyx << trim END
result+='C'
END
pyx << trim
result+='D'
.
call assert_equal('ABCD', pyxeval('result'))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -332,7 +332,7 @@ func Test_ruby_Vim_evaluate_list()
call setline(line('$'), ['2 line 2'])
ruby Vim.command("normal /^2\n")
let l = ["abc", "def"]
ruby << EOF
ruby << trim EOF
curline = $curbuf.line_number
l = Vim.evaluate("l");
$curbuf.append(curline, l.join("\n"))
@@ -394,3 +394,22 @@ func Test_ruby_p()
let messages = split(execute('message'), "\n")
call assert_equal(0, len(messages))
endfunc
" Test for various heredoc syntax
func Test_ruby_heredoc()
ruby << END
Vim.command('let s = "A"')
END
ruby <<
Vim.command('let s ..= "B"')
.
ruby << trim END
Vim.command('let s ..= "C"')
END
ruby << trim
Vim.command('let s ..= "D"')
.
call assert_equal('ABCD', s)
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -67,7 +67,7 @@ func Test_vim_buffer()
" Test ::vim::buffer list
call assert_equal('2', TclEval('llength [::vim::buffer list]'))
call assert_equal(b1.' '.b2, TclEval('::vim::buffer list'))
tcl <<EOF
tcl << trim EOF
proc eachbuf { cmd } {
foreach b [::vim::buffer list] { $b command $cmd }
}
@@ -680,3 +680,22 @@ func Test_set_cursor()
normal j
call assert_equal([2, 5], [line('.'), col('.')])
endfunc
" Test for different syntax for ruby heredoc
func Test_tcl_heredoc()
tcl << END
::vim::command {let s = "A"}
END
tcl <<
::vim::command {let s ..= "B"}
.
tcl << trim END
::vim::command {let s ..= "C"}
END
tcl << trim
::vim::command {let s ..= "D"}
.
call assert_equal('ABCD', s)
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -2830,10 +2830,19 @@ ex_function(exarg_T *eap)
{
// ":python <<" continues until a dot, like ":append"
p = skipwhite(arg + 2);
if (STRNCMP(p, "trim", 4) == 0)
{
// Ignore leading white space.
p = skipwhite(p + 4);
heredoc_trimmed = vim_strnsave(theline,
(int)(skipwhite(theline) - theline));
}
if (*p == NUL)
skip_until = vim_strsave((char_u *)".");
else
skip_until = vim_strsave(p);
skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p));
do_concat = FALSE;
is_heredoc = TRUE;
}
// Check for ":let v =<< [trim] EOF"

View File

@@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
578,
/**/
577,
/**/

View File

@@ -4207,7 +4207,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
// [let] varname =<< [trim] {end}
eap->getline = heredoc_getline;
eap->cookie = cctx;
l = heredoc_get(eap, op + 3);
l = heredoc_get(eap, op + 3, FALSE);
// Push each line and the create the list.
FOR_ALL_LIST_ITEMS(l, li)