diff options
-rw-r--r-- | runtime/lua/vim/filetype.lua | 2 | ||||
-rwxr-xr-x | scripts/gen_vimdoc.py | 6 | ||||
-rw-r--r-- | src/nvim/api/options.c | 22 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 7 |
4 files changed, 28 insertions, 9 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 320d6a2a5b..6c4894208f 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -33,7 +33,7 @@ end function M.getlines(bufnr, start_lnum, end_lnum) if not end_lnum then -- Return a single line as a string - return api.nvim_buf_get_lines(bufnr, start_lnum - 1, start_lnum, false)[1] + return api.nvim_buf_get_lines(bufnr, start_lnum - 1, start_lnum, false)[1] or '' end return api.nvim_buf_get_lines(bufnr, start_lnum - 1, end_lnum, false) end diff --git a/scripts/gen_vimdoc.py b/scripts/gen_vimdoc.py index 220b099df5..22fd155d32 100755 --- a/scripts/gen_vimdoc.py +++ b/scripts/gen_vimdoc.py @@ -59,8 +59,8 @@ if sys.version_info < MIN_PYTHON_VERSION: print("requires Python {}.{}+".format(*MIN_PYTHON_VERSION)) sys.exit(1) -doxygen_version = tuple([int(i) for i in subprocess.check_output(["doxygen", "-v"], - universal_newlines=True).split()[0].split('.')]) +doxygen_version = tuple((int(i) for i in subprocess.check_output(["doxygen", "-v"], + universal_newlines=True).split()[0].split('.'))) if doxygen_version < MIN_DOXYGEN_VERSION: print("\nRequires doxygen {}.{}.{}+".format(*MIN_DOXYGEN_VERSION)) @@ -1096,7 +1096,6 @@ def main(config, args): docs = '' - i = 0 for filename in CONFIG[target]['section_order']: try: title, helptag, section_doc = sections.pop(filename) @@ -1104,7 +1103,6 @@ def main(config, args): msg(f'warning: empty docs, skipping (target={target}): {filename}') msg(f' existing docs: {sections.keys()}') continue - i += 1 if filename not in CONFIG[target]['append_only']: docs += sep docs += '\n%s%s' % (title, diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c index 19ce25f676..8c174fc129 100644 --- a/src/nvim/api/options.c +++ b/src/nvim/api/options.c @@ -162,6 +162,19 @@ void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error return; } + // If: + // - window id is provided + // - scope is not provided + // - 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 (opt_type == SREQ_WIN && scope == 0) { + int flags = get_option_value_strict(name.data, NULL, NULL, opt_type, to); + if (flags & SOPT_GLOBAL) { + scope = OPT_LOCAL; + } + } + long numval = 0; char *stringval = NULL; @@ -460,11 +473,12 @@ void set_option_to(uint64_t channel_id, void *to, int type, String name, Object stringval = value.data.string.data; } - WITH_SCRIPT_CONTEXT(channel_id, { - const int opt_flags = (type == SREQ_WIN && !(flags & SOPT_GLOBAL)) - ? 0 : (type == SREQ_GLOBAL) - ? OPT_GLOBAL : OPT_LOCAL; + // For global-win-local options -> setlocal + // For win-local options -> setglobal and setlocal (opt_flags == 0) + const int opt_flags = (type == SREQ_WIN && !(flags & SOPT_GLOBAL)) ? 0 : + (type == SREQ_GLOBAL) ? OPT_GLOBAL : OPT_LOCAL; + WITH_SCRIPT_CONTEXT(channel_id, { access_option_value_for(name.data, &numval, &stringval, opt_flags, type, to, false, err); }); } diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 646c5ac8ca..883e0e373b 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1428,6 +1428,13 @@ describe('lua stdlib', function() vim.wo[1000].cole = 0 ]] eq(0, funcs.luaeval "vim.wo[1000].cole") + + -- Can handle global-local values + exec_lua [[vim.o.scrolloff = 100]] + exec_lua [[vim.wo.scrolloff = 200]] + eq(200, funcs.luaeval "vim.wo.scrolloff") + exec_lua [[vim.wo.scrolloff = -1]] + eq(100, funcs.luaeval "vim.wo.scrolloff") end) describe('vim.opt', function() |