Skip to content

Commit 63dbfd3

Browse files
committed
patch 8.1.1045: E315 ml_get error when using Python and hidden buffer
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)
1 parent c3e92c1 commit 63dbfd3

4 files changed

Lines changed: 178 additions & 2 deletions

File tree

src/if_py_both.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4392,7 +4392,10 @@ SetBufferLine(buf_T *buf, PyInt n, PyObject *line, PyInt *len_change)
43924392
RAISE_DELETE_LINE_FAIL;
43934393
else
43944394
{
4395-
if (buf == curbuf)
4395+
if (buf == curbuf && (save_curwin != NULL
4396+
|| save_curbuf.br_buf == NULL))
4397+
// Using an existing window for the buffer, adjust the cursor
4398+
// position.
43964399
py_fix_cursor((linenr_T)n, (linenr_T)n + 1, (linenr_T)-1);
43974400
if (save_curbuf.br_buf == NULL)
43984401
/* Only adjust marks if we managed to switch to a window that
@@ -4642,7 +4645,10 @@ SetBufferLineList(
46424645
(long)MAXLNUM, (long)extra);
46434646
changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
46444647

4645-
if (buf == curbuf)
4648+
if (buf == curbuf && (save_curwin != NULL
4649+
|| save_curbuf.br_buf == NULL))
4650+
// Using an existing window for the buffer, adjust the cursor
4651+
// position.
46464652
py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)extra);
46474653

46484654
/* END of region without "return". */

src/testdir/test_python2.vim

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,87 @@ func Test_skipped_python_command_does_not_affect_pyxversion()
7171
endif
7272
call assert_equal(0, &pyxversion) " This assertion would have failed with Vim 8.0.0251. (pyxversion was introduced in 8.0.0251.)
7373
endfunc
74+
75+
func _SetUpHiddenBuffer()
76+
py import vim
77+
new
78+
edit hidden
79+
setlocal bufhidden=hide
80+
81+
enew
82+
let lnum = 0
83+
while lnum < 10
84+
call append( 1, string( lnum ) )
85+
let lnum = lnum + 1
86+
endwhile
87+
normal G
88+
89+
call assert_equal( line( '.' ), 11 )
90+
endfunc
91+
92+
func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Clear()
93+
call _SetUpHiddenBuffer()
94+
py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = None
95+
call assert_equal( line( '.' ), 11 )
96+
bwipe!
97+
endfunc
98+
99+
func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_List()
100+
call _SetUpHiddenBuffer()
101+
py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = [ 'test' ]
102+
call assert_equal( line( '.' ), 11 )
103+
bwipe!
104+
endfunc
105+
106+
func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Str()
107+
call _SetUpHiddenBuffer()
108+
py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = 'test'
109+
call assert_equal( line( '.' ), 11 )
110+
bwipe!
111+
endfunc
112+
113+
func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_ClearLine()
114+
call _SetUpHiddenBuffer()
115+
py vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = None
116+
call assert_equal( line( '.' ), 11 )
117+
bwipe!
118+
endfunc
119+
120+
func _SetUpVisibleBuffer()
121+
py import vim
122+
new
123+
let lnum = 0
124+
while lnum < 10
125+
call append( 1, string( lnum ) )
126+
let lnum = lnum + 1
127+
endwhile
128+
normal G
129+
call assert_equal( line( '.' ), 11 )
130+
endfunc
131+
132+
func Test_Write_To_Current_Buffer_Fixes_Cursor_Clear()
133+
call _SetUpVisibleBuffer()
134+
135+
py vim.current.buffer[:] = None
136+
call assert_equal( line( '.' ), 1 )
137+
138+
bwipe!
139+
endfunc
140+
141+
func Test_Write_To_Current_Buffer_Fixes_Cursor_List()
142+
call _SetUpVisibleBuffer()
143+
144+
py vim.current.buffer[:] = [ 'test' ]
145+
call assert_equal( line( '.' ), 1 )
146+
147+
bwipe!
148+
endfunction
149+
150+
func Test_Write_To_Current_Buffer_Fixes_Cursor_Str()
151+
call _SetUpVisibleBuffer()
152+
153+
py vim.current.buffer[-1] = None
154+
call assert_equal( line( '.' ), 10 )
155+
156+
bwipe!
157+
endfunction

src/testdir/test_python3.vim

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,87 @@ func Test_skipped_python3_command_does_not_affect_pyxversion()
7171
endif
7272
call assert_equal(0, &pyxversion) " This assertion would have failed with Vim 8.0.0251. (pyxversion was introduced in 8.0.0251.)
7373
endfunc
74+
75+
func _SetUpHiddenBuffer()
76+
py3 import vim
77+
new
78+
edit hidden
79+
setlocal bufhidden=hide
80+
81+
enew
82+
let lnum = 0
83+
while lnum < 10
84+
call append( 1, string( lnum ) )
85+
let lnum = lnum + 1
86+
endwhile
87+
normal G
88+
89+
call assert_equal( line( '.' ), 11 )
90+
endfunc
91+
92+
func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Clear()
93+
call _SetUpHiddenBuffer()
94+
py3 vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = None
95+
call assert_equal( line( '.' ), 11 )
96+
bwipe!
97+
endfunc
98+
99+
func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_List()
100+
call _SetUpHiddenBuffer()
101+
py3 vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][:] = [ 'test' ]
102+
call assert_equal( line( '.' ), 11 )
103+
bwipe!
104+
endfunc
105+
106+
func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_Str()
107+
call _SetUpHiddenBuffer()
108+
py3 vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = 'test'
109+
call assert_equal( line( '.' ), 11 )
110+
bwipe!
111+
endfunc
112+
113+
func Test_Write_To_HiddenBuffer_Does_Not_Fix_Cursor_ClearLine()
114+
call _SetUpHiddenBuffer()
115+
py3 vim.buffers[ int( vim.eval( 'bufnr("hidden")' ) ) ][0] = None
116+
call assert_equal( line( '.' ), 11 )
117+
bwipe!
118+
endfunc
119+
120+
func _SetUpVisibleBuffer()
121+
py3 import vim
122+
new
123+
let lnum = 0
124+
while lnum < 10
125+
call append( 1, string( lnum ) )
126+
let lnum = lnum + 1
127+
endwhile
128+
normal G
129+
call assert_equal( line( '.' ), 11 )
130+
endfunc
131+
132+
func Test_Write_To_Current_Buffer_Fixes_Cursor_Clear()
133+
call _SetUpVisibleBuffer()
134+
135+
py3 vim.current.buffer[:] = None
136+
call assert_equal( line( '.' ), 1 )
137+
138+
bwipe!
139+
endfunc
140+
141+
func Test_Write_To_Current_Buffer_Fixes_Cursor_List()
142+
call _SetUpVisibleBuffer()
143+
144+
py3 vim.current.buffer[:] = [ 'test' ]
145+
call assert_equal( line( '.' ), 1 )
146+
147+
bwipe!
148+
endfunction
149+
150+
func Test_Write_To_Current_Buffer_Fixes_Cursor_Str()
151+
call _SetUpVisibleBuffer()
152+
153+
py3 vim.current.buffer[-1] = None
154+
call assert_equal( line( '.' ), 10 )
155+
156+
bwipe!
157+
endfunction

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ static char *(features[]) =
775775

776776
static int included_patches[] =
777777
{ /* Add new patch number below this line */
778+
/**/
779+
1045,
778780
/**/
779781
1044,
780782
/**/

0 commit comments

Comments
 (0)