diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-01-14 22:28:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-14 22:28:21 +0800 |
commit | 686168c648e46986088f677028c2b245f6b78303 (patch) | |
tree | dd0c7ea0b1e3b5f0970444ed015703fd5d170c52 /src/nvim/usercmd.c | |
parent | 2065ce877ef81bcd66132bd26e75aa4d761dca12 (diff) | |
download | rneovim-686168c648e46986088f677028c2b245f6b78303.tar.gz rneovim-686168c648e46986088f677028c2b245f6b78303.tar.bz2 rneovim-686168c648e46986088f677028c2b245f6b78303.zip |
vim-patch:8.2.4398: some command completion functions are too long (#21799)
Problem: Some command completion functions are too long.
Solution: Refactor code into separate functions. Add a few more tests.
(Yegappan Lakshmanan, closes vim/vim#9785)
https://github.com/vim/vim/commit/b31aec3b9387ed12677dca09069c3ae98c6c7447
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/usercmd.c')
-rw-r--r-- | src/nvim/usercmd.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index f8ed190fb2..883d7321d2 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -25,8 +25,10 @@ #include "nvim/keycodes.h" #include "nvim/lua/executor.h" #include "nvim/macros.h" +#include "nvim/mapping.h" #include "nvim/mbyte.h" #include "nvim/memory.h" +#include "nvim/menu.h" #include "nvim/message.h" #include "nvim/option_defs.h" #include "nvim/os/input.h" @@ -220,6 +222,7 @@ char *find_ucmd(exarg_T *eap, char *p, int *full, expand_T *xp, int *complp) return p; } +/// Set completion context for :command const char *set_context_in_user_cmd(expand_T *xp, const char *arg_in) { const char *arg = arg_in; @@ -271,6 +274,47 @@ const char *set_context_in_user_cmd(expand_T *xp, const char *arg_in) return (const char *)skipwhite(p); } +/// Set the completion context for the argument of a user defined command. +const char *set_context_in_user_cmdarg(const char *cmd FUNC_ATTR_UNUSED, const char *arg, + uint32_t argt, int context, expand_T *xp, bool forceit) +{ + if (context == EXPAND_NOTHING) { + return NULL; + } + + if (argt & EX_XFILE) { + // EX_XFILE: file names are handled above. + xp->xp_context = context; + return NULL; + } + + if (context == EXPAND_MENUS) { + return (const char *)set_context_in_menu_cmd(xp, cmd, (char *)arg, forceit); + } + if (context == EXPAND_COMMANDS) { + return arg; + } + if (context == EXPAND_MAPPINGS) { + return (const char *)set_context_in_map_cmd(xp, "map", (char *)arg, forceit, false, false, + CMD_map); + } + // Find start of last argument. + const char *p = arg; + while (*p) { + if (*p == ' ') { + // argument starts after a space + arg = p + 1; + } else if (*p == '\\' && *(p + 1) != NUL) { + p++; // skip over escaped character + } + MB_PTR_ADV(p); + } + xp->xp_pattern = (char *)arg; + xp->xp_context = context; + + return NULL; +} + char *expand_user_command_name(int idx) { return get_user_commands(NULL, idx - CMD_SIZE); |