aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-06-12 21:01:16 +0200
committerGitHub <noreply@github.com>2022-06-12 21:01:16 +0200
commitfeba56af7d032c948a78c21735502bebe45f8361 (patch)
treee8c240f53b4448aeb7352a59fcab6de58ee298fc /src/nvim/api/vim.c
parent2de0d6714497e4259f467516e52852c1016d5318 (diff)
parent612944c5863caabc7b71b66c9deb73a983c69803 (diff)
downloadrneovim-feba56af7d032c948a78c21735502bebe45f8361.tar.gz
rneovim-feba56af7d032c948a78c21735502bebe45f8361.tar.bz2
rneovim-feba56af7d032c948a78c21735502bebe45f8361.zip
Merge pull request #18936 from bfredl/apioption
refactor(api): reorganize code
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r--src/nvim/api/vim.c284
1 files changed, 0 insertions, 284 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 5f7162cdd6..77b4900f4f 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -708,220 +708,6 @@ void nvim_set_vvar(String name, Object value, Error *err)
dict_set_var(&vimvardict, name, value, false, false, err);
}
-/// Gets the global value of an option.
-///
-/// @param name Option name
-/// @param[out] err Error details, if any
-/// @return Option value (global)
-Object nvim_get_option(String name, Error *err)
- FUNC_API_SINCE(1)
-{
- return get_option_from(NULL, SREQ_GLOBAL, name, err);
-}
-
-/// Gets the value of an option. The behavior of this function matches that of
-/// |:set|: the local value of an option is returned if it exists; otherwise,
-/// the global value is returned. Local values always correspond to the current
-/// buffer or window. To get a buffer-local or window-local option for a
-/// specific buffer or window, use |nvim_buf_get_option()| or
-/// |nvim_win_get_option()|.
-///
-/// @param name Option name
-/// @param opts Optional parameters
-/// - scope: One of 'global' or 'local'. Analogous to
-/// |:setglobal| and |:setlocal|, respectively.
-/// @param[out] err Error details, if any
-/// @return Option value
-Object nvim_get_option_value(String name, Dict(option) *opts, Error *err)
- FUNC_API_SINCE(9)
-{
- Object rv = OBJECT_INIT;
-
- int scope = 0;
- if (opts->scope.type == kObjectTypeString) {
- if (!strcmp(opts->scope.data.string.data, "local")) {
- scope = OPT_LOCAL;
- } else if (!strcmp(opts->scope.data.string.data, "global")) {
- scope = OPT_GLOBAL;
- } else {
- api_set_error(err, kErrorTypeValidation, "invalid scope: must be 'local' or 'global'");
- goto end;
- }
- } else if (HAS_KEY(opts->scope)) {
- api_set_error(err, kErrorTypeValidation, "invalid value for key: scope");
- goto end;
- }
-
- long numval = 0;
- char *stringval = NULL;
- switch (get_option_value(name.data, &numval, &stringval, scope)) {
- case 0:
- rv = STRING_OBJ(cstr_as_string(stringval));
- break;
- case 1:
- rv = INTEGER_OBJ(numval);
- break;
- case 2:
- switch (numval) {
- case 0:
- case 1:
- rv = BOOLEAN_OBJ(numval);
- break;
- default:
- // Boolean options that return something other than 0 or 1 should return nil. Currently this
- // only applies to 'autoread' which uses -1 as a local value to indicate "unset"
- rv = NIL;
- break;
- }
- break;
- default:
- api_set_error(err, kErrorTypeValidation, "unknown option '%s'", name.data);
- goto end;
- }
-
-end:
- return rv;
-}
-
-/// Sets the value of an option. The behavior of this function matches that of
-/// |:set|: for global-local options, both the global and local value are set
-/// unless otherwise specified with {scope}.
-///
-/// Note the options {win} and {buf} cannot be used together.
-///
-/// @param name Option name
-/// @param value New option value
-/// @param opts Optional parameters
-/// - scope: One of 'global' or 'local'. Analogous to
-/// |:setglobal| and |:setlocal|, respectively.
-/// - win: |window-ID|. Used for setting window local option.
-/// - buf: Buffer number. Used for setting buffer local option.
-/// @param[out] err Error details, if any
-void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error *err)
- FUNC_API_SINCE(9)
-{
- int scope = 0;
- if (opts->scope.type == kObjectTypeString) {
- if (!strcmp(opts->scope.data.string.data, "local")) {
- scope = OPT_LOCAL;
- } else if (!strcmp(opts->scope.data.string.data, "global")) {
- scope = OPT_GLOBAL;
- } else {
- api_set_error(err, kErrorTypeValidation, "invalid scope: must be 'local' or 'global'");
- return;
- }
- } else if (HAS_KEY(opts->scope)) {
- api_set_error(err, kErrorTypeValidation, "invalid value for key: scope");
- return;
- }
-
- int opt_type = SREQ_GLOBAL;
- void *to = NULL;
-
- if (opts->win.type == kObjectTypeInteger) {
- opt_type = SREQ_WIN;
- to = find_window_by_handle((int)opts->win.data.integer, err);
- } else if (HAS_KEY(opts->win)) {
- api_set_error(err, kErrorTypeValidation, "invalid value for key: win");
- return;
- }
-
- if (opts->buf.type == kObjectTypeInteger) {
- scope = OPT_LOCAL;
- opt_type = SREQ_BUF;
- to = find_buffer_by_handle((int)opts->buf.data.integer, err);
- } else if (HAS_KEY(opts->buf)) {
- api_set_error(err, kErrorTypeValidation, "invalid value for key: buf");
- return;
- }
-
- if (HAS_KEY(opts->scope) && HAS_KEY(opts->buf)) {
- api_set_error(err, kErrorTypeValidation, "scope and buf cannot be used together");
- return;
- }
-
- if (HAS_KEY(opts->win) && HAS_KEY(opts->buf)) {
- api_set_error(err, kErrorTypeValidation, "buf and win cannot be used together");
- return;
- }
-
- long numval = 0;
- char *stringval = NULL;
-
- switch (value.type) {
- case kObjectTypeInteger:
- numval = value.data.integer;
- break;
- case kObjectTypeBoolean:
- numval = value.data.boolean ? 1 : 0;
- break;
- case kObjectTypeString:
- stringval = value.data.string.data;
- break;
- case kObjectTypeNil:
- scope |= OPT_CLEAR;
- break;
- default:
- api_set_error(err, kErrorTypeValidation, "invalid value for option");
- return;
- }
-
- set_option_value_for(name.data, numval, stringval, scope, opt_type, to, err);
-}
-
-/// Gets the option information for all options.
-///
-/// The dictionary has the full option names as keys and option metadata
-/// dictionaries as detailed at |nvim_get_option_info|.
-///
-/// @return dictionary of all options
-Dictionary nvim_get_all_options_info(Error *err)
- FUNC_API_SINCE(7)
-{
- return get_all_vimoptions();
-}
-
-/// Gets the option information for one option
-///
-/// Resulting dictionary has keys:
-/// - name: Name of the option (like 'filetype')
-/// - shortname: Shortened name of the option (like 'ft')
-/// - type: type of option ("string", "number" or "boolean")
-/// - default: The default value for the option
-/// - was_set: Whether the option was set.
-///
-/// - last_set_sid: Last set script id (if any)
-/// - last_set_linenr: line number where option was set
-/// - last_set_chan: Channel where option was set (0 for local)
-///
-/// - scope: one of "global", "win", or "buf"
-/// - global_local: whether win or buf option has a global value
-///
-/// - commalist: List of comma separated values
-/// - flaglist: List of single char flags
-///
-///
-/// @param name Option name
-/// @param[out] err Error details, if any
-/// @return Option Information
-Dictionary nvim_get_option_info(String name, Error *err)
- FUNC_API_SINCE(7)
-{
- return get_vimoption(name, err);
-}
-
-/// Sets the global value of an option.
-///
-/// @param channel_id
-/// @param name Option name
-/// @param value New option value
-/// @param[out] err Error details, if any
-void nvim_set_option(uint64_t channel_id, String name, Object value, Error *err)
- FUNC_API_SINCE(1)
-{
- set_option_to(channel_id, NULL, SREQ_GLOBAL, name, value, err);
-}
-
/// Echo a message.
///
/// @param chunks A list of [text, hl_group] arrays, each representing a
@@ -1679,21 +1465,6 @@ void nvim_del_keymap(uint64_t channel_id, String mode, String lhs, Error *err)
nvim_buf_del_keymap(channel_id, -1, mode, lhs, err);
}
-/// Gets a map of global (non-buffer-local) Ex commands.
-///
-/// Currently only |user-commands| are supported, not builtin Ex commands.
-///
-/// @param opts Optional parameters. Currently only supports
-/// {"builtin":false}
-/// @param[out] err Error details, if any.
-///
-/// @returns Map of maps describing commands.
-Dictionary nvim_get_commands(Dict(get_commands) *opts, Error *err)
- FUNC_API_SINCE(4)
-{
- return nvim_buf_get_commands(-1, opts, err);
-}
-
/// Returns a 2-tuple (Array), where item 0 is the current channel id and item
/// 1 is the |api-metadata| map (Dictionary).
///
@@ -2483,58 +2254,3 @@ 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_create_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>|
-/// - fargs: (table) The args split by unescaped whitespace (when more than one
-/// argument is allowed), if any |<f-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>|
-/// - smods: (table) Command modifiers in a structured format. Has the same
-/// structure as the "mods" key of |nvim_parse_cmd()|.
-/// @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". 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-completion-customlist|. Additional parameters:
-/// - desc: (string) Used for listing the command when a Lua function is used for
-/// {command}.
-/// - force: (boolean, default true) Override any previous definition.
-/// - preview: (function) Preview callback for 'inccommand' |:command-preview|
-/// @param[out] err Error details, if any.
-void nvim_create_user_command(String name, Object command, Dict(user_command) *opts, Error *err)
- FUNC_API_SINCE(9)
-{
- create_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);
-}