Skip to content

Commit a24f0a5

Browse files
committed
patch 7.4.1123
Problem: Using ":argadd" when there are no arguments results in the second argument to be the current one. (Yegappan Lakshmanan) Solution: Correct the w_arg_idx value.
1 parent 42c9cfa commit a24f0a5

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

src/ex_cmds2.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,6 +2836,7 @@ alist_add_list(count, files, after)
28362836
int after; /* where to add: 0 = before first one */
28372837
{
28382838
int i;
2839+
int old_argcount = ARGCOUNT;
28392840

28402841
if (ga_grow(&ALIST(curwin)->al_ga, count) == OK)
28412842
{
@@ -2852,8 +2853,8 @@ alist_add_list(count, files, after)
28522853
ARGLIST[after + i].ae_fnum = buflist_add(files[i], BLN_LISTED);
28532854
}
28542855
ALIST(curwin)->al_ga.ga_len += count;
2855-
if (curwin->w_arg_idx >= after)
2856-
++curwin->w_arg_idx;
2856+
if (old_argcount > 0 && curwin->w_arg_idx >= after)
2857+
curwin->w_arg_idx += count;
28572858
return after;
28582859
}
28592860

src/testdir/test_arglist.vim

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,55 @@ func Test_argidx()
2020
1argdelete
2121
call assert_equal(0, argidx())
2222
endfunc
23+
24+
func Test_argadd()
25+
%argdelete
26+
argadd a b c
27+
call assert_equal(0, argidx())
28+
29+
%argdelete
30+
argadd a
31+
call assert_equal(0, argidx())
32+
argadd b c d
33+
call assert_equal(0, argidx())
34+
35+
call Init_abc()
36+
argadd x
37+
call Assert_argc(['a', 'b', 'x', 'c'])
38+
call assert_equal(1, argidx())
39+
40+
call Init_abc()
41+
0argadd x
42+
call Assert_argc(['x', 'a', 'b', 'c'])
43+
call assert_equal(2, argidx())
44+
45+
call Init_abc()
46+
1argadd x
47+
call Assert_argc(['a', 'x', 'b', 'c'])
48+
call assert_equal(2, argidx())
49+
50+
call Init_abc()
51+
$argadd x
52+
call Assert_argc(['a', 'b', 'c', 'x'])
53+
call assert_equal(1, argidx())
54+
55+
call Init_abc()
56+
$argadd x
57+
+2argadd y
58+
call Assert_argc(['a', 'b', 'c', 'x', 'y'])
59+
call assert_equal(1, argidx())
60+
endfunc
61+
62+
func Init_abc()
63+
args a b c
64+
next
65+
endfunc
66+
67+
func Assert_argc(l)
68+
call assert_equal(len(a:l), argc())
69+
let i = 0
70+
while i < len(a:l) && i < argc()
71+
call assert_equal(a:l[i], argv(i))
72+
let i += 1
73+
endwhile
74+
endfunc

src/version.c

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

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
1123,
744746
/**/
745747
1122,
746748
/**/

0 commit comments

Comments
 (0)