diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-12-28 23:18:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-28 23:18:07 +0100 |
commit | 7bb593169ec8c4253d2e8a373fa2ce41cec1cc74 (patch) | |
tree | f1916b215749503bcaa0e4b934c248a75d096003 /src/nvim/api/vim.c | |
parent | 08616571f47cc367a5fe59b52295708b9fda3b09 (diff) | |
parent | eff11b3c3fcb9aa777deafb0a33b1523aa05b603 (diff) | |
download | rneovim-7bb593169ec8c4253d2e8a373fa2ce41cec1cc74.tar.gz rneovim-7bb593169ec8c4253d2e8a373fa2ce41cec1cc74.tar.bz2 rneovim-7bb593169ec8c4253d2e8a373fa2ce41cec1cc74.zip |
Merge pull request #16752 from gpanders/lua-user-commands
feat(api): implement nvim_{add,del}_user_command
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r-- | src/nvim/api/vim.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index fb59e0fb44..dfc606f927 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2363,3 +2363,52 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * return result; } + +/// Create a new user command |user-commands| +/// +/// {name} is the name of the new command. The name must begin with an uppercase letter. +/// +/// {command} is the replacement text or Lua function to execute. +/// +/// Example: +/// <pre> +/// :call nvim_add_user_command('SayHello', 'echo "Hello world!"', {}) +/// :SayHello +/// Hello world! +/// </pre> +/// +/// @param name Name of the new user command. Must begin with an uppercase letter. +/// @param command Replacement command to execute when this user command is executed. When called +/// from Lua, the command can also be a Lua function. The function is called with a +/// single table argument that contains the following keys: +/// - args: (string) The args passed to the command, if any |<args>| +/// - bang: (boolean) "true" if the command was executed with a ! modifier |<bang>| +/// - line1: (number) The starting line of the command range |<line1>| +/// - line2: (number) The final line of the command range |<line2>| +/// - range: (number) The number of items in the command range: 0, 1, or 2 |<range>| +/// - count: (number) Any count supplied |<count>| +/// - reg: (string) The optional register, if specified |<reg>| +/// - mods: (string) Command modifiers, if any |<mods>| +/// @param opts Optional command attributes. See |command-attributes| for more details. To use +/// boolean attributes (such as |:command-bang| or |:command-bar|) set the value to +/// "true". When using a Lua function for {command} you can also provide a "desc" +/// key that will be displayed when listing commands. In addition to the string +/// options listed in |:command-complete|, the "complete" key also accepts a Lua +/// function which works like the "customlist" completion mode +/// |:command-complete-customlist|. +/// @param[out] err Error details, if any. +void nvim_add_user_command(String name, Object command, Dict(user_command) *opts, Error *err) + FUNC_API_SINCE(9) +{ + add_user_command(name, command, opts, 0, err); +} + +/// Delete a user-defined command. +/// +/// @param name Name of the command to delete. +/// @param[out] err Error details, if any. +void nvim_del_user_command(String name, Error *err) + FUNC_API_SINCE(9) +{ + nvim_buf_del_user_command(-1, name, err); +} |