summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-04-14 20:15:49 +0200
committerBram Moolenaar <Bram@vim.org>2020-04-14 20:15:49 +0200
commit6c2b7b8055b96463f78abb70f58c4c6d6d4b9d55 (patch)
tree597e3992bed8691b13c5a2c4a459d2541b9acc18 /src
parent7a1637f4c00ac3d0cbf894803ada1586a1717470 (diff)
patch 8.2.0578: heredoc for interfaces does not support "trim"v8.2.0578
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)
Diffstat (limited to 'src')
-rw-r--r--src/evalvars.c21
-rw-r--r--src/ex_getln.c41
-rw-r--r--src/proto/evalvars.pro2
-rw-r--r--src/testdir/test86.in1822
-rw-r--r--src/testdir/test87.in1864
-rw-r--r--src/testdir/test_lua.vim29
-rw-r--r--src/testdir/test_perl.vim23
-rw-r--r--src/testdir/test_python2.vim19
-rw-r--r--src/testdir/test_python3.vim33
-rw-r--r--src/testdir/test_pyx2.vim27
-rw-r--r--src/testdir/test_pyx3.vim27
-rw-r--r--src/testdir/test_ruby.vim29
-rw-r--r--src/testdir/test_tcl.vim23
-rw-r--r--src/userfunc.c11
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c2
16 files changed, 2073 insertions, 1902 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index d32b76a87b..5dddd0903f 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -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)
{
@@ -598,8 +604,15 @@ heredoc_get(exarg_T *eap, char_u *cmd)
}
else
{
- emsg(_("E172: Missing marker"));
- return NULL;
+ // 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();
@@ -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);
diff --git a/src/ex_getln.c b/src/ex_getln.c
index accedb5403..9b959fbad5 100644
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -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;
- ga_init2(&ga, 1, 0x400);
+ l = heredoc_get(eap, cmd, TRUE);
+ if (l == NULL)
+ return NULL;
- if (cmd[2] != NUL)
- end_pattern = (char *)skipwhite(cmd + 2);
- else
- end_pattern = dot;
+ ga_init2(&ga, 1, 0x400);
- 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)
diff --git a/src/proto/evalvars.pro b/src/proto/evalvars.pro
index 352097d430..c53c115bf1 100644
--- a/src/proto/evalvars.pro
+++ b/src/proto/evalvars.pro
@@ -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);
diff --git a/src/testdir/test86.in b/src/testdir/test86.in
index c706a3d938..e24c13d1ca 100644
--- a/src/testdir/test86.in
+++ b/src/testdir/test86.in
@@ -37,20 +37,20 @@ STARTTEST
:fun d.f()
: return 1
:endfun
-py << EOF
-d=vim.bindeval('d')
-d['1']='asd'
-d.update() # Must not do anything, including throwing errors
-d.update(b=[1, 2, f])
-d.update((('-1', {'a': 1}),))
-d.update({'0': -1})
-dk = d.keys()
-dv = d.values()
-di = d.items()
-cmpfun = lambda a, b: cmp(repr(a), repr(b))
-dk.sort(cmpfun)
-dv.sort(cmpfun)
-di.sort(cmpfun)
+py << trim EOF
+ d=vim.bindeval('d')
+ d['1']='asd'
+ d.update() # Must not do anything, including throwing errors
+ d.update(b=[1, 2, f])
+ d.update((('-1', {'a': 1}),))
+ d.update({'0': -1})
+ dk = d.keys()
+ dv = d.values()
+ di = d.items()
+ cmpfun = lambda a, b: cmp(repr(a), repr(b))
+ dk.sort(cmpfun)
+ dv.sort(cmpfun)
+ di.sort(cmpfun)
EOF
:$put =pyeval('d[''f''](self={})')
:$put =pyeval('repr(dk)')
@@ -208,52 +208,52 @@ EOF
:let l = [0, 1, 2, 3]
:py l=vim.bindeval('l')
:lockvar! l
-py << EOF
-def emsg(ei):
- return ei[0].__name__ + ':' + repr(ei[1].args)
+py << trim EOF
+ def emsg(ei):
+ return ei[0].__name__ + ':' + repr(ei[1].args)
-try:
- l[2]='i'
-except vim.error:
- cb.append('l[2] threw vim.error: ' + emsg(sys.exc_info()))
+ try:
+ l[2]='i'
+ except vim.error:
+ cb.append('l[2] threw vim.error: ' + emsg(sys.exc_info()))
EOF
:$put =string(l)
:unlockvar! l
:"
:" Function calls
-py << EOF
-import sys
-def ee(expr, g=globals(), l=locals()):
- try:
- exec(expr, g, l)
- except:
- ei = sys.exc_info()
- msg = emsg(ei)
- msg = msg.replace('TypeError:(\'argument 1 ', 'TypeError:(\'')
- if expr.find('None') > -1:
- msg = msg.replace('TypeError:(\'iteration over non-sequence\',)',
- 'TypeError:("\'NoneType\' object is not iterable",)')
- if expr.find('FailingNumber') > -1:
- msg = msg.replace(', not \'FailingNumber\'', '').replace('"', '\'')
- msg = msg.replace('TypeError:(\'iteration over non-sequence\',)',
- 'TypeError:("\'FailingNumber\' object is not iterable",)')
- if msg.find('(\'\'') > -1 or msg.find('(\'can\'t') > -1:
- msg = msg.replace('(\'', '("').replace('\',)', '",)')
- # Some Python versions say can't, others cannot.
- if msg.find('can\'t') > -1:
- msg = msg.replace('can\'t', 'cannot')
- # Some Python versions use single quote, some double quote
- if msg.find('"cannot ') > -1:
- msg = msg.replace('"cannot ', '\'cannot ')
- if msg.find(' attributes"') > -1:
- msg = msg.replace(' attributes"', ' attributes\'')
- if expr == 'fd(self=[])':
- # HACK: PyMapping_Check changed meaning
- msg = msg.replace('AttributeError:(\'keys\',)',
- 'TypeError:(\'unable to convert list to vim dictionary\',)')
- vim.current.buffer.append(expr + ':' + msg)
- else:
- vim.current.buffer.append(expr + ':NOT FAILED')
+py << trim EOF
+ import sys
+ def ee(expr, g=globals(), l=locals()):
+ try:
+ exec(expr, g, l)
+ except:
+ ei = sys.exc_info()
+ msg = emsg(ei)
+ msg = msg.replace('TypeError:(\'argument 1 ', 'TypeError:(\'')
+ if expr.find('None') > -1:
+ msg = msg.replace('TypeError:(\'iteration over non-sequence\',)',
+ 'TypeError:("\'NoneType\' object is not iterable",)')
+ if expr.find('FailingNumber') > -1:
+ msg = msg.replace(', not \'FailingNumber\'', '').replace('"', '\'')
+ msg = msg.replace('TypeError:(\'iteration over non-sequence\',)',
+ 'TypeError:("\'FailingNumber\' object is not iterable",)')
+ if msg.find('(\'\'') > -1 or msg.find('(\'can\'t') > -1:
+ msg = msg.replace('(\'', '("').replace('\',)', '",)')
+ # Some Python versions say can't, others cannot.
+ if msg.find('can\'t') > -1:
+ msg = msg.replace('can\'t', 'cannot')
+ # Some Python versions use single quote, some double quote
+ if msg.find('"cannot ') > -1:
+ msg = msg.replace('"cannot ', '\'cannot ')
+ if msg.find(' attributes"') > -1:
+ msg = msg.replace(' attributes"', ' attributes\'')
+ if expr == 'fd(self=[])':
+ # HACK: PyMapping_Check changed meaning
+ msg = msg.replace('AttributeError:(\'keys\',)',
+ 'TypeError:(\'unable to convert list to vim dictionary\',)')
+ vim.current.buffer.append(expr + ':' + msg)
+ else:
+ vim.current.buffer.append(expr + ':NOT FAILED')
EOF
:fun New(...)
: return ['NewStart']+a:000+['NewEnd']
@@ -283,26 +283,26 @@ EOF
:endif
:let messages=[]
:delfunction DictNew
-py <<EOF
-d=vim.bindeval('{}')
-m=vim.bindeval('messages')
-def em(expr, g=globals(), l=locals()):
- try:
- exec(expr, g, l)
- except:
- m.extend([sys.exc_type.__name__])
+py << trim EOF
+ d=vim.bindeval('{}')
+ m=vim.bindeval('messages')
+ def em(expr, g=globals(), l=locals()):
+ try:
+ exec(expr, g, l)
+ except:
+ m.extend([sys.exc_type.__name__])
-em('d["abc1"]')
-em('d["abc1"]="\\0"')
-em('d["abc1"]=vim')
-em('d[""]=1')
-em('d["a\\0b"]=1')
-em('d[u"a\\0b"]=1')
+ em('d["abc1"]')
+ em('d["abc1"]="\\0"')
+ em('d["abc1"]=vim')
+ em('d[""]=1')
+ em('d["a\\0b"]=1')
+ em('d[u"a\\0b"]=1')
-em('d.pop("abc1")')
-em('d.popitem()')
-del em
-del m
+ em('d.pop("abc1")')
+ em('d.popitem()')
+ del em
+ del m
EOF
:$put =messages
:unlet messages
@@ -367,24 +367,24 @@ EOF
:" threading
:let l = [0]
:py l=vim.bindeval('l')
-py <<EOF
-import threading
-import time
+py << trim EOF
+ import threading
+ import time
-class T(threading.Thread):
- def __init__(self):
- threading.Thread.__init__(self)
- self.t = 0
- self.running = True
+ class T(threading.Thread):
+ def __init__(self):
+ threading.Thread.__init__(self)
+ self.t = 0
+ self.running = True
- def run(self):
- while self.running:
- self.t += 1
- time.sleep(0.1)
+ def run(self):
+ while self.running:
+ self.t += 1
+ time.sleep(0.1)
-t = T()
-del T
-t.start()
+ t = T()
+ del T
+ t.start()
EOF
:sleep 1
:py t.running = False
@@ -400,18 +400,18 @@ EOF
:" settrace
:let l = []
:py l=vim.bindeval('l')
-py <<EOF
-import sys
+py << trim EOF
+ import sys
-def traceit(frame, event, arg):
- global l
- if event == "line":
- l.extend([frame.f_lineno])
- return traceit
+ def traceit(frame, event, arg):
+ global l
+ if event == "line":
+ l.extend([frame.f_lineno])
+ return traceit
-def trace_main():
- for i in range(5):
- pass
+ def trace_main():
+ for i in range(5):
+ pass
EOF
:py sys.settrace(traceit)
:py trace_main()
@@ -497,19 +497,19 @@ EOF
: put =' W: '.wvals
: put =' B: '.wvals
:endfun
-py << EOF
-def e(s, g=globals(), l=locals()):
- try:
- exec(s, g, l)
- except:
- vim.command('return ' + repr(sys.exc_type.__name__))
+py << trim EOF
+ def e(s, g=globals(), l=locals()):
+ try:
+ exec(s, g, l)
+ except:
+ vim.command('return ' + repr(sys.exc_type.__name__))
-def ev(s, g=globals(), l=locals()):
- try:
- return eval(s, g, l)
- except:
- vim.command('let exc=' + repr(sys.exc_type.__name__))
- return 0
+ def ev(s, g=globals(), l=locals()):
+ try:
+ return eval(s, g, l)
+ except:
+ vim.command('let exc=' + repr(sys.exc_type.__name__))
+ return 0
EOF
:fun E(s)
: python e(vim.eval('a:s'))
@@ -627,52 +627,52 @@ 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
-# Tests BufferAppend and BufferItem
-cb.append(b[0])
-# Tests BufferSlice and BufferAssSlice
-cb.append('abc5') # Will be overwritten
-cb[-1:] = b[:-2]
-# Test BufferLength and BufferAssSlice
-cb.append('def') # Will not be overwritten
-cb[len(cb):] = b[:]
-# Test BufferAssItem and BufferMark
-cb.append('ghi') # Will be overwritten
-cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1]))
-# Test BufferRepr
-cb.append(repr(cb) + repr(b))
-# Modify foreign buffer
-b.append('foo')
-b[0]='bar'
-b[0:0]=['baz']
-vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number)
-# Test assigning to name property
-import os
-old_name = cb.name
-cb.name = 'foo'
-cb.append(cb.name[-11:].replace(os.path.sep, '/'))
-b.name = 'bar'
-cb.append(b.name[-11:].replace(os.path.sep, '/'))
-cb.name = old_name
-cb.append(cb.name[-17:].replace(os.path.sep, '/'))
-del old_name
-# Test CheckBuffer
-for _b in vim.buffers:
- if _b is not cb:
- vim.command('bwipeout! ' + str(_b.number))
-del _b
-cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid)))
-for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc6")', 'b.name = "!"'):
- try:
- exec(expr)
- except vim.error:
- pass
- else:
- # Usually a SEGV here
- # Should not happen in any case
- cb.append('No exception for ' + expr)
-vim.command('cd .')
-del b
+py << trim EOF
+ # Tests BufferAppend and BufferItem
+ cb.append(b[0])
+ # Tests BufferSlice and BufferAssSlice
+ cb.append('abc5') # Will be overwritten
+ cb[-1:] = b[:-2]
+ # Test BufferLength and BufferAssSlice
+ cb.append('def') # Will not be overwritten
+ cb[len(cb):] = b[:]
+ # Test BufferAssItem and BufferMark
+ cb.append('ghi') # Will be overwritten
+ cb[-1] = repr((len(cb) - cb.mark('a')[0], cb.mark('a')[1]))
+ # Test BufferRepr
+ cb.append(repr(cb) + repr(b))
+ # Modify foreign buffer
+ b.append('foo')
+ b[0]='bar'
+ b[0:0]=['baz']
+ vim.command('call append("$", getbufline(%i, 1, "$"))' % b.number)
+ # Test assigning to name property
+ import os
+ old_name = cb.name
+ cb.name = 'foo'
+ cb.append(cb.name[-11:].replace(os.path.sep, '/'))
+ b.name = 'bar'
+ cb.append(b.name[-11:].replace(os.path.sep, '/'))
+ cb.name = old_name
+ cb.append(cb.name[-17:].replace(os.path.sep, '/'))
+ del old_name
+ # Test CheckBuffer
+ for _b in vim.buffers:
+ if _b is not cb:
+ vim.command('bwipeout! ' + str(_b.number))
+ del _b
+ cb.append('valid: b:%s, cb:%s' % (repr(b.valid), repr(cb.valid)))
+ for expr in ('b[1]','b[:] = ["A", "B"]','b[:]','b.append("abc6")', 'b.name = "!"'):
+ try:
+ exec(expr)
+ except vim.error:
+ pass
+ else:
+ # Usually a SEGV here
+ # Should not happen in any case
+ cb.append('No exception for ' + expr)
+ vim.command('cd .')
+ del b
EOF
:augroup BUFS
: autocmd!
@@ -687,59 +687,59 @@ EOF
:buffer #
:edit c
:buffer #
-py << EOF
-try:
- from __builtin__ import next
-except ImportError:
- next = lambda o: o.next()
-# Check GCing iterator that was not fully exhausted
-i = iter(vim.buffers)
-cb.append('i:' + str(next(i)))
-# and also check creating more than one iterator at a time
-i2 = iter(vim.buffers)
-cb.append('i2:' + str(next(i2)))
-cb.append('i:' + str(next(i)))
-# The following should trigger GC and not cause any problems
-del i
-del i2
-i3 = iter(vim.buffers)
-cb.append('i3:' + str(next(i3)))
-del i3
+py << trim EOF
+ try:
+ from __builtin__ import next
+ except ImportError:
+ next = lambda o: o.next()
+ # Check GCing iterator that was not fully exhausted
+ i = iter(vim.buffers)
+ cb.append('i:' + str(next(i)))
+ # and also check creating more than one iterator at a time
+ i2 = iter(vim.buffers)
+ cb.append('i2:' + str(next(i2)))
+ cb.append('i:' + str(next(i)))
+ # The following should trigger GC and not cause any problems
+ del i
+ del i2
+ i3 = iter(vim.buffers)
+ cb.append('i3:' + str(next(i3)))
+ del i3
-prevnum = 0
-for b in vim.buffers:
- # Check buffer order
- if prevnum >= b.number:
- cb.append('!!! Buffer numbers not in strictly ascending order')
- # Check indexing: vim.buffers[number].number == number
- cb.append(str(b.number) + ':' + repr(vim.buffers[b.number]) + '=' + repr(b))
- prevnum = b.number
-del prevnum
+ prevnum = 0
+ for b in vim.buffers:
+ # Check buffer order
+ if prevnum >= b.number:
+ cb.append('!!! Buffer numbers not in strictly ascending order')
+ # Check indexing: vim.buffers[number].number == number
+ cb.append(str(b.number) + ':' + repr(vim.buffers[b.number]) + '=' + repr(b))
+ prevnum = b.number
+ del prevnum
-cb.append(str(len(vim.buffers)))
+ cb.append(str(len(vim.buffers)))
-bnums = list(map(lambda b: b.number, vim.buffers))[1:]
+ bnums = list(map(lambda b: b.number, vim.buffers))[1:]
-# Test wiping out buffer with existing iterator
-i4 = iter(vim.buffers)
-cb.append('i4:' + str(next(i4)))
-vim.command('bwipeout! ' + str(bnums.pop(0)))
-try:
- next(i4)
-except vim.error:
- pass
-else:
- cb.append('!!!! No vim.error')
-i4 = iter(vim.buffers)
-vim.command('bwipeout! ' + str(bnums.pop(-1)))
-vim.command('bwipeout! ' + str(bnums.pop(-1)))
-cb.append('i4:' + str(next(i4)))
-try:
- next(i4)
-except StopIteration:
- cb.append('StopIteration')
-del i4
-del bnums
+ # Test wiping out buffer with existing iterator
+ i4 = iter(vim.buffers)
+ cb.append('i4:' + str(next(i4)))
+ vim.command('bwipeout! ' + str(bnums.pop(0)))
+ try:
+ next(i4)
+ except vim.error:
+ pass
+ else:
+ cb.append('!!!! No vim.error')
+ i4 = iter(vim.buffers)
+ vim.command('bwipeout! ' + str(bnums.pop(-1)))
+ vim.command('bwipeout! ' + str(bnums.pop(-1)))
+ cb.append('i4:' + str(next(i4)))
+ try:
+ next(i4)
+ except StopIteration:
+ cb.append('StopIteration')
+ del i4
+ del bnums
EOF
:"
:" Test vim.{tabpage,window}list and vim.{tabpage,window} objects
@@ -750,128 +750,128 @@ EOF
:vnew a.2
:vnew b.2
:vnew c.2
-py << EOF
-cb.append('Number of tabs: ' + str(len(vim.tabpages)))
-cb.append('Current tab pages:')
-def W(w):
- if repr(w).find('(unknown)') != -1:
- return '<window object (unknown)>'
- else:
- return repr(w)
+py << trim EOF
+ cb.append('Number of tabs: ' + str(len(vim.tabpages)))
+ cb.append('Current tab pages:')
+ def W(w):
+ if repr(w).find('(unknown)') != -1:
+ return '<window object (unknown)>'
+ else:
+ return repr(w)
-start = len(cb)
+ start = len(cb)
-def Cursor(w):
- if w.buffer is cb:
- return repr((start - w.cursor[0], w.cursor[1]))
- else:
- return repr(w.cursor)
+ def Cursor(w):
+ if w.buffer is cb:
+ return repr((start - w.cursor[0], w.cursor[1]))
+ else:
+ return repr(w.cursor)
-for t in vim.tabpages:
- cb.append(' ' + repr(t) + '(' + str(t.number) + ')' + ': ' + str(len(t.windows)) + ' windows, current is ' + W(t.window))
- cb.append(' Windows:')
- for w in t.windows:
- cb.append(' ' + W(w) + '(' + str(w.number) + ')' + ': displays buffer ' + repr(w.buffer) + '; cursor is at ' + Cursor(w))
- # Other values depend on the size of the terminal, so they are checked partly:
- for attr in ('height', 'row', 'width', 'col'):
- try:
- aval = getattr(w, attr)
- if type(aval) is not long:
- raise TypeError
- if aval < 0:
- raise ValueError
- except Exception:
- cb.append('!!!!!! Error while getting attribute ' + attr + ': ' + sys.exc_type.__name__)
- del aval
- del attr
- w.cursor = (len(w.buffer), 0)
-del W
-del Cursor
-cb.append('Number of windows in current tab page: ' + str(len(vim.windows)))
-if list(vim.windows) != list(vim.current.tabpage.windows):
- cb.append('!!!!!! Windows differ')
+ for t in vim.tabpages:
+ cb.append(' ' + repr(t) + '(' + str(t.number) + ')' + ': ' + str(len(t.windows)) + ' windows, current is ' + W(t.window))
+ cb.append(' Windows:')
+ for w in t.windows:
+ cb.append(' ' + W(w) + '(' + str(w.number) + ')' + ': displays buffer ' + repr(w.buffer) + '; cursor is at ' + Cursor(w))
+ # Other values depend on the size of the terminal, so they are checked partly:
+ for attr in ('height', 'row', 'width', 'col'):
+ try:
+ aval = getattr(w, attr)
+ if type(aval) is not long:
+ raise TypeError
+ if aval < 0:
+ raise ValueError
+ except Exception:
+ cb.append('!!!!!! Error while getting attribute ' + attr + ': ' + sys.exc_type.__name__)
+ del aval
+ del attr
+ w.cursor = (len(w.buffer), 0)
+ del W
+ del Cursor
+ cb.append('Number of windows in current tab page: ' + str(len(vim.windows)))
+ if list(vim.windows) != list(vim.current.tabpage.windows):
+ cb.append('!!!!!! Windows differ')
EOF
:"
:" Test vim.current
-py << EOF
-def H(o):
- return repr(o)
-cb.append('Current tab page: ' + repr(vim.current.tabpage))
-cb.append('Current window: ' + repr(vim.current.window) + ': ' + H(vim.current.window) + ' is ' + H(vim.current.tabpage.window))
-cb.append('Current buffer: ' + repr(vim.current.buffer) + ': ' + H(vim.current.buffer) + ' is ' + H(vim.current.window.buffer)+ ' is ' + H(vim.current.tabpage.window.buffer))
-del H
-# Assigning: fails
-try:
- vim.current.window = vim.tabpages[0].window
-except ValueError:
- cb.append('ValueError at assigning foreign tab window')
+py << trim EOF
+ def H(o):
+ return repr(o)
+ cb.append('Current tab page: ' + repr(vim.current.tabpage))
+ cb.append('Current window: ' + repr(vim.current.window) + ': ' + H(vim.current.window) + ' is ' + H(vim.current.tabpage.window))
+ cb.append('Current buffer: ' + repr(vim.current.buffer) + ': ' + H(vim.current.buffer) + ' is ' + H(vim.current.window.buffer)+ ' is ' + H(vim.current.tabpage.window.buffer))
+ del H
+ # Assigning: fails
+ try:
+ vim.current.window = vim.tabpages[0].window
+ except ValueError:
+ cb.append('ValueError at assigning foreign tab window')
-for attr in ('window', 'tabpage', 'buffer'):
- try:
- setattr(vim.current, attr, None)
- except TypeError:
- cb.append('Type error at assigning None to vim.current.' + attr)
-del attr
+ for attr in ('window', 'tabpage', 'buffer'):
+ try:
+ setattr(vim.current, attr, None)
+ except TypeError:
+ cb.append('Type error at assigning None to vim.current.' + attr)
+ del attr
-# Assigning: success
-vim.current.tabpage = vim.tabpages[-2]
-vim.current.buffer = cb
-vim.current.window = vim.windows[0]
-vim.current.window.cursor = (len(vim.current.buffer), 0)
-cb.append('Current tab page: ' + repr(vim.current.tabpage))
-cb.append('Current window: ' + repr(vim.current.window))
-cb.append('Current buffer: ' + repr(vim.current.buffer))
-cb.append('Current line: ' + repr(vim.current.line))
-ws = list(vim.windows)
-ts = list(vim.tabpages)
-for b in vim.buffers:
- if b is not cb:
- vim.command('bwipeout! ' + str(b.number))
-del b
-cb.append('w.valid: ' + repr([w.valid for w in ws]))
-cb.append('t.valid: ' + repr([t.valid for t in ts]))
-del w
-del t
-del ts
-del ws
+ # Assigning: success
+ vim.current.tabpage = vim.tabpages[-2]
+ vim.current.buffer = cb
+ vim.current.window = vim.windows[0]
+ vim.current.window.cursor = (len(vim.current.buffer), 0)
+ cb.append('Current tab page: ' + repr(vim.current.tabpage))
+ cb.append('Current window: ' + repr(vim.current.window))
+ cb.append('Current buffer: ' + repr(vim.current.buffer))
+ cb.append('Current line: ' + repr(vim.current.line))
+ ws = list(vim.windows)
+ ts = list(vim.tabpages)
+ for b in vim.buffers:
+ if b is not cb:
+ vim.command('bwipeout! ' + str(b.number))
+ del b
+ cb.append('w.valid: ' + repr([w.valid for w in ws]))
+ cb.append('t.valid: ' + repr([t.valid for t in ts]))
+ del w
+ del t
+ del ts
+ del ws
EOF
:tabonly!
:only!
:"
:" Test types
-py << EOF
-for expr, attr in (
- ('vim.vars', 'Dictionary'),
- ('vim.options', 'Options'),
- ('vim.bindeval("{}")', 'Dictionary'),
- ('vim.bindeval("[]")', 'List'),
- ('vim.bindeval("function(\'tr\')")', 'Function'),
- ('vim.current.buffer', 'Buffer'),
- ('vim.current.range', 'Range'),
- ('vim.current.window', 'Window'),
- ('vim.current.tabpage', 'TabPage'),
-):
- cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr)))
-del expr
-del attr
+py << trim EOF
+ for expr, attr in (
+ ('vim.vars', 'Dictionary'),
+ ('vim.options', 'Options'),
+ ('vim.bindeval("{}")', 'Dictionary'),
+ ('vim.bindeval("[]")', 'List'),
+ ('vim.bindeval("function(\'tr\')")', 'Function'),
+ ('vim.current.buffer', 'Buffer'),
+ ('vim.current.range', 'Range'),
+ ('vim.current.window', 'Window'),
+ ('vim.current.tabpage', 'TabPage'),
+ ):
+ cb.append(expr + ':' + attr + ':' + repr(type(eval(expr)) is getattr(vim, attr)))
+ del expr
+ del attr
EOF
:"
:" Test __dir__() method
-py << EOF
-for name, o in (
- ('current', vim.current),
- ('buffer', vim.current.buffer),
- ('window', vim.current.window),
- ('tabpage', vim.current.tabpage),
- ('range', vim.current.range),
- ('dictionary', vim.bindeval('{}')),
- ('list', vim.bindeval('[]')),
- ('function', vim.bindeval('function("tr")')),
- ('output', sys.stdout),
- ):
- cb.append(name + ':' + ','.join(dir(o)))
-del name
-del o
+py << trim EOF
+ for name, o in (
+ ('current', vim.current),
+ ('buffer', vim.current.buffer),
+ ('window', vim.current.window),
+ ('tabpage', vim.current.tabpage),
+ ('range', vim.current.range),
+ ('dictionary', vim.bindeval('{}')),
+ ('list', vim.bindeval('[]')),
+ ('function', vim.bindeval('function("tr")')),
+ ('output', sys.stdout),
+ ):
+ cb.append(name + ':' + ','.join(dir(o)))
+ del name
+ del o
EOF
:"
:" Test vim.*.__new__
@@ -904,63 +904,63 @@ EOF
:py Pt = vim.bindeval('Pt')
:unlet Pt
:py del Pt
-py << EOF
-def ecall(out_prefix, func, *args, **kwargs):
- line = out_prefix + ': '
- try:
- ret = func(*args, **kwargs)
- except Exception:
- line += '!exception: ' + emsg(sys.exc_info())
- else:
- line += '!result: ' + vim.Function('string')(ret)
- cb.append(line)
-a = vim.Function('Args')
-pa1 = vim.Function('Args', args=['abcArgsPA1'])
-pa2 = vim.Function('Args', args=[])
-pa3 = vim.Function('Args', args=['abcArgsPA3'], self={'abcSelfPA3': 'abcSelfPA3Val'})
-pa4 = vim.Function('Args', self={'abcSelfPA4': 'abcSelfPA4Val'})
-cb.append('a: ' + repr(a))
-cb.append('pa1: ' + repr(pa1))
-cb.append('pa2: ' + repr(pa2))
-cb.append('pa3: ' + repr(pa3))
-cb.append('pa4: ' + repr(pa4))
-sa = vim.Function('SelfArgs')
-psa1 = vim.Function('SelfArgs', args=['abcArgsPSA1'])
-psa2 = vim.Function('SelfArgs', args=[])
-psa3 = vim.Function('SelfArgs', args=['abcArgsPSA3'], self={'abcSelfPSA3': 'abcSelfPSA3Val'})
-psa4 = vim.Function('SelfArgs', self={'abcSelfPSA4': 'abcSelfPSA4Val'})
-psa5 = vim.Function('SelfArgs', self={'abcSelfPSA5': 'abcSelfPSA5Val'}, auto_rebind=0)
-psa6 = vim.Function('SelfArgs', args=['abcArgsPSA6'], self={'abcSelfPSA6': 'abcSelfPSA6Val'}, auto_rebind=())
-psa7 = vim.Function('SelfArgs', args=['abcArgsPSA7'], auto_rebind=[])
-psa8 = vim.Function('SelfArgs', auto_rebind=False)
-psa9 = vim.Function('SelfArgs', self={'abcSelfPSA9': 'abcSelfPSA9Val'}, auto_rebind=True)
-psaA = vim.Function('SelfArgs', args=['abcArgsPSAA'], self={'abcSelfPSAA': 'abcSelfPSAAVal'}, auto_rebind=1)
-psaB = vim.Function('SelfArgs', args=['abcArgsPSAB'], auto_rebind={'abcARPSAB': 'abcARPSABVal'})
-psaC = vim.Function('SelfArgs', auto_rebind=['abcARPSAC'])
-cb.append('sa: ' + repr(sa))
-cb.append('psa1: ' + repr(psa1))
-cb.append('psa2: ' + repr(psa2))
-cb.append('psa3: ' + repr(psa3))
-cb.append('psa4: ' + repr(psa4))
-cb.append('psa5: ' + repr(psa5))
-cb.append('psa6: ' + repr(psa6))
-cb.append('psa7: ' + repr(psa7))
-cb.append('psa8: ' + repr(psa8))
-cb.append('psa9: ' + repr(psa9))
-cb.append('psaA: ' + repr(psaA))
-cb.append('psaB: ' + repr(psaB))
-cb.append('psaC: ' + repr(psaC))
+py << trim EOF
+ def ecall(out_prefix, func, *args, **kwargs):
+ line = out_prefix + ': '
+ try:
+ ret = func(*args, **kwargs)
+ except Exception:
+ line += '!exception: ' + emsg(sys.exc_info())
+ else:
+ line += '!result: ' + vim.Function('string')(ret)
+ cb.append(line)
+ a = vim.Function('Args')
+ pa1 = vim.Function('Args', args=['abcArgsPA1'])
+ pa2 = vim.Function('Args', args=[])
+ pa3 = vim.Function('Args', args=['abcArgsPA3'], self={'abcSelfPA3': 'abcSelfPA3Val'})
+ pa4 = vim.Function('Args', self={'abcSelfPA4': 'abcSelfPA4Val'})
+ cb.append('a: ' + repr(a))
+ cb.append('pa1: ' + repr(pa1))
+ cb.append('pa2: ' + repr(pa2))
+ cb.append('pa3: ' + repr(pa3))
+ cb.append('pa4: ' + repr(pa4))
+ sa = vim.Function('SelfArgs')
+ psa1 = vim.Function('SelfArgs', args=['abcArgsPSA1'])
+ psa2 = vim.Function('SelfArgs', args=[])
+ psa3 = vim.Function('SelfArgs', args=['abcArgsPSA3'], self={'abcSelfPSA3': 'abcSelfPSA3Val'})
+ psa4 = vim.Function('SelfArgs', self={'abcSelfPSA4': 'abcSelfPSA4Val'})
+ psa5 = vim.Function('SelfArgs', self={'abcSelfPSA5': 'abcSelfPSA5Val'}, auto_rebind=0)
+ psa6 = vim.Function('SelfArgs', args=['abcArgsPSA6'], self={'abcSelfPSA6': 'abcSelfPSA6Val'}, auto_rebind=())
+ psa7 = vim.Function('SelfArgs', args=['abcArgsPSA7'], auto_rebind=[])
+ psa8 = vim.Function('SelfArgs', auto_rebind=False)
+ psa9 = vim.Function('SelfArgs', self={'abcSelfPSA9': 'abcSelfPSA9Val'}, auto_rebind=True)
+ psaA = vim.Function('SelfArgs', args=['abcArgsPSAA'], self={'abcSelfPSAA': 'abcSelfPSAAVal'}, auto_rebind=1)
+ psaB = vim.Function('SelfArgs', args=['abcArgsPSAB'], auto_rebind={'abcARPSAB': 'abcARPSABVal'})
+ psaC = vim.Function('SelfArgs', auto_rebind=['abcARPSAC'])
+ cb.append('sa: ' + repr(sa))
+ cb.append('psa1: ' + repr(psa1))
+ cb.append('psa2: ' + repr(psa2))
+ cb.append('psa3: ' + repr(psa3))
+ cb.append('psa4: ' + repr(psa4))
+ cb.append('psa5: ' + repr(psa5))
+ cb.append('psa6: ' + repr(psa6))
+ cb.append('psa7: ' + repr(psa7))
+ cb.append('psa8: ' + repr(psa8))
+ cb.append('psa9: