aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval.c
diff options
context:
space:
mode:
authorShougo Matsushita <Shougo.Matsu@gmail.com>2016-07-23 11:33:38 +0900
committerJustin M. Keyes <justinkz@gmail.com>2016-08-01 03:33:38 -0400
commit23f591dba078fee16ab6e4debfcd051e799ca4f8 (patch)
tree0a469e39398562b3145821b8b9b1ed124e9b48a1 /src/nvim/eval.c
parent70ae6ac344472e51ac75316992e2c03464b4f6ad (diff)
downloadrneovim-23f591dba078fee16ab6e4debfcd051e799ca4f8.tar.gz
rneovim-23f591dba078fee16ab6e4debfcd051e799ca4f8.tar.bz2
rneovim-23f591dba078fee16ab6e4debfcd051e799ca4f8.zip
[RFC] vim-patch:7.4.2011, vim-patch:7.4.2012, vim-patch:7.4.2066 #5106
vim-patch:7.4.2011 Problem: It is not easy to get a list of command arguments. Solution: Add getcompletion(). (Yegappan Lakshmanan) https://github.com/vim/vim/commit/aa4d73235bf4deee167aa5314b89ae3d3db334b7 vim-patch:7.4.2012 Problem: Test for getcompletion() does not pass on all systems. Solution: Only test what is supported. https://github.com/vim/vim/commit/0d3e24be5686c0710aa3c6671e4c626d6cb21a5f vim-patch:7.4.2066 Problem: getcompletion() not well tested. Solution: Add more testing. https://github.com/vim/vim/commit/c1fb763184c8ae82300357867fa2070aa94366e9
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r--src/nvim/eval.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 824b298592..8a96278673 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -6791,6 +6791,7 @@ static struct fst {
{ "getcmdpos", 0, 0, f_getcmdpos },
{ "getcmdtype", 0, 0, f_getcmdtype },
{ "getcmdwintype", 0, 0, f_getcmdwintype },
+ { "getcompletion", 2, 2, f_getcompletion },
{ "getcurpos", 0, 0, f_getcurpos },
{ "getcwd", 0, 2, f_getcwd },
{ "getfontname", 0, 1, f_getfontname },
@@ -9983,6 +9984,50 @@ static void f_getcmdwintype(typval_T *argvars, typval_T *rettv)
rettv->vval.v_string[0] = cmdwin_type;
}
+// "getcompletion()" function
+static void f_getcompletion(typval_T *argvars, typval_T *rettv)
+{
+ char_u *pat;
+ expand_T xpc;
+ int options = WILD_KEEP_ALL | WILD_SILENT | WILD_USE_NL
+ | WILD_LIST_NOTFOUND | WILD_NO_BEEP;
+
+ if (p_wic) {
+ options |= WILD_ICASE;
+ }
+
+ ExpandInit(&xpc);
+ xpc.xp_pattern = get_tv_string(&argvars[0]);
+ xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
+ xpc.xp_context = cmdcomplete_str_to_type(get_tv_string(&argvars[1]));
+ if (xpc.xp_context == EXPAND_NOTHING) {
+ if (argvars[1].v_type == VAR_STRING) {
+ EMSG2(_(e_invarg2), argvars[1].vval.v_string);
+ } else {
+ EMSG(_(e_invarg));
+ }
+ return;
+ }
+
+ if (xpc.xp_context == EXPAND_MENUS) {
+ set_context_in_menu_cmd(&xpc, (char_u *)"menu", xpc.xp_pattern, false);
+ xpc.xp_pattern_len = STRLEN(xpc.xp_pattern);
+ }
+
+ pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
+ if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL)) {
+ int i;
+
+ ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
+
+ for (i = 0; i < xpc.xp_numfiles; i++) {
+ list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1);
+ }
+ }
+ xfree(pat);
+ ExpandCleanup(&xpc);
+}
+
/// `getcwd([{win}[, {tab}]])` function
///
/// Every scope not specified implies the currently selected scope object.