diff options
-rw-r--r-- | runtime/doc/if_lua.txt | 7 | ||||
-rw-r--r-- | runtime/doc/if_mzsch.txt | 9 | ||||
-rw-r--r-- | runtime/doc/if_perl.txt | 2 | ||||
-rw-r--r-- | runtime/doc/if_pyth.txt | 11 | ||||
-rw-r--r-- | runtime/doc/if_ruby.txt | 8 | ||||
-rw-r--r-- | runtime/doc/if_tcl.txt | 7 | ||||
-rw-r--r-- | src/evalvars.c | 21 | ||||
-rw-r--r-- | src/ex_getln.c | 41 | ||||
-rw-r--r-- | src/proto/evalvars.pro | 2 | ||||
-rw-r--r-- | src/testdir/test86.in | 1822 | ||||
-rw-r--r-- | src/testdir/test87.in | 1864 | ||||
-rw-r--r-- | src/testdir/test_lua.vim | 29 | ||||
-rw-r--r-- | src/testdir/test_perl.vim | 23 | ||||
-rw-r--r-- | src/testdir/test_python2.vim | 19 | ||||
-rw-r--r-- | src/testdir/test_python3.vim | 33 | ||||
-rw-r--r-- | src/testdir/test_pyx2.vim | 27 | ||||
-rw-r--r-- | src/testdir/test_pyx3.vim | 27 | ||||
-rw-r--r-- | src/testdir/test_ruby.vim | 29 | ||||
-rw-r--r-- | src/testdir/test_tcl.vim | 23 | ||||
-rw-r--r-- | src/userfunc.c | 11 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 2 |
22 files changed, 2093 insertions, 1926 deletions
diff --git a/runtime/doc/if_lua.txt b/runtime/doc/if_lua.txt index ad20b014a3..75bb963a9f 100644 --- a/runtime/doc/if_lua.txt +++ b/runtime/doc/if_lua.txt @@ -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. diff --git a/runtime/doc/if_mzsch.txt b/runtime/doc/if_mzsch.txt index da438295e6..6420856a67 100644 --- a/runtime/doc/if_mzsch.txt +++ b/runtime/doc/if_mzsch.txt @@ -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}. diff --git a/runtime/doc/if_perl.txt b/runtime/doc/if_perl.txt index f1bf923766..b0bad1e6ad 100644 --- a/runtime/doc/if_perl.txt +++ b/runtime/doc/if_perl.txt @@ -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}. diff --git a/runtime/doc/if_pyth.txt b/runtime/doc/if_pyth.txt index 88e0df6b4c..572e6bf7bf 100644 --- a/runtime/doc/if_pyth.txt +++ b/runtime/doc/if_pyth.txt @@ -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 diff --git a/runtime/doc/if_ruby.txt b/runtime/doc/if_ruby.txt index 45236600e5..dc8349fc44 100644 --- a/runtime/doc/if_ruby.txt +++ b/runtime/doc/if_ruby.txt @@ -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. diff --git a/runtime/doc/if_tcl.txt b/runtime/doc/if_tcl.txt index f7c0d6f250..60ac6bcc5e 100644 --- a/runtime/doc/if_tcl.txt +++ b/runtime/doc/if_tcl.txt @@ -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. 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: |