diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-05-31 17:44:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-31 17:44:13 +0200 |
commit | 7380ebfc17723662f6fe1e38372f54b3d67fe082 (patch) | |
tree | e079f85a72f851e5c0a8e08f52db0cb4a8b26163 /src/nvim/api/private/helpers.c | |
parent | 5d840fa7e6ba7d58a89d3126ee914cb0e42168ca (diff) | |
parent | 46536f53e82967dcac8d030ee3394cdb156f9603 (diff) | |
download | rneovim-7380ebfc17723662f6fe1e38372f54b3d67fe082.tar.gz rneovim-7380ebfc17723662f6fe1e38372f54b3d67fe082.tar.bz2 rneovim-7380ebfc17723662f6fe1e38372f54b3d67fe082.zip |
Merge pull request #18194 from famiu/feat/usercmd_preview
feat: user command "preview" (like inccommand)
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r-- | src/nvim/api/private/helpers.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 3cccbc3cdf..6981ecc455 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1438,6 +1438,7 @@ void create_user_command(String name, Object command, Dict(user_command) *opts, char *rep = NULL; LuaRef luaref = LUA_NOREF; LuaRef compl_luaref = LUA_NOREF; + LuaRef preview_luaref = LUA_NOREF; if (!uc_validate_name(name.data)) { api_set_error(err, kErrorTypeValidation, "Invalid command name"); @@ -1592,6 +1593,14 @@ void create_user_command(String name, Object command, Dict(user_command) *opts, goto err; } + if (opts->preview.type == kObjectTypeLuaRef) { + argt |= EX_PREVIEW; + preview_luaref = api_new_luaref(opts->preview.data.luaref); + } else if (HAS_KEY(opts->preview)) { + api_set_error(err, kErrorTypeValidation, "Invalid value for 'preview'"); + goto err; + } + switch (command.type) { case kObjectTypeLuaRef: luaref = api_new_luaref(command.data.luaref); @@ -1611,7 +1620,7 @@ void create_user_command(String name, Object command, Dict(user_command) *opts, } if (uc_add_command(name.data, name.size, rep, argt, def, flags, compl, compl_arg, compl_luaref, - addr_type_arg, luaref, force) != OK) { + preview_luaref, addr_type_arg, luaref, force) != OK) { api_set_error(err, kErrorTypeException, "Failed to create user command"); // Do not goto err, since uc_add_command now owns luaref, compl_luaref, and compl_arg } |