]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.0341: :argadd in empty buffer changes the buffer name v8.1.0341
authorBram Moolenaar <Bram@vim.org>
Fri, 31 Aug 2018 21:06:22 +0000 (23:06 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 31 Aug 2018 21:06:22 +0000 (23:06 +0200)
Problem:    :argadd in empty buffer changes the buffer name. (Pavol Juhas)
Solution:   Don't re-use the current buffer when not going to edit the file.
            (closes #3397)  Do re-use the current buffer for :next.

src/ex_cmds2.c
src/testdir/test_arglist.vim
src/testdir/test_command_count.vim
src/version.c

index 89effa1417e494b5b863bbd32f3053dcfcb121f1..a58b955f3c7b2eb594ebf5e22d7f3a9e88fdbe5d 100644 (file)
@@ -2445,10 +2445,10 @@ buf_write_all(buf_T *buf, int forceit)
  */
 
 static char_u  *do_one_arg(char_u *str);
-static int     do_arglist(char_u *str, int what, int after);
+static int     do_arglist(char_u *str, int what, int after, int will_edit);
 static void    alist_check_arg_idx(void);
 static int     editing_arg_idx(win_T *win);
-static int     alist_add_list(int count, char_u **files, int after);
+static void    alist_add_list(int count, char_u **files, int after, int will_edit);
 #define AL_SET 1
 #define AL_ADD 2
 #define AL_DEL 3
@@ -2553,7 +2553,7 @@ get_arglist_exp(
     void
 set_arglist(char_u *str)
 {
-    do_arglist(str, AL_SET, 0);
+    do_arglist(str, AL_SET, 0, FALSE);
 }
 
 /*
@@ -2567,7 +2567,8 @@ set_arglist(char_u *str)
 do_arglist(
     char_u     *str,
     int                what,
-    int                after UNUSED)           /* 0 means before first one */
+    int                after UNUSED,   // 0 means before first one
+    int                will_edit)      // will edit added argument
 {
     garray_T   new_ga;
     int                exp_count;
@@ -2652,11 +2653,11 @@ do_arglist(
 
        if (what == AL_ADD)
        {
-           (void)alist_add_list(exp_count, exp_files, after);
+           alist_add_list(exp_count, exp_files, after, will_edit);
            vim_free(exp_files);
        }
        else /* what == AL_SET */
-           alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0);
+           alist_set(ALIST(curwin), exp_count, exp_files, will_edit, NULL, 0);
     }
 
     alist_check_arg_idx();
@@ -2932,7 +2933,7 @@ ex_next(exarg_T *eap)
     {
        if (*eap->arg != NUL)               /* redefine file list */
        {
-           if (do_arglist(eap->arg, AL_SET, 0) == FAIL)
+           if (do_arglist(eap->arg, AL_SET, 0, TRUE) == FAIL)
                return;
            i = 0;
        }
@@ -2952,7 +2953,7 @@ ex_argedit(exarg_T *eap)
     // Whether curbuf will be reused, curbuf->b_ffname will be set.
     int curbuf_is_reusable = curbuf_reusable();
 
-    if (do_arglist(eap->arg, AL_ADD, i) == FAIL)
+    if (do_arglist(eap->arg, AL_ADD, i, TRUE) == FAIL)
        return;
 #ifdef FEAT_TITLE
     maketitle();
@@ -2974,7 +2975,8 @@ ex_argedit(exarg_T *eap)
 ex_argadd(exarg_T *eap)
 {
     do_arglist(eap->arg, AL_ADD,
-              eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1);
+              eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1,
+              FALSE);
 #ifdef FEAT_TITLE
     maketitle();
 #endif
@@ -3024,7 +3026,7 @@ ex_argdelete(exarg_T *eap)
     else if (*eap->arg == NUL)
        EMSG(_(e_argreq));
     else
-       do_arglist(eap->arg, AL_DEL, 0);
+       do_arglist(eap->arg, AL_DEL, 0, FALSE);
 #ifdef FEAT_TITLE
     maketitle();
 #endif
@@ -3269,13 +3271,13 @@ ex_listdo(exarg_T *eap)
  * Add files[count] to the arglist of the current window after arg "after".
  * The file names in files[count] must have been allocated and are taken over.
  * Files[] itself is not taken over.
- * Returns index of first added argument.  Returns -1 when failed (out of mem).
  */
-    static int
+    static void
 alist_add_list(
     int                count,
     char_u     **files,
-    int                after)      /* where to add: 0 = before first one */
+    int                after,      // where to add: 0 = before first one
+    int                will_edit)  // will edit adding argument
 {
     int                i;
     int                old_argcount = ARGCOUNT;
@@ -3291,19 +3293,19 @@ alist_add_list(
                                       (ARGCOUNT - after) * sizeof(aentry_T));
        for (i = 0; i < count; ++i)
        {
+           int flags = BLN_LISTED | (will_edit ? BLN_CURBUF : 0);
+
            ARGLIST[after + i].ae_fname = files[i];
-           ARGLIST[after + i].ae_fnum =
-                               buflist_add(files[i], BLN_LISTED | BLN_CURBUF);
+           ARGLIST[after + i].ae_fnum = buflist_add(files[i], flags);
        }
        ALIST(curwin)->al_ga.ga_len += count;
        if (old_argcount > 0 && curwin->w_arg_idx >= after)
            curwin->w_arg_idx += count;
-       return after;
+       return;
     }
 
     for (i = 0; i < count; ++i)
        vim_free(files[i]);
-    return -1;
 }
 
 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
index 87bda700d10bc695dca3be00ab3d7b1950aa5216..a6c71c9f5f4d80014501085e78faf156cd90b5ea 100644 (file)
@@ -80,6 +80,24 @@ func Test_argadd()
   call assert_equal(0, len(argv()))
 endfunc
 
+func Test_argadd_empty_curbuf()
+  new
+  let curbuf = bufnr('%')
+  call writefile(['test', 'Xargadd'], 'Xargadd')
+  " must not re-use the current buffer.
+  argadd Xargadd
+  call assert_equal(curbuf, bufnr('%'))
+  call assert_equal('', bufname('%'))
+  call assert_equal(1, line('$'))
+  rew
+  call assert_notequal(curbuf, bufnr('%'))
+  call assert_equal('Xargadd', bufname('%'))
+  call assert_equal(2, line('$'))
+
+  %argd
+  bwipe!
+endfunc
+
 func Init_abc()
   args a b c
   next
index 7262789ab42f039e0fc4d4f7bf5aea071d32ed21..55b230373fdbad0e6ec2fe1ee360d7e43c0bba0e 100644 (file)
@@ -158,7 +158,9 @@ endfunc
 func Test_command_count_4()
   %argd
   let bufnr = bufnr('$')
-  arga aa bb cc dd ee ff
+  next aa bb cc dd ee ff
+  call assert_equal(bufnr, bufnr('%'))
+
   3argu
   let args = []
   .,$-argdo call add(args, expand('%'))
index d5daaf42bfcb0125bac9ff2952cdb7d6382b6553..c7787e752887e8606d85516abb60d196e9c3d930 100644 (file)
@@ -794,6 +794,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    341,
 /**/
     340,
 /**/