patch 9.1.0046: :drop does not re-use empty buffer

Commit: 
https://github.com/vim/vim/commit/f96dc8d07f752ddd96d1447d85278a85255a1462
Author: Rocco Mao <dapeng....@qq.com>
Date:   Tue Jan 23 21:27:19 2024 +0100

    patch 9.1.0046: :drop does not re-use empty buffer
    
    Problem:  :drop does not re-use empty buffer
              (Rocco Mao)
    Solution: Make :drop re-use an empty buffer
              (Rocco Mao)
    
    fixes: #13851
    closes: #13881
    
    Signed-off-by: Rocco Mao <dapeng....@qq.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/arglist.c b/src/arglist.c
index d28b31da4..292af30a1 100644
--- a/src/arglist.c
+++ b/src/arglist.c
@@ -502,7 +502,7 @@ do_arglist(
     void
 set_arglist(char_u *str)
 {
-    do_arglist(str, AL_SET, 0, FALSE);
+    do_arglist(str, AL_SET, 0, TRUE);
 }
 
 /*
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index d8e891c2b..eacff50d1 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -5425,8 +5425,7 @@ ex_smile(exarg_T *eap UNUSED)
 
 /*
  * ":drop"
- * Opens the first argument in a window.  When there are two or more arguments
- * the argument list is redefined.
+ * Opens the first argument in a window, and the argument list is redefined.
  */
     void
 ex_drop(exarg_T *eap)
@@ -5463,6 +5462,8 @@ ex_drop(exarg_T *eap)
        // edited in a window yet.  It's like ":tab all" but without closing
        // windows or tabs.
        ex_all(eap);
+       cmdmod.cmod_tab = 0;
+       ex_rewind(eap);
        return;
     }
 
@@ -5486,6 +5487,7 @@ ex_drop(exarg_T *eap)
                buf_check_timestamp(curbuf, FALSE);
                curbuf->b_p_ar = save_ar;
            }
+           ex_rewind(eap);
            return;
        }
     }
diff --git a/src/testdir/test_excmd.vim b/src/testdir/test_excmd.vim
index 47fc26726..6a7829b78 100644
--- a/src/testdir/test_excmd.vim
+++ b/src/testdir/test_excmd.vim
@@ -84,18 +84,27 @@ endfunc
 " Test for the :drop command
 func Test_drop_cmd()
   call writefile(['L1', 'L2'], 'Xdropfile', 'D')
+  " Test for reusing the current buffer
   enew | only
+  let expected_nr = bufnr()
   drop Xdropfile
+  call assert_equal(expected_nr, bufnr())
   call assert_equal('L2', getline(2))
   " Test for switching to an existing window
   below new
   drop Xdropfile
   call assert_equal(1, winnr())
-  " Test for splitting the current window
+  " Test for splitting the current window (set nohidden)
   enew | only
   set modified
   drop Xdropfile
   call assert_equal(2, winnr('$'))
+  " Not splitting the current window even if modified (set hidden)
+  set hidden
+  enew | only
+  set modified
+  drop Xdropfile
+  call assert_equal(1, winnr('$'))
   " Check for setting the argument list
   call assert_equal(['Xdropfile'], argv())
   enew | only!
diff --git a/src/testdir/test_tabpage.vim b/src/testdir/test_tabpage.vim
index 906fefcab..46aed221e 100644
--- a/src/testdir/test_tabpage.vim
+++ b/src/testdir/test_tabpage.vim
@@ -164,6 +164,74 @@ func Test_tabpage_drop()
   bwipe!
   bwipe!
   call assert_equal(1, tabpagenr('$'))
+
+  call assert_equal(1, winnr('$'))
+  call assert_equal('', bufname(''))
+  call writefile(['L1', 'L2'], 'Xdropfile', 'D')
+
+  " Test for ':tab drop single-file': reuse current buffer
+  let expected_nr = bufnr()
+  tab drop Xdropfile
+  call assert_equal(1, tabpagenr('$'))
+  call assert_equal(expected_nr, bufnr())
+  call assert_equal('L2', getline(2))
+  bwipe!
+
+  " Test for ':tab drop single-file': not reuse modified buffer
+  set modified
+  let expected_nr = bufnr() + 1
+  tab drop Xdropfile
+  call assert_equal(2, tabpagenr())
+  call assert_equal(2, tabpagenr('$'))
+  call assert_equal(expected_nr, bufnr())
+  call assert_equal('L2', getline(2))
+  bwipe!
+
+  " Test for ':tab drop single-file': multiple tabs already exist
+  tab split f2
+  tab split f3
+  let expected_nr = bufnr() + 1
+  tab drop Xdropfile
+  call assert_equal(4, tabpagenr())
+  call assert_equal(4, tabpagenr('$'))
+  call assert_equal(expected_nr, bufnr())
+  call assert_equal('L2', getline(2))
+  %bwipe!
+
+  " Test for ':tab drop multi-files': reuse current buffer
+  let expected_nr = bufnr()
+  tab drop Xdropfile f1 f2 f3
+  call assert_equal(1, tabpagenr())
+  call assert_equal(4, tabpagenr('$'))
+  call assert_equal(expected_nr, bufnr())
+  call assert_equal('L2', getline(2))
+  %bwipe!
+
+  " Test for ':tab drop multi-files': not reuse modified buffer
+  set modified
+  let expected_nr = bufnr() + 1
+  tab drop Xdropfile f1 f2 f3
+  call assert_equal(2, tabpagenr())
+  call assert_equal(5, tabpagenr('$'))
+  call assert_equal(expected_nr, bufnr())
+  call assert_equal('L2', getline(2))
+  %bwipe!
+
+  " Test for ':tab drop multi-files': multiple tabs already exist
+  tab split f2
+  tab split f3
+  let expected_nr = bufnr() + 1
+  tab drop a b c
+  call assert_equal(4, tabpagenr())
+  call assert_equal(6, tabpagenr('$'))
+  call assert_equal(expected_nr, bufnr())
+  let expected_nr = bufnr() + 3
+  tab drop Xdropfile f1 f2 f3
+  call assert_equal(5, tabpagenr())
+  call assert_equal(8, tabpagenr('$'))
+  call assert_equal(expected_nr, bufnr())
+  call assert_equal('L2', getline(2))
+  %bwipe!
 endfunc
 
 " Test autocommands
@@ -260,14 +328,14 @@ function Test_tabpage_with_autocmd_tab_drop()
 
   let s:li = []
   tab drop test1
-  call assert_equal(['BufLeave', 'BufEnter'], s:li)
+  call assert_equal(['BufEnter'], s:li)
 
   let s:li = []
   tab drop test2 test3
   call assert_equal([
         \ 'TabLeave', 'TabEnter', 'TabLeave', 'TabEnter',
         \ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter',
-        \ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter'], s:li)
+        \ 'TabLeave', 'WinEnter', 'TabEnter', 'BufEnter', 'BufEnter'], s:li)
 
   autocmd! TestTabpageGroup
   augroup! TestTabpageGroup
diff --git a/src/version.c b/src/version.c
index 925451218..ccfcb16a9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    46,
 /**/
     45,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rSNPJ-009atS-3z%40256bit.org.

Raspunde prin e-mail lui