diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-08-21 07:29:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-21 07:29:49 +0800 |
commit | 694814cdd54ac245d1f4d2c28dce7e9132fcb616 (patch) | |
tree | 70258002f855c8b921998bc1d90b992840dc5a1f /src | |
parent | ac99e63d73df84cc20766ad86655724f3a0345b9 (diff) | |
download | rneovim-694814cdd54ac245d1f4d2c28dce7e9132fcb616.tar.gz rneovim-694814cdd54ac245d1f4d2c28dce7e9132fcb616.tar.bz2 rneovim-694814cdd54ac245d1f4d2c28dce7e9132fcb616.zip |
vim-patch:9.0.1774: no support for custom cmdline completion (#24808)
Problem: no support for custom cmdline completion
Solution: Add new vimscript functions
Add the following two functions:
- getcmdcompltype() returns custom and customlist functions
- getcompletion() supports both custom and customlist
closes: vim/vim#12228
https://github.com/vim/vim/commit/92997dda789ad8061841128cbc99b15ec0374411
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/cmdexpand.c | 22 | ||||
-rw-r--r-- | src/nvim/eval.lua | 4 | ||||
-rw-r--r-- | src/nvim/ex_getln.c | 14 | ||||
-rw-r--r-- | src/nvim/usercmd.c | 7 |
4 files changed, 43 insertions, 4 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index eb9394c8ff..9470f77ab5 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -3515,12 +3515,34 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) ExpandInit(&xpc); xpc.xp_pattern = (char *)pattern; xpc.xp_pattern_len = strlen(xpc.xp_pattern); + xpc.xp_line = (char *)pattern; + xpc.xp_context = cmdcomplete_str_to_type(type); if (xpc.xp_context == EXPAND_NOTHING) { semsg(_(e_invarg2), type); return; } + if (xpc.xp_context == EXPAND_USER_DEFINED) { + // Must be "custom,funcname" pattern + if (strncmp(type, "custom,", 7) != 0) { + semsg(_(e_invarg2), type); + return; + } + + xpc.xp_arg = (char *)(type + 7); + } + + if (xpc.xp_context == EXPAND_USER_LIST) { + // Must be "customlist,funcname" pattern + if (strncmp(type, "customlist,", 11) != 0) { + semsg(_(e_invarg2), type); + return; + } + + xpc.xp_arg = (char *)(type + 11); + } + if (xpc.xp_context == EXPAND_MENUS) { set_context_in_menu_cmd(&xpc, "menu", xpc.xp_pattern, false); xpc.xp_pattern_len = strlen(xpc.xp_pattern); diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 154023b25f..be87201bbf 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -3582,7 +3582,9 @@ M.funcs = { color color schemes command Ex command compiler compilers - diff_buffer |:diffget| and |:diffput| completion + custom,{func} custom completion, defined via {func} + customlist,{func} custom completion, defined via {func} + diff_buffer |:diffget| and |:diffput| completion dir directory names environment environment variable names event autocommand events diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 17c17e60ce..89f5e92c33 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4165,11 +4165,19 @@ static char *get_cmdline_completion(void) } char *cmd_compl = get_user_cmd_complete(p->xpc, p->xpc->xp_context); - if (cmd_compl != NULL) { - return xstrdup(cmd_compl); + if (cmd_compl == NULL) { + return NULL; } - return NULL; + if (p->xpc->xp_context == EXPAND_USER_LIST + || p->xpc->xp_context == EXPAND_USER_DEFINED) { + size_t buflen = strlen(cmd_compl) + strlen(p->xpc->xp_arg) + 2; + char *buffer = xmalloc(buflen); + snprintf(buffer, buflen, "%s,%s", cmd_compl, p->xpc->xp_arg); + return buffer; + } + + return xstrdup(cmd_compl); } /// "getcmdcompltype()" function diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 65720342ce..e585818e75 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -425,6 +425,13 @@ char *get_user_cmd_complete(expand_T *xp, int idx) int cmdcomplete_str_to_type(const char *complete_str) { + if (strncmp(complete_str, "custom,", 7) == 0) { + return EXPAND_USER_DEFINED; + } + if (strncmp(complete_str, "customlist,", 11) == 0) { + return EXPAND_USER_LIST; + } + for (int i = 0; i < (int)(ARRAY_SIZE(command_complete)); i++) { char *cmd_compl = get_command_complete(i); if (cmd_compl == NULL) { |