Mercurial > vim
changeset 12347:61a9642297cc v8.0.1053
patch 8.0.1053: setline() does not work on startup
commit https://github.com/vim/vim/commit/9d954207e2cc807b475bb04f8b59ef5bb3772d99
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 4 20:34:19 2017 +0200
patch 8.0.1053: setline() does not work on startup
Problem: setline() does not work on startup. (Manuel Ortega)
Solution: Do not check for ml_mfp to be set for the current buffer.
(Christian Brabandt)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 04 Sep 2017 20:45:04 +0200 |
parents | 51a433bd74bf |
children | 4cdd0cb2b2b4 |
files | src/evalfunc.c src/testdir/shared.vim src/testdir/test_alot.vim src/testdir/test_bufline.vim src/testdir/test_timers.vim src/version.c |
diffstat | 6 files changed, 31 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -9885,7 +9885,10 @@ set_buffer_lines(buf_T *buf, linenr_T ln buf_T *curbuf_save; int is_curbuf = buf == curbuf; - if (buf == NULL || buf->b_ml.ml_mfp == NULL || lnum < 1) + /* When using the current buffer ml_mfp will be set if needed. Useful when + * setline() is used on startup. For other buffers the buffer must be + * loaded. */ + if (buf == NULL || (!is_curbuf && buf->b_ml.ml_mfp == NULL) || lnum < 1) { rettv->vval.v_number = 1; /* FAIL */ return;
--- a/src/testdir/shared.vim +++ b/src/testdir/shared.vim @@ -166,15 +166,21 @@ func s:feedkeys(timer) endfunc " Get the command to run Vim, with -u NONE and --not-a-term arguments. +" If there is an argument use it instead of "NONE". " Returns an empty string on error. -func GetVimCommand() +func GetVimCommand(...) if !filereadable('vimcmd') return '' endif + if a:0 == 0 + let name = 'NONE' + else + let name = a:1 + endif let cmd = readfile('vimcmd')[0] - let cmd = substitute(cmd, '-u \f\+', '-u NONE', '') - if cmd !~ '-u NONE' - let cmd = cmd . ' -u NONE' + let cmd = substitute(cmd, '-u \f\+', '-u ' . name, '') + if cmd !~ '-u '. name + let cmd = cmd . ' -u ' . name endif let cmd .= ' --not-a-term' let cmd = substitute(cmd, 'VIMRUNTIME=.*VIMRUNTIME;', '', '')
--- a/src/testdir/test_alot.vim +++ b/src/testdir/test_alot.vim @@ -1,6 +1,8 @@ " A series of tests that can run in one Vim invocation. " This makes testing go faster, since Vim doesn't need to restart. +source shared.vim + set belloff=all source test_assign.vim source test_bufline.vim
--- a/src/testdir/test_bufline.vim +++ b/src/testdir/test_bufline.vim @@ -24,3 +24,16 @@ func Test_setbufline_getbufline() call assert_equal([], getbufline(b, 6)) exe "bwipe! " . b endfunc + +func Test_setline_startup() + let cmd = GetVimCommand('Xscript') + if cmd == '' + return + endif + call writefile(['call setline(1, "Hello")', 'w Xtest', 'q!'], 'Xscript') + call system(cmd) + call assert_equal(['Hello'], readfile('Xtest')) + + call delete('Xscript') + call delete('Xtest') +endfunc