From 5c3bbb67e7c59b2fa18e37fdd9845a0e7e3381db Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 11 Jul 2022 20:55:26 +0800 Subject: vim-patch:8.2.3363: when :edit reuses the current buffer the alternate file is set (#19306) Problem: When :edit reuses the current buffer the alternate file is set to the same buffer. Solution: Only set the alternate file when not reusing the buffer. (closes vim/vim#8783) https://github.com/vim/vim/commit/b8bd2e6ebab03baf2672067067a599df69a278c0 Cherry-pick Test_cmdline_expand_special() from patches 8.2.{0243,2873}. Move Test_cmd_backtick() to the right place. --- src/nvim/ex_cmds.c | 6 ++++++ src/nvim/testdir/test_cmdline.vim | 34 ++++++++++++++++++++++++++-------- src/nvim/testdir/test_undo.vim | 2 +- 3 files changed, 33 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index f97caf0703..1955a0b3d0 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -2415,6 +2415,8 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum * Otherwise we re-use the current buffer. */ if (other_file) { + const int prev_alt_fnum = curwin->w_alt_fnum; + if (!(flags & (ECMD_ADDBUF | ECMD_ALTBUF))) { if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) { curwin->w_alt_fnum = curbuf->b_fnum; @@ -2458,6 +2460,10 @@ int do_ecmd(int fnum, char *ffname, char *sfname, exarg_T *eap, linenr_T newlnum if (buf == NULL) { goto theend; } + if (curwin->w_alt_fnum == buf->b_fnum && prev_alt_fnum != 0) { + // reusing the buffer, keep the old alternate file + curwin->w_alt_fnum = prev_alt_fnum; + } if (buf->b_ml.ml_mfp == NULL) { // No memfile yet. oldbuf = false; diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 4207e4767e..9885d356fd 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -1328,14 +1328,6 @@ func Test_cmdwin_jump_to_win() call assert_equal(1, winnr('$')) endfunc -" Test for backtick expression in the command line -func Test_cmd_backtick() - %argd - argadd `=['a', 'b', 'c']` - call assert_equal(['a', 'b', 'c'], argv()) - %argd -endfunc - func Test_cmdlineclear_tabenter() " See test/functional/legacy/cmdline_spec.lua CheckScreendump @@ -1355,6 +1347,32 @@ func Test_cmdlineclear_tabenter() call delete('XtestCmdlineClearTabenter') endfunc +" Test for expanding special keywords in cmdline +func Test_cmdline_expand_special() + new + %bwipe! + call assert_fails('e #', 'E194:') + call assert_fails('e ', 'E495:') + call assert_fails('e ', 'E496:') + call assert_fails('e ', 'E497:') + call writefile([], 'Xfile.cpp') + call writefile([], 'Xfile.java') + new Xfile.cpp + call feedkeys(":e %:r\\\"\", 'xt') + call assert_equal('"e Xfile.cpp Xfile.java', @:) + close + call delete('Xfile.cpp') + call delete('Xfile.java') +endfunc + +" Test for backtick expression in the command line +func Test_cmd_backtick() + %argd + argadd `=['a', 'b', 'c']` + call assert_equal(['a', 'b', 'c'], argv()) + %argd +endfunc + func Test_cmdwin_tabpage() tabedit " v8.2.1919 isn't ported yet, so E492 is thrown after E11 here. diff --git a/src/nvim/testdir/test_undo.vim b/src/nvim/testdir/test_undo.vim index 848860649e..af92328387 100644 --- a/src/nvim/testdir/test_undo.vim +++ b/src/nvim/testdir/test_undo.vim @@ -579,7 +579,7 @@ func Test_undofile_2() " add 10 lines, delete 6 lines, undo 3 set undofile - call setbufline(0, 1, ['one', 'two', 'three', 'four', 'five', 'six', + call setbufline('%', 1, ['one', 'two', 'three', 'four', 'five', 'six', \ 'seven', 'eight', 'nine', 'ten']) set undolevels=100 normal 3Gdd -- cgit