]> granicus.if.org Git - vim/commitdiff
patch 8.0.1053: setline() does not work on startup v8.0.1053
authorBram Moolenaar <Bram@vim.org>
Mon, 4 Sep 2017 18:34:19 +0000 (20:34 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 4 Sep 2017 18:34:19 +0000 (20:34 +0200)
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)

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

index 2692de61f49d64f4f906d62306978e55231742d9..cf9c8d8ec34decc727e2b1b4e423eb347922da33 100644 (file)
@@ -9885,7 +9885,10 @@ set_buffer_lines(buf_T *buf, linenr_T lnum, typval_T *lines, typval_T *rettv)
     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;
index a305c90cb6deabb35d32e75262cf770f50d4606f..691199a97c631de28b30efdc4cf06c82f90bd1cf 100644 (file)
@@ -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;', '', '')
index 189cd82d12d22359504af819c6d6b999baf5e72a..61c3472b2ae7de0f68ee9f34dcbb427a42c8be49 100644 (file)
@@ -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
index 7df36aa6a22f30b46aff312d60f6a9310f1b4dd1..2fe6739ed3df8fa0705f7d524f18b7f52d3e35b4 100644 (file)
@@ -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
index 0c6bb8338fbb636f85696cc0ce2d60bf001e95bc..142bfc8a54eb2f8ebad2fa136d813ee543d81b54 100644 (file)
@@ -1,7 +1,5 @@
 " Test for timers
 
-source shared.vim
-
 if !has('timers')
   finish
 endif
index 2b30a090f105b68432531f342edc3e18e1d294b3..5f49b381f463edcec696f97e9eba438e480e680b 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1053,
 /**/
     1052,
 /**/