diff options
author | Daniel Hahler <git@thequod.de> | 2019-06-18 00:09:45 +0200 |
---|---|---|
committer | Daniel Hahler <git@thequod.de> | 2019-06-18 00:18:52 +0200 |
commit | 8db93d0d83d834d736c1dddb51a4c94c89aae1be (patch) | |
tree | 9cab05aa2ad474037a697a6d3264304b33072b99 /src | |
parent | 9485061baac53e5a6f07ddf05751b152078a1ab1 (diff) | |
download | rneovim-8db93d0d83d834d736c1dddb51a4c94c89aae1be.tar.gz rneovim-8db93d0d83d834d736c1dddb51a4c94c89aae1be.tar.bz2 rneovim-8db93d0d83d834d736c1dddb51a4c94c89aae1be.zip |
vim-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)
https://github.com/vim/vim/commit/9d954207e2cc807b475bb04f8b59ef5bb3772d99
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 5 | ||||
-rw-r--r-- | src/nvim/testdir/shared.vim | 14 | ||||
-rw-r--r-- | src/nvim/testdir/test_bufline.vim | 15 |
3 files changed, 29 insertions, 5 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index d426fb2064..5ab1e0ebbe 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -14854,7 +14854,10 @@ static void set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines, 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; } diff --git a/src/nvim/testdir/shared.vim b/src/nvim/testdir/shared.vim index ac34dec569..a5cf4def4f 100644 --- a/src/nvim/testdir/shared.vim +++ b/src/nvim/testdir/shared.vim @@ -190,12 +190,18 @@ func s:feedkeys(timer) endfunc " Get the command to run Vim, with -u NONE and --headless arguments. +" If there is an argument use it instead of "NONE". " Returns an empty string on error. -func GetVimCommand() +func GetVimCommand(...) + if a:0 == 0 + let name = 'NONE' + else + let name = a:1 + endif let cmd = v:progpath - 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 .= ' --headless -i NONE' let cmd = substitute(cmd, 'VIMRUNTIME=.*VIMRUNTIME;', '', '') diff --git a/src/nvim/testdir/test_bufline.vim b/src/nvim/testdir/test_bufline.vim index 7df36aa6a2..30e8ed8b42 100644 --- a/src/nvim/testdir/test_bufline.vim +++ b/src/nvim/testdir/test_bufline.vim @@ -1,5 +1,7 @@ " Tests for setbufline() and getbufline() +source shared.vim + func Test_setbufline_getbufline() new let b = bufnr('%') @@ -24,3 +26,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 |