diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2014-08-18 00:27:07 -0400 | 
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2014-08-18 00:27:07 -0400 | 
| commit | a0e593e26163c730e75a362dcc9e34a645021aff (patch) | |
| tree | a4ebd7da8d7a5ba8edf9b5cb9fa49d42fd5048b7 /src/nvim/eval.c | |
| parent | 6dcd629ed6e61fbebcf715cd1b362773f1f209ec (diff) | |
| parent | 5617ee8f352a2ddb61f52e5e0ae7347957d95991 (diff) | |
| download | rneovim-a0e593e26163c730e75a362dcc9e34a645021aff.tar.gz rneovim-a0e593e26163c730e75a362dcc9e34a645021aff.tar.bz2 rneovim-a0e593e26163c730e75a362dcc9e34a645021aff.zip  | |
Merge pull request #1019 from splinterofchaos/globpath
vim-patch:7.4.279
Diffstat (limited to 'src/nvim/eval.c')
| -rw-r--r-- | src/nvim/eval.c | 57 | 
1 files changed, 40 insertions, 17 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 7234afc0ce..5bda9fcd3f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6408,7 +6408,7 @@ static struct fst {    {"getwinposy",      0, 0, f_getwinposy},    {"getwinvar",       2, 3, f_getwinvar},    {"glob",            1, 3, f_glob}, -  {"globpath",        2, 3, f_globpath}, +  {"globpath",        2, 4, f_globpath},    {"has",             1, 1, f_has},    {"has_key",         2, 2, f_has_key},    {"haslocaldir",     0, 0, f_haslocaldir}, @@ -9605,27 +9605,50 @@ static void f_glob(typval_T *argvars, typval_T *rettv)      rettv->vval.v_string = NULL;  } -/* - * "globpath()" function - */ +/// "globpath()" function  static void f_globpath(typval_T *argvars, typval_T *rettv)  { -  int flags = 0; -  char_u buf1[NUMBUFLEN]; -  char_u      *file = get_tv_string_buf_chk(&argvars[1], buf1); -  int error = FALSE; +  int flags = 0;  // Flags for globpath. +  int error = false; -  /* When the optional second argument is non-zero, don't remove matches -  * for 'wildignore' and don't put matches for 'suffixes' at the end. */ -  if (argvars[2].v_type != VAR_UNKNOWN -      && get_tv_number_chk(&argvars[2], &error)) -    flags |= WILD_KEEP_ALL; +  // Return a string, or a list if the optional third argument is non-zero.    rettv->v_type = VAR_STRING; -  if (file == NULL || error) + +  if (argvars[2].v_type != VAR_UNKNOWN) { +    // When the optional second argument is non-zero, don't remove matches +    // for 'wildignore' and don't put matches for 'suffixes' at the end. +    if (get_tv_number_chk(&argvars[2], &error)) { +      flags |= WILD_KEEP_ALL; +    } + +    if (argvars[3].v_type != VAR_UNKNOWN +        && get_tv_number_chk(&argvars[3], &error)) { +      rettv->v_type = VAR_LIST; +      rettv->vval.v_list = NULL; +    } +  } + +  char_u buf1[NUMBUFLEN]; +  char_u *file = get_tv_string_buf_chk(&argvars[1], buf1); +  if (file != NULL && !error) { +    garray_T ga; +    ga_init(&ga, (int)sizeof(char_u *), 10); +    globpath(get_tv_string(&argvars[0]), file, &ga, flags); + +    if (rettv->v_type == VAR_STRING) { +      rettv->vval.v_string = ga_concat_strings_sep(&ga, "\n"); +    } else { +      rettv_list_alloc(rettv); +      for (int i = 0; i < ga.ga_len; i++) { +        list_append_string(rettv->vval.v_list, +                           ((char_u **)(ga.ga_data))[i], -1); +      } +    } + +    ga_clear_strings(&ga); +  } else {      rettv->vval.v_string = NULL; -  else -    rettv->vval.v_string = globpath(get_tv_string(&argvars[0]), file, -        flags); +  }  }  /*  | 
