Skip to content

Commit 398ee73

Browse files
committed
patch 8.0.0847: :argadd without argument can't handle space in file name
Problem: :argadd without argument can't handle space in file name. (Harm te Hennepe) Solution: Escape the space. (Yasuhiro Matsumoto, closes #1917)
1 parent 7c9aec4 commit 398ee73

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

src/ex_cmds2.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,8 +2320,8 @@ do_one_arg(char_u *str)
23202320
* Separate the arguments in "str" and return a list of pointers in the
23212321
* growarray "gap".
23222322
*/
2323-
int
2324-
get_arglist(garray_T *gap, char_u *str)
2323+
static int
2324+
get_arglist(garray_T *gap, char_u *str, int escaped)
23252325
{
23262326
ga_init2(gap, (int)sizeof(char_u *), 20);
23272327
while (*str != NUL)
@@ -2333,6 +2333,10 @@ get_arglist(garray_T *gap, char_u *str)
23332333
}
23342334
((char_u **)gap->ga_data)[gap->ga_len++] = str;
23352335

2336+
/* If str is escaped, don't handle backslashes or spaces */
2337+
if (!escaped)
2338+
return OK;
2339+
23362340
/* Isolate one argument, change it in-place, put a NUL after it. */
23372341
str = do_one_arg(str);
23382342
}
@@ -2355,7 +2359,7 @@ get_arglist_exp(
23552359
garray_T ga;
23562360
int i;
23572361

2358-
if (get_arglist(&ga, str) == FAIL)
2362+
if (get_arglist(&ga, str, TRUE) == FAIL)
23592363
return FAIL;
23602364
if (wig == TRUE)
23612365
i = expand_wildcards(ga.ga_len, (char_u **)ga.ga_data,
@@ -2401,6 +2405,7 @@ do_arglist(
24012405
char_u *p;
24022406
int match;
24032407
#endif
2408+
int arg_escaped = TRUE;
24042409

24052410
/*
24062411
* Set default argument for ":argadd" command.
@@ -2410,12 +2415,13 @@ do_arglist(
24102415
if (curbuf->b_ffname == NULL)
24112416
return FAIL;
24122417
str = curbuf->b_fname;
2418+
arg_escaped = FALSE;
24132419
}
24142420

24152421
/*
24162422
* Collect all file name arguments in "new_ga".
24172423
*/
2418-
if (get_arglist(&new_ga, str) == FAIL)
2424+
if (get_arglist(&new_ga, str, arg_escaped) == FAIL)
24192425
return FAIL;
24202426

24212427
#ifdef FEAT_LISTCMDS

src/proto/ex_cmds2.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ int can_abandon(buf_T *buf, int forceit);
5252
int check_changed_any(int hidden, int unload);
5353
int check_fname(void);
5454
int buf_write_all(buf_T *buf, int forceit);
55-
int get_arglist(garray_T *gap, char_u *str);
5655
int get_arglist_exp(char_u *str, int *fcountp, char_u ***fnamesp, int wig);
5756
void set_arglist(char_u *str);
5857
void check_arg_idx(win_T *win);

src/testdir/test_arglist.vim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,19 @@ func Test_argadd()
6565
%argd
6666
edit d
6767
arga
68-
call assert_equal(len(argv()), 1)
69-
call assert_equal(get(argv(), 0, ''), 'd')
68+
call assert_equal(1, len(argv()))
69+
call assert_equal('d', get(argv(), 0, ''))
70+
71+
%argd
72+
edit some\ file
73+
arga
74+
call assert_equal(1, len(argv()))
75+
call assert_equal('some file', get(argv(), 0, ''))
7076

7177
%argd
7278
new
7379
arga
74-
call assert_equal(len(argv()), 0)
80+
call assert_equal(0, len(argv()))
7581
endfunc
7682

7783
func Init_abc()

src/version.c

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

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
847,
772774
/**/
773775
846,
774776
/**/

0 commit comments

Comments
 (0)