aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/options.c
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2022-12-19 16:37:45 +0000
committerFamiu Haque <famiuhaque@proton.me>2023-05-21 15:14:01 +0600
commit1fe1bb084d0099fc4f9bfdc11189485d0f74b75a (patch)
treeec823587a4c7ea6991330f6db362846e0fb7bc21 /src/nvim/api/options.c
parente3e6fadfd82861471c32fdcabe00bbef3de84563 (diff)
downloadrneovim-1fe1bb084d0099fc4f9bfdc11189485d0f74b75a.tar.gz
rneovim-1fe1bb084d0099fc4f9bfdc11189485d0f74b75a.tar.bz2
rneovim-1fe1bb084d0099fc4f9bfdc11189485d0f74b75a.zip
refactor(options): deprecate nvim[_buf|_win]_[gs]et_option
Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: famiu <famiuhaque@protonmail.com>
Diffstat (limited to 'src/nvim/api/options.c')
-rw-r--r--src/nvim/api/options.c216
1 files changed, 2 insertions, 214 deletions
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index 2d1b170d2d..6193a5c75b 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -341,218 +341,6 @@ Dictionary nvim_get_option_info2(String name, Dict(option) *opts, Error *err)
return get_vimoption(name, scope, buf, win, 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);
-}
-
-/// 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, Arena *arena, Error *err)
- FUNC_API_SINCE(1)
-{
- return get_option_from(NULL, SREQ_GLOBAL, name, err);
-}
-
-/// Gets a buffer option value
-///
-/// @param buffer Buffer handle, or 0 for current buffer
-/// @param name Option name
-/// @param[out] err Error details, if any
-/// @return Option value
-Object nvim_buf_get_option(Buffer buffer, String name, Arena *arena, Error *err)
- FUNC_API_SINCE(1)
-{
- buf_T *buf = find_buffer_by_handle(buffer, err);
-
- if (!buf) {
- return (Object)OBJECT_INIT;
- }
-
- return get_option_from(buf, SREQ_BUF, name, err);
-}
-
-/// Sets a buffer option value. Passing `nil` as value deletes the option (only
-/// works if there's a global fallback)
-///
-/// @param channel_id
-/// @param buffer Buffer handle, or 0 for current buffer
-/// @param name Option name
-/// @param value Option value
-/// @param[out] err Error details, if any
-void nvim_buf_set_option(uint64_t channel_id, Buffer buffer, String name, Object value, Error *err)
- FUNC_API_SINCE(1)
-{
- buf_T *buf = find_buffer_by_handle(buffer, err);
-
- if (!buf) {
- return;
- }
-
- set_option_to(channel_id, buf, SREQ_BUF, name, value, err);
-}
-
-/// Gets a window option value
-///
-/// @param window Window handle, or 0 for current window
-/// @param name Option name
-/// @param[out] err Error details, if any
-/// @return Option value
-Object nvim_win_get_option(Window window, String name, Arena *arena, Error *err)
- FUNC_API_SINCE(1)
-{
- win_T *win = find_window_by_handle(window, err);
-
- if (!win) {
- return (Object)OBJECT_INIT;
- }
-
- return get_option_from(win, SREQ_WIN, name, err);
-}
-
-/// Sets a window option value. Passing `nil` as value deletes the option (only
-/// works if there's a global fallback)
-///
-/// @param channel_id
-/// @param window Window handle, or 0 for current window
-/// @param name Option name
-/// @param value Option value
-/// @param[out] err Error details, if any
-void nvim_win_set_option(uint64_t channel_id, Window window, String name, Object value, Error *err)
- FUNC_API_SINCE(1)
-{
- win_T *win = find_window_by_handle(window, err);
-
- if (!win) {
- return;
- }
-
- set_option_to(channel_id, win, SREQ_WIN, name, value, err);
-}
-
-/// Gets the value of a global or local (buffer, window) option.
-///
-/// @param from If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer
-/// to the window or buffer.
-/// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF`
-/// @param name The option name
-/// @param[out] err Details of an error that may have occurred
-/// @return the option value
-static Object get_option_from(void *from, int type, String name, Error *err)
-{
- Object rv = OBJECT_INIT;
-
- VALIDATE_S(name.size > 0, "option name", "<empty>", {
- return rv;
- });
-
- // Return values
- int64_t numval;
- char *stringval = NULL;
-
- int flags = get_option_value_strict(name.data, &numval, &stringval, type, from);
- VALIDATE_S(flags != 0, "option name", name.data, {
- return rv;
- });
-
- if (flags & SOPT_BOOL) {
- rv.type = kObjectTypeBoolean;
- rv.data.boolean = numval ? true : false;
- } else if (flags & SOPT_NUM) {
- rv.type = kObjectTypeInteger;
- rv.data.integer = numval;
- } else if (flags & SOPT_STRING) {
- if (!stringval) {
- api_set_error(err, kErrorTypeException, "Failed to get option '%s'", name.data);
- return rv;
- }
- rv.type = kObjectTypeString;
- rv.data.string.data = stringval;
- rv.data.string.size = strlen(stringval);
- } else {
- api_set_error(err, kErrorTypeException, "Unknown type for option '%s'", name.data);
- }
-
- return rv;
-}
-
-/// Sets the value of a global or local (buffer, window) option.
-///
-/// @param to If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer
-/// to the window or buffer.
-/// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF`
-/// @param name The option name
-/// @param[out] err Details of an error that may have occurred
-void set_option_to(uint64_t channel_id, void *to, int type, String name, Object value, Error *err)
-{
- VALIDATE_S(name.size > 0, "option name", "<empty>", {
- return;
- });
-
- int flags = get_option_value_strict(name.data, NULL, NULL, type, to);
- VALIDATE_S(flags != 0, "option name", name.data, {
- return;
- });
-
- if (value.type == kObjectTypeNil) {
- if (type == SREQ_GLOBAL) {
- api_set_error(err, kErrorTypeException, "Cannot unset option '%s'", name.data);
- return;
- } else if (!(flags & SOPT_GLOBAL)) {
- api_set_error(err, kErrorTypeException,
- "Cannot unset option '%s' because it doesn't have a global value",
- name.data);
- return;
- } else {
- unset_global_local_option(name.data, to);
- return;
- }
- }
-
- long numval = 0;
- char *stringval = NULL;
-
- if (flags & SOPT_BOOL) {
- VALIDATE(value.type == kObjectTypeBoolean, "Option '%s' value must be Boolean", name.data, {
- return;
- });
- numval = value.data.boolean;
- } else if (flags & SOPT_NUM) {
- VALIDATE(value.type == kObjectTypeInteger, "Option '%s' value must be Integer", name.data, {
- return;
- });
- VALIDATE((value.data.integer <= INT_MAX && value.data.integer >= INT_MIN),
- "Option '%s' value is out of range", name.data, {
- return;
- });
- numval = (int)value.data.integer;
- } else {
- VALIDATE(value.type == kObjectTypeString, "Option '%s' value must be String", name.data, {
- return;
- });
- stringval = value.data.string.data;
- }
-
- // For global-win-local options -> setlocal
- // For win-local options -> setglobal and setlocal (opt_flags == 0)
- const int opt_flags = (type == SREQ_WIN && !(flags & SOPT_GLOBAL)) ? 0 :
- (type == SREQ_GLOBAL) ? OPT_GLOBAL : OPT_LOCAL;
-
- WITH_SCRIPT_CONTEXT(channel_id, {
- access_option_value_for(name.data, &numval, &stringval, opt_flags, type, to, false, err);
- });
-}
-
static getoption_T access_option_value(char *key, long *numval, char **stringval, int opt_flags,
bool get, Error *err)
{
@@ -571,8 +359,8 @@ static getoption_T access_option_value(char *key, long *numval, char **stringval
}
}
-static getoption_T access_option_value_for(char *key, long *numval, char **stringval, int opt_flags,
- int opt_type, void *from, bool get, Error *err)
+getoption_T access_option_value_for(char *key, long *numval, char **stringval, int opt_flags,
+ int opt_type, void *from, bool get, Error *err)
{
bool need_switch = false;
switchwin_T switchwin;