Hi all,

I am attaching a patch to add a function to get the command-line
completion matches.

- Yegappan

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 66dbd9a..2535863 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1989,6 +1989,8 @@ getchar([expr])                   Number  get one 
character from the user
 getcharmod()                   Number  modifiers for the last typed character
 getcharsearch()                        Dict    last character search
 getcmdline()                   String  return the current command-line
+getcmdmatches({pat}, {type})
+                               List    list of cmdline completion matches
 getcmdpos()                    Number  return cursor position in command-line
 getcmdtype()                   String  return current command-line type
 getcmdwintype()                        String  return current command-line 
window type
@@ -3975,6 +3977,46 @@ getcmdline()                                             
*getcmdline()*
                        :cmap <F7> <C-\>eescape(getcmdline(), ' \')<CR>
 <              Also see |getcmdtype()|, |getcmdpos()| and |setcmdpos()|.
 
+getcmdmatches({pat}, {type})                   *getcmdmatches()*
+               Return a list of command-line completion matches. The
+               following completion types {type} are supported:
+
+               augroup         autocmd groups
+               buffer          buffer names
+               behave          :behave suboptions
+               color           color schemes
+               command         Ex command (and arguments)
+               compiler        compilers
+               cscope          |:cscope| suboptions
+               dir             directory names
+               environment     environment variable names
+               event           autocommand events
+               expression      Vim expression
+               file            file and directory names
+               file_in_path    file and directory names in |'path'|
+               filetype        filetype names |'filetype'|
+               function        function name
+               help            help subjects
+               highlight       highlight groups
+               history         :history suboptions
+               locale          locale names (as output of locale -a)
+               mapping         mapping name
+               menu            menus
+               option          options
+               shellcmd        Shell command
+               sign            |:sign| suboptions
+               syntax          syntax file names |'syntax'|
+               syntime         |:syntime| suboptions
+               tag             tags
+               tag_listfiles   tags, file names
+               user            user names
+               var             user variables
+
+               If {pat} is an empty string, then all the matches are returned.
+               Otherwise only items matching {pat} are returned. See
+               |wildcards| for the use of special characters in {pat}. In case
+               of an error, an empty list is returned.
+
 getcmdpos()                                            *getcmdpos()*
                Return the position of the cursor in the command line as a
                byte count.  The first column is 1.
diff --git a/src/eval.c b/src/eval.c
index 4a1ad4f..73d7330 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -592,6 +592,7 @@ static void f_getchar(typval_T *argvars, typval_T *rettv);
 static void f_getcharmod(typval_T *argvars, typval_T *rettv);
 static void f_getcharsearch(typval_T *argvars, typval_T *rettv);
 static void f_getcmdline(typval_T *argvars, typval_T *rettv);
+static void f_getcmdmatches(typval_T *argvars, typval_T *rettv);
 static void f_getcmdpos(typval_T *argvars, typval_T *rettv);
 static void f_getcmdtype(typval_T *argvars, typval_T *rettv);
 static void f_getcmdwintype(typval_T *argvars, typval_T *rettv);
@@ -8594,6 +8595,7 @@ static struct fst
     {"getcharmod",     0, 0, f_getcharmod},
     {"getcharsearch",  0, 0, f_getcharsearch},
     {"getcmdline",     0, 0, f_getcmdline},
+    {"getcmdmatches",  2, 2, f_getcmdmatches},
     {"getcmdpos",      0, 0, f_getcmdpos},
     {"getcmdtype",     0, 0, f_getcmdtype},
     {"getcmdwintype",  0, 0, f_getcmdwintype},
@@ -12900,6 +12902,50 @@ f_getcmdline(typval_T *argvars UNUSED, typval_T *rettv)
     rettv->vval.v_string = get_cmdline_str();
 }
 
+#if defined(FEAT_CMDL_COMPL)
+/*
+ * "getcmdmatches()" function
+ */
+    static void
+f_getcmdmatches(typval_T *argvars, typval_T *rettv)
+{
+    char_u     *s;
+    char_u     *pat;
+    expand_T   xpc;
+    int                matchcount;
+    char_u     **matches;
+    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_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);
+    }
+    vim_free(pat);
+    ExpandCleanup(&xpc);
+}
+#endif
+
 /*
  * "getcmdpos()" function
  */
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index ad4ba7c..78c48d5 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -7048,6 +7048,18 @@ parse_compl_arg(
 # endif
     return OK;
 }
+
+    int
+cmdcomplete_str_to_type(char_u *complete_str)
+{
+    int i;
+
+    for (i = 0; command_complete[i].expand != 0; ++i)
+       if (STRCMP(complete_str, command_complete[i].name) == 0)
+           return command_complete[i].expand;
+
+    return EXPAND_NOTHING;
+}
 #endif
 
     static void
diff --git a/src/proto/ex_docmd.pro b/src/proto/ex_docmd.pro
index 6ff1588..b92ce80 100644
--- a/src/proto/ex_docmd.pro
+++ b/src/proto/ex_docmd.pro
@@ -25,6 +25,7 @@ char_u *get_user_cmd_nargs(expand_T *xp, int idx);
 char_u *get_user_cmd_complete(expand_T *xp, int idx);
 int parse_addr_type_arg(char_u *value, int vallen, long *argt, int 
*addr_type_arg);
 int parse_compl_arg(char_u *value, int vallen, int *complp, long *argt, char_u 
**compl_arg);
+int cmdcomplete_str_to_type(char_u *complete_str);
 void not_exiting(void);
 void tabpage_close(int forceit);
 void tabpage_close_other(tabpage_T *tp, int forceit);

Raspunde prin e-mail lui