Skip to content

Commit 32bbd00

Browse files
committed
patch 8.1.0341: :argadd in empty buffer changes the buffer name
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.
1 parent 9049b68 commit 32bbd00

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

src/ex_cmds2.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,10 +2445,10 @@ buf_write_all(buf_T *buf, int forceit)
24452445
*/
24462446

24472447
static char_u *do_one_arg(char_u *str);
2448-
static int do_arglist(char_u *str, int what, int after);
2448+
static int do_arglist(char_u *str, int what, int after, int will_edit);
24492449
static void alist_check_arg_idx(void);
24502450
static int editing_arg_idx(win_T *win);
2451-
static int alist_add_list(int count, char_u **files, int after);
2451+
static void alist_add_list(int count, char_u **files, int after, int will_edit);
24522452
#define AL_SET 1
24532453
#define AL_ADD 2
24542454
#define AL_DEL 3
@@ -2553,7 +2553,7 @@ get_arglist_exp(
25532553
void
25542554
set_arglist(char_u *str)
25552555
{
2556-
do_arglist(str, AL_SET, 0);
2556+
do_arglist(str, AL_SET, 0, FALSE);
25572557
}
25582558

25592559
/*
@@ -2567,7 +2567,8 @@ set_arglist(char_u *str)
25672567
do_arglist(
25682568
char_u *str,
25692569
int what,
2570-
int after UNUSED) /* 0 means before first one */
2570+
int after UNUSED, // 0 means before first one
2571+
int will_edit) // will edit added argument
25712572
{
25722573
garray_T new_ga;
25732574
int exp_count;
@@ -2652,11 +2653,11 @@ do_arglist(
26522653

26532654
if (what == AL_ADD)
26542655
{
2655-
(void)alist_add_list(exp_count, exp_files, after);
2656+
alist_add_list(exp_count, exp_files, after, will_edit);
26562657
vim_free(exp_files);
26572658
}
26582659
else /* what == AL_SET */
2659-
alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0);
2660+
alist_set(ALIST(curwin), exp_count, exp_files, will_edit, NULL, 0);
26602661
}
26612662

26622663
alist_check_arg_idx();
@@ -2932,7 +2933,7 @@ ex_next(exarg_T *eap)
29322933
{
29332934
if (*eap->arg != NUL) /* redefine file list */
29342935
{
2935-
if (do_arglist(eap->arg, AL_SET, 0) == FAIL)
2936+
if (do_arglist(eap->arg, AL_SET, 0, TRUE) == FAIL)
29362937
return;
29372938
i = 0;
29382939
}
@@ -2952,7 +2953,7 @@ ex_argedit(exarg_T *eap)
29522953
// Whether curbuf will be reused, curbuf->b_ffname will be set.
29532954
int curbuf_is_reusable = curbuf_reusable();
29542955

2955-
if (do_arglist(eap->arg, AL_ADD, i) == FAIL)
2956+
if (do_arglist(eap->arg, AL_ADD, i, TRUE) == FAIL)
29562957
return;
29572958
#ifdef FEAT_TITLE
29582959
maketitle();
@@ -2974,7 +2975,8 @@ ex_argedit(exarg_T *eap)
29742975
ex_argadd(exarg_T *eap)
29752976
{
29762977
do_arglist(eap->arg, AL_ADD,
2977-
eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1);
2978+
eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1,
2979+
FALSE);
29782980
#ifdef FEAT_TITLE
29792981
maketitle();
29802982
#endif
@@ -3024,7 +3026,7 @@ ex_argdelete(exarg_T *eap)
30243026
else if (*eap->arg == NUL)
30253027
EMSG(_(e_argreq));
30263028
else
3027-
do_arglist(eap->arg, AL_DEL, 0);
3029+
do_arglist(eap->arg, AL_DEL, 0, FALSE);
30283030
#ifdef FEAT_TITLE
30293031
maketitle();
30303032
#endif
@@ -3269,13 +3271,13 @@ ex_listdo(exarg_T *eap)
32693271
* Add files[count] to the arglist of the current window after arg "after".
32703272
* The file names in files[count] must have been allocated and are taken over.
32713273
* Files[] itself is not taken over.
3272-
* Returns index of first added argument. Returns -1 when failed (out of mem).
32733274
*/
3274-
static int
3275+
static void
32753276
alist_add_list(
32763277
int count,
32773278
char_u **files,
3278-
int after) /* where to add: 0 = before first one */
3279+
int after, // where to add: 0 = before first one
3280+
int will_edit) // will edit adding argument
32793281
{
32803282
int i;
32813283
int old_argcount = ARGCOUNT;
@@ -3291,19 +3293,19 @@ alist_add_list(
32913293
(ARGCOUNT - after) * sizeof(aentry_T));
32923294
for (i = 0; i < count; ++i)
32933295
{
3296+
int flags = BLN_LISTED | (will_edit ? BLN_CURBUF : 0);
3297+
32943298
ARGLIST[after + i].ae_fname = files[i];
3295-
ARGLIST[after + i].ae_fnum =
3296-
buflist_add(files[i], BLN_LISTED | BLN_CURBUF);
3299+
ARGLIST[after + i].ae_fnum = buflist_add(files[i], flags);
32973300
}
32983301
ALIST(curwin)->al_ga.ga_len += count;
32993302
if (old_argcount > 0 && curwin->w_arg_idx >= after)
33003303
curwin->w_arg_idx += count;
3301-
return after;
3304+
return;
33023305
}
33033306

33043307
for (i = 0; i < count; ++i)
33053308
vim_free(files[i]);
3306-
return -1;
33073309
}
33083310

33093311
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)

src/testdir/test_arglist.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ func Test_argadd()
8080
call assert_equal(0, len(argv()))
8181
endfunc
8282

83+
func Test_argadd_empty_curbuf()
84+
new
85+
let curbuf = bufnr('%')
86+
call writefile(['test', 'Xargadd'], 'Xargadd')
87+
" must not re-use the current buffer.
88+
argadd Xargadd
89+
call assert_equal(curbuf, bufnr('%'))
90+
call assert_equal('', bufname('%'))
91+
call assert_equal(1, line('$'))
92+
rew
93+
call assert_notequal(curbuf, bufnr('%'))
94+
call assert_equal('Xargadd', bufname('%'))
95+
call assert_equal(2, line('$'))
96+
97+
%argd
98+
bwipe!
99+
endfunc
100+
83101
func Init_abc()
84102
args a b c
85103
next

src/testdir/test_command_count.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ endfunc
158158
func Test_command_count_4()
159159
%argd
160160
let bufnr = bufnr('$')
161-
arga aa bb cc dd ee ff
161+
next aa bb cc dd ee ff
162+
call assert_equal(bufnr, bufnr('%'))
163+
162164
3argu
163165
let args = []
164166
.,$-argdo call add(args, expand('%'))

src/version.c

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

795795
static int included_patches[] =
796796
{ /* Add new patch number below this line */
797+
/**/
798+
341,
797799
/**/
798800
340,
799801
/**/

0 commit comments

Comments
 (0)