From c6f0a1920630d5d4059781c03a8ddae804d805bc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 8 Aug 2025 06:14:17 +0800 Subject: [PATCH 1/2] vim-patch:8.1.0425: ml_get error and crash with appendbufline() Problem: ml_get error and crash with appendbufline(). (Masashi Iizuka) Solution: Set per-window buffer info. (Hirohito Higashi, closes vim/vim#3455) https://github.com/vim/vim/commit/9cea87c5775948a35098f3602746c20ecf95dbcd Co-authored-by: Bram Moolenaar --- src/nvim/buffer.c | 3 +++ test/old/testdir/test_bufline.vim | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index d8c46020bc..3bd8ebab2c 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1729,6 +1729,9 @@ static void enter_buffer(buf_T *buf) // mark cursor position as being invalid curwin->w_valid = 0; + buflist_setfpos(curbuf, curwin, curbuf->b_last_cursor.mark.lnum, + curbuf->b_last_cursor.mark.col, true); + // Make sure the buffer is loaded. if (curbuf->b_ml.ml_mfp == NULL) { // need to load the file // If there is no filetype, allow for detecting one. Esp. useful for diff --git a/test/old/testdir/test_bufline.vim b/test/old/testdir/test_bufline.vim index 29ec46a606..09438cf716 100644 --- a/test/old/testdir/test_bufline.vim +++ b/test/old/testdir/test_bufline.vim @@ -158,6 +158,33 @@ func Test_appendbufline() exe "bwipe! " . b endfunc +func Test_appendbufline_no_E315() + let after = [ + \ 'set stl=%f ls=2', + \ 'new', + \ 'let buf = bufnr("%")', + \ 'quit', + \ 'vsp', + \ 'exec "buffer" buf', + \ 'wincmd w', + \ 'call appendbufline(buf, 0, "abc")', + \ 'redraw', + \ 'while getbufline(buf, 1)[0] =~ "^\\s*$"', + \ ' sleep 10m', + \ 'endwhile', + \ 'au VimLeavePre * call writefile([v:errmsg], "Xerror")', + \ 'au VimLeavePre * call writefile(["done"], "Xdone")', + \ 'qall!', + \ ] + if !RunVim([], after, '--clean') + return + endif + call assert_notmatch("^E315:", readfile("Xerror")[0]) + call assert_equal("done", readfile("Xdone")[0]) + call delete("Xerror") + call delete("Xdone") +endfunc + func Test_deletebufline() new let b = bufnr('%') From 7230296bdb7150182a58d0a066521e4212fd5aac Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 8 Aug 2025 06:15:15 +0800 Subject: [PATCH 2/2] vim-patch:9.1.1601: Patch v8.1.0425 was wrong Problem: Patch v8.1.0425 was wrong Solution: Revert that patch (Hirohito Higashi) This is because the root cause was fixed in 8.1.0786 and a regression occurred elsewhere. related: vim/vim#3455 related: vim/vim#3830 fixes: vim/vim#11558 closes: vim/vim#17899 https://github.com/vim/vim/commit/6abe5e490470d339f5e9a07a478f839cebf23812 Co-authored-by: Hirohito Higashi --- src/nvim/buffer.c | 3 --- test/old/testdir/test_buffer.vim | 27 +++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 3bd8ebab2c..d8c46020bc 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1729,9 +1729,6 @@ static void enter_buffer(buf_T *buf) // mark cursor position as being invalid curwin->w_valid = 0; - buflist_setfpos(curbuf, curwin, curbuf->b_last_cursor.mark.lnum, - curbuf->b_last_cursor.mark.col, true); - // Make sure the buffer is loaded. if (curbuf->b_ml.ml_mfp == NULL) { // need to load the file // If there is no filetype, allow for detecting one. Esp. useful for diff --git a/test/old/testdir/test_buffer.vim b/test/old/testdir/test_buffer.vim index cf4d264066..19799a5478 100644 --- a/test/old/testdir/test_buffer.vim +++ b/test/old/testdir/test_buffer.vim @@ -609,4 +609,31 @@ func Test_closed_buffer_still_in_window() %bw! endfunc +" Cursor position should be restored when switching to a buffer previously +" viewed in a window, regardless of whether it's visible in another one. +func Test_switch_to_previously_viewed_buffer() + set nostartofline + new Xviewbuf + call setline(1, range(1, 200)) + let oldwin = win_getid() + vsplit + + call cursor(100, 3) + edit Xotherbuf + buffer Xviewbuf + call assert_equal([0, 100, 3, 0], getpos('.')) + + exe win_id2win(oldwin) .. 'close' + setlocal bufhidden=hide + + call cursor(200, 3) + edit Xotherbuf + buffer Xviewbuf + call assert_equal([0, 200, 3, 0], getpos('.')) + + bwipe! Xotherbuf + bwipe! Xviewbuf + set startofline& +endfunc + " vim: shiftwidth=2 sts=2 expandtab