0
0
mirror of https://github.com/vim/vim.git synced 2025-08-23 19:34:27 -04:00

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)
This commit is contained in:
Bram Moolenaar 2017-09-04 20:34:19 +02:00
parent e88fc7a574
commit 9d954207e2
6 changed files with 31 additions and 7 deletions

View File

@ -9885,7 +9885,10 @@ set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines, typval_T *rettv)
buf_T *curbuf_save; buf_T *curbuf_save;
int is_curbuf = buf == curbuf; 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 */ rettv->vval.v_number = 1; /* FAIL */
return; return;

View File

@ -166,15 +166,21 @@ func s:feedkeys(timer)
endfunc endfunc
" Get the command to run Vim, with -u NONE and --not-a-term arguments. " 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. " Returns an empty string on error.
func GetVimCommand() func GetVimCommand(...)
if !filereadable('vimcmd') if !filereadable('vimcmd')
return '' return ''
endif endif
if a:0 == 0
let name = 'NONE'
else
let name = a:1
endif
let cmd = readfile('vimcmd')[0] let cmd = readfile('vimcmd')[0]
let cmd = substitute(cmd, '-u \f\+', '-u NONE', '') let cmd = substitute(cmd, '-u \f\+', '-u ' . name, '')
if cmd !~ '-u NONE' if cmd !~ '-u '. name
let cmd = cmd . ' -u NONE' let cmd = cmd . ' -u ' . name
endif endif
let cmd .= ' --not-a-term' let cmd .= ' --not-a-term'
let cmd = substitute(cmd, 'VIMRUNTIME=.*VIMRUNTIME;', '', '') let cmd = substitute(cmd, 'VIMRUNTIME=.*VIMRUNTIME;', '', '')

View File

@ -1,6 +1,8 @@
" A series of tests that can run in one Vim invocation. " A series of tests that can run in one Vim invocation.
" This makes testing go faster, since Vim doesn't need to restart. " This makes testing go faster, since Vim doesn't need to restart.
source shared.vim
set belloff=all set belloff=all
source test_assign.vim source test_assign.vim
source test_bufline.vim source test_bufline.vim

View File

@ -24,3 +24,16 @@ func Test_setbufline_getbufline()
call assert_equal([], getbufline(b, 6)) call assert_equal([], getbufline(b, 6))
exe "bwipe! " . b exe "bwipe! " . b
endfunc 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

View File

@ -1,7 +1,5 @@
" Test for timers " Test for timers
source shared.vim
if !has('timers') if !has('timers')
finish finish
endif endif

View File

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