aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@proton.me>2024-11-17 02:56:16 +0600
committerGitHub <noreply@github.com>2024-11-16 12:56:16 -0800
commit29ded889579a9d590e8ea885a9a402ff4bae87be (patch)
tree476bc3746cfac48f141e5ab0aaf562480502fad2
parentbe8648f345aed5e403251990721918c8302be760 (diff)
downloadrneovim-29ded889579a9d590e8ea885a9a402ff4bae87be.tar.gz
rneovim-29ded889579a9d590e8ea885a9a402ff4bae87be.tar.bz2
rneovim-29ded889579a9d590e8ea885a9a402ff4bae87be.zip
refactor(options): remove `.indir`, redesign option scopes #31066
Problem: The way option scopes currently work is inflexible and does not allow for nested option scopes or easily finding the value of an option at any arbitrary scope without having to do long handwritten switch-case statements like in `get_varp()`. `.indir` is also confusing and redundant since option indices for each scope can be autogenerated. Solution: Expand option scopes in such a way that an option can support any amount of scopes using a set of scope flags, similarly to how it's already done for option types. Also make options contain information about its index at each scope it supports. This allows for massively simplifying `get_varp()` and `get_varp_scope()` in the future by just using a struct for options at each scope. This would be done by creating a table that stores the offset of an option's variable at a scope by using the option's index at that scope as a key. This PR also autogenerates enums for option indices at each scope to remove the need for `.indir` entirely, and also to allow easily iterating over options all options that support any scope. Ref: #29314
-rwxr-xr-xscripts/gen_eval_files.lua10
-rw-r--r--src/nvim/CMakeLists.txt10
-rw-r--r--src/nvim/api/deprecated.c60
-rw-r--r--src/nvim/api/options.c42
-rw-r--r--src/nvim/api/vim.c8
-rw-r--r--src/nvim/buffer_defs.h4
-rw-r--r--src/nvim/diff.c4
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/file_search.c2
-rw-r--r--src/nvim/fold.c2
-rw-r--r--src/nvim/generators/gen_options.lua219
-rw-r--r--src/nvim/generators/gen_options_enum.lua129
-rw-r--r--src/nvim/indent.c2
-rw-r--r--src/nvim/option.c803
-rw-r--r--src/nvim/option.h57
-rw-r--r--src/nvim/option_defs.h41
-rw-r--r--src/nvim/options.lua287
-rw-r--r--src/nvim/textformat.c2
-rw-r--r--src/nvim/window.c4
-rw-r--r--src/nvim/winfloat.c4
20 files changed, 800 insertions, 892 deletions
diff --git a/scripts/gen_eval_files.lua b/scripts/gen_eval_files.lua
index edf95043c5..a9431ae2e5 100755
--- a/scripts/gen_eval_files.lua
+++ b/scripts/gen_eval_files.lua
@@ -617,8 +617,8 @@ local function render_option_meta(_f, opt, write)
end
for _, s in pairs {
- { 'wo', 'window' },
- { 'bo', 'buffer' },
+ { 'wo', 'win' },
+ { 'bo', 'buf' },
{ 'go', 'global' },
} do
local id, scope = s[1], s[2]
@@ -661,8 +661,8 @@ end
local function scope_to_doc(s)
local m = {
global = 'global',
- buffer = 'local to buffer',
- window = 'local to window',
+ buf = 'local to buffer',
+ win = 'local to window',
tab = 'local to tab page',
}
@@ -717,7 +717,7 @@ local function get_option_meta()
local optinfo = vim.api.nvim_get_all_options_info()
local ret = {} --- @type table<string,vim.option_meta>
for _, o in ipairs(opts) do
- local is_window_option = #o.scope == 1 and o.scope[1] == 'window'
+ local is_window_option = #o.scope == 1 and o.scope[1] == 'win'
local is_option_hidden = o.immutable and not o.varname and not is_window_option
if not is_option_hidden and o.desc then
if o.full_name == 'cmdheight' then
diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt
index cb71144130..344b4bef00 100644
--- a/src/nvim/CMakeLists.txt
+++ b/src/nvim/CMakeLists.txt
@@ -308,7 +308,6 @@ set(GENERATOR_C_GRAMMAR ${GENERATOR_DIR}/c_grammar.lua)
set(GENERATOR_HASHY ${GENERATOR_DIR}/hashy.lua)
set(GENERATOR_PRELOAD ${GENERATOR_DIR}/preload.lua)
set(HEADER_GENERATOR ${GENERATOR_DIR}/gen_declarations.lua)
-set(OPTIONS_ENUM_GENERATOR ${GENERATOR_DIR}/gen_options_enum.lua)
set(OPTIONS_GENERATOR ${GENERATOR_DIR}/gen_options.lua)
# GENERATED_DIR and GENERATED_INCLUDES_DIR
@@ -687,16 +686,11 @@ add_custom_command(OUTPUT ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
DEPENDS ${LUA_GEN_DEPS} ${EVENTS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/auevents.lua
)
-add_custom_command(OUTPUT ${GENERATED_OPTIONS}
- COMMAND ${LUA_GEN} ${OPTIONS_GENERATOR} ${GENERATED_OPTIONS}
+add_custom_command(OUTPUT ${GENERATED_OPTIONS} ${GENERATED_OPTIONS_ENUM} ${GENERATED_OPTIONS_MAP}
+ COMMAND ${LUA_GEN} ${OPTIONS_GENERATOR} ${GENERATED_OPTIONS} ${GENERATED_OPTIONS_ENUM} ${GENERATED_OPTIONS_MAP}
DEPENDS ${LUA_GEN_DEPS} ${OPTIONS_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/options.lua
)
-add_custom_command(OUTPUT ${GENERATED_OPTIONS_ENUM} ${GENERATED_OPTIONS_MAP}
- COMMAND ${LUA_GEN} ${OPTIONS_ENUM_GENERATOR} ${GENERATED_OPTIONS_ENUM} ${GENERATED_OPTIONS_MAP}
- DEPENDS ${LUA_GEN_DEPS} ${OPTIONS_ENUM_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/options.lua
-)
-
# NVIM_GENERATED_FOR_SOURCES and NVIM_GENERATED_FOR_HEADERS must be mutually exclusive.
foreach(hfile ${NVIM_GENERATED_FOR_HEADERS})
list(FIND NVIM_GENERATED_FOR_SOURCES ${hfile} hfile_idx)
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c
index b3ba832fec..b38a7d4173 100644
--- a/src/nvim/api/deprecated.c
+++ b/src/nvim/api/deprecated.c
@@ -533,7 +533,7 @@ void nvim_set_option(uint64_t channel_id, String name, Object value, Error *err)
FUNC_API_SINCE(1)
FUNC_API_DEPRECATED_SINCE(11)
{
- set_option_to(channel_id, NULL, kOptReqGlobal, name, value, err);
+ set_option_to(channel_id, NULL, kOptScopeGlobal, name, value, err);
}
/// Gets the global value of an option.
@@ -546,7 +546,7 @@ Object nvim_get_option(String name, Error *err)
FUNC_API_SINCE(1)
FUNC_API_DEPRECATED_SINCE(11)
{
- return get_option_from(NULL, kOptReqGlobal, name, err);
+ return get_option_from(NULL, kOptScopeGlobal, name, err);
}
/// Gets a buffer option value
@@ -566,7 +566,7 @@ Object nvim_buf_get_option(Buffer buffer, String name, Error *err)
return (Object)OBJECT_INIT;
}
- return get_option_from(buf, kOptReqBuf, name, err);
+ return get_option_from(buf, kOptScopeBuf, name, err);
}
/// Sets a buffer option value. Passing `nil` as value deletes the option (only
@@ -588,7 +588,7 @@ void nvim_buf_set_option(uint64_t channel_id, Buffer buffer, String name, Object
return;
}
- set_option_to(channel_id, buf, kOptReqBuf, name, value, err);
+ set_option_to(channel_id, buf, kOptScopeBuf, name, value, err);
}
/// Gets a window option value
@@ -608,7 +608,7 @@ Object nvim_win_get_option(Window window, String name, Error *err)
return (Object)OBJECT_INIT;
}
- return get_option_from(win, kOptReqWin, name, err);
+ return get_option_from(win, kOptScopeWin, name, err);
}
/// Sets a window option value. Passing `nil` as value deletes the option (only
@@ -630,48 +630,18 @@ void nvim_win_set_option(uint64_t channel_id, Window window, String name, Object
return;
}
- set_option_to(channel_id, win, kOptReqWin, name, value, err);
-}
-
-/// Check if option has a value in the requested scope.
-///
-/// @param opt_idx Option index in options[] table.
-/// @param req_scope Requested option scope. See OptReqScope in option.h.
-///
-/// @return true if option has a value in the requested scope, false otherwise.
-static bool option_has_scope(OptIndex opt_idx, OptReqScope req_scope)
-{
- if (opt_idx == kOptInvalid) {
- return false;
- }
-
- vimoption_T *opt = get_option(opt_idx);
-
- // TTY option.
- if (is_tty_option(opt->fullname)) {
- return req_scope == kOptReqGlobal;
- }
-
- switch (req_scope) {
- case kOptReqGlobal:
- return opt->var != VAR_WIN;
- case kOptReqBuf:
- return opt->indir & PV_BUF;
- case kOptReqWin:
- return opt->indir & PV_WIN;
- }
- UNREACHABLE;
+ set_option_to(channel_id, win, kOptScopeWin, name, value, err);
}
/// Gets the value of a global or local (buffer, window) option.
///
/// @param[in] from Pointer to buffer or window for local option value.
-/// @param req_scope Requested option scope. See OptReqScope in option.h.
+/// @param req_scope Requested option scope. See OptScope in option.h.
/// @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, OptReqScope req_scope, String name, Error *err)
+static Object get_option_from(void *from, OptScope req_scope, String name, Error *err)
{
VALIDATE_S(name.size > 0, "option name", "<empty>", {
return (Object)OBJECT_INIT;
@@ -681,7 +651,7 @@ static Object get_option_from(void *from, OptReqScope req_scope, String name, Er
OptVal value = NIL_OPTVAL;
if (option_has_scope(opt_idx, req_scope)) {
- value = get_option_value_for(opt_idx, req_scope == kOptReqGlobal ? OPT_GLOBAL : OPT_LOCAL,
+ value = get_option_value_for(opt_idx, req_scope == kOptScopeGlobal ? OPT_GLOBAL : OPT_LOCAL,
req_scope, from, err);
if (ERROR_SET(err)) {
return (Object)OBJECT_INIT;
@@ -698,11 +668,11 @@ static Object get_option_from(void *from, OptReqScope req_scope, String name, Er
/// Sets the value of a global or local (buffer, window) option.
///
/// @param[in] to Pointer to buffer or window for local option value.
-/// @param req_scope Requested option scope. See OptReqScope in option.h.
+/// @param req_scope Requested option scope. See OptScope in option.h.
/// @param name The option name.
/// @param value New option value.
/// @param[out] err Details of an error that may have occurred.
-static void set_option_to(uint64_t channel_id, void *to, OptReqScope req_scope, String name,
+static void set_option_to(uint64_t channel_id, void *to, OptScope req_scope, String name,
Object value, Error *err)
{
VALIDATE_S(name.size > 0, "option name", "<empty>", {
@@ -725,12 +695,12 @@ static void set_option_to(uint64_t channel_id, void *to, OptReqScope req_scope,
return;
});
- int attrs = get_option_attrs(opt_idx);
// For global-win-local options -> setlocal
// For win-local options -> setglobal and setlocal (opt_flags == 0)
- const int opt_flags = (req_scope == kOptReqWin && !(attrs & SOPT_GLOBAL))
- ? 0
- : (req_scope == kOptReqGlobal) ? OPT_GLOBAL : OPT_LOCAL;
+ const int opt_flags
+ = (req_scope == kOptScopeWin && !option_has_scope(opt_idx, kOptScopeGlobal))
+ ? 0
+ : ((req_scope == kOptScopeGlobal) ? OPT_GLOBAL : OPT_LOCAL);
WITH_SCRIPT_CONTEXT(channel_id, {
set_option_value_for(name.data, opt_idx, optval, opt_flags, req_scope, to, err);
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index 96866d80ba..bbfd00f2ea 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -23,8 +23,8 @@
#endif
static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex *opt_idxp,
- int *scope, OptReqScope *req_scope, void **from,
- char **filetype, Error *err)
+ int *scope, OptScope *req_scope, void **from, char **filetype,
+ Error *err)
{
#define HAS_KEY_X(d, v) HAS_KEY(d, option, v)
if (HAS_KEY_X(opts, scope)) {
@@ -39,14 +39,14 @@ static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex *
}
}
- *req_scope = kOptReqGlobal;
+ *req_scope = kOptScopeGlobal;
if (filetype != NULL && HAS_KEY_X(opts, filetype)) {
*filetype = opts->filetype.data;
}
if (HAS_KEY_X(opts, win)) {
- *req_scope = kOptReqWin;
+ *req_scope = kOptScopeWin;
*from = find_window_by_handle(opts->win, err);
if (ERROR_SET(err)) {
return FAIL;
@@ -59,7 +59,7 @@ static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex *
return FAIL;
});
*scope = OPT_LOCAL;
- *req_scope = kOptReqBuf;
+ *req_scope = kOptScopeBuf;
*from = find_buffer_by_handle(opts->buf, err);
if (ERROR_SET(err)) {
return FAIL;
@@ -78,18 +78,17 @@ static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex *
});
*opt_idxp = find_option(name);
- int flags = get_option_attrs(*opt_idxp);
- if (flags == 0) {
+ if (*opt_idxp == kOptInvalid) {
// unknown option
api_set_error(err, kErrorTypeValidation, "Unknown option '%s'", name);
- } else if (*req_scope == kOptReqBuf || *req_scope == kOptReqWin) {
+ } else if (*req_scope == kOptScopeBuf || *req_scope == kOptScopeWin) {
// if 'buf' or 'win' is passed, make sure the option supports it
- int req_flags = *req_scope == kOptReqBuf ? SOPT_BUF : SOPT_WIN;
- if (!(flags & req_flags)) {
- char *tgt = *req_scope & kOptReqBuf ? "buf" : "win";
- char *global = flags & SOPT_GLOBAL ? "global " : "";
- char *req = flags & SOPT_BUF ? "buffer-local "
- : flags & SOPT_WIN ? "window-local " : "";
+ if (!option_has_scope(*opt_idxp, *req_scope)) {
+ char *tgt = *req_scope == kOptScopeBuf ? "buf" : "win";
+ char *global = option_has_scope(*opt_idxp, kOptScopeGlobal) ? "global " : "";
+ char *req = option_has_scope(*opt_idxp, kOptScopeBuf)
+ ? "buffer-local "
+ : (option_has_scope(*opt_idxp, kOptScopeWin) ? "window-local " : "");
api_set_error(err, kErrorTypeValidation, "'%s' cannot be passed for %s%soption '%s'",
tgt, global, req, name);
@@ -153,7 +152,7 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err)
{
OptIndex opt_idx = 0;
int scope = 0;
- OptReqScope req_scope = kOptReqGlobal;
+ OptScope req_scope = kOptScopeGlobal;
void *from = NULL;
char *filetype = NULL;
@@ -218,7 +217,7 @@ void nvim_set_option_value(uint64_t channel_id, String name, Object value, Dict(
{
OptIndex opt_idx = 0;
int scope = 0;
- OptReqScope req_scope = kOptReqGlobal;
+ OptScope req_scope = kOptScopeGlobal;
void *to = NULL;
if (!validate_option_value_args(opts, name.data, &opt_idx, &scope, &req_scope, &to, NULL, err)) {
return;
@@ -230,9 +229,8 @@ void nvim_set_option_value(uint64_t channel_id, String name, Object value, Dict(
// - option is global or local to window (global-local)
//
// Then force scope to local since we don't want to change the global option
- if (req_scope == kOptReqWin && scope == 0) {
- int flags = get_option_attrs(opt_idx);
- if (flags & SOPT_GLOBAL) {
+ if (req_scope == kOptScopeWin && scope == 0) {
+ if (option_has_scope(opt_idx, kOptScopeGlobal)) {
scope = OPT_LOCAL;
}
}
@@ -305,15 +303,15 @@ Dict nvim_get_option_info2(String name, Dict(option) *opts, Arena *arena, Error
{
OptIndex opt_idx = 0;
int scope = 0;
- OptReqScope req_scope = kOptReqGlobal;
+ OptScope req_scope = kOptScopeGlobal;
void *from = NULL;
if (!validate_option_value_args(opts, name.data, &opt_idx, &scope, &req_scope, &from, NULL,
err)) {
return (Dict)ARRAY_DICT_INIT;
}
- buf_T *buf = (req_scope == kOptReqBuf) ? (buf_T *)from : curbuf;
- win_T *win = (req_scope == kOptReqWin) ? (win_T *)from : curwin;
+ buf_T *buf = (req_scope == kOptScopeBuf) ? (buf_T *)from : curbuf;
+ win_T *win = (req_scope == kOptScopeWin) ? (win_T *)from : curwin;
return get_vimoption(name, scope, buf, win, arena, err);
}
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index e6ec88c5e8..199b9a9690 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -1004,10 +1004,10 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err)
buf_copy_options(buf, BCO_ENTER | BCO_NOHELP);
if (scratch) {
- set_option_direct_for(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("hide"), OPT_LOCAL, 0, kOptReqBuf,
- buf);
- set_option_direct_for(kOptBuftype, STATIC_CSTR_AS_OPTVAL("nofile"), OPT_LOCAL, 0, kOptReqBuf,
- buf);
+ set_option_direct_for(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("hide"), OPT_LOCAL, 0,
+ kOptScopeBuf, buf);
+ set_option_direct_for(kOptBuftype, STATIC_CSTR_AS_OPTVAL("nofile"), OPT_LOCAL, 0,
+ kOptScopeBuf, buf);
assert(buf->b_ml.ml_mfp->mf_fd < 0); // ml_open() should not have opened swapfile already
buf->b_p_swf = false;
buf->b_p_ml = false;
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index e6bd63f4f8..d33734ccfe 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -206,7 +206,7 @@ typedef struct {
OptInt wo_winbl;
#define w_p_winbl w_onebuf_opt.wo_winbl // 'winblend'
- LastSet wo_script_ctx[WV_COUNT]; // SCTXs for window-local options
+ LastSet wo_script_ctx[kWinOptCount]; // SCTXs for window-local options
#define w_p_script_ctx w_onebuf_opt.wo_script_ctx
} winopt_T;
@@ -512,7 +512,7 @@ struct file_buffer {
// or contents of the file being edited.
bool b_p_initialized; // set when options initialized
- LastSet b_p_script_ctx[BV_COUNT]; // SCTXs for buffer-local options
+ LastSet b_p_script_ctx[kBufOptCount]; // SCTXs for buffer-local options
int b_p_ai; ///< 'autoindent'
int b_p_ai_nopaste; ///< b_p_ai saved for paste mode
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index a690c70875..f1dd08f0e6 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -1390,8 +1390,8 @@ void diff_win_options(win_T *wp, bool addbuf)
}
wp->w_p_fdm_save = xstrdup(wp->w_p_fdm);
}
- set_option_direct_for(kOptFoldmethod, STATIC_CSTR_AS_OPTVAL("diff"), OPT_LOCAL, 0, kOptReqWin,
- wp);
+ set_option_direct_for(kOptFoldmethod, STATIC_CSTR_AS_OPTVAL("diff"), OPT_LOCAL, 0,
+ kOptScopeWin, wp);
if (!wp->w_p_diff) {
wp->w_p_fen_save = wp->w_p_fen;
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 9acbc05fdf..ab6115f145 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -1368,7 +1368,7 @@ int eval_foldexpr(win_T *wp, int *cp)
const bool use_sandbox = was_set_insecurely(wp, kOptFoldexpr, OPT_LOCAL);
char *arg = skipwhite(wp->w_p_fde);
- current_sctx = wp->w_p_script_ctx[WV_FDE].script_ctx;
+ current_sctx = wp->w_p_script_ctx[kWinOptFoldexpr].script_ctx;
emsg_off++;
if (use_sandbox) {
diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c
index aeaf448a05..d183978d2d 100644
--- a/src/nvim/file_search.c
+++ b/src/nvim/file_search.c
@@ -1648,7 +1648,7 @@ static char *eval_includeexpr(const char *const ptr, const size_t len)
{
const sctx_T save_sctx = current_sctx;
set_vim_var_string(VV_FNAME, ptr, (ptrdiff_t)len);
- current_sctx = curbuf->b_p_script_ctx[BV_INEX].script_ctx;
+ current_sctx = curbuf->b_p_script_ctx[kBufOptIncludeexpr].script_ctx;
char *res = eval_to_string_safe(curbuf->b_p_inex,
was_set_insecurely(curwin, kOptIncludeexpr, OPT_LOCAL),
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index e7231c31ab..c9699cb161 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -1731,7 +1731,7 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo
curwin = wp;
curbuf = wp->w_buffer;
- current_sctx = wp->w_p_script_ctx[WV_FDT].script_ctx;
+ current_sctx = wp->w_p_script_ctx[kWinOptFoldtext].script_ctx;
emsg_off++; // handle exceptions, but don't display errors
diff --git a/src/nvim/generators/gen_options.lua b/src/nvim/generators/gen_options.lua
index 92349b5298..02f3ac3257 100644
--- a/src/nvim/generators/gen_options.lua
+++ b/src/nvim/generators/gen_options.lua
@@ -1,6 +1,10 @@
local options_file = arg[1]
+local options_enum_file = arg[2]
+local options_map_file = arg[3]
local opt_fd = assert(io.open(options_file, 'w'))
+local opt_enum_fd = assert(io.open(options_enum_file, 'w'))
+local opt_map_fd = assert(io.open(options_map_file, 'w'))
local w = function(s)
if s:match('^ %.') then
@@ -10,10 +14,129 @@ local w = function(s)
end
end
+--- @param s string
+local function enum_w(s)
+ opt_enum_fd:write(s .. '\n')
+end
+
+--- @param s string
+local function map_w(s)
+ opt_map_fd:write(s .. '\n')
+end
+
--- @module 'nvim.options'
local options = require('options')
+local options_meta = options.options
local cstr = options.cstr
+local valid_scopes = options.valid_scopes
+
+--- Options for each scope.
+--- @type table<string, vim.option_meta[]>
+local scope_options = {}
+for _, scope in ipairs(valid_scopes) do
+ scope_options[scope] = {}
+end
+
+--- @param s string
+--- @return string
+local lowercase_to_titlecase = function(s)
+ return s:sub(1, 1):upper() .. s:sub(2)
+end
+
+-- Generate options enum file
+enum_w('// IWYU pragma: private, include "nvim/option_defs.h"')
+enum_w('')
+
+--- Map of option name to option index
+--- @type table<string, string>
+local option_index = {}
+
+-- Generate option index enum and populate the `option_index` and `scope_option` dicts.
+enum_w('typedef enum {')
+enum_w(' kOptInvalid = -1,')
+
+for i, o in ipairs(options_meta) do
+ local enum_val_name = 'kOpt' .. lowercase_to_titlecase(o.full_name)
+ enum_w((' %s = %u,'):format(enum_val_name, i - 1))
+
+ option_index[o.full_name] = enum_val_name
+
+ if o.abbreviation then
+ option_index[o.abbreviation] = enum_val_name
+ end
+
+ if o.alias then
+ o.alias = type(o.alias) == 'string' and { o.alias } or o.alias
+
+ for _, v in ipairs(o.alias) do
+ option_index[v] = enum_val_name
+ end
+ end
+
+ for _, scope in ipairs(o.scope) do
+ table.insert(scope_options[scope], o)
+ end
+end
+
+enum_w(' // Option count')
+enum_w('#define kOptCount ' .. tostring(#options_meta))
+enum_w('} OptIndex;')
+
+--- @param scope string
+--- @param option_name string
+--- @return string
+local get_scope_option = function(scope, option_name)
+ return ('k%sOpt%s'):format(lowercase_to_titlecase(scope), lowercase_to_titlecase(option_name))
+end
+
+-- Generate option index enum for each scope
+for _, scope in ipairs(valid_scopes) do
+ enum_w('')
+
+ local scope_name = lowercase_to_titlecase(scope)
+ enum_w('typedef enum {')
+ enum_w((' %s = -1,'):format(get_scope_option(scope, 'Invalid')))
+
+ for idx, option in ipairs(scope_options[scope]) do
+ enum_w((' %s = %u,'):format(get_scope_option(scope, option.full_name), idx - 1))
+ end
+
+ enum_w((' // %s option count'):format(scope_name))
+ enum_w(('#define %s %d'):format(get_scope_option(scope, 'Count'), #scope_options[scope]))
+ enum_w(('} %sOptIndex;'):format(scope_name))
+end
+
+-- Generate reverse lookup from option scope index to option index for each scope.
+for _, scope in ipairs(valid_scopes) do
+ enum_w('')
+ enum_w(('EXTERN const OptIndex %s_opt_idx[] INIT( = {'):format(scope))
+ for _, option in ipairs(scope_options[scope]) do
+ local idx = option_index[option.full_name]
+ enum_w((' [%s] = %s,'):format(get_scope_option(scope, option.full_name), idx))
+ end
+ enum_w('});')
+end
+
+opt_enum_fd:close()
+
+-- Generate option index map.
+local hashy = require('generators.hashy')
+local neworder, hashfun = hashy.hashy_hash('find_option', vim.tbl_keys(option_index), function(idx)
+ return ('option_hash_elems[%s].name'):format(idx)
+end)
+
+map_w('static const struct { const char *name; OptIndex opt_idx; } option_hash_elems[] = {')
+
+for _, name in ipairs(neworder) do
+ assert(option_index[name] ~= nil)
+ map_w((' { .name = "%s", .opt_idx = %s },'):format(name, option_index[name]))
+end
+
+map_w('};\n')
+map_w('static ' .. hashfun)
+
+opt_map_fd:close()
local redraw_flags = {
ui_option = 'kOptFlagUIOption',
@@ -35,12 +158,6 @@ local list_flags = {
flagscomma = 'kOptFlagComma|kOptFlagFlagList',
}
---- @param s string
---- @return string
-local lowercase_to_titlecase = function(s)
- return s:sub(1, 1):upper() .. s:sub(2)
-end
-
--- @param o vim.option_meta
--- @return string
local function get_flags(o)
@@ -95,6 +212,12 @@ local function opt_type_enum(opt_type)
return ('kOptValType%s'):format(lowercase_to_titlecase(opt_type))
end
+--- @param scope vim.option_scope
+--- @return string
+local function opt_scope_enum(scope)
+ return ('kOptScope%s'):format(lowercase_to_titlecase(scope))
+end
+
--- @param o vim.option_meta
--- @return string
local function get_type_flags(o)
@@ -110,6 +233,35 @@ local function get_type_flags(o)
return type_flags
end
+--- @param o vim.option_meta
+--- @return string
+local function get_scope_flags(o)
+ local scope_flags = '0'
+
+ for _, scope in ipairs(o.scope) do
+ scope_flags = ('%s | (1 << %s)'):format(scope_flags, opt_scope_enum(scope))
+ end
+
+ return scope_flags
+end
+
+--- @param o vim.option_meta
+--- @return string
+local function get_scope_idx(o)
+ --- @type string[]
+ local strs = {}
+
+ for _, scope in pairs(valid_scopes) do
+ local has_scope = vim.tbl_contains(o.scope, scope)
+ strs[#strs + 1] = (' [%s] = %s'):format(
+ opt_scope_enum(scope),
+ get_scope_option(scope, has_scope and o.full_name or 'Invalid')
+ )
+ end
+
+ return ('{\n%s\n }'):format(table.concat(strs, ',\n'))
+end
+
--- @param c string|string[]
--- @param base_string? string
--- @return string
@@ -166,7 +318,6 @@ end
--- @param d vim.option_value|function
--- @param n string
--- @return string
-
local get_defaults = function(d, n)
if d == nil then
error("option '" .. n .. "' should have a default value")
@@ -174,9 +325,6 @@ local get_defaults = function(d, n)
return get_opt_val(d)
end
---- @type [string,string][]
-local defines = {}
-
--- @param i integer
--- @param o vim.option_meta
local function dump_option(i, o)
@@ -187,42 +335,28 @@ local function dump_option(i, o)
end
w(' .flags=' .. get_flags(o))
w(' .type_flags=' .. get_type_flags(o))
+ w(' .scope_flags=' .. get_scope_flags(o))
+ w(' .scope_idx=' .. get_scope_idx(o))
if o.enable_if then
w(get_cond(o.enable_if))
end
- if o.varname then
- w(' .var=&' .. o.varname)
- elseif o.immutable then
- -- Immutable options can directly point to the default value.
- w((' .var=&options[%u].def_val.data'):format(i - 1))
- elseif #o.scope == 1 and o.scope[1] == 'window' then
- w(' .var=VAR_WIN')
+ local is_window_local = #o.scope == 1 and o.scope[1] == 'win'
+
+ if not is_window_local then
+ if o.varname then
+ w(' .var=&' .. o.varname)
+ elseif o.immutable then
+ -- Immutable options can directly point to the default value.
+ w((' .var=&options[%u].def_val.data'):format(i - 1))
+ else
+ -- Option must be immutable or have a variable.
+ assert(false)
+ end
else
- -- Option must be immutable or have a variable.
- assert(false)
+ w(' .var=NULL')
end
w(' .immutable=' .. (o.immutable and 'true' or 'false'))
- if #o.scope == 1 and o.scope[1] == 'global' then
- w(' .indir=PV_NONE')
- else
- assert(#o.scope == 1 or #o.scope == 2)
- assert(#o.scope == 1 or o.scope[1] == 'global')
- local min_scope = o.scope[#o.scope]
- local varname = o.pv_name or o.varname or ('p_' .. (o.abbreviation or o.full_name))
- local pv_name = (
- 'OPT_'
- .. min_scope:sub(1, 3):upper()
- .. '('
- .. (min_scope:sub(1, 1):upper() .. 'V_' .. varname:sub(3):upper())
- .. ')'
- )
- if #o.scope == 2 then
- pv_name = 'OPT_BOTH(' .. pv_name .. ')'
- end
- table.insert(defines, { 'PV_' .. varname:sub(3):upper(), pv_name })
- w(' .indir=' .. pv_name)
- end
if o.cb then
w(' .opt_did_set_cb=' .. o.cb)
end
@@ -235,7 +369,6 @@ local function dump_option(i, o)
w((' .var=&options[%u].def_val.data'):format(i - 1))
-- Option is always immutable on the false branch of `enable_if`.
w(' .immutable=true')
- w(' .indir=PV_NONE')
w('#endif')
end
if o.defaults then
@@ -256,6 +389,7 @@ local function dump_option(i, o)
w(' },')
end
+-- Generate options[] array.
w([[
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h"
@@ -274,8 +408,3 @@ for i, o in ipairs(options.options) do
dump_option(i, o)
end
w('};')
-w('')
-
-for _, v in ipairs(defines) do
- w('#define ' .. v[1] .. ' ' .. v[2])
-end
diff --git a/src/nvim/generators/gen_options_enum.lua b/src/nvim/generators/gen_options_enum.lua
deleted file mode 100644
index d1419137d3..0000000000
--- a/src/nvim/generators/gen_options_enum.lua
+++ /dev/null
@@ -1,129 +0,0 @@
--- Generates option index enum and map of option name to option index.
--- Handles option full name, short name and aliases.
--- Also generates BV_ and WV_ enum constants.
-
-local options_enum_file = arg[1]
-local options_map_file = arg[2]
-local options_enum_fd = assert(io.open(options_enum_file, 'w'))
-local options_map_fd = assert(io.open(options_map_file, 'w'))
-
---- @param s string
-local function enum_w(s)
- options_enum_fd:write(s .. '\n')
-end
-
---- @param s string
-local function map_w(s)
- options_map_fd:write(s .. '\n')
-end
-
-enum_w('// IWYU pragma: private, include "nvim/option_defs.h"')
-enum_w('')
-
---- @param s string
---- @return string
-local lowercase_to_titlecase = function(s)
- return s:sub(1, 1):upper() .. s:sub(2)
-end
-
---- @type vim.option_meta[]
-local options = require('options').options
-
--- Generate BV_ enum constants.
-enum_w('/// "indir" values for buffer-local options.')
-enum_w('/// These need to be defined globally, so that the BV_COUNT can be used with')
-enum_w('/// b_p_script_stx[].')
-enum_w('enum {')
-
-local bv_val = 0
-
-for _, o in ipairs(options) do
- assert(#o.scope == 1 or #o.scope == 2)
- assert(#o.scope == 1 or o.scope[1] == 'global')
- local min_scope = o.scope[#o.scope]
- if min_scope == 'buffer' then
- local varname = o.pv_name or o.varname or ('p_' .. (o.abbreviation or o.full_name))
- local bv_name = 'BV_' .. varname:sub(3):upper()
- enum_w((' %s = %u,'):format(bv_name, bv_val))
- bv_val = bv_val + 1
- end
-end
-
-enum_w((' BV_COUNT = %u, ///< must be the last one'):format(bv_val))
-enum_w('};')
-enum_w('')
-
--- Generate WV_ enum constants.
-enum_w('/// "indir" values for window-local options.')
-enum_w('/// These need to be defined globally, so that the WV_COUNT can be used in the')
-enum_w('/// window structure.')
-enum_w('enum {')
-
-local wv_val = 0
-
-for _, o in ipairs(options) do
- assert(#o.scope == 1 or #o.scope == 2)
- assert(#o.scope == 1 or o.scope[1] == 'global')
- local min_scope = o.scope[#o.scope]
- if min_scope == 'window' then
- local varname = o.pv_name or o.varname or ('p_' .. (o.abbreviation or o.full_name))
- local wv_name = 'WV_' .. varname:sub(3):upper()
- enum_w((' %s = %u,'):format(wv_name, wv_val))
- wv_val = wv_val + 1
- end
-end
-
-enum_w((' WV_COUNT = %u, ///< must be the last one'):format(wv_val))
-enum_w('};')
-enum_w('')
-
---- @type { [string]: string }
-local option_index = {}
-
--- Generate option index enum and populate the `option_index` dict.
-enum_w('typedef enum {')
-enum_w(' kOptInvalid = -1,')
-
-for i, o in ipairs(options) do
- local enum_val_name = 'kOpt' .. lowercase_to_titlecase(o.full_name)
- enum_w((' %s = %u,'):format(enum_val_name, i - 1))
-
- option_index[o.full_name] = enum_val_name
-
- if o.abbreviation then
- option_index[o.abbreviation] = enum_val_name
- end
-
- if o.alias then
- o.alias = type(o.alias) == 'string' and { o.alias } or o.alias
-
- for _, v in ipairs(o.alias) do
- option_index[v] = enum_val_name
- end
- end
-end
-
-enum_w(' // Option count, used when iterating through options')
-enum_w('#define kOptIndexCount ' .. tostring(#options))
-enum_w('} OptIndex;')
-enum_w('')
-
-options_enum_fd:close()
-
---- Generate option index map.
-local hashy = require('generators.hashy')
-local neworder, hashfun = hashy.hashy_hash('find_option', vim.tbl_keys(option_index), function(idx)
- return ('option_hash_elems[%s].name'):format(idx)
-end)
-
-map_w('static const struct { const char *name; OptIndex opt_idx; } option_hash_elems[] = {')
-
-for _, name in ipairs(neworder) do
- assert(option_index[name] ~= nil)
- map_w((' { .name = "%s", .opt_idx = %s },'):format(name, option_index[name]))
-end
-
-map_w('};\n')
-map_w('static ' .. hashfun)
-
-options_map_fd:close()
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index 58215f738c..e487728901 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -1182,7 +1182,7 @@ int get_expr_indent(void)
sandbox++;
}
textlock++;
- current_sctx = curbuf->b_p_script_ctx[BV_INDE].script_ctx;
+ current_sctx = curbuf->b_p_script_ctx[kBufOptIndentexpr].script_ctx;
// Need to make a copy, the 'indentexpr' option could be changed while
// evaluating it.
diff --git a/src/nvim/option.c b/src/nvim/option.c
index efd52f9233..8e94c342f7 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -303,7 +303,7 @@ static void set_init_default_cdpath(void)
/// them.
static void set_init_expand_env(void)
{
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
vimoption_T *opt = &options[opt_idx];
if (opt->flags & kOptFlagNoDefExp) {
continue;
@@ -435,7 +435,7 @@ void set_init_1(bool clean_arg)
static OptVal get_option_default(const OptIndex opt_idx, int opt_flags)
{
vimoption_T *opt = &options[opt_idx];
- bool is_global_local_option = opt->indir & PV_BOTH;
+ bool is_global_local_option = option_is_global_local(opt_idx);
#ifdef UNIX
if (opt_idx == kOptModeline && getuid() == ROOT_UID) {
@@ -461,7 +461,7 @@ static OptVal get_option_default(const OptIndex opt_idx, int opt_flags)
/// This ensures that we don't need to always check if the option default is allocated or not.
static void alloc_options_default(void)
{
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
options[opt_idx].def_val = optval_copy(options[opt_idx].def_val);
}
}
@@ -500,7 +500,7 @@ static void set_option_default(const OptIndex opt_idx, int opt_flags)
/// @param opt_flags Option flags.
static void set_options_default(int opt_flags)
{
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
if (!(options[opt_idx].flags & kOptFlagNoDefault)) {
set_option_default(opt_idx, opt_flags);
}
@@ -564,16 +564,16 @@ static char *find_dup_item(char *origval, const char *newval, const size_t newva
/// Free all options.
void free_all_options(void)
{
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
bool hidden = is_option_hidden(opt_idx);
- if (options[opt_idx].indir == PV_NONE || hidden) {
+ if (option_is_global_only(opt_idx) || hidden) {
// global option: free value and default value.
// hidden option: free default value only.
if (!hidden) {
optval_free(optval_from_varp(opt_idx, options[opt_idx].var));
}
- } else if (options[opt_idx].var != VAR_WIN) {
+ } else if (!option_is_window_local(opt_idx)) {
// buffer-local option: free global value.
optval_free(optval_from_varp(opt_idx, options[opt_idx].var));
}
@@ -977,12 +977,12 @@ static int validate_opt_idx(win_T *win, OptIndex opt_idx, int opt_flags, uint32_
// Skip all options that are not window-local (used when showing
// an already loaded buffer in a window).
- if ((opt_flags & OPT_WINONLY) && (opt_idx == kOptInvalid || options[opt_idx].var != VAR_WIN)) {
+ if ((opt_flags & OPT_WINONLY) && (opt_idx == kOptInvalid || !option_is_window_local(opt_idx))) {
return FAIL;
}
// Skip all options that are window-local (used for :vimgrep).
- if ((opt_flags & OPT_NOWIN) && opt_idx != kOptInvalid && options[opt_idx].var == VAR_WIN) {
+ if ((opt_flags & OPT_NOWIN) && opt_idx != kOptInvalid && option_is_window_local(opt_idx)) {
return FAIL;
}
@@ -999,10 +999,7 @@ static int validate_opt_idx(win_T *win, OptIndex opt_idx, int opt_flags, uint32_
// In diff mode some options are overruled. This avoids that
// 'foldmethod' becomes "marker" instead of "diff" and that
// "wrap" gets set.
- if (win->w_p_diff
- && opt_idx != kOptInvalid // shut up coverity warning
- && (options[opt_idx].indir == PV_FDM
- || options[opt_idx].indir == PV_WRAP)) {
+ if (win->w_p_diff && (opt_idx == kOptFoldmethod || opt_idx == kOptWrap)) {
return FAIL;
}
}
@@ -1099,7 +1096,7 @@ static OptVal get_option_newval(OptIndex opt_idx, int opt_flags, set_prefix_T pr
vimoption_T *opt = &options[opt_idx];
char *arg = *argp;
// When setting the local value of a global option, the old value may be the global value.
- const bool oldval_is_global = ((int)opt->indir & PV_BOTH) && (opt_flags & OPT_LOCAL);
+ const bool oldval_is_global = option_is_global_local(opt_idx) && (opt_flags & OPT_LOCAL);
OptVal oldval = optval_from_varp(opt_idx, oldval_is_global ? get_varp(opt) : varp);
OptVal newval = NIL_OPTVAL;
@@ -1285,10 +1282,10 @@ static void do_one_set_option(int opt_flags, char **argp, bool *did_show, char *
// Mention where the option was last set.
if (varp == options[opt_idx].var) {
option_last_set_msg(options[opt_idx].last_set);
- } else if ((int)options[opt_idx].indir & PV_WIN) {
- option_last_set_msg(curwin->w_p_script_ctx[(int)options[opt_idx].indir & PV_MASK]);
- } else if ((int)options[opt_idx].indir & PV_BUF) {
- option_last_set_msg(curbuf->b_p_script_ctx[(int)options[opt_idx].indir & PV_MASK]);
+ } else if (option_has_scope(opt_idx, kOptScopeWin)) {
+ option_last_set_msg(curwin->w_p_script_ctx[option_scope_idx(opt_idx, kOptScopeWin)]);
+ } else if (option_has_scope(opt_idx, kOptScopeBuf)) {
+ option_last_set_msg(curbuf->b_p_script_ctx[option_scope_idx(opt_idx, kOptScopeBuf)]);
}
}
@@ -1643,7 +1640,7 @@ static void didset_options2(void)
/// Check for string options that are NULL (normally only termcap options).
void check_options(void)
{
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
if ((option_has_type(opt_idx, kOptValTypeString)) && options[opt_idx].var != NULL) {
check_string_option((char **)get_varp(&(options[opt_idx])));
}
@@ -1673,24 +1670,25 @@ uint32_t *insecure_flag(win_T *const wp, OptIndex opt_idx, int opt_flags)
{
if (opt_flags & OPT_LOCAL) {
assert(wp != NULL);
- switch ((int)options[opt_idx].indir) {
- case PV_STL:
+ switch (opt_idx) {
+ case kOptStatusline:
return &wp->w_p_stl_flags;
- case PV_WBR:
+ case kOptWinbar:
return &wp->w_p_wbr_flags;
- case PV_FDE:
+ case kOptFoldexpr:
return &wp->w_p_fde_flags;
- case PV_FDT:
+ case kOptFoldtext:
return &wp->w_p_fdt_flags;
- case PV_INDE:
+ case kOptIndentexpr:
return &wp->w_buffer->b_p_inde_flags;
- case PV_FEX:
+ case kOptFormatexpr:
return &wp->w_buffer->b_p_fex_flags;
- case PV_INEX:
+ case kOptIncludeexpr:
return &wp->w_buffer->b_p_inex_flags;
+ default:
+ break;
}
}
-
// Nothing special, return global flags field.
return &options[opt_idx].flags;
}
@@ -1804,7 +1802,6 @@ sctx_T *get_option_sctx(OptIndex opt_idx)
void set_option_sctx(OptIndex opt_idx, int opt_flags, sctx_T script_ctx)
{
bool both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
- int indir = (int)options[opt_idx].indir;
nlua_set_sctx(&script_ctx);
LastSet last_set = {
.script_ctx = script_ctx,
@@ -1818,17 +1815,17 @@ void set_option_sctx(OptIndex opt_idx, int opt_flags, sctx_T script_ctx)
// Remember where the option was set. For local options need to do that
// in the buffer or window structure.
- if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0) {
+ if (both || (opt_flags & OPT_GLOBAL) || option_is_global_only(opt_idx)) {
options[opt_idx].last_set = last_set;
}
if (both || (opt_flags & OPT_LOCAL)) {
- if (indir & PV_BUF) {
- curbuf->b_p_script_ctx[indir & PV_MASK] = last_set;
- } else if (indir & PV_WIN) {
- curwin->w_p_script_ctx[indir & PV_MASK] = last_set;
+ if (option_has_scope(opt_idx, kOptScopeBuf)) {
+ curbuf->b_p_script_ctx[option_scope_idx(opt_idx, kOptScopeBuf)] = last_set;
+ } else if ((option_has_scope(opt_idx, kOptScopeWin))) {
+ curwin->w_p_script_ctx[option_scope_idx(opt_idx, kOptScopeWin)] = last_set;
if (both) {
// also setting the "all buffers" value
- curwin->w_allbuf_opt.wo_script_ctx[indir & PV_MASK] = last_set;
+ curwin->w_allbuf_opt.wo_script_ctx[option_scope_idx(opt_idx, kOptScopeWin)] = last_set;
}
}
}
@@ -3267,7 +3264,7 @@ OptVal object_as_optval(Object o, bool *error)
/// Get an allocated string containing a list of valid types for an option.
/// For options with a singular type, it returns the name of the type. For options with multiple
/// possible types, it returns a slash separated list of types. For example, if an option can be a
-/// number, boolean or string, the function returns "Number/Boolean/String"
+/// number, boolean or string, the function returns "number/boolean/string"
static char *option_get_valid_types(OptIndex opt_idx)
{
StringBuilder str = KV_INITIAL_VALUE;
@@ -3299,14 +3296,73 @@ static char *option_get_valid_types(OptIndex opt_idx)
bool is_option_hidden(OptIndex opt_idx)
{
// Hidden options are always immutable and point to their default value
- return opt_idx == kOptInvalid
- ? false
- : (options[opt_idx].immutable && options[opt_idx].var == &options[opt_idx].def_val.data);
+ return opt_idx != kOptInvalid && options[opt_idx].immutable
+ && options[opt_idx].var == &options[opt_idx].def_val.data;
+}
+
+/// Check if option is multitype (supports multiple types).
+static bool option_is_multitype(OptIndex opt_idx)
+{
+ const OptTypeFlags type_flags = get_option(opt_idx)->type_flags;
+ assert(type_flags != 0);
+ return !is_power_of_two(type_flags);
+}
+
+/// Check if option supports a specific type.
+bool option_has_type(OptIndex opt_idx, OptValType type)
+{
+ // Ensure that type flags variable can hold all types.
+ STATIC_ASSERT(kOptValTypeSize <= sizeof(OptTypeFlags) * 8,
+ "Option type_flags cannot fit all option types");
+ // Ensure that the type is valid before accessing type_flags.
+ assert(type > kOptValTypeNil && type < kOptValTypeSize);
+ // Bitshift 1 by the value of type to get the type's corresponding flag, and check if it's set in
+ // the type_flags bit field.
+ return get_option(opt_idx)->type_flags & (1 << type);
}
+/// Check if option supports a specific scope.
+bool option_has_scope(OptIndex opt_idx, OptScope scope)
+{
+ // Ensure that scope flags variable can hold all scopes.
+ STATIC_ASSERT(kOptScopeSize <= sizeof(OptScopeFlags) * 8,
+ "Option scope_flags cannot fit all option scopes");
+ // Ensure that the scope is valid before accessing scope_flags.
+ assert(scope >= kOptScopeGlobal && scope < kOptScopeSize);
+ // Bitshift 1 by the value of scope to get the scope's corresponding flag, and check if it's set
+ // in the scope_flags bit field.
+ return get_option(opt_idx)->scope_flags & (1 << scope);
+}
+
+/// Check if option is global-local.
static inline bool option_is_global_local(OptIndex opt_idx)
{
- return opt_idx == kOptInvalid ? false : (options[opt_idx].indir & PV_BOTH);
+ // Global-local options have at least two types, so their type flag cannot be a power of two.
+ return opt_idx != kOptInvalid && !is_power_of_two(options[opt_idx].scope_flags);
+}
+
+/// Check if option only supports global scope.
+static inline bool option_is_global_only(OptIndex opt_idx)
+{
+ // For an option to be global-only, it has to only have a single scope, which means the scope
+ // flags must be a power of two, and it must have the global scope.
+ return opt_idx != kOptInvalid && is_power_of_two(options[opt_idx].scope_flags)
+ && option_has_scope(opt_idx, kOptScopeGlobal);
+}
+
+/// Check if option only supports window scope.
+static inline bool option_is_window_local(OptIndex opt_idx)
+{
+ // For an option to be window-local it has to only have a single scope, which means the scope
+ // flags must be a power of two, and it must have the window scope.
+ return opt_idx != kOptInvalid && is_power_of_two(options[opt_idx].scope_flags)
+ && option_has_scope(opt_idx, kOptScopeWin);
+}
+
+/// Get option index for scope.
+ssize_t option_scope_idx(OptIndex opt_idx, OptScope scope)
+{
+ return options[opt_idx].scope_idx[scope];
}
/// Get option flags.
@@ -3357,7 +3413,7 @@ static OptVal get_option_unset_value(OptIndex opt_idx)
vimoption_T *opt = &options[opt_idx];
// For global-local options, use the unset value of the local value.
- if (opt->indir & PV_BOTH) {
+ if (option_is_global_local(opt_idx)) {
// String global-local options always use an empty string for the unset value.
if (option_has_type(opt_idx, kOptValTypeString)) {
return STATIC_CSTR_AS_OPTVAL("");
@@ -3389,7 +3445,7 @@ static bool is_option_local_value_unset(OptIndex opt_idx)
vimoption_T *opt = get_option(opt_idx);
// Local value of option that isn't global-local is always considered set.
- if (!((int)opt->indir & PV_BOTH)) {
+ if (!option_is_global_local(opt_idx)) {
return false;
}
@@ -3748,10 +3804,10 @@ void set_option_direct(OptIndex opt_idx, OptVal value, int opt_flags, scid_T set
/// @param set_sid Script ID. Special values:
/// 0: Use current script ID.
/// SID_NONE: Don't set script ID.
-/// @param req_scope Requested option scope. See OptReqScope in option.h.
+/// @param req_scope Requested option scope. See OptScope in option.h.
/// @param[in] from Target buffer/window.
void set_option_direct_for(OptIndex opt_idx, OptVal value, int opt_flags, scid_T set_sid,
- OptReqScope req_scope, void *const from)
+ OptScope req_scope, void *const from)
{
buf_T *save_curbuf = curbuf;
win_T *save_curwin = curwin;
@@ -3760,15 +3816,15 @@ void set_option_direct_for(OptIndex opt_idx, OptVal value, int opt_flags, scid_T
// side-effects when setting an option directly. Just change the values of curbuf and curwin if
// needed, no need to properly switch the window / buffer.
switch (req_scope) {
- case kOptReqGlobal:
+ case kOptScopeGlobal:
break;
- case kOptReqBuf:
- curbuf = (buf_T *)from;
- break;
- case kOptReqWin:
+ case kOptScopeWin:
curwin = (win_T *)from;
curbuf = curwin->w_buffer;
break;
+ case kOptScopeBuf:
+ curbuf = (buf_T *)from;
+ break;
}
set_option_direct(opt_idx, value, opt_flags, set_sid);
@@ -3855,16 +3911,17 @@ void set_option_value_give_err(const OptIndex opt_idx, OptVal value, int opt_fla
/// Switch current context to get/set option value for window/buffer.
///
/// @param[out] ctx Current context. switchwin_T for window and aco_save_T for buffer.
-/// @param req_scope Requested option scope. See OptReqScope in option.h.
+/// @param req_scope Requested option scope. See OptScope in option.h.
/// @param[in] from Target buffer/window.
/// @param[out] err Error message, if any.
///
/// @return true if context was switched, false otherwise.
-static bool switch_option_context(void *const ctx, OptReqScope req_scope, void *const from,
- Error *err)
+static bool switch_option_context(void *const ctx, OptScope req_scope, void *const from, Error *err)
{
switch (req_scope) {
- case kOptReqWin: {
+ case kOptScopeGlobal:
+ return false;
+ case kOptScopeWin: {
win_T *const win = (win_T *)from;
switchwin_T *const switchwin = (switchwin_T *)ctx;
@@ -3884,7 +3941,7 @@ static bool switch_option_context(void *const ctx, OptReqScope req_scope, void *
}
return true;
}
- case kOptReqBuf: {
+ case kOptScopeBuf: {
buf_T *const buf = (buf_T *)from;
aco_save_T *const aco = (aco_save_T *)ctx;
@@ -3894,76 +3951,44 @@ static bool switch_option_context(void *const ctx, OptReqScope req_scope, void *
aucmd_prepbuf(aco, buf);
return true;
}
- case kOptReqGlobal:
- return false;
}
UNREACHABLE;
}
/// Restore context after getting/setting option for window/buffer. See switch_option_context() for
/// params.
-static void restore_option_context(void *const ctx, OptReqScope req_scope)
+static void restore_option_context(void *const ctx, OptScope req_scope)
{
switch (req_scope) {
- case kOptReqWin:
+ case kOptScopeGlobal:
+ break;
+ case kOptScopeWin:
restore_win_noblock((switchwin_T *)ctx, true);
break;
- case kOptReqBuf:
+ case kOptScopeBuf:
aucmd_restbuf((aco_save_T *)ctx);
break;
- case kOptReqGlobal:
- break;
}
}
-/// Get attributes for an option.
-///
-/// @param opt_idx Option index in options[] table.
-///
-/// @return Option attributes.
-/// 0 for hidden or unknown option.
-/// See SOPT_* in option_defs.h for other flags.
-int get_option_attrs(OptIndex opt_idx)
-{
- if (opt_idx == kOptInvalid) {
- return 0;
- }
-
- vimoption_T *opt = get_option(opt_idx);
-
- int attrs = 0;
-
- if (opt->indir == PV_NONE || (opt->indir & PV_BOTH)) {
- attrs |= SOPT_GLOBAL;
- }
- if (opt->indir & PV_WIN) {
- attrs |= SOPT_WIN;
- } else if (opt->indir & PV_BUF) {
- attrs |= SOPT_BUF;
- }
-
- assert(attrs != 0);
- return attrs;
-}
-
/// Get option value for buffer / window.
///
/// @param opt_idx Option index in options[] table.
/// @param[out] flagsp Set to the option flags (see OptFlags) (if not NULL).
/// @param[in] scope Option scope (can be OPT_LOCAL, OPT_GLOBAL or a combination).
/// @param[out] hidden Whether option is hidden.
-/// @param req_scope Requested option scope. See OptReqScope in option.h.
+/// @param req_scope Requested option scope. See OptScope in option.h.
/// @param[in] from Target buffer/window.
/// @param[out] err Error message, if any.
///
/// @return Option value. Must be freed by caller.
-OptVal get_option_value_for(OptIndex opt_idx, int scope, const OptReqScope req_scope,
- void *const from, Error *err)
+OptVal get_option_value_for(OptIndex opt_idx, int scope, const OptScope req_scope, void *const from,
+ Error *err)
{
switchwin_T switchwin;
aco_save_T aco;
- void *ctx = req_scope == kOptReqWin ? (void *)&switchwin
- : (req_scope == kOptReqBuf ? (void *)&aco : NULL);
+ void *ctx = req_scope == kOptScopeWin ? (void *)&switchwin
+ : (req_scope == kOptScopeBuf ? (void *)&aco : NULL);
bool switched = switch_option_context(ctx, req_scope, from, err);
if (ERROR_SET(err)) {
@@ -3985,17 +4010,17 @@ OptVal get_option_value_for(OptIndex opt_idx, int scope, const OptReqScope req_s
/// @param opt_idx Option index in options[] table.
/// @param[in] value Option value.
/// @param[in] opt_flags Flags: OPT_LOCAL, OPT_GLOBAL, or 0 (both).
-/// @param req_scope Requested option scope. See OptReqScope in option.h.
+/// @param req_scope Requested option scope. See OptScope in option.h.
/// @param[in] from Target buffer/window.
/// @param[out] err Error message, if any.
void set_option_value_for(const char *name, OptIndex opt_idx, OptVal value, const int opt_flags,
- const OptReqScope req_scope, void *const from, Error *err)
+ const OptScope req_scope, void *const from, Error *err)
FUNC_ATTR_NONNULL_ARG(1)
{
switchwin_T switchwin;
aco_save_T aco;
- void *ctx = req_scope == kOptReqWin ? (void *)&switchwin
- : (req_scope == kOptReqBuf ? (void *)&aco : NULL);
+ void *ctx = req_scope == kOptScopeWin ? (void *)&switchwin
+ : (req_scope == kOptScopeBuf ? (void *)&aco : NULL);
bool switched = switch_option_context(ctx, req_scope, from, err);
if (ERROR_SET(err)) {
@@ -4040,7 +4065,7 @@ static void showoptions(bool all, int opt_flags)
// collect the items in items[]
int item_count = 0;
vimoption_T *opt;
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
opt = &options[opt_idx];
// apply :filter /pat/
if (message_filtered(opt->fullname)) {
@@ -4049,7 +4074,7 @@ static void showoptions(bool all, int opt_flags)
void *varp = NULL;
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) != 0) {
- if (opt->indir != PV_NONE) {
+ if (!option_is_global_only(opt_idx)) {
varp = get_varp_scope(opt, opt_flags);
}
} else {
@@ -4124,7 +4149,7 @@ static int optval_default(OptIndex opt_idx, void *varp)
/// Send update to UIs with values of UI relevant options
void ui_refresh_options(void)
{
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
uint32_t flags = options[opt_idx].flags;
if (!(flags & kOptFlagUIOption)) {
continue;
@@ -4204,13 +4229,13 @@ int makeset(FILE *fd, int opt_flags, int local_only)
// kOptFlagPriMkrc flag and once without.
for (int pri = 1; pri >= 0; pri--) {
vimoption_T *opt;
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
opt = &options[opt_idx];
if (!(opt->flags & kOptFlagNoMkrc)
&& ((pri == 1) == ((opt->flags & kOptFlagPriMkrc) != 0))) {
// skip global option when only doing locals
- if (opt->indir == PV_NONE && !(opt_flags & OPT_GLOBAL)) {
+ if (option_is_global_only(opt_idx) && !(opt_flags & OPT_GLOBAL)) {
continue;
}
@@ -4237,21 +4262,19 @@ int makeset(FILE *fd, int opt_flags, int local_only)
int round = 2;
void *varp_local = NULL; // fresh value
- if (opt->indir != PV_NONE) {
- if (opt->var == VAR_WIN) {
- // skip window-local option when only doing globals
- if (!(opt_flags & OPT_LOCAL)) {
- continue;
- }
- // When fresh value of window-local option is not at the
- // default, need to write it too.
- if (!(opt_flags & OPT_GLOBAL) && !local_only) {
- void *varp_fresh = get_varp_scope(opt, OPT_GLOBAL); // local value
- if (!optval_default(opt_idx, varp_fresh)) {
- round = 1;
- varp_local = varp;
- varp = varp_fresh;
- }
+ if (option_is_window_local(opt_idx)) {
+ // skip window-local option when only doing globals
+ if (!(opt_flags & OPT_LOCAL)) {
+ continue;
+ }
+ // When fresh value of window-local option is not at the
+ // default, need to write it too.
+ if (!(opt_flags & OPT_GLOBAL) && !local_only) {
+ void *varp_fresh = get_varp_scope(opt, OPT_GLOBAL); // local value
+ if (!optval_default(opt_idx, varp_fresh)) {
+ round = 1;
+ varp_local = varp;
+ varp = varp_fresh;
}
}
}
@@ -4267,9 +4290,9 @@ int makeset(FILE *fd, int opt_flags, int local_only)
}
bool do_endif = false;
- // Don't set 'syntax' and 'filetype' again if the value is
- // already right, avoids reloading the syntax file.
- if (opt->indir == PV_SYN || opt->indir == PV_FT) {
+ // Don't set 'syntax' and 'filetype' again if the value is already right, avoids reloading
+ // the syntax file.
+ if (opt_idx == kOptSyntax || opt_idx == kOptFiletype) {
if (fprintf(fd, "if &%s != '%s'", opt->fullname,
*(char **)(varp)) < 0
|| put_eol(fd) < 0) {
@@ -4325,7 +4348,7 @@ static int put_set(FILE *fd, char *cmd, OptIndex opt_idx, void *varp)
char *name = opt->fullname;
uint64_t flags = opt->flags;
- if ((opt->indir & PV_BOTH) && varp != opt->var
+ if (option_is_global_local(opt_idx) && varp != opt->var
&& optval_equal(value, get_option_unset_value(opt_idx))) {
// Processing unset local value of global-local option. Do nothing.
return OK;
@@ -4430,76 +4453,80 @@ static int put_set(FILE *fd, char *cmd, OptIndex opt_idx, void *varp)
void *get_varp_scope_from(vimoption_T *p, int scope, buf_T *buf, win_T *win)
{
- if ((scope & OPT_GLOBAL) && p->indir != PV_NONE) {
- if (p->var == VAR_WIN) {
+ OptIndex opt_idx = get_opt_idx(p);
+
+ if ((scope & OPT_GLOBAL) && !option_is_global_only(opt_idx)) {
+ if (option_is_window_local(opt_idx)) {
return GLOBAL_WO(get_varp_from(p, buf, win));
}
return p->var;
}
- if ((scope & OPT_LOCAL) && ((int)p->indir & PV_BOTH)) {
- switch ((int)p->indir) {
- case PV_FP:
+
+ if ((scope & OPT_LOCAL) && option_is_global_local(opt_idx)) {
+ switch (opt_idx) {
+ case kOptFormatprg:
return &(buf->b_p_fp);
- case PV_FFU:
+ case kOptFindfunc:
return &(buf->b_p_ffu);
- case PV_EFM:
+ case kOptErrorformat:
return &(buf->b_p_efm);
- case PV_GP:
+ case kOptGrepprg:
return &(buf->b_p_gp);
- case PV_MP:
+ case kOptMakeprg:
return &(buf->b_p_mp);
- case PV_EP:
+ case kOptEqualprg:
return &(buf->b_p_ep);
- case PV_KP:
+ case kOptKeywordprg:
return &(buf->b_p_kp);
- case PV_PATH:
+ case kOptPath:
return &(buf->b_p_path);
- case PV_AR:
+ case kOptAutoread:
return &(buf->b_p_ar);
- case PV_TAGS:
+ case kOptTags:
return &(buf->b_p_tags);
- case PV_TC:
+ case kOptTagcase:
return &(buf->b_p_tc);
- case PV_SISO:
+ case kOptSidescrolloff:
return &(win->w_p_siso);
- case PV_SO:
+ case kOptScrolloff:
return &(win->w_p_so);
- case PV_DEF:
+ case kOptDefine:
return &(buf->b_p_def);
- case PV_INC:
+ case kOptInclude:
return &(buf->b_p_inc);
- case PV_COT:
+ case kOptCompleteopt:
return &(buf->b_p_cot);
- case PV_DICT:
+ case kOptDictionary:
return &(buf->b_p_dict);
- case PV_TSR:
+ case kOptThesaurus:
return &(buf->b_p_tsr);
- case PV_TSRFU:
+ case kOptThesaurusfunc:
return &(buf->b_p_tsrfu);
- case PV_TFU:
+ case kOptTagfunc:
return &(buf->b_p_tfu);
- case PV_SBR:
+ case kOptShowbreak:
return &(win->w_p_sbr);
- case PV_STL:
+ case kOptStatusline:
return &(win->w_p_stl);
- case PV_WBR:
+ case kOptWinbar:
return &(win->w_p_wbr);
- case PV_UL:
+ case kOptUndolevels:
return &(buf->b_p_ul);
- case PV_LW:
+ case kOptLispwords:
return &(buf->b_p_lw);
- case PV_BKC:
+ case kOptBackupcopy:
return &(buf->b_p_bkc);
- case PV_MENC:
+ case kOptMakeencoding:
return &(buf->b_p_menc);
- case PV_FCS:
+ case kOptFillchars:
return &(win->w_p_fcs);
- case PV_LCS:
+ case kOptListchars:
return &(win->w_p_lcs);
- case PV_VE:
+ case kOptVirtualedit:
return &(win->w_p_ve);
+ default:
+ abort();
}
- return NULL; // "cannot happen"
}
return get_varp_from(p, buf, win);
}
@@ -4521,291 +4548,290 @@ void *get_option_varp_scope_from(OptIndex opt_idx, int scope, buf_T *buf, win_T
void *get_varp_from(vimoption_T *p, buf_T *buf, win_T *win)
{
- // hidden options always use the same var pointer
- if (is_option_hidden(get_opt_idx(p))) {
- return p->var;
- }
+ OptIndex opt_idx = get_opt_idx(p);
- switch ((int)p->indir) {
- case PV_NONE:
+ // Hidden options and global-only options always use the same var pointer
+ if (is_option_hidden(opt_idx) || option_is_global_only(opt_idx)) {
return p->var;
+ }
+ switch (opt_idx) {
// global option with local value: use local value if it's been set
- case PV_EP:
+ case kOptEqualprg:
return *buf->b_p_ep != NUL ? &buf->b_p_ep : p->var;
- case PV_KP:
+ case kOptKeywordprg:
return *buf->b_p_kp != NUL ? &buf->b_p_kp : p->var;
- case PV_PATH:
+ case kOptPath:
return *buf->b_p_path != NUL ? &(buf->b_p_path) : p->var;
- case PV_AR:
+ case kOptAutoread:
return buf->b_p_ar >= 0 ? &(buf->b_p_ar) : p->var;
- case PV_TAGS:
+ case kOptTags:
return *buf->b_p_tags != NUL ? &(buf->b_p_tags) : p->var;
- case PV_TC:
+ case kOptTagcase:
return *buf->b_p_tc != NUL ? &(buf->b_p_tc) : p->var;
- case PV_SISO:
+ case kOptSidescrolloff:
return win->w_p_siso >= 0 ? &(win->w_p_siso) : p->var;
- case PV_SO:
+ case kOptScrolloff:
return win->w_p_so >= 0 ? &(win->w_p_so) : p->var;
- case PV_BKC:
+ case kOptBackupcopy:
return *buf->b_p_bkc != NUL ? &(buf->b_p_bkc) : p->var;
- case PV_DEF:
+ case kOptDefine:
return *buf->b_p_def != NUL ? &(buf->b_p_def) : p->var;
- case PV_INC:
+ case kOptInclude:
return *buf->b_p_inc != NUL ? &(buf->b_p_inc) : p->var;
- case PV_COT:
+ case kOptCompleteopt:
return *buf->b_p_cot != NUL ? &(buf->b_p_cot) : p->var;
- case PV_DICT:
+ case kOptDictionary:
return *buf->b_p_dict != NUL ? &(buf->b_p_dict) : p->var;
- case PV_TSR:
+ case kOptThesaurus:
return *buf->b_p_tsr != NUL ? &(buf->b_p_tsr) : p->var;
- case PV_TSRFU:
+ case kOptThesaurusfunc:
return *buf->b_p_tsrfu != NUL ? &(buf->b_p_tsrfu) : p->var;
- case PV_FP:
+ case kOptFormatprg:
return *buf->b_p_fp != NUL ? &(buf->b_p_fp) : p->var;
- case PV_FFU:
+ case kOptFindfunc:
return *buf->b_p_ffu != NUL ? &(buf->b_p_ffu) : p->var;
- case PV_EFM:
+ case kOptErrorformat:
return *buf->b_p_efm != NUL ? &(buf->b_p_efm) : p->var;
- case PV_GP:
+ case kOptGrepprg:
return *buf->b_p_gp != NUL ? &(buf->b_p_gp) : p->var;
- case PV_MP:
+ case kOptMakeprg:
return *buf->b_p_mp != NUL ? &(buf->b_p_mp) : p->var;
- case PV_SBR:
+ case kOptShowbreak:
return *win->w_p_sbr != NUL ? &(win->w_p_sbr) : p->var;
- case PV_STL:
+ case kOptStatusline:
return *win->w_p_stl != NUL ? &(win->w_p_stl) : p->var;
- case PV_WBR:
+ case kOptWinbar:
return *win->w_p_wbr != NUL ? &(win->w_p_wbr) : p->var;
- case PV_UL:
+ case kOptUndolevels:
return buf->b_p_ul != NO_LOCAL_UNDOLEVEL ? &(buf->b_p_ul) : p->var;
- case PV_LW:
+ case kOptLispwords:
return *buf->b_p_lw != NUL ? &(buf->b_p_lw) : p->var;
- case PV_MENC:
+ case kOptMakeencoding:
return *buf->b_p_menc != NUL ? &(buf->b_p_menc) : p->var;
- case PV_FCS:
+ case kOptFillchars:
return *win->w_p_fcs != NUL ? &(win->w_p_fcs) : p->var;
- case PV_LCS:
+ case kOptListchars:
return *win->w_p_lcs != NUL ? &(win->w_p_lcs) : p->var;
- case PV_VE:
+ case kOptVirtualedit:
return *win->w_p_ve != NUL ? &win->w_p_ve : p->var;
- case PV_ARAB:
+ case kOptArabic:
return &(win->w_p_arab);
- case PV_LIST:
+ case kOptList:
return &(win->w_p_list);
- case PV_SPELL:
+ case kOptSpell:
return &(win->w_p_spell);
- case PV_CUC:
+ case kOptCursorcolumn:
return &(win->w_p_cuc);
- case PV_CUL:
+ case kOptCursorline:
return &(win->w_p_cul);
- case PV_CULOPT:
+ case kOptCursorlineopt:
return &(win->w_p_culopt);
- case PV_CC:
+ case kOptColorcolumn:
return &(win->w_p_cc);
- case PV_DIFF:
+ case kOptDiff:
return &(win->w_p_diff);
- case PV_FDC:
+ case kOptFoldcolumn:
return &(win->w_p_fdc);
- case PV_FEN:
+ case kOptFoldenable:
return &(win->w_p_fen);
- case PV_FDI:
+ case kOptFoldignore:
return &(win->w_p_fdi);
- case PV_FDL:
+ case kOptFoldlevel:
return &(win->w_p_fdl);
- case PV_FDM:
+ case kOptFoldmethod:
return &(win->w_p_fdm);
- case PV_FML:
+ case kOptFoldminlines:
return &(win->w_p_fml);
- case PV_FDN:
+ case kOptFoldnestmax:
return &(win->w_p_fdn);
- case PV_FDE:
+ case kOptFoldexpr:
return &(win->w_p_fde);
- case PV_FDT:
+ case kOptFoldtext:
return &(win->w_p_fdt);
- case PV_FMR:
+ case kOptFoldmarker:
return &(win->w_p_fmr);
- case PV_NU:
+ case kOptNumber:
return &(win->w_p_nu);
- case PV_RNU:
+ case kOptRelativenumber:
return &(win->w_p_rnu);
- case PV_NUW:
+ case kOptNumberwidth:
return &(win->w_p_nuw);
- case PV_WFB:
+ case kOptWinfixbuf:
return &(win->w_p_wfb);
- case PV_WFH:
+ case kOptWinfixheight:
return &(win->w_p_wfh);
- case PV_WFW:
+ case kOptWinfixwidth:
return &(win->w_p_wfw);
- case PV_PVW:
+ case kOptPreviewwindow:
return &(win->w_p_pvw);
- case PV_RL:
+ case kOptRightleft:
return &(win->w_p_rl);
- case PV_RLC:
+ case kOptRightleftcmd:
return &(win->w_p_rlc);
- case PV_SCROLL:
+ case kOptScroll:
return &(win->w_p_scr);
- case PV_SMS:
+ case kOptSmoothscroll:
return &(win->w_p_sms);
- case PV_WRAP:
+ case kOptWrap:
return &(win->w_p_wrap);
- case PV_LBR:
+ case kOptLinebreak:
return &(win->w_p_lbr);
- case PV_BRI:
+ case kOptBreakindent:
return &(win->w_p_bri);
- case PV_BRIOPT:
+ case kOptBreakindentopt:
return &(win->w_p_briopt);
- case PV_SCBIND:
+ case kOptScrollbind:
return &(win->w_p_scb);
- case PV_CRBIND:
+ case kOptCursorbind:
return &(win->w_p_crb);
- case PV_COCU:
+ case kOptConcealcursor:
return &(win->w_p_cocu);
- case PV_COLE:
+ case kOptConceallevel:
return &(win->w_p_cole);
- case PV_AI:
+ case kOptAutoindent:
return &(buf->b_p_ai);
- case PV_BIN:
+ case kOptBinary:
return &(buf->b_p_bin);
- case PV_BOMB:
+ case kOptBomb:
return &(buf->b_p_bomb);
- case PV_BH:
+ case kOptBufhidden:
return &(buf->b_p_bh);
- case PV_BT:
+ case kOptBuftype:
return &(buf->b_p_bt);
- case PV_BL:
+ case kOptBuflisted:
return &(buf->b_p_bl);
- case PV_CHANNEL:
+ case kOptChannel:
return &(buf->b_p_channel);
- case PV_CI:
+ case kOptCopyindent:
return &(buf->b_p_ci);
- case PV_CIN:
+ case kOptCindent:
return &(buf->b_p_cin);
- case PV_CINK:
+ case kOptCinkeys:
return &(buf->b_p_cink);
- case PV_CINO:
+ case kOptCinoptions:
return &(buf->b_p_cino);
- case PV_CINSD:
+ case kOptCinscopedecls:
return &(buf->b_p_cinsd);
- case PV_CINW:
+ case kOptCinwords:
return &(buf->b_p_cinw);
- case PV_COM:
+ case kOptComments:
return &(buf->b_p_com);
- case PV_CMS:
+ case kOptCommentstring:
return &(buf->b_p_cms);
- case PV_CPT:
+ case kOptComplete:
return &(buf->b_p_cpt);
#ifdef BACKSLASH_IN_FILENAME
- case PV_CSL:
+ case kOptCompleteslash:
return &(buf->b_p_csl);
#endif
- case PV_CFU:
+ case kOptCompletefunc:
return &(buf->b_p_cfu);
- case PV_OFU:
+ case kOptOmnifunc:
return &(buf->b_p_ofu);
- case PV_EOF:
+ case kOptEndoffile:
return &(buf->b_p_eof);
- case PV_EOL:
+ case kOptEndofline:
return &(buf->b_p_eol);
- case PV_FIXEOL:
+ case kOptFixendofline:
return &(buf->b_p_fixeol);
- case PV_ET:
+ case kOptExpandtab:
return &(buf->b_p_et);
- case PV_FENC:
+ case kOptFileencoding:
return &(buf->b_p_fenc);
- case PV_FF:
+ case kOptFileformat:
return &(buf->b_p_ff);
- case PV_FT:
+ case kOptFiletype:
return &(buf->b_p_ft);
- case PV_FO:
+ case kOptFormatoptions:
return &(buf->b_p_fo);
- case PV_FLP:
+ case kOptFormatlistpat:
return &(buf->b_p_flp);
- case PV_IMI:
+ case kOptIminsert:
return &(buf->b_p_iminsert);
- case PV_IMS:
+ case kOptImsearch:
return &(buf->b_p_imsearch);
- case PV_INF:
+ case kOptInfercase:
return &(buf->b_p_inf);
- case PV_ISK:
+ case kOptIskeyword:
return &(buf->b_p_isk);
- case PV_INEX:
+ case kOptIncludeexpr:
return &(buf->b_p_inex);
- case PV_INDE:
+ case kOptIndentexpr:
return &(buf->b_p_inde);
- case PV_INDK:
+ case kOptIndentkeys:
return &(buf->b_p_indk);
- case PV_FEX:
+ case kOptFormatexpr:
return &(buf->b_p_fex);
- case PV_LISP:
+ case kOptLisp:
return &(buf->b_p_lisp);
- case PV_LOP:
+ case kOptLispoptions:
return &(buf->b_p_lop);
- case PV_ML:
+ case kOptModeline:
return &(buf->b_p_ml);
- case PV_MPS:
+ case kOptMatchpairs:
return &(buf->b_p_mps);
- case PV_MA:
+ case kOptModifiable:
return &(buf->b_p_ma);
- case PV_MOD:
+ case kOptModified:
return &(buf->b_changed);
- case PV_NF:
+ case kOptNrformats:
return &(buf->b_p_nf);
- case PV_PI:
+ case kOptPreserveindent:
return &(buf->b_p_pi);
- case PV_QE:
+ case kOptQuoteescape:
return &(buf->b_p_qe);
- case PV_RO:
+ case kOptReadonly:
return &(buf->b_p_ro);
- case PV_SCBK:
+ case kOptScrollback:
return &(buf->b_p_scbk);
- case PV_SI:
+ case kOptSmartindent:
return &(buf->b_p_si);
- case PV_STS:
+ case kOptSofttabstop:
return &(buf->b_p_sts);
- case PV_SUA:
+ case kOptSuffixesadd:
return &(buf->b_p_sua);
- case PV_SWF:
+ case kOptSwapfile:
return &(buf->b_p_swf);
- case PV_SMC:
+ case kOptSynmaxcol:
return &(buf->b_p_smc);
- case PV_SYN:
+ case kOptSyntax:
return &(buf->b_p_syn);
- case PV_SPC:
+ case kOptSpellcapcheck:
return &(win->w_s->b_p_spc);
- case PV_SPF:
+ case kOptSpellfile:
return &(win->w_s->b_p_spf);
- case PV_SPL:
+ case kOptSpelllang:
return &(win->w_s->b_p_spl);
- case PV_SPO:
+ case kOptSpelloptions:
return &(win->w_s->b_p_spo);
- case PV_SW:
+ case kOptShiftwidth:
return &(buf->b_p_sw);
- case PV_TFU:
+ case kOptTagfunc:
return &(buf->b_p_tfu);
- case PV_TS:
+ case kOptTabstop:
return &(buf->b_p_ts);
- case PV_TW:
+ case kOptTextwidth:
return &(buf->b_p_tw);
- case PV_UDF:
+ case kOptUndofile:
return &(buf->b_p_udf);
- case PV_WM:
+ case kOptWrapmargin:
return &(buf->b_p_wm);
- case PV_VSTS:
+ case kOptVarsofttabstop:
return &(buf->b_p_vsts);
- case PV_VTS:
+ case kOptVartabstop:
return &(buf->b_p_vts);
- case PV_KMAP:
+ case kOptKeymap:
return &(buf->b_p_keymap);
- case PV_SCL:
+ case kOptSigncolumn:
return &(win->w_p_scl);
- case PV_WINHL:
+ case kOptWinhighlight:
return &(win->w_p_winhl);
- case PV_WINBL:
+ case kOptWinblend:
return &(win->w_p_winbl);
- case PV_STC:
+ case kOptStatuscolumn:
return &(win->w_p_stc);
default:
iemsg(_("E356: get_varp ERROR"));
@@ -5008,26 +5034,8 @@ void didset_window_options(win_T *wp, bool valid_cursor)
wp->w_grid_alloc.blending = wp->w_p_winbl > 0;
}
-/// Index into the options table for a buffer-local option enum.
-static OptIndex buf_opt_idx[BV_COUNT];
#define COPY_OPT_SCTX(buf, bv) buf->b_p_script_ctx[bv] = options[buf_opt_idx[bv]].last_set
-/// Initialize buf_opt_idx[] if not done already.
-static void init_buf_opt_idx(void)
-{
- static bool did_init_buf_opt_idx = false;
-
- if (did_init_buf_opt_idx) {
- return;
- }
- did_init_buf_opt_idx = true;
- for (OptIndex i = 0; i < kOptIndexCount; i++) {
- if (options[i].indir & PV_BUF) {
- buf_opt_idx[options[i].indir & PV_MASK] = i;
- }
- }
-}
-
/// Copy global option values to local options for one buffer.
/// Used when creating a new buffer and sometimes when entering a buffer.
/// flags:
@@ -5065,7 +5073,6 @@ void buf_copy_options(buf_T *buf, int flags)
if (should_copy || (flags & BCO_ALWAYS)) {
CLEAR_FIELD(buf->b_p_script_ctx);
- init_buf_opt_idx();
// Don't copy the options specific to a help buffer when
// BCO_NOHELP is given or the options were initialized already
// (jumping back to a help file with CTRL-T or CTRL-O)
@@ -5101,61 +5108,61 @@ void buf_copy_options(buf_T *buf, int flags)
}
buf->b_p_ai = p_ai;
- COPY_OPT_SCTX(buf, BV_AI);
+ COPY_OPT_SCTX(buf, kBufOptAutoindent);
buf->b_p_ai_nopaste = p_ai_nopaste;
buf->b_p_sw = p_sw;
- COPY_OPT_SCTX(buf, BV_SW);
+ COPY_OPT_SCTX(buf, kBufOptShiftwidth);
buf->b_p_scbk = p_scbk;
- COPY_OPT_SCTX(buf, BV_SCBK);
+ COPY_OPT_SCTX(buf, kBufOptScrollback);
buf->b_p_tw = p_tw;
- COPY_OPT_SCTX(buf, BV_TW);
+ COPY_OPT_SCTX(buf, kBufOptTextwidth);
buf->b_p_tw_nopaste = p_tw_nopaste;
buf->b_p_tw_nobin = p_tw_nobin;
buf->b_p_wm = p_wm;
- COPY_OPT_SCTX(buf, BV_WM);
+ COPY_OPT_SCTX(buf, kBufOptWrapmargin);
buf->b_p_wm_nopaste = p_wm_nopaste;
buf->b_p_wm_nobin = p_wm_nobin;
buf->b_p_bin = p_bin;
- COPY_OPT_SCTX(buf, BV_BIN);
+ COPY_OPT_SCTX(buf, kBufOptBinary);
buf->b_p_bomb = p_bomb;
- COPY_OPT_SCTX(buf, BV_BOMB);
+ COPY_OPT_SCTX(buf, kBufOptBomb);
buf->b_p_et = p_et;
- COPY_OPT_SCTX(buf, BV_ET);
+ COPY_OPT_SCTX(buf, kBufOptExpandtab);
buf->b_p_fixeol = p_fixeol;
- COPY_OPT_SCTX(buf, BV_FIXEOL);
+ COPY_OPT_SCTX(buf, kBufOptFixendofline);
buf->b_p_et_nobin = p_et_nobin;
buf->b_p_et_nopaste = p_et_nopaste;
buf->b_p_ml = p_ml;
- COPY_OPT_SCTX(buf, BV_ML);
+ COPY_OPT_SCTX(buf, kBufOptModeline);
buf->b_p_ml_nobin = p_ml_nobin;
buf->b_p_inf = p_inf;
- COPY_OPT_SCTX(buf, BV_INF);
+ COPY_OPT_SCTX(buf, kBufOptInfercase);
if (cmdmod.cmod_flags & CMOD_NOSWAPFILE) {
buf->b_p_swf = false;
} else {
buf->b_p_swf = p_swf;
- COPY_OPT_SCTX(buf, BV_SWF);
+ COPY_OPT_SCTX(buf, kBufOptSwapfile);
}
buf->b_p_cpt = xstrdup(p_cpt);
- COPY_OPT_SCTX(buf, BV_CPT);
+ COPY_OPT_SCTX(buf, kBufOptComplete);
#ifdef BACKSLASH_IN_FILENAME
buf->b_p_csl = xstrdup(p_csl);
- COPY_OPT_SCTX(buf, BV_CSL);
+ COPY_OPT_SCTX(buf, kBufOptCompleteslash);
#endif
buf->b_p_cfu = xstrdup(p_cfu);
- COPY_OPT_SCTX(buf, BV_CFU);
+ COPY_OPT_SCTX(buf, kBufOptCompletefunc);
set_buflocal_cfu_callback(buf);
buf->b_p_ofu = xstrdup(p_ofu);
- COPY_OPT_SCTX(buf, BV_OFU);
+ COPY_OPT_SCTX(buf, kBufOptOmnifunc);
set_buflocal_ofu_callback(buf);
buf->b_p_tfu = xstrdup(p_tfu);
- COPY_OPT_SCTX(buf, BV_TFU);
+ COPY_OPT_SCTX(buf, kBufOptTagfunc);
set_buflocal_tfu_callback(buf);
buf->b_p_sts = p_sts;
- COPY_OPT_SCTX(buf, BV_STS);
+ COPY_OPT_SCTX(buf, kBufOptSofttabstop);
buf->b_p_sts_nopaste = p_sts_nopaste;
buf->b_p_vsts = xstrdup(p_vsts);
- COPY_OPT_SCTX(buf, BV_VSTS);
+ COPY_OPT_SCTX(buf, kBufOptVarsofttabstop);
if (p_vsts && p_vsts != empty_string_option) {
tabstop_set(p_vsts, &buf->b_p_vsts_array);
} else {
@@ -5163,75 +5170,75 @@ void buf_copy_options(buf_T *buf, int flags)
}
buf->b_p_vsts_nopaste = p_vsts_nopaste ? xstrdup(p_vsts_nopaste) : NULL;
buf->b_p_com = xstrdup(p_com);
- COPY_OPT_SCTX(buf, BV_COM);
+ COPY_OPT_SCTX(buf, kBufOptComments);
buf->b_p_cms = xstrdup(p_cms);
- COPY_OPT_SCTX(buf, BV_CMS);
+ COPY_OPT_SCTX(buf, kBufOptCommentstring);
buf->b_p_fo = xstrdup(p_fo);
- COPY_OPT_SCTX(buf, BV_FO);
+ COPY_OPT_SCTX(buf, kBufOptFormatoptions);
buf->b_p_flp = xstrdup(p_flp);
- COPY_OPT_SCTX(buf, BV_FLP);
+ COPY_OPT_SCTX(buf, kBufOptFormatlistpat);
buf->b_p_nf = xstrdup(p_nf);
- COPY_OPT_SCTX(buf, BV_NF);
+ COPY_OPT_SCTX(buf, kBufOptNrformats);
buf->b_p_mps = xstrdup(p_mps);
- COPY_OPT_SCTX(buf, BV_MPS);
+ COPY_OPT_SCTX(buf, kBufOptMatchpairs);
buf->b_p_si = p_si;
- COPY_OPT_SCTX(buf, BV_SI);
+ COPY_OPT_SCTX(buf, kBufOptSmartindent);
buf->b_p_channel = 0;
buf->b_p_ci = p_ci;
- COPY_OPT_SCTX(buf, BV_CI);
+ COPY_OPT_SCTX(buf, kBufOptCopyindent);
buf->b_p_cin = p_cin;
- COPY_OPT_SCTX(buf, BV_CIN);
+ COPY_OPT_SCTX(buf, kBufOptCindent);
buf->b_p_cink = xstrdup(p_cink);
- COPY_OPT_SCTX(buf, BV_CINK);
+ COPY_OPT_SCTX(buf, kBufOptCinkeys);
buf->b_p_cino = xstrdup(p_cino);
- COPY_OPT_SCTX(buf, BV_CINO);
+ COPY_OPT_SCTX(buf, kBufOptCinoptions);
buf->b_p_cinsd = xstrdup(p_cinsd);
- COPY_OPT_SCTX(buf, BV_CINSD);
+ COPY_OPT_SCTX(buf, kBufOptCinscopedecls);
buf->b_p_lop = xstrdup(p_lop);
- COPY_OPT_SCTX(buf, BV_LOP);
+ COPY_OPT_SCTX(buf, kBufOptLispoptions);
// Don't copy 'filetype', it must be detected
buf->b_p_ft = empty_string_option;
buf->b_p_pi = p_pi;
- COPY_OPT_SCTX(buf, BV_PI);
+ COPY_OPT_SCTX(buf, kBufOptPreserveindent);
buf->b_p_cinw = xstrdup(p_cinw);
- COPY_OPT_SCTX(buf, BV_CINW);
+ COPY_OPT_SCTX(buf, kBufOptCinwords);
buf->b_p_lisp = p_lisp;
- COPY_OPT_SCTX(buf, BV_LISP);
+ COPY_OPT_SCTX(buf, kBufOptLisp);
// Don't copy 'syntax', it must be set
buf->b_p_syn = empty_string_option;
buf->b_p_smc = p_smc;
- COPY_OPT_SCTX(buf, BV_SMC);
+ COPY_OPT_SCTX(buf, kBufOptSynmaxcol);
buf->b_s.b_syn_isk = empty_string_option;
buf->b_s.b_p_spc = xstrdup(p_spc);
- COPY_OPT_SCTX(buf, BV_SPC);
+ COPY_OPT_SCTX(buf, kBufOptSpellcapcheck);
compile_cap_prog(&buf->b_s);
buf->b_s.b_p_spf = xstrdup(p_spf);
- COPY_OPT_SCTX(buf, BV_SPF);
+ COPY_OPT_SCTX(buf, kBufOptSpellfile);
buf->b_s.b_p_spl = xstrdup(p_spl);
- COPY_OPT_SCTX(buf, BV_SPL);
+ COPY_OPT_SCTX(buf, kBufOptSpelllang);
buf->b_s.b_p_spo = xstrdup(p_spo);
- COPY_OPT_SCTX(buf, BV_SPO);
+ COPY_OPT_SCTX(buf, kBufOptSpelloptions);
buf->b_s.b_p_spo_flags = spo_flags;
buf->b_p_inde = xstrdup(p_inde);
- COPY_OPT_SCTX(buf, BV_INDE);
+ COPY_OPT_SCTX(buf, kBufOptIndentexpr);
buf->b_p_indk = xstrdup(p_indk);
- COPY_OPT_SCTX(buf, BV_INDK);
+ COPY_OPT_SCTX(buf, kBufOptIndentkeys);
buf->b_p_fp = empty_string_option;
buf->b_p_fex = xstrdup(p_fex);
- COPY_OPT_SCTX(buf, BV_FEX);
+ COPY_OPT_SCTX(buf, kBufOptFormatexpr);
buf->b_p_sua = xstrdup(p_sua);
- COPY_OPT_SCTX(buf, BV_SUA);
+ COPY_OPT_SCTX(buf, kBufOptSuffixesadd);
buf->b_p_keymap = xstrdup(p_keymap);
- COPY_OPT_SCTX(buf, BV_KMAP);
+ COPY_OPT_SCTX(buf, kBufOptKeymap);
buf->b_kmap_state |= KEYMAP_INIT;
// This isn't really an option, but copying the langmap and IME
// state from the current buffer is better than resetting it.
buf->b_p_iminsert = p_iminsert;
- COPY_OPT_SCTX(buf, BV_IMI);
+ COPY_OPT_SCTX(buf, kBufOptIminsert);
buf->b_p_imsearch = p_imsearch;
- COPY_OPT_SCTX(buf, BV_IMS);
+ COPY_OPT_SCTX(buf, kBufOptImsearch);
// options that are normally global but also have a local value
// are not copied, start using the global value
@@ -5252,16 +5259,16 @@ void buf_copy_options(buf_T *buf, int flags)
buf->b_p_def = empty_string_option;
buf->b_p_inc = empty_string_option;
buf->b_p_inex = xstrdup(p_inex);
- COPY_OPT_SCTX(buf, BV_INEX);
+ COPY_OPT_SCTX(buf, kBufOptIncludeexpr);
buf->b_p_cot = empty_string_option;
buf->b_cot_flags = 0;
buf->b_p_dict = empty_string_option;
buf->b_p_tsr = empty_string_option;
buf->b_p_tsrfu = empty_string_option;
buf->b_p_qe = xstrdup(p_qe);
- COPY_OPT_SCTX(buf, BV_QE);
+ COPY_OPT_SCTX(buf, kBufOptQuoteescape);
buf->b_p_udf = p_udf;
- COPY_OPT_SCTX(buf, BV_UDF);
+ COPY_OPT_SCTX(buf, kBufOptUndofile);
buf->b_p_lw = empty_string_option;
buf->b_p_menc = empty_string_option;
@@ -5278,12 +5285,12 @@ void buf_copy_options(buf_T *buf, int flags)
}
} else {
buf->b_p_isk = xstrdup(p_isk);
- COPY_OPT_SCTX(buf, BV_ISK);
+ COPY_OPT_SCTX(buf, kBufOptIskeyword);
did_isk = true;
buf->b_p_ts = p_ts;
- COPY_OPT_SCTX(buf, BV_TS);
+ COPY_OPT_SCTX(buf, kBufOptTabstop);
buf->b_p_vts = xstrdup(p_vts);
- COPY_OPT_SCTX(buf, BV_VTS);
+ COPY_OPT_SCTX(buf, kBufOptVartabstop);
if (p_vts && p_vts != empty_string_option && !buf->b_p_vts_array) {
tabstop_set(p_vts, &buf->b_p_vts_array);
} else {
@@ -5294,7 +5301,7 @@ void buf_copy_options(buf_T *buf, int flags)
clear_string_option(&buf->b_p_bt);
}
buf->b_p_ma = p_ma;
- COPY_OPT_SCTX(buf, BV_MA);
+ COPY_OPT_SCTX(buf, kBufOptModifiable);
}
}
@@ -5645,7 +5652,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, char *fuzzystr, int *numM
}
}
char *str;
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
str = options[opt_idx].fullname;
if (is_option_hidden(opt_idx)) {
continue;
@@ -6306,11 +6313,11 @@ dict_T *get_winbuf_options(const int bufopt)
{
dict_T *const d = tv_dict_alloc();
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
vimoption_T *opt = &options[opt_idx];
- if ((bufopt && (opt->indir & PV_BUF))
- || (!bufopt && (opt->indir & PV_WIN))) {
+ if ((bufopt && (option_has_scope(opt_idx, kOptScopeBuf)))
+ || (!bufopt && (option_has_scope(opt_idx, kOptScopeWin)))) {
void *varp = get_varp(opt);
if (varp != NULL) {
@@ -6353,8 +6360,8 @@ Dict get_vimoption(String name, int scope, buf_T *buf, win_T *win, Arena *arena,
Dict get_all_vimoptions(Arena *arena)
{
- Dict retval = arena_dict(arena, kOptIndexCount);
- for (OptIndex opt_idx = 0; opt_idx < kOptIndexCount; opt_idx++) {
+ Dict retval = arena_dict(arena, kOptCount);
+ for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
Dict opt_dict = vimoption2dict(&options[opt_idx], OPT_GLOBAL, curbuf, curwin, arena);
PUT_C(retval, options[opt_idx].fullname, DICT_OBJ(opt_dict));
}
@@ -6363,15 +6370,16 @@ Dict get_all_vimoptions(Arena *arena)
static Dict vimoption2dict(vimoption_T *opt, int req_scope, buf_T *buf, win_T *win, Arena *arena)
{
+ OptIndex opt_idx = get_opt_idx(opt);
Dict dict = arena_dict(arena, 13);
PUT_C(dict, "name", CSTR_AS_OBJ(opt->fullname));
PUT_C(dict, "shortname", CSTR_AS_OBJ(opt->shortname));
const char *scope;
- if (opt->indir & PV_BUF) {
+ if (option_has_scope(opt_idx, kOptScopeBuf)) {
scope = "buf";
- } else if (opt->indir & PV_WIN) {
+ } else if (option_has_scope(opt_idx, kOptScopeWin)) {
scope = "win";
} else {
scope = "global";
@@ -6380,7 +6388,7 @@ static Dict vimoption2dict(vimoption_T *opt, int req_scope, buf_T *buf, win_T *w
PUT_C(dict, "scope", CSTR_AS_OBJ(scope));
// welcome to the jungle
- PUT_C(dict, "global_local", BOOLEAN_OBJ(opt->indir & PV_BOTH));
+ PUT_C(dict, "global_local", BOOLEAN_OBJ(option_is_global_local(opt_idx)));
PUT_C(dict, "commalist", BOOLEAN_OBJ(opt->flags & kOptFlagComma));
PUT_C(dict, "flaglist", BOOLEAN_OBJ(opt->flags & kOptFlagFlagList));
@@ -6391,11 +6399,11 @@ static Dict vimoption2dict(vimoption_T *opt, int req_scope, buf_T *buf, win_T *w
last_set = opt->last_set;
} else {
// Scope is either OPT_LOCAL or a fallback mode was requested.
- if (opt->indir & PV_BUF) {
- last_set = buf->b_p_script_ctx[opt->indir & PV_MASK];
+ if (option_has_scope(opt_idx, kOptScopeBuf)) {
+ last_set = buf->b_p_script_ctx[opt->scope_idx[kOptScopeBuf]];
}
- if (opt->indir & PV_WIN) {
- last_set = win->w_p_script_ctx[opt->indir & PV_MASK];
+ if (option_has_scope(opt_idx, kOptScopeWin)) {
+ last_set = win->w_p_script_ctx[opt->scope_idx[kOptScopeWin]];
}
if (req_scope != OPT_LOCAL && last_set.script_ctx.sc_sid == 0) {
last_set = opt->last_set;
@@ -6412,24 +6420,3 @@ static Dict vimoption2dict(vimoption_T *opt, int req_scope, buf_T *buf, win_T *w
return dict;
}
-
-/// Check if option is multitype (supports multiple types).
-static bool option_is_multitype(OptIndex opt_idx)
-{
- const OptTypeFlags type_flags = get_option(opt_idx)->type_flags;
- assert(type_flags != 0);
- return !is_power_of_two(type_flags);
-}
-
-/// Check if option supports a specific type.
-bool option_has_type(OptIndex opt_idx, OptValType type)
-{
- // Ensure that type flags variable can hold all types.
- STATIC_ASSERT(kOptValTypeSize <= sizeof(OptTypeFlags) * 8,
- "Option type_flags cannot fit all option types");
- // Ensure that the type is valid before accessing type_flags.
- assert(type > kOptValTypeNil && type < kOptValTypeSize);
- // Bitshift 1 by the value of type to get the type's corresponding flag, and check if it's set in
- // the type_flags bit field.
- return get_option(opt_idx)->type_flags & (1 << type);
-}
diff --git a/src/nvim/option.h b/src/nvim/option.h
index 138d90da97..cba5b00d95 100644
--- a/src/nvim/option.h
+++ b/src/nvim/option.h
@@ -13,56 +13,6 @@
#include "nvim/option_defs.h" // IWYU pragma: keep
#include "nvim/types_defs.h" // IWYU pragma: keep
-/// The options that are local to a window or buffer have "indir" set to one of
-/// these values. Special values:
-/// PV_NONE: global option.
-/// PV_WIN is added: window-local option
-/// PV_BUF is added: buffer-local option
-/// PV_BOTH is added: global option which also has a local value.
-enum {
- PV_BOTH = 0x1000,
- PV_WIN = 0x2000,
- PV_BUF = 0x4000,
- PV_MASK = 0x0fff,
-};
-#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
-#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
-#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
-
-/// WV_ and BV_ values get typecasted to this for the "indir" field
-typedef enum {
- PV_NONE = 0,
- PV_MAXVAL = 0xffff, ///< to avoid warnings for value out of range
-} idopt_T;
-
-// Options local to a window have a value local to a buffer and global to all
-// buffers. Indicate this by setting "var" to VAR_WIN.
-#define VAR_WIN ((char *)-1)
-
-typedef struct {
- char *fullname; ///< full option name
- char *shortname; ///< permissible abbreviation
- uint32_t flags; ///< see above
- OptTypeFlags type_flags; ///< option type flags, see OptValType
- void *var; ///< global option: pointer to variable;
- ///< window-local option: VAR_WIN;
- ///< buffer-local option: global value
- idopt_T indir; ///< global option: PV_NONE;
- ///< local option: indirect option index
- bool immutable; ///< option is immutable, trying to set its value will give an error.
-
- /// callback function to invoke after an option is modified to validate and
- /// apply the new value.
- opt_did_set_cb_T opt_did_set_cb;
-
- /// callback function to invoke when expanding possible values on the
- /// cmdline. Only useful for string options.
- opt_expand_cb_T opt_expand_cb;
-
- OptVal def_val; ///< default value
- LastSet last_set; ///< script in which the option was last set
-} vimoption_T;
-
/// flags for buf_copy_options()
enum {
BCO_ENTER = 1, ///< going to enter the buffer
@@ -85,13 +35,6 @@ typedef enum {
OPT_SKIPRTP = 0x80, ///< "skiprtp" in 'sessionoptions'
} OptionSetFlags;
-/// Return value from get_option_attrs().
-enum {
- SOPT_GLOBAL = 0x01, ///< Option has global value
- SOPT_WIN = 0x02, ///< Option has window-local value
- SOPT_BUF = 0x04, ///< Option has buffer-local value
-};
-
/// Get name of OptValType as a string.
static inline const char *optval_type_get_name(const OptValType type)
{
diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h
index e32edbf727..832e03148a 100644
--- a/src/nvim/option_defs.h
+++ b/src/nvim/option_defs.h
@@ -54,12 +54,20 @@ typedef enum {
kOptValTypeNumber,
kOptValTypeString,
} OptValType;
-
/// Always update this whenever a new option type is added.
#define kOptValTypeSize (kOptValTypeString + 1)
-
typedef uint32_t OptTypeFlags;
+/// Scopes that an option can support.
+typedef enum {
+ kOptScopeGlobal = 0, ///< Request global option value
+ kOptScopeWin, ///< Request window-local option value
+ kOptScopeBuf, ///< Request buffer-local option value
+} OptScope;
+/// Always update this whenever a new option scope is added.
+#define kOptScopeSize (kOptScopeBuf + 1)
+typedef uint8_t OptScopeFlags;
+
typedef union {
// boolean options are actually tri-states because they have a third "None" value.
TriState boolean;
@@ -161,9 +169,26 @@ typedef struct {
/// caller.
typedef int (*opt_expand_cb_T)(optexpand_T *args, int *numMatches, char ***matches);
-/// Requested option scopes for various functions in option.c
-typedef enum {
- kOptReqGlobal = 0, ///< Request global option value
- kOptReqWin = 1, ///< Request window-local option value
- kOptReqBuf = 2, ///< Request buffer-local option value
-} OptReqScope;
+typedef struct {
+ char *fullname; ///< full option name
+ char *shortname; ///< permissible abbreviation
+ uint32_t flags; ///< see above
+ OptTypeFlags type_flags; ///< option type flags, see OptValType
+ OptScopeFlags scope_flags; ///< option scope flags, see OptScope
+ void *var; ///< global option: pointer to variable;
+ ///< window-local option: NULL;
+ ///< buffer-local option: global value
+ ssize_t scope_idx[kOptScopeSize]; ///< index of option at every scope.
+ bool immutable; ///< option is immutable, trying to set it will give an error.
+
+ /// callback function to invoke after an option is modified to validate and
+ /// apply the new value.
+ opt_did_set_cb_T opt_did_set_cb;
+
+ /// callback function to invoke when expanding possible values on the
+ /// cmdline. Only useful for string options.
+ opt_expand_cb_T opt_expand_cb;
+
+ OptVal def_val; ///< default value
+ LastSet last_set; ///< script in which the option was last set
+} vimoption_T;
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 6fab0621f9..baacb2b858 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -7,7 +7,6 @@
--- @field alias? string|string[]
--- @field short_desc? string|fun(): string
--- @field varname? string
---- @field pv_name? string
--- @field type vim.option_type|vim.option_type[]
--- @field immutable? boolean
--- @field list? 'comma'|'onecomma'|'commacolon'|'onecommacolon'|'flags'|'flagscomma'
@@ -41,7 +40,7 @@
--- @field doc? string Default to show in options.txt
--- @field meta? integer|boolean|string Default to use in Lua meta files
---- @alias vim.option_scope 'global'|'buffer'|'window'
+--- @alias vim.option_scope 'global'|'buf'|'win'
--- @alias vim.option_type 'boolean'|'number'|'string'
--- @alias vim.option_value boolean|number|string
@@ -81,6 +80,8 @@ end
-- luacheck: ignore 621
return {
cstr = cstr,
+ --- @type string[]
+ valid_scopes = { 'global', 'buf', 'win' },
--- @type vim.option_meta[]
--- The order of the options MUST be alphabetic for ":set all".
options = {
@@ -173,7 +174,7 @@ return {
]=],
full_name = 'arabic',
redraw = { 'curswant' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('Arabic as a default second language'),
type = 'boolean',
},
@@ -236,7 +237,7 @@ return {
a different way.
]=],
full_name = 'autoindent',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('take indent for new line from previous line'),
type = 'boolean',
varname = 'p_ai',
@@ -256,7 +257,7 @@ return {
<
]=],
full_name = 'autoread',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('autom. read file when changed outside of Vim'),
type = 'boolean',
varname = 'p_ar',
@@ -457,7 +458,7 @@ return {
expand_cb = 'expand_set_backupcopy',
full_name = 'backupcopy',
list = 'onecomma',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_("make backup as a copy, don't rename the file"),
type = 'string',
varname = 'p_bkc',
@@ -667,7 +668,7 @@ return {
]=],
full_name = 'binary',
redraw = { 'statuslines' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('read/write/edit file in binary mode'),
type = 'boolean',
varname = 'p_bin',
@@ -695,7 +696,7 @@ return {
full_name = 'bomb',
no_mkrc = true,
redraw = { 'statuslines' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('a Byte Order Mark to the file'),
type = 'boolean',
varname = 'p_bomb',
@@ -729,7 +730,7 @@ return {
]=],
full_name = 'breakindent',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('wrapped line repeats indent'),
type = 'boolean',
},
@@ -771,7 +772,7 @@ return {
full_name = 'breakindentopt',
list = 'onecomma',
redraw = { 'current_buffer' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_("settings for 'breakindent'"),
type = 'string',
},
@@ -823,7 +824,7 @@ return {
expand_cb = 'expand_set_bufhidden',
full_name = 'bufhidden',
noglob = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('what to do when buffer is no longer in window'),
type = 'string',
varname = 'p_bh',
@@ -841,7 +842,7 @@ return {
]=],
full_name = 'buflisted',
noglob = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('whether the buffer shows up in the buffer list'),
tags = { 'E85' },
type = 'boolean',
@@ -900,7 +901,7 @@ return {
expand_cb = 'expand_set_buftype',
full_name = 'buftype',
noglob = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
tags = { 'E382' },
short_desc = N_('special type of buffer'),
type = 'string',
@@ -1015,7 +1016,7 @@ return {
full_name = 'channel',
no_mkrc = true,
nodefault = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('Channel connected to the buffer'),
type = 'number',
varname = 'p_channel',
@@ -1093,7 +1094,7 @@ return {
option or 'indentexpr'.
]=],
full_name = 'cindent',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('do C program indenting'),
type = 'boolean',
varname = 'p_cin',
@@ -1111,7 +1112,7 @@ return {
]=],
full_name = 'cinkeys',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_("keys that trigger indent when 'cindent' is set"),
type = 'string',
varname = 'p_cink',
@@ -1128,7 +1129,7 @@ return {
]=],
full_name = 'cinoptions',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_("how to do indenting when 'cindent' is set"),
type = 'string',
varname = 'p_cino',
@@ -1146,7 +1147,7 @@ return {
]=],
full_name = 'cinscopedecls',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_("words that are recognized by 'cino-g'"),
type = 'string',
varname = 'p_cinsd',
@@ -1165,7 +1166,7 @@ return {
]=],
full_name = 'cinwords',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_("words where 'si' and 'cin' add an indent"),
type = 'string',
varname = 'p_cinw',
@@ -1267,7 +1268,7 @@ return {
full_name = 'colorcolumn',
list = 'onecomma',
redraw = { 'current_window', 'highlight_only' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('columns to highlight'),
type = 'string',
},
@@ -1312,7 +1313,7 @@ return {
]=],
full_name = 'comments',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('patterns that can start a comment line'),
tags = { 'E524', 'E525' },
type = 'string',
@@ -1328,7 +1329,7 @@ return {
Used for |commenting| and to add markers for folding, see |fold-marker|.
]=],
full_name = 'commentstring',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('template for comments; used for fold marker'),
tags = { 'E537' },
type = 'string',
@@ -1385,7 +1386,7 @@ return {
expand_cb = 'expand_set_complete',
full_name = 'complete',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('specify how Insert mode completion works'),
tags = { 'E535' },
type = 'string',
@@ -1407,7 +1408,7 @@ return {
]=],
full_name = 'completefunc',
func = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
secure = true,
short_desc = N_('function to be used for Insert mode completion'),
type = 'string',
@@ -1483,7 +1484,7 @@ return {
expand_cb = 'expand_set_completeopt',
full_name = 'completeopt',
list = 'onecomma',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('options for Insert mode completion'),
type = 'string',
varname = 'p_cot',
@@ -1508,7 +1509,7 @@ return {
enable_if = 'BACKSLASH_IN_FILENAME',
expand_cb = 'expand_set_completeslash',
full_name = 'completeslash',
- scope = { 'buffer' },
+ scope = { 'buf' },
type = 'string',
varname = 'p_csl',
},
@@ -1537,7 +1538,7 @@ return {
full_name = 'concealcursor',
list = 'flags',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('whether concealable text is hidden in cursor line'),
type = 'string',
},
@@ -1566,7 +1567,7 @@ return {
]=],
full_name = 'conceallevel',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('whether concealable text is shown or hidden'),
type = 'number',
},
@@ -1604,7 +1605,7 @@ return {
See 'preserveindent'.
]=],
full_name = 'copyindent',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_("make 'autoindent' use existing indent structure"),
type = 'boolean',
varname = 'p_ci',
@@ -1865,8 +1866,7 @@ return {
taken into account.
]=],
full_name = 'cursorbind',
- pv_name = 'p_crbind',
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('move cursor in window as it moves in other windows'),
type = 'boolean',
},
@@ -1885,7 +1885,7 @@ return {
]=],
full_name = 'cursorcolumn',
redraw = { 'current_window', 'highlight_only' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('highlight the screen column of the cursor'),
type = 'boolean',
},
@@ -1900,7 +1900,7 @@ return {
]=],
full_name = 'cursorline',
redraw = { 'current_window', 'highlight_only' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('highlight the screen line of the cursor'),
type = 'boolean',
},
@@ -1928,7 +1928,7 @@ return {
full_name = 'cursorlineopt',
list = 'onecomma',
redraw = { 'current_window', 'highlight_only' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_("settings for 'cursorline'"),
type = 'string',
},
@@ -1979,7 +1979,7 @@ return {
<
]=],
full_name = 'define',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('pattern to be used to find a macro definition'),
type = 'string',
varname = 'p_def',
@@ -2036,7 +2036,7 @@ return {
full_name = 'dictionary',
list = 'onecomma',
normal_dname_chars = true,
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('list of file names used for keyword completion'),
type = 'string',
varname = 'p_dict',
@@ -2051,7 +2051,7 @@ return {
full_name = 'diff',
noglob = true,
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('diff mode for the current window'),
type = 'boolean',
},
@@ -2377,7 +2377,7 @@ return {
full_name = 'endoffile',
no_mkrc = true,
redraw = { 'statuslines' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('write CTRL-Z for last line in file'),
type = 'boolean',
varname = 'p_eof',
@@ -2403,7 +2403,7 @@ return {
full_name = 'endofline',
no_mkrc = true,
redraw = { 'statuslines' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('write <EOL> for last line in file'),
type = 'boolean',
varname = 'p_eol',
@@ -2448,7 +2448,7 @@ return {
]=],
expand = true,
full_name = 'equalprg',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
secure = true,
short_desc = N_('external program to use for "=" command'),
type = 'string',
@@ -2504,7 +2504,7 @@ return {
]=],
full_name = 'errorformat',
list = 'onecomma',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('description of the lines in the error file'),
type = 'string',
varname = 'p_efm',
@@ -2540,7 +2540,7 @@ return {
on, use CTRL-V<Tab>. See also |:retab| and |ins-expandtab|.
]=],
full_name = 'expandtab',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('use spaces when <Tab> is inserted'),
type = 'boolean',
varname = 'p_et',
@@ -2614,7 +2614,7 @@ return {
full_name = 'fileencoding',
no_mkrc = true,
redraw = { 'statuslines', 'current_buffer' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('file encoding for multi-byte text'),
tags = { 'E213' },
type = 'string',
@@ -2710,7 +2710,7 @@ return {
full_name = 'fileformat',
no_mkrc = true,
redraw = { 'curswant', 'statuslines' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('file format used for file I/O'),
type = 'string',
varname = 'p_ff',
@@ -2829,7 +2829,7 @@ return {
full_name = 'filetype',
noglob = true,
normal_fname_chars = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('type of file, used for autocommands'),
type = 'string',
varname = 'p_ft',
@@ -2904,7 +2904,7 @@ return {
full_name = 'fillchars',
list = 'onecomma',
redraw = { 'current_window' },
- scope = { 'global', 'window' },
+ scope = { 'global', 'win' },
short_desc = N_('characters to use for displaying special items'),
type = 'string',
varname = 'p_fcs',
@@ -2962,7 +2962,7 @@ return {
]=],
full_name = 'findfunc',
func = true,
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
secure = true,
short_desc = N_('function called for :find'),
tags = { 'E1514' },
@@ -2984,7 +2984,7 @@ return {
]=],
full_name = 'fixendofline',
redraw = { 'statuslines' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('make sure last line in file has <EOL>'),
type = 'boolean',
varname = 'p_fixeol',
@@ -3024,7 +3024,7 @@ return {
expand_cb = 'expand_set_foldcolumn',
full_name = 'foldcolumn',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('width of the column used to indicate folds'),
type = 'string',
},
@@ -3042,7 +3042,7 @@ return {
]=],
full_name = 'foldenable',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('set to display all folds open'),
type = 'boolean',
},
@@ -3067,7 +3067,7 @@ return {
full_name = 'foldexpr',
modelineexpr = true,
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('expression used when \'foldmethod\' is "expr"'),
type = 'string',
},
@@ -3083,7 +3083,7 @@ return {
]=],
full_name = 'foldignore',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('ignore lines when \'foldmethod\' is "indent"'),
type = 'string',
},
@@ -3100,7 +3100,7 @@ return {
]=],
full_name = 'foldlevel',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('close folds with a level higher than this'),
type = 'number',
},
@@ -3139,7 +3139,7 @@ return {
full_name = 'foldmarker',
list = 'onecomma',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('markers used when \'foldmethod\' is "marker"'),
tags = { 'E536' },
type = 'string',
@@ -3160,7 +3160,7 @@ return {
expand_cb = 'expand_set_foldmethod',
full_name = 'foldmethod',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('folding type'),
type = 'string',
},
@@ -3179,7 +3179,7 @@ return {
]=],
full_name = 'foldminlines',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('minimum number of lines for a fold to be closed'),
type = 'number',
},
@@ -3194,7 +3194,7 @@ return {
]=],
full_name = 'foldnestmax',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('maximum fold depth'),
type = 'number',
},
@@ -3267,7 +3267,7 @@ return {
full_name = 'foldtext',
modelineexpr = true,
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('expression used to display for a closed fold'),
type = 'string',
},
@@ -3319,7 +3319,7 @@ return {
]=],
full_name = 'formatexpr',
modelineexpr = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('expression used with "gq" command'),
type = 'string',
varname = 'p_fex',
@@ -3339,7 +3339,7 @@ return {
character and white space.
]=],
full_name = 'formatlistpat',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('pattern used to recognize a list header'),
type = 'string',
varname = 'p_flp',
@@ -3359,7 +3359,7 @@ return {
expand_cb = 'expand_set_formatoptions',
full_name = 'formatoptions',
list = 'flags',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('how automatic formatting is to be done'),
type = 'string',
varname = 'p_fo',
@@ -3382,7 +3382,7 @@ return {
]=],
expand = true,
full_name = 'formatprg',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
secure = true,
short_desc = N_('name of external program used with "gq" command'),
type = 'string',
@@ -3490,7 +3490,7 @@ return {
]=],
expand = true,
full_name = 'grepprg',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
secure = true,
short_desc = N_('program to use for ":grep"'),
type = 'string',
@@ -4132,8 +4132,7 @@ return {
It is also used for the argument of commands like "r" and "f".
]=],
full_name = 'iminsert',
- pv_name = 'p_imi',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('use :lmap or IM in Insert mode'),
type = 'number',
varname = 'p_iminsert',
@@ -4155,8 +4154,7 @@ return {
option to a valid keymap name.
]=],
full_name = 'imsearch',
- pv_name = 'p_ims',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('use :lmap or IM when typing a search pattern'),
type = 'number',
varname = 'p_imsearch',
@@ -4203,7 +4201,7 @@ return {
See |option-backslash| about including spaces and backslashes.
]=],
full_name = 'include',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('pattern to be used to find an include file'),
type = 'string',
varname = 'p_inc',
@@ -4245,7 +4243,7 @@ return {
]=],
full_name = 'includeexpr',
modelineexpr = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('expression used to process an include line'),
type = 'string',
varname = 'p_inex',
@@ -4340,7 +4338,7 @@ return {
]=],
full_name = 'indentexpr',
modelineexpr = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('expression used to obtain the indent of a line'),
type = 'string',
varname = 'p_inde',
@@ -4357,7 +4355,7 @@ return {
]=],
full_name = 'indentkeys',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_("keys that trigger indenting with 'indentexpr'"),
type = 'string',
varname = 'p_indk',
@@ -4376,7 +4374,7 @@ return {
With 'noinfercase' the match is used as-is.
]=],
full_name = 'infercase',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('adjust case of match for keyword completion'),
type = 'boolean',
varname = 'p_inf',
@@ -4507,7 +4505,7 @@ return {
]=],
full_name = 'iskeyword',
list = 'comma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('characters included in keywords'),
type = 'string',
varname = 'p_isk',
@@ -4608,9 +4606,8 @@ return {
full_name = 'keymap',
normal_fname_chars = true,
pri_mkrc = true,
- pv_name = 'p_kmap',
redraw = { 'statuslines', 'current_buffer' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('name of a keyboard mapping'),
type = 'string',
varname = 'p_keymap',
@@ -4662,7 +4659,7 @@ return {
]=],
expand = true,
full_name = 'keywordprg',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
secure = true,
short_desc = N_('program to use for the "K" command'),
type = 'string',
@@ -4833,7 +4830,7 @@ return {
]=],
full_name = 'linebreak',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('wrap long lines at a blank'),
type = 'boolean',
},
@@ -4897,7 +4894,7 @@ return {
calling an external program if 'equalprg' is empty.
]=],
full_name = 'lisp',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('indenting for Lisp'),
type = 'boolean',
varname = 'p_lisp',
@@ -4919,8 +4916,7 @@ return {
expand_cb = 'expand_set_lispoptions',
full_name = 'lispoptions',
list = 'onecomma',
- pv_name = 'p_lop',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('options for lisp indenting'),
type = 'string',
varname = 'p_lop',
@@ -4938,8 +4934,7 @@ return {
]=],
full_name = 'lispwords',
list = 'onecomma',
- pv_name = 'p_lw',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('words that change how lisp indenting works'),
type = 'string',
varname = 'p_lispwords',
@@ -4966,7 +4961,7 @@ return {
]=],
full_name = 'list',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('<Tab> and <EOL>'),
type = 'boolean',
},
@@ -5077,7 +5072,7 @@ return {
full_name = 'listchars',
list = 'onecomma',
redraw = { 'current_window' },
- scope = { 'global', 'window' },
+ scope = { 'global', 'win' },
short_desc = N_('characters for displaying in list mode'),
type = 'string',
varname = 'p_lcs',
@@ -5158,7 +5153,7 @@ return {
]=],
expand_cb = 'expand_set_encoding',
full_name = 'makeencoding',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('Converts the output of external commands'),
type = 'string',
varname = 'p_menc',
@@ -5185,7 +5180,7 @@ return {
]=],
expand = true,
full_name = 'makeprg',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
secure = true,
short_desc = N_('program to use for the ":make" command'),
type = 'string',
@@ -5215,7 +5210,7 @@ return {
]=],
full_name = 'matchpairs',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('pairs of characters that "%" can match'),
type = 'string',
varname = 'p_mps',
@@ -5377,7 +5372,7 @@ return {
no lines are checked. See |modeline|.
]=],
full_name = 'modeline',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('recognize modelines at start or end of file'),
type = 'boolean',
varname = 'p_ml',
@@ -5425,7 +5420,7 @@ return {
]=],
full_name = 'modifiable',
noglob = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('changes to the text are not possible'),
tags = { 'E21' },
type = 'boolean',
@@ -5461,7 +5456,7 @@ return {
full_name = 'modified',
no_mkrc = true,
redraw = { 'statuslines' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('buffer has been modified'),
type = 'boolean',
varname = 'p_mod',
@@ -5821,7 +5816,7 @@ return {
expand_cb = 'expand_set_nrformats',
full_name = 'nrformats',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('number formats recognized for CTRL-A command'),
type = 'string',
varname = 'p_nf',
@@ -5855,7 +5850,7 @@ return {
]=],
full_name = 'number',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('print the line number in front of each line'),
type = 'boolean',
},
@@ -5877,7 +5872,7 @@ return {
]=],
full_name = 'numberwidth',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('number of columns used for the line number'),
type = 'number',
},
@@ -5899,7 +5894,7 @@ return {
]=],
full_name = 'omnifunc',
func = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
secure = true,
short_desc = N_('function for filetype-specific completion'),
type = 'string',
@@ -6102,7 +6097,7 @@ return {
expand = true,
full_name = 'path',
list = 'comma',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('list of directories searched with "gf" et.al.'),
tags = { 'E343', 'E345', 'E347', 'E854' },
type = 'string',
@@ -6126,7 +6121,7 @@ return {
Use |:retab| to clean up white space.
]=],
full_name = 'preserveindent',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('preserve the indent structure when reindenting'),
type = 'boolean',
varname = 'p_pi',
@@ -6156,7 +6151,7 @@ return {
full_name = 'previewwindow',
noglob = true,
redraw = { 'statuslines' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('identifies the preview window'),
tags = { 'E590' },
type = 'boolean',
@@ -6275,7 +6270,7 @@ return {
text "foo\"bar\\" considered to be one string.
]=],
full_name = 'quoteescape',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('escape characters used in a string'),
type = 'string',
varname = 'p_qe',
@@ -6297,7 +6292,7 @@ return {
full_name = 'readonly',
noglob = true,
redraw = { 'statuslines' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('disallow writing the buffer'),
type = 'boolean',
varname = 'p_ro',
@@ -6413,7 +6408,7 @@ return {
]=],
full_name = 'relativenumber',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('show relative line number in front of each line'),
type = 'boolean',
},
@@ -6470,7 +6465,7 @@ return {
]=],
full_name = 'rightleft',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('window is right-to-left oriented'),
type = 'boolean',
},
@@ -6490,7 +6485,7 @@ return {
expand_cb = 'expand_set_rightleftcmd',
full_name = 'rightleftcmd',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('commands for which editing works right-to-left'),
type = 'string',
},
@@ -6672,8 +6667,7 @@ return {
]=],
full_name = 'scroll',
no_mkrc = true,
- pv_name = 'p_scroll',
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('lines to scroll with CTRL-U and CTRL-D'),
type = 'number',
},
@@ -6695,7 +6689,7 @@ return {
]=],
full_name = 'scrollback',
redraw = { 'current_buffer' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('lines to scroll with CTRL-U and CTRL-D'),
type = 'number',
varname = 'p_scbk',
@@ -6716,8 +6710,7 @@ return {
with scroll-binding, but ":split file" does not.
]=],
full_name = 'scrollbind',
- pv_name = 'p_scbind',
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('scroll in window as other windows scroll'),
type = 'boolean',
},
@@ -6754,7 +6747,7 @@ return {
< For scrolling horizontally see 'sidescrolloff'.
]=],
full_name = 'scrolloff',
- scope = { 'global', 'window' },
+ scope = { 'global', 'win' },
short_desc = N_('minimum nr. of lines above and below cursor'),
type = 'number',
varname = 'p_so',
@@ -7404,7 +7397,7 @@ return {
function to get the effective shiftwidth value.
]=],
full_name = 'shiftwidth',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('number of spaces to use for (auto)indent step'),
type = 'number',
varname = 'p_sw',
@@ -7502,7 +7495,7 @@ return {
]=],
full_name = 'showbreak',
redraw = { 'all_windows' },
- scope = { 'global', 'window' },
+ scope = { 'global', 'win' },
short_desc = N_('string to use at the start of wrapped lines'),
tags = { 'E595' },
type = 'string',
@@ -7676,7 +7669,7 @@ return {
<
]=],
full_name = 'sidescrolloff',
- scope = { 'global', 'window' },
+ scope = { 'global', 'win' },
short_desc = N_('min. nr. of columns to left and right of cursor'),
type = 'number',
varname = 'p_siso',
@@ -7706,7 +7699,7 @@ return {
expand_cb = 'expand_set_signcolumn',
full_name = 'signcolumn',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('when to display the sign column'),
type = 'string',
},
@@ -7752,7 +7745,7 @@ return {
right.
]=],
full_name = 'smartindent',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('smart autoindenting for C programs'),
type = 'boolean',
varname = 'p_si',
@@ -7792,9 +7785,8 @@ return {
NOTE: partly implemented, doesn't work yet for |gj| and |gk|.
]=],
full_name = 'smoothscroll',
- pv_name = 'p_sms',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_("scroll by screen lines when 'wrap' is set"),
type = 'boolean',
},
@@ -7819,7 +7811,7 @@ return {
to anything other than an empty string.
]=],
full_name = 'softtabstop',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('number of spaces that <Tab> uses while editing'),
type = 'number',
varname = 'p_sts',
@@ -7833,7 +7825,7 @@ return {
]=],
full_name = 'spell',
redraw = { 'current_window', 'highlight_only' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('spell checking'),
type = 'boolean',
},
@@ -7854,7 +7846,7 @@ return {
]=],
full_name = 'spellcapcheck',
redraw = { 'current_buffer', 'highlight_only' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('pattern to locate end of a sentence'),
type = 'string',
varname = 'p_spc',
@@ -7890,7 +7882,7 @@ return {
expand = true,
full_name = 'spellfile',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
secure = true,
short_desc = N_('files where |zg| and |zw| store words'),
type = 'string',
@@ -7943,7 +7935,7 @@ return {
full_name = 'spelllang',
list = 'onecomma',
redraw = { 'current_buffer', 'highlight_only' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('language(s) to do spell checking for'),
type = 'string',
varname = 'p_spl',
@@ -7968,7 +7960,7 @@ return {
full_name = 'spelloptions',
list = 'onecomma',
redraw = { 'current_buffer', 'highlight_only' },
- scope = { 'buffer' },
+ scope = { 'buf' },
secure = true,
type = 'string',
varname = 'p_spo',
@@ -8189,7 +8181,7 @@ return {
]=],
full_name = 'statuscolumn',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
secure = true,
short_desc = N_('custom format for the status column'),
type = 'string',
@@ -8413,7 +8405,7 @@ return {
full_name = 'statusline',
modelineexpr = true,
redraw = { 'statuslines' },
- scope = { 'global', 'window' },
+ scope = { 'global', 'win' },
short_desc = N_('custom format for the status line'),
tags = { 'E540', 'E542' },
type = 'string',
@@ -8454,7 +8446,7 @@ return {
]=],
full_name = 'suffixesadd',
list = 'onecomma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('suffixes added when searching for a file'),
type = 'string',
varname = 'p_sua',
@@ -8485,7 +8477,7 @@ return {
]=],
full_name = 'swapfile',
redraw = { 'statuslines' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('whether to use a swapfile for a buffer'),
type = 'boolean',
varname = 'p_swf',
@@ -8545,7 +8537,7 @@ return {
]=],
full_name = 'synmaxcol',
redraw = { 'current_buffer' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('maximum column to find syntax items'),
type = 'number',
varname = 'p_smc',
@@ -8582,7 +8574,7 @@ return {
full_name = 'syntax',
noglob = true,
normal_fname_chars = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('syntax to be loaded for current buffer'),
type = 'string',
varname = 'p_syn',
@@ -8705,7 +8697,7 @@ return {
]=],
full_name = 'tabstop',
redraw = { 'current_buffer' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('number of spaces that <Tab> in file uses'),
type = 'number',
varname = 'p_ts',
@@ -8784,7 +8776,7 @@ return {
]=],
expand_cb = 'expand_set_tagcase',
full_name = 'tagcase',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('how to handle case when searching in tags files'),
type = 'string',
varname = 'p_tc',
@@ -8805,7 +8797,7 @@ return {
]=],
full_name = 'tagfunc',
func = true,
- scope = { 'buffer' },
+ scope = { 'buf' },
secure = true,
short_desc = N_('function used to perform tag searches'),
type = 'string',
@@ -8862,7 +8854,7 @@ return {
expand = true,
full_name = 'tags',
list = 'onecomma',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('list of file names used by the tag command'),
tags = { 'E433' },
type = 'string',
@@ -9002,7 +8994,7 @@ return {
]=],
full_name = 'textwidth',
redraw = { 'current_buffer', 'highlight_only' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('maximum width of text that is being inserted'),
type = 'number',
varname = 'p_tw',
@@ -9031,7 +9023,7 @@ return {
full_name = 'thesaurus',
list = 'onecomma',
normal_dname_chars = true,
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('list of thesaurus files for keyword completion'),
type = 'string',
varname = 'p_tsr',
@@ -9051,7 +9043,7 @@ return {
]=],
full_name = 'thesaurusfunc',
func = true,
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
secure = true,
short_desc = N_('function used for thesaurus completion'),
type = 'string',
@@ -9285,7 +9277,7 @@ return {
When 'undofile' is turned off the undo file is NOT deleted.
]=],
full_name = 'undofile',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('save undo information in a file'),
type = 'boolean',
varname = 'p_udf',
@@ -9314,7 +9306,7 @@ return {
Also see |clear-undo|.
]=],
full_name = 'undolevels',
- scope = { 'global', 'buffer' },
+ scope = { 'global', 'buf' },
short_desc = N_('maximum number of changes that can be undone'),
type = 'number',
varname = 'p_ul',
@@ -9401,7 +9393,7 @@ return {
]=],
full_name = 'varsofttabstop',
list = 'comma',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('list of numbers of spaces that <Tab> uses while editing'),
type = 'string',
varname = 'p_vsts',
@@ -9424,7 +9416,7 @@ return {
full_name = 'vartabstop',
list = 'comma',
redraw = { 'current_buffer' },
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('list of numbers of spaces that <Tab> in file uses'),
type = 'string',
varname = 'p_vts',
@@ -9570,7 +9562,7 @@ return {
full_name = 'virtualedit',
list = 'onecomma',
redraw = { 'curswant' },
- scope = { 'global', 'window' },
+ scope = { 'global', 'win' },
short_desc = N_('when to use virtual editing'),
type = 'string',
varname = 'p_ve',
@@ -9917,7 +9909,7 @@ return {
full_name = 'winbar',
modelineexpr = true,
redraw = { 'statuslines' },
- scope = { 'global', 'window' },
+ scope = { 'global', 'win' },
short_desc = N_('custom format for the window bar'),
type = 'string',
varname = 'p_wbr',
@@ -9935,7 +9927,7 @@ return {
]=],
full_name = 'winblend',
redraw = { 'current_window', 'highlight_only' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('Controls transparency level for floating windows'),
type = 'number',
},
@@ -9974,8 +9966,7 @@ return {
command has a "!" modifier, it can force switching buffers.
]=],
full_name = 'winfixbuf',
- pv_name = 'p_wfb',
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('pin a window to a specific buffer'),
type = 'boolean',
},
@@ -9990,7 +9981,7 @@ return {
]=],
full_name = 'winfixheight',
redraw = { 'statuslines' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('keep window height when opening/closing windows'),
type = 'boolean',
},
@@ -10004,7 +9995,7 @@ return {
]=],
full_name = 'winfixwidth',
redraw = { 'statuslines' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('keep window width when opening/closing windows'),
type = 'boolean',
},
@@ -10065,7 +10056,7 @@ return {
full_name = 'winhighlight',
list = 'onecommacolon',
redraw = { 'current_window', 'highlight_only' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('Setup window-local highlights'),
type = 'string',
},
@@ -10156,7 +10147,7 @@ return {
]=],
full_name = 'wrap',
redraw = { 'current_window' },
- scope = { 'window' },
+ scope = { 'win' },
short_desc = N_('lines wrap and continue on the next line'),
type = 'boolean',
},
@@ -10173,7 +10164,7 @@ return {
See also 'formatoptions' and |ins-textwidth|.
]=],
full_name = 'wrapmargin',
- scope = { 'buffer' },
+ scope = { 'buf' },
short_desc = N_('chars from the right where wrapping starts'),
type = 'number',
varname = 'p_wm',
diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c
index 9095d4e8c9..06b3aa0411 100644
--- a/src/nvim/textformat.c
+++ b/src/nvim/textformat.c
@@ -863,7 +863,7 @@ int fex_format(linenr_T lnum, long count, int c)
// Make a copy, the option could be changed while calling it.
char *fex = xstrdup(curbuf->b_p_fex);
- current_sctx = curbuf->b_p_script_ctx[BV_FEX].script_ctx;
+ current_sctx = curbuf->b_p_script_ctx[kBufOptFormatexpr].script_ctx;
// Evaluate the function.
if (use_sandbox) {
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 5f17d3220d..c3f3e075f1 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -6755,8 +6755,8 @@ void win_comp_scroll(win_T *wp)
if (wp->w_p_scr != old_w_p_scr) {
// Used by "verbose set scroll".
- wp->w_p_script_ctx[WV_SCROLL].script_ctx.sc_sid = SID_WINLAYOUT;
- wp->w_p_script_ctx[WV_SCROLL].script_ctx.sc_lnum = 0;
+ wp->w_p_script_ctx[kWinOptScroll].script_ctx.sc_sid = SID_WINLAYOUT;
+ wp->w_p_script_ctx[kWinOptScroll].script_ctx.sc_lnum = 0;
}
}
diff --git a/src/nvim/winfloat.c b/src/nvim/winfloat.c
index 4698487708..b8a51d686d 100644
--- a/src/nvim/winfloat.c
+++ b/src/nvim/winfloat.c
@@ -412,8 +412,8 @@ win_T *win_float_create(bool enter, bool new_buf)
return handle_error_and_cleanup(wp, &err);
}
buf->b_p_bl = false; // unlist
- set_option_direct_for(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("wipe"), OPT_LOCAL, 0, kOptReqBuf,
- buf);
+ set_option_direct_for(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("wipe"), OPT_LOCAL, 0,
+ kOptScopeBuf, buf);
win_set_buf(wp, buf, &err);
if (ERROR_SET(&err)) {
return handle_error_and_cleanup(wp, &err);