]> granicus.if.org Git - vim/commitdiff
patch 8.1.1045: E315 ml_get error when using Python and hidden buffer v8.1.1045
authorBram Moolenaar <Bram@vim.org>
Sat, 23 Mar 2019 16:41:59 +0000 (17:41 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 23 Mar 2019 16:41:59 +0000 (17:41 +0100)
Problem:    E315 ml_get error when using Python and hidden buffer.
Solution:   Make sure the cursor position is valid. (Ben Jackson,
            closes #4153, closes #4154)

src/if_py_both.h
src/testdir/test_python2.vim
src/testdir/test_python3.vim
src/version.c

index 8d11488d3989da551dc4bd9ed4fdd7992a29059b..b27f93e49eb333a545659458f7f79a4afabf4831 100644 (file)
@@ -4392,7 +4392,10 @@ SetBufferLine(buf_T *buf, PyInt n, PyObject *line, PyInt *len_change)
            RAISE_DELETE_LINE_FAIL;
        else
        {
-           if (buf == curbuf)
+           if (buf == curbuf && (save_curwin != NULL
+                                          || save_curbuf.br_buf == NULL))
+               // Using an existing window for the buffer, adjust the cursor
+               // position.
                py_fix_cursor((linenr_T)n, (linenr_T)n + 1, (linenr_T)-1);
            if (save_curbuf.br_buf == NULL)
                /* Only adjust marks if we managed to switch to a window that
@@ -4642,7 +4645,10 @@ SetBufferLineList(
                                                  (long)MAXLNUM, (long)extra);
        changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
 
-       if (buf == curbuf)
+       if (buf == curbuf && (save_curwin != NULL
+                                          || save_curbuf.br_buf == NULL))
+           // Using an existing window for the buffer, adjust the cursor
+           // position.
            py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra);
 
        /* END of region without "return". */
index 43c89c972a548996a3f27dabff8dd5e012908258..97b44f2ebad5f9cfacf9bf11a350997b106c750d 100644 (file)
@@ -71,3 +71,87 @@ func Test_skipped_python_command_does_not_affect_pyxversion()
   endif
   call assert_equal(0, &pyxversion)  " This assertion would have failed with Vim 8.0.0251. (pyxversion was introduced in 8.0.0251.)
 endfunc
+
+func _SetUpHiddenBuffer()
+  py import vim
+  new
+  edit hidden
+  setlocal bufhidden=hide
+
+  enew
+  let lnum = 0
+  while lnum < 10
+    call append( 1, string( lnum ) )
+    let lnum = lnum + 1
+  endwhile
+  normal G
+
+  call assert_equal( line( '.' ), 11 )
+endfunc
+
+func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Clear()
+  call _SetUpHiddenBuffer()
+  py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = None
+  call assert_equal( line( '.' ), 11 )
+  bwipe!
+endfunc
+
+func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_List()
+  call _SetUpHiddenBuffer()
+  py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = [ 'test' ]
+  call assert_equal( line( '.' ), 11 )
+  bwipe!
+endfunc
+
+func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Str()
+  call _SetUpHiddenBuffer()
+  py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = 'test'
+  call assert_equal( line( '.' ), 11 )
+  bwipe!
+endfunc
+
+func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_ClearLine()
+  call _SetUpHiddenBuffer()
+  py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = None
+  call assert_equal( line( '.' ), 11 )
+  bwipe!
+endfunc
+
+func _SetUpVisibleBuffer()
+  py import vim
+  new
+  let lnum = 0
+  while lnum < 10
+    call append( 1, string( lnum ) )
+    let lnum = lnum + 1
+  endwhile
+  normal G
+  call assert_equal( line( '.' ), 11 )
+endfunc
+
+func Test_Write_To_Current_Buffer_Fixes_Cursor_Clear()
+  call _SetUpVisibleBuffer()
+
+  py vim.current.buffer[:] = None
+  call assert_equal( line( '.' ), 1 )
+
+  bwipe!
+endfunc
+
+func Test_Write_To_Current_Buffer_Fixes_Cursor_List()
+  call _SetUpVisibleBuffer()
+
+  py vim.current.buffer[:] = [ 'test' ]
+  call assert_equal( line( '.' ), 1 )
+
+  bwipe!
+endfunction
+
+func Test_Write_To_Current_Buffer_Fixes_Cursor_Str()
+  call _SetUpVisibleBuffer()
+
+  py vim.current.buffer[-1] = None
+  call assert_equal( line( '.' ), 10 )
+
+  bwipe!
+endfunction
index 272ff9ef85db3635f4be9d8d7d1cffb5ebb5902d..bc05f68ce2ce515ad7ea9e7db80cd950413ed65b 100644 (file)
@@ -71,3 +71,87 @@ func Test_skipped_python3_command_does_not_affect_pyxversion()
   endif
   call assert_equal(0, &pyxversion)  " This assertion would have failed with Vim 8.0.0251. (pyxversion was introduced in 8.0.0251.)
 endfunc
+
+func _SetUpHiddenBuffer()
+  py3 import vim
+  new
+  edit hidden
+  setlocal bufhidden=hide
+
+  enew
+  let lnum = 0
+  while lnum < 10
+    call append( 1, string( lnum ) )
+    let lnum = lnum + 1
+  endwhile
+  normal G
+
+  call assert_equal( line( '.' ), 11 )
+endfunc
+
+func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Clear()
+  call _SetUpHiddenBuffer()
+  py3 vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = None
+  call assert_equal( line( '.' ), 11 )
+  bwipe!
+endfunc
+
+func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_List()
+  call _SetUpHiddenBuffer()
+  py3 vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = [ 'test' ]
+  call assert_equal( line( '.' ), 11 )
+  bwipe!
+endfunc
+
+func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Str()
+  call _SetUpHiddenBuffer()
+  py3 vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = 'test'
+  call assert_equal( line( '.' ), 11 )
+  bwipe!
+endfunc
+
+func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_ClearLine()
+  call _SetUpHiddenBuffer()
+  py3 vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = None
+  call assert_equal( line( '.' ), 11 )
+  bwipe!
+endfunc
+
+func _SetUpVisibleBuffer()
+  py3 import vim
+  new
+  let lnum = 0
+  while lnum < 10
+    call append( 1, string( lnum ) )
+    let lnum = lnum + 1
+  endwhile
+  normal G
+  call assert_equal( line( '.' ), 11 )
+endfunc
+
+func Test_Write_To_Current_Buffer_Fixes_Cursor_Clear()
+  call _SetUpVisibleBuffer()
+
+  py3 vim.current.buffer[:] = None
+  call assert_equal( line( '.' ), 1 )
+
+  bwipe!
+endfunc
+
+func Test_Write_To_Current_Buffer_Fixes_Cursor_List()
+  call _SetUpVisibleBuffer()
+
+  py3 vim.current.buffer[:] = [ 'test' ]
+  call assert_equal( line( '.' ), 1 )
+
+  bwipe!
+endfunction
+
+func Test_Write_To_Current_Buffer_Fixes_Cursor_Str()
+  call _SetUpVisibleBuffer()
+
+  py3 vim.current.buffer[-1] = None
+  call assert_equal( line( '.' ), 10 )
+
+  bwipe!
+endfunction
index d0f63efae7577a64935a4e736bd89750134a8da7..133fd3e5722e2237ae996476b8b164504abf363d 100644 (file)
@@ -775,6 +775,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1045,
 /**/
     1044,
 /**/