refactor(options): deprecate nvim[_buf|_win]_[gs]et_option

Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Co-authored-by: famiu <famiuhaque@protonmail.com>
This commit is contained in:
Lewis Russell 2022-12-19 16:37:45 +00:00 committed by Famiu Haque
parent e3e6fadfd8
commit 1fe1bb084d
87 changed files with 725 additions and 785 deletions

View File

@ -486,7 +486,7 @@ Example: create a float with scratch buffer: >vim
\ 'row': 1, 'anchor': 'NW', 'style': 'minimal'} \ 'row': 1, 'anchor': 'NW', 'style': 'minimal'}
let win = nvim_open_win(buf, 0, opts) let win = nvim_open_win(buf, 0, opts)
" optional: change highlight, otherwise Pmenu is used " optional: change highlight, otherwise Pmenu is used
call nvim_win_set_option(win, 'winhl', 'Normal:MyHighlight') call nvim_set_option_value('winhl', 'Normal:MyHighlight', {'win': win})
< <
============================================================================== ==============================================================================
@ -1917,25 +1917,6 @@ nvim_parse_cmd({str}, {opts}) *nvim_parse_cmd()*
============================================================================== ==============================================================================
Options Functions *api-options* Options Functions *api-options*
nvim_buf_get_option({buffer}, {name}) *nvim_buf_get_option()*
Gets a buffer option value
Parameters: ~
• {buffer} Buffer handle, or 0 for current buffer
• {name} Option name
Return: ~
Option value
nvim_buf_set_option({buffer}, {name}, {value}) *nvim_buf_set_option()*
Sets a buffer option value. Passing `nil` as value deletes the option
(only works if there's a global fallback)
Parameters: ~
• {buffer} Buffer handle, or 0 for current buffer
• {name} Option name
• {value} Option value
nvim_get_all_options_info() *nvim_get_all_options_info()* nvim_get_all_options_info() *nvim_get_all_options_info()*
Gets the option information for all options. Gets the option information for all options.
@ -1945,15 +1926,6 @@ nvim_get_all_options_info() *nvim_get_all_options_info()*
Return: ~ Return: ~
dictionary of all options dictionary of all options
nvim_get_option({name}) *nvim_get_option()*
Gets the global value of an option.
Parameters: ~
• {name} Option name
Return: ~
Option value (global)
nvim_get_option_info2({name}, {*opts}) *nvim_get_option_info2()* nvim_get_option_info2({name}, {*opts}) *nvim_get_option_info2()*
Gets the option information for one option from arbitrary buffer or window Gets the option information for one option from arbitrary buffer or window
@ -2010,13 +1982,6 @@ nvim_get_option_value({name}, {*opts}) *nvim_get_option_value()*
Return: ~ Return: ~
Option value Option value
nvim_set_option({name}, {value}) *nvim_set_option()*
Sets the global value of an option.
Parameters: ~
• {name} Option name
• {value} New option value
*nvim_set_option_value()* *nvim_set_option_value()*
nvim_set_option_value({name}, {value}, {*opts}) nvim_set_option_value({name}, {value}, {*opts})
Sets the value of an option. The behavior of this function matches that of Sets the value of an option. The behavior of this function matches that of
@ -2034,25 +1999,6 @@ nvim_set_option_value({name}, {value}, {*opts})
• win: |window-ID|. Used for setting window local option. • win: |window-ID|. Used for setting window local option.
• buf: Buffer number. Used for setting buffer local option. • buf: Buffer number. Used for setting buffer local option.
nvim_win_get_option({window}, {name}) *nvim_win_get_option()*
Gets a window option value
Parameters: ~
• {window} Window handle, or 0 for current window
• {name} Option name
Return: ~
Option value
nvim_win_set_option({window}, {name}, {value}) *nvim_win_set_option()*
Sets a window option value. Passing `nil` as value deletes the option
(only works if there's a global fallback)
Parameters: ~
• {window} Window handle, or 0 for current window
• {name} Option name
• {value} Option value
============================================================================== ==============================================================================
Buffer Functions *api-buffer* Buffer Functions *api-buffer*

View File

@ -21,6 +21,12 @@ API
- *nvim_get_hl_by_id()* Use |nvim_get_hl()| instead. - *nvim_get_hl_by_id()* Use |nvim_get_hl()| instead.
- *nvim_exec()* Use |nvim_exec2()| instead. - *nvim_exec()* Use |nvim_exec2()| instead.
- *nvim_get_option_info()* Use |nvim_get_option_info2()| instead. - *nvim_get_option_info()* Use |nvim_get_option_info2()| instead.
- *nvim_buf_get_option()* Use |nvim_get_option_value()| instead.
- *nvim_buf_set_option()* Use |nvim_set_option_value()| instead.
- *nvim_get_option()* Use |nvim_get_option_value()| instead.
- *nvim_set_option()* Use |nvim_set_option_value()| instead.
- *nvim_win_get_option()* Use |nvim_get_option_value()| instead.
- *nvim_win_set_option()* Use |nvim_set_option_value()| instead.
COMMANDS COMMANDS
- *:rv* *:rviminfo* Deprecated alias to |:rshada| command. - *:rv* *:rviminfo* Deprecated alias to |:rshada| command.

View File

@ -800,8 +800,8 @@ formatexpr({opts}) *vim.lsp.formatexpr()*
Currently only supports a single client. This can be set via `setlocal Currently only supports a single client. This can be set via `setlocal
formatexpr=v:lua.vim.lsp.formatexpr()` but will typically or in formatexpr=v:lua.vim.lsp.formatexpr()` but will typically or in
`on_attach` via `vim.api.nvim_buf_set_option(bufnr, 'formatexpr', `on_attach` via `vim.bo[bufnr].formatexpr =
'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})')`. 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})'`.
Parameters: ~ Parameters: ~
• {opts} (table) options for customizing the formatting expression • {opts} (table) options for customizing the formatting expression

View File

@ -401,7 +401,7 @@ For example consider the following Lua omnifunc handler: >lua
return {'stuff', 'steam', 'strange things'} return {'stuff', 'steam', 'strange things'}
end end
end end
vim.api.nvim_buf_set_option(0, 'omnifunc', 'v:lua.mymod.omnifunc') vim.bo[buf].omnifunc = 'v:lua.mymod.omnifunc'
Note: The module ("mymod" in the above example) must either be a Lua global, Note: The module ("mymod" in the above example) must either be a Lua global,
or use require() as shown above to access it from a package. or use require() as shown above to access it from a package.

View File

@ -84,7 +84,7 @@ The following deprecated functions or APIs were removed.
============================================================================== ==============================================================================
DEPRECATIONS *news-deprecations* DEPRECATIONS *news-deprecations*
The following functions are now deprecated and will be removed in the next The following functions are now deprecated and will be removed in a future
release. release.
• Checkhealth functions: • Checkhealth functions:
@ -94,4 +94,12 @@ release.
- |health#report_start|, |vim.health.report_start()| Use |vim.health.start()| instead. - |health#report_start|, |vim.health.report_start()| Use |vim.health.start()| instead.
- |health#report_warn|, |vim.health.report_warn()| Use |vim.health.warn()| instead. - |health#report_warn|, |vim.health.report_warn()| Use |vim.health.warn()| instead.
• |API| functions:
- |nvim_buf_get_option()| Use |nvim_get_option_value()| instead.
- |nvim_buf_set_option()| Use |nvim_set_option_value()| instead.
- |nvim_get_option()| Use |nvim_get_option_value()| instead.
- |nvim_set_option()| Use |nvim_set_option_value()| instead.
- |nvim_win_get_option()| Use |nvim_get_option_value()| instead.
- |nvim_win_set_option()| Use |nvim_set_option_value()| instead.
vim:tw=78:ts=8:sw=2:et:ft=help:norl: vim:tw=78:ts=8:sw=2:et:ft=help:norl:

View File

@ -8,12 +8,8 @@ local sync = require('vim.lsp.sync')
local semantic_tokens = require('vim.lsp.semantic_tokens') local semantic_tokens = require('vim.lsp.semantic_tokens')
local api = vim.api local api = vim.api
local nvim_err_writeln, nvim_buf_get_lines, nvim_command, nvim_buf_get_option, nvim_exec_autocmds = local nvim_err_writeln, nvim_buf_get_lines, nvim_command, nvim_exec_autocmds =
api.nvim_err_writeln, api.nvim_err_writeln, api.nvim_buf_get_lines, api.nvim_command, api.nvim_exec_autocmds
api.nvim_buf_get_lines,
api.nvim_command,
api.nvim_buf_get_option,
api.nvim_exec_autocmds
local uv = vim.loop local uv = vim.loop
local tbl_isempty, tbl_extend = vim.tbl_isempty, vim.tbl_extend local tbl_isempty, tbl_extend = vim.tbl_isempty, vim.tbl_extend
local validate = vim.validate local validate = vim.validate
@ -137,7 +133,7 @@ local format_line_ending = {
---@param bufnr (number) ---@param bufnr (number)
---@return string ---@return string
local function buf_get_line_ending(bufnr) local function buf_get_line_ending(bufnr)
return format_line_ending[nvim_buf_get_option(bufnr, 'fileformat')] or '\n' return format_line_ending[vim.bo[bufnr].fileformat] or '\n'
end end
local client_index = 0 local client_index = 0
@ -319,7 +315,7 @@ end
local function buf_get_full_text(bufnr) local function buf_get_full_text(bufnr)
local line_ending = buf_get_line_ending(bufnr) local line_ending = buf_get_line_ending(bufnr)
local text = table.concat(nvim_buf_get_lines(bufnr, 0, -1, true), line_ending) local text = table.concat(nvim_buf_get_lines(bufnr, 0, -1, true), line_ending)
if nvim_buf_get_option(bufnr, 'eol') then if vim.bo[bufnr].eol then
text = text .. line_ending text = text .. line_ending
end end
return text return text
@ -709,7 +705,7 @@ local function text_document_did_open_handler(bufnr, client)
if not api.nvim_buf_is_loaded(bufnr) then if not api.nvim_buf_is_loaded(bufnr) then
return return
end end
local filetype = nvim_buf_get_option(bufnr, 'filetype') local filetype = vim.bo[bufnr].filetype
local params = { local params = {
textDocument = { textDocument = {
@ -2177,7 +2173,7 @@ end
--- ---
--- Currently only supports a single client. This can be set via --- Currently only supports a single client. This can be set via
--- `setlocal formatexpr=v:lua.vim.lsp.formatexpr()` but will typically or in `on_attach` --- `setlocal formatexpr=v:lua.vim.lsp.formatexpr()` but will typically or in `on_attach`
--- via ``vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})')``. --- via ``vim.bo[bufnr].formatexpr = 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})'``.
--- ---
---@param opts table options for customizing the formatting expression which takes the ---@param opts table options for customizing the formatting expression which takes the
--- following optional keys: --- following optional keys:

View File

@ -454,7 +454,7 @@ function M.signature_help(_, result, ctx, config)
local client = vim.lsp.get_client_by_id(ctx.client_id) local client = vim.lsp.get_client_by_id(ctx.client_id)
local triggers = local triggers =
vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters') vim.tbl_get(client.server_capabilities, 'signatureHelpProvider', 'triggerCharacters')
local ft = api.nvim_buf_get_option(ctx.bufnr, 'filetype') local ft = vim.bo[ctx.bufnr].filetype
local lines, hl = util.convert_signature_help_to_markdown_lines(result, ft, triggers) local lines, hl = util.convert_signature_help_to_markdown_lines(result, ft, triggers)
lines = util.trim_empty_lines(lines) lines = util.trim_empty_lines(lines)
if vim.tbl_isempty(lines) then if vim.tbl_isempty(lines) then

View File

@ -401,7 +401,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
if not api.nvim_buf_is_loaded(bufnr) then if not api.nvim_buf_is_loaded(bufnr) then
vim.fn.bufload(bufnr) vim.fn.bufload(bufnr)
end end
api.nvim_buf_set_option(bufnr, 'buflisted', true) vim.bo[bufnr].buflisted = true
-- Fix reversed range and indexing each text_edits -- Fix reversed range and indexing each text_edits
local index = 0 local index = 0
@ -530,11 +530,7 @@ function M.apply_text_edits(text_edits, bufnr, offset_encoding)
-- Remove final line if needed -- Remove final line if needed
local fix_eol = has_eol_text_edit local fix_eol = has_eol_text_edit
fix_eol = fix_eol fix_eol = fix_eol and (vim.bo[bufnr].eol or (vim.bo[bufnr].fixeol and not vim.bo[bufnr].binary))
and (
api.nvim_buf_get_option(bufnr, 'eol')
or (api.nvim_buf_get_option(bufnr, 'fixeol') and not api.nvim_buf_get_option(bufnr, 'binary'))
)
fix_eol = fix_eol and get_line(bufnr, max - 1) == '' fix_eol = fix_eol and get_line(bufnr, max - 1) == ''
if fix_eol then if fix_eol then
api.nvim_buf_set_lines(bufnr, -2, -1, false, {}) api.nvim_buf_set_lines(bufnr, -2, -1, false, {})
@ -1076,7 +1072,7 @@ function M.make_floating_popup_options(width, height, opts)
local wincol = opts.relative == 'mouse' and vim.fn.getmousepos().column or vim.fn.wincol() local wincol = opts.relative == 'mouse' and vim.fn.getmousepos().column or vim.fn.wincol()
if wincol + width + (opts.offset_x or 0) <= api.nvim_get_option('columns') then if wincol + width + (opts.offset_x or 0) <= vim.o.columns then
anchor = anchor .. 'W' anchor = anchor .. 'W'
col = 0 col = 0
else else
@ -1142,7 +1138,7 @@ function M.show_document(location, offset_encoding, opts)
or focus and api.nvim_get_current_win() or focus and api.nvim_get_current_win()
or create_window_without_focus() or create_window_without_focus()
api.nvim_buf_set_option(bufnr, 'buflisted', true) vim.bo[bufnr].buflisted = true
api.nvim_win_set_buf(win, bufnr) api.nvim_win_set_buf(win, bufnr)
if focus then if focus then
api.nvim_set_current_win(win) api.nvim_set_current_win(win)
@ -1201,12 +1197,12 @@ function M.preview_location(location, opts)
end end
local range = location.targetRange or location.range local range = location.targetRange or location.range
local contents = api.nvim_buf_get_lines(bufnr, range.start.line, range['end'].line + 1, false) local contents = api.nvim_buf_get_lines(bufnr, range.start.line, range['end'].line + 1, false)
local syntax = api.nvim_buf_get_option(bufnr, 'syntax') local syntax = vim.bo[bufnr].syntax
if syntax == '' then if syntax == '' then
-- When no syntax is set, we use filetype as fallback. This might not result -- When no syntax is set, we use filetype as fallback. This might not result
-- in a valid syntax definition. See also ft detection in stylize_markdown. -- in a valid syntax definition. See also ft detection in stylize_markdown.
-- An empty syntax is more common now with TreeSitter, since TS disables syntax. -- An empty syntax is more common now with TreeSitter, since TS disables syntax.
syntax = api.nvim_buf_get_option(bufnr, 'filetype') syntax = vim.bo[bufnr].filetype
end end
opts = opts or {} opts = opts or {}
opts.focus_id = 'location' opts.focus_id = 'location'
@ -1665,7 +1661,7 @@ function M.open_floating_preview(contents, syntax, opts)
contents = M.stylize_markdown(floating_bufnr, contents, opts) contents = M.stylize_markdown(floating_bufnr, contents, opts)
else else
if syntax then if syntax then
api.nvim_buf_set_option(floating_bufnr, 'syntax', syntax) vim.bo[floating_bufnr].syntax = syntax
end end
api.nvim_buf_set_lines(floating_bufnr, 0, -1, true, contents) api.nvim_buf_set_lines(floating_bufnr, 0, -1, true, contents)
end end
@ -1681,16 +1677,16 @@ function M.open_floating_preview(contents, syntax, opts)
local float_option = M.make_floating_popup_options(width, height, opts) local float_option = M.make_floating_popup_options(width, height, opts)
local floating_winnr = api.nvim_open_win(floating_bufnr, false, float_option) local floating_winnr = api.nvim_open_win(floating_bufnr, false, float_option)
if do_stylize then if do_stylize then
api.nvim_win_set_option(floating_winnr, 'conceallevel', 2) vim.wo[floating_winnr].conceallevel = 2
api.nvim_win_set_option(floating_winnr, 'concealcursor', 'n') vim.wo[floating_winnr].concealcursor = 'n'
end end
-- disable folding -- disable folding
api.nvim_win_set_option(floating_winnr, 'foldenable', false) vim.wo[floating_winnr].foldenable = false
-- soft wrapping -- soft wrapping
api.nvim_win_set_option(floating_winnr, 'wrap', opts.wrap) vim.wo[floating_winnr].wrap = opts.wrap
api.nvim_buf_set_option(floating_bufnr, 'modifiable', false) vim.bo[floating_bufnr].modifiable = false
api.nvim_buf_set_option(floating_bufnr, 'bufhidden', 'wipe') vim.bo[floating_bufnr].bufhidden = 'wipe'
api.nvim_buf_set_keymap( api.nvim_buf_set_keymap(
floating_bufnr, floating_bufnr,
'n', 'n',

View File

@ -1328,11 +1328,11 @@ function! s:OpenHoverPreview(lines, filetype) abort
\ }) \ })
if a:filetype isnot v:null if a:filetype isnot v:null
call nvim_win_set_option(float_win_id, 'filetype', a:filetype) call nvim_set_option_value('filetype', a:filetype, { 'win' : float_win_id })
endif endif
call nvim_buf_set_option(buf, 'modified', v:false) call nvim_set_option_value('modified', v:false, { 'buf' : buf })
call nvim_buf_set_option(buf, 'modifiable', v:false) call nvim_set_option_value('modifiable', v:false, { 'buf' : buf })
" Unlike preview window, :pclose does not close window. Instead, close " Unlike preview window, :pclose does not close window. Instead, close
" hover window automatically when cursor is moved. " hover window automatically when cursor is moved.

View File

@ -8,6 +8,7 @@
#include "nvim/api/buffer.h" #include "nvim/api/buffer.h"
#include "nvim/api/deprecated.h" #include "nvim/api/deprecated.h"
#include "nvim/api/extmark.h" #include "nvim/api/extmark.h"
#include "nvim/api/options.h"
#include "nvim/api/private/defs.h" #include "nvim/api/private/defs.h"
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/api/private/validate.h" #include "nvim/api/private/validate.h"
@ -522,3 +523,222 @@ Dictionary nvim_get_option_info(String name, Error *err)
{ {
return get_vimoption(name, OPT_GLOBAL, curbuf, curwin, err); return get_vimoption(name, OPT_GLOBAL, curbuf, curwin, err);
} }
/// Sets the global value of an option.
///
/// @deprecated
/// @param channel_id
/// @param name Option name
/// @param value New option value
/// @param[out] err Error details, if any
void nvim_set_option(uint64_t channel_id, String name, Object value, Error *err)
FUNC_API_SINCE(1)
{
set_option_to(channel_id, NULL, SREQ_GLOBAL, name, value, err);
}
/// Gets the global value of an option.
///
/// @deprecated
/// @param name Option name
/// @param[out] err Error details, if any
/// @return Option value (global)
Object nvim_get_option(String name, Arena *arena, Error *err)
FUNC_API_SINCE(1)
{
return get_option_from(NULL, SREQ_GLOBAL, name, err);
}
/// Gets a buffer option value
///
/// @deprecated
/// @param buffer Buffer handle, or 0 for current buffer
/// @param name Option name
/// @param[out] err Error details, if any
/// @return Option value
Object nvim_buf_get_option(Buffer buffer, String name, Arena *arena, Error *err)
FUNC_API_SINCE(1)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) {
return (Object)OBJECT_INIT;
}
return get_option_from(buf, SREQ_BUF, name, err);
}
/// Sets a buffer option value. Passing `nil` as value deletes the option (only
/// works if there's a global fallback)
///
/// @deprecated
/// @param channel_id
/// @param buffer Buffer handle, or 0 for current buffer
/// @param name Option name
/// @param value Option value
/// @param[out] err Error details, if any
void nvim_buf_set_option(uint64_t channel_id, Buffer buffer, String name, Object value, Error *err)
FUNC_API_SINCE(1)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) {
return;
}
set_option_to(channel_id, buf, SREQ_BUF, name, value, err);
}
/// Gets a window option value
///
/// @deprecated
/// @param window Window handle, or 0 for current window
/// @param name Option name
/// @param[out] err Error details, if any
/// @return Option value
Object nvim_win_get_option(Window window, String name, Arena *arena, Error *err)
FUNC_API_SINCE(1)
{
win_T *win = find_window_by_handle(window, err);
if (!win) {
return (Object)OBJECT_INIT;
}
return get_option_from(win, SREQ_WIN, name, err);
}
/// Sets a window option value. Passing `nil` as value deletes the option (only
/// works if there's a global fallback)
///
/// @deprecated
/// @param channel_id
/// @param window Window handle, or 0 for current window
/// @param name Option name
/// @param value Option value
/// @param[out] err Error details, if any
void nvim_win_set_option(uint64_t channel_id, Window window, String name, Object value, Error *err)
FUNC_API_SINCE(1)
{
win_T *win = find_window_by_handle(window, err);
if (!win) {
return;
}
set_option_to(channel_id, win, SREQ_WIN, name, value, err);
}
/// Gets the value of a global or local (buffer, window) option.
///
/// @param from If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer
/// to the window or buffer.
/// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF`
/// @param name The option name
/// @param[out] err Details of an error that may have occurred
/// @return the option value
static Object get_option_from(void *from, int type, String name, Error *err)
{
Object rv = OBJECT_INIT;
VALIDATE_S(name.size > 0, "option name", "<empty>", {
return rv;
});
// Return values
int64_t numval;
char *stringval = NULL;
int flags = get_option_value_strict(name.data, &numval, &stringval, type, from);
VALIDATE_S(flags != 0, "option name", name.data, {
return rv;
});
if (flags & SOPT_BOOL) {
rv.type = kObjectTypeBoolean;
rv.data.boolean = numval ? true : false;
} else if (flags & SOPT_NUM) {
rv.type = kObjectTypeInteger;
rv.data.integer = numval;
} else if (flags & SOPT_STRING) {
if (!stringval) {
api_set_error(err, kErrorTypeException, "Failed to get option '%s'", name.data);
return rv;
}
rv.type = kObjectTypeString;
rv.data.string.data = stringval;
rv.data.string.size = strlen(stringval);
} else {
api_set_error(err, kErrorTypeException, "Unknown type for option '%s'", name.data);
}
return rv;
}
/// Sets the value of a global or local (buffer, window) option.
///
/// @param to If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer
/// to the window or buffer.
/// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF`
/// @param name The option name
/// @param[out] err Details of an error that may have occurred
static void set_option_to(uint64_t channel_id, void *to, int type, String name, Object value,
Error *err)
{
VALIDATE_S(name.size > 0, "option name", "<empty>", {
return;
});
int flags = get_option_value_strict(name.data, NULL, NULL, type, to);
VALIDATE_S(flags != 0, "option name", name.data, {
return;
});
if (value.type == kObjectTypeNil) {
if (type == SREQ_GLOBAL) {
api_set_error(err, kErrorTypeException, "Cannot unset option '%s'", name.data);
return;
} else if (!(flags & SOPT_GLOBAL)) {
api_set_error(err, kErrorTypeException,
"Cannot unset option '%s' because it doesn't have a global value",
name.data);
return;
} else {
unset_global_local_option(name.data, to);
return;
}
}
long numval = 0;
char *stringval = NULL;
if (flags & SOPT_BOOL) {
VALIDATE(value.type == kObjectTypeBoolean, "Option '%s' value must be Boolean", name.data, {
return;
});
numval = value.data.boolean;
} else if (flags & SOPT_NUM) {
VALIDATE(value.type == kObjectTypeInteger, "Option '%s' value must be Integer", name.data, {
return;
});
VALIDATE((value.data.integer <= INT_MAX && value.data.integer >= INT_MIN),
"Option '%s' value is out of range", name.data, {
return;
});
numval = (int)value.data.integer;
} else {
VALIDATE(value.type == kObjectTypeString, "Option '%s' value must be String", name.data, {
return;
});
stringval = value.data.string.data;
}
// For global-win-local options -> setlocal
// For win-local options -> setglobal and setlocal (opt_flags == 0)
const int opt_flags = (type == SREQ_WIN && !(flags & SOPT_GLOBAL)) ? 0 :
(type == SREQ_GLOBAL) ? OPT_GLOBAL : OPT_LOCAL;
WITH_SCRIPT_CONTEXT(channel_id, {
access_option_value_for(name.data, &numval, &stringval, opt_flags, type, to, false, err);
});
}

View File

@ -341,218 +341,6 @@ Dictionary nvim_get_option_info2(String name, Dict(option) *opts, Error *err)
return get_vimoption(name, scope, buf, win, err); return get_vimoption(name, scope, buf, win, err);
} }
/// Sets the global value of an option.
///
/// @param channel_id
/// @param name Option name
/// @param value New option value
/// @param[out] err Error details, if any
void nvim_set_option(uint64_t channel_id, String name, Object value, Error *err)
FUNC_API_SINCE(1)
{
set_option_to(channel_id, NULL, SREQ_GLOBAL, name, value, err);
}
/// Gets the global value of an option.
///
/// @param name Option name
/// @param[out] err Error details, if any
/// @return Option value (global)
Object nvim_get_option(String name, Arena *arena, Error *err)
FUNC_API_SINCE(1)
{
return get_option_from(NULL, SREQ_GLOBAL, name, err);
}
/// Gets a buffer option value
///
/// @param buffer Buffer handle, or 0 for current buffer
/// @param name Option name
/// @param[out] err Error details, if any
/// @return Option value
Object nvim_buf_get_option(Buffer buffer, String name, Arena *arena, Error *err)
FUNC_API_SINCE(1)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) {
return (Object)OBJECT_INIT;
}
return get_option_from(buf, SREQ_BUF, name, err);
}
/// Sets a buffer option value. Passing `nil` as value deletes the option (only
/// works if there's a global fallback)
///
/// @param channel_id
/// @param buffer Buffer handle, or 0 for current buffer
/// @param name Option name
/// @param value Option value
/// @param[out] err Error details, if any
void nvim_buf_set_option(uint64_t channel_id, Buffer buffer, String name, Object value, Error *err)
FUNC_API_SINCE(1)
{
buf_T *buf = find_buffer_by_handle(buffer, err);
if (!buf) {
return;
}
set_option_to(channel_id, buf, SREQ_BUF, name, value, err);
}
/// Gets a window option value
///
/// @param window Window handle, or 0 for current window
/// @param name Option name
/// @param[out] err Error details, if any
/// @return Option value
Object nvim_win_get_option(Window window, String name, Arena *arena, Error *err)
FUNC_API_SINCE(1)
{
win_T *win = find_window_by_handle(window, err);
if (!win) {
return (Object)OBJECT_INIT;
}
return get_option_from(win, SREQ_WIN, name, err);
}
/// Sets a window option value. Passing `nil` as value deletes the option (only
/// works if there's a global fallback)
///
/// @param channel_id
/// @param window Window handle, or 0 for current window
/// @param name Option name
/// @param value Option value
/// @param[out] err Error details, if any
void nvim_win_set_option(uint64_t channel_id, Window window, String name, Object value, Error *err)
FUNC_API_SINCE(1)
{
win_T *win = find_window_by_handle(window, err);
if (!win) {
return;
}
set_option_to(channel_id, win, SREQ_WIN, name, value, err);
}
/// Gets the value of a global or local (buffer, window) option.
///
/// @param from If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer
/// to the window or buffer.
/// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF`
/// @param name The option name
/// @param[out] err Details of an error that may have occurred
/// @return the option value
static Object get_option_from(void *from, int type, String name, Error *err)
{
Object rv = OBJECT_INIT;
VALIDATE_S(name.size > 0, "option name", "<empty>", {
return rv;
});
// Return values
int64_t numval;
char *stringval = NULL;
int flags = get_option_value_strict(name.data, &numval, &stringval, type, from);
VALIDATE_S(flags != 0, "option name", name.data, {
return rv;
});
if (flags & SOPT_BOOL) {
rv.type = kObjectTypeBoolean;
rv.data.boolean = numval ? true : false;
} else if (flags & SOPT_NUM) {
rv.type = kObjectTypeInteger;
rv.data.integer = numval;
} else if (flags & SOPT_STRING) {
if (!stringval) {
api_set_error(err, kErrorTypeException, "Failed to get option '%s'", name.data);
return rv;
}
rv.type = kObjectTypeString;
rv.data.string.data = stringval;
rv.data.string.size = strlen(stringval);
} else {
api_set_error(err, kErrorTypeException, "Unknown type for option '%s'", name.data);
}
return rv;
}
/// Sets the value of a global or local (buffer, window) option.
///
/// @param to If `type` is `SREQ_WIN` or `SREQ_BUF`, this must be a pointer
/// to the window or buffer.
/// @param type One of `SREQ_GLOBAL`, `SREQ_WIN` or `SREQ_BUF`
/// @param name The option name
/// @param[out] err Details of an error that may have occurred
void set_option_to(uint64_t channel_id, void *to, int type, String name, Object value, Error *err)
{
VALIDATE_S(name.size > 0, "option name", "<empty>", {
return;
});
int flags = get_option_value_strict(name.data, NULL, NULL, type, to);
VALIDATE_S(flags != 0, "option name", name.data, {
return;
});
if (value.type == kObjectTypeNil) {
if (type == SREQ_GLOBAL) {
api_set_error(err, kErrorTypeException, "Cannot unset option '%s'", name.data);
return;
} else if (!(flags & SOPT_GLOBAL)) {
api_set_error(err, kErrorTypeException,
"Cannot unset option '%s' because it doesn't have a global value",
name.data);
return;
} else {
unset_global_local_option(name.data, to);
return;
}
}
long numval = 0;
char *stringval = NULL;
if (flags & SOPT_BOOL) {
VALIDATE(value.type == kObjectTypeBoolean, "Option '%s' value must be Boolean", name.data, {
return;
});
numval = value.data.boolean;
} else if (flags & SOPT_NUM) {
VALIDATE(value.type == kObjectTypeInteger, "Option '%s' value must be Integer", name.data, {
return;
});
VALIDATE((value.data.integer <= INT_MAX && value.data.integer >= INT_MIN),
"Option '%s' value is out of range", name.data, {
return;
});
numval = (int)value.data.integer;
} else {
VALIDATE(value.type == kObjectTypeString, "Option '%s' value must be String", name.data, {
return;
});
stringval = value.data.string.data;
}
// For global-win-local options -> setlocal
// For win-local options -> setglobal and setlocal (opt_flags == 0)
const int opt_flags = (type == SREQ_WIN && !(flags & SOPT_GLOBAL)) ? 0 :
(type == SREQ_GLOBAL) ? OPT_GLOBAL : OPT_LOCAL;
WITH_SCRIPT_CONTEXT(channel_id, {
access_option_value_for(name.data, &numval, &stringval, opt_flags, type, to, false, err);
});
}
static getoption_T access_option_value(char *key, long *numval, char **stringval, int opt_flags, static getoption_T access_option_value(char *key, long *numval, char **stringval, int opt_flags,
bool get, Error *err) bool get, Error *err)
{ {
@ -571,8 +359,8 @@ static getoption_T access_option_value(char *key, long *numval, char **stringval
} }
} }
static getoption_T access_option_value_for(char *key, long *numval, char **stringval, int opt_flags, getoption_T access_option_value_for(char *key, long *numval, char **stringval, int opt_flags,
int opt_type, void *from, bool get, Error *err) int opt_type, void *from, bool get, Error *err)
{ {
bool need_switch = false; bool need_switch = false;
switchwin_T switchwin; switchwin_T switchwin;

View File

@ -3,6 +3,7 @@
#include "nvim/api/keysets.h" #include "nvim/api/keysets.h"
#include "nvim/api/private/defs.h" #include "nvim/api/private/defs.h"
#include "nvim/option.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "api/options.h.generated.h" # include "api/options.h.generated.h"

View File

@ -630,19 +630,19 @@ describe('api/buf', function()
eq('Index out of bounds', pcall_err(get_offset, 6)) eq('Index out of bounds', pcall_err(get_offset, 6))
eq('Index out of bounds', pcall_err(get_offset, -1)) eq('Index out of bounds', pcall_err(get_offset, -1))
curbufmeths.set_option('eol', false) meths.set_option_value('eol', false, {buf=0})
curbufmeths.set_option('fixeol', false) meths.set_option_value('fixeol', false, {buf=0})
eq(28, get_offset(5)) eq(28, get_offset(5))
-- fileformat is ignored -- fileformat is ignored
curbufmeths.set_option('fileformat', 'dos') meths.set_option_value('fileformat', 'dos', {buf=0})
eq(0, get_offset(0)) eq(0, get_offset(0))
eq(6, get_offset(1)) eq(6, get_offset(1))
eq(15, get_offset(2)) eq(15, get_offset(2))
eq(16, get_offset(3)) eq(16, get_offset(3))
eq(24, get_offset(4)) eq(24, get_offset(4))
eq(28, get_offset(5)) eq(28, get_offset(5))
curbufmeths.set_option('eol', true) meths.set_option_value('eol', true, {buf=0})
eq(29, get_offset(5)) eq(29, get_offset(5))
command("set hidden") command("set hidden")
@ -697,23 +697,23 @@ describe('api/buf', function()
end) end)
end) end)
describe('nvim_buf_get_option, nvim_buf_set_option', function() describe('nvim_get_option_value, nvim_set_option_value', function()
it('works', function() it('works', function()
eq(8, curbuf('get_option', 'shiftwidth')) eq(8, nvim('get_option_value', 'shiftwidth', {buf = 0}))
curbuf('set_option', 'shiftwidth', 4) nvim('set_option_value', 'shiftwidth', 4, {buf=0})
eq(4, curbuf('get_option', 'shiftwidth')) eq(4, nvim('get_option_value', 'shiftwidth', {buf = 0}))
-- global-local option -- global-local option
curbuf('set_option', 'define', 'test') nvim('set_option_value', 'define', 'test', {buf = 0})
eq('test', curbuf('get_option', 'define')) eq('test', nvim('get_option_value', 'define', {buf = 0}))
-- Doesn't change the global value -- Doesn't change the global value
eq([[^\s*#\s*define]], nvim('get_option', 'define')) eq([[^\s*#\s*define]], nvim('get_option_value', 'define', {scope='global'}))
end) end)
it('returns values for unset local options', function() it('returns values for unset local options', function()
-- 'undolevels' is only set to its "unset" value when a new buffer is -- 'undolevels' is only set to its "unset" value when a new buffer is
-- created -- created
command('enew') command('enew')
eq(-123456, curbuf('get_option', 'undolevels')) eq(-123456, nvim('get_option_value', 'undolevels', {buf=0}))
end) end)
end) end)

View File

@ -1401,7 +1401,7 @@ describe('API/extmarks', function()
it('in read-only buffer', function() it('in read-only buffer', function()
command("view! runtime/doc/help.txt") command("view! runtime/doc/help.txt")
eq(true, curbufmeths.get_option('ro')) eq(true, meths.get_option_value('ro', {buf=0}))
local id = set_extmark(ns, 0, 0, 2) local id = set_extmark(ns, 0, 0, 2)
eq({{id, 0, 2}}, get_extmarks(ns,0, -1)) eq({{id, 0, 2}}, get_extmarks(ns,0, -1))
end) end)
@ -1474,7 +1474,7 @@ describe('API/extmarks', function()
it('in prompt buffer', function() it('in prompt buffer', function()
feed('dd') feed('dd')
local id = set_extmark(ns, marks[1], 0, 0, {}) local id = set_extmark(ns, marks[1], 0, 0, {})
curbufmeths.set_option('buftype', 'prompt') meths.set_option_value('buftype', 'prompt', {buf = 0})
feed('i<esc>') feed('i<esc>')
eq({{id, 0, 2}}, get_extmarks(ns, 0, -1)) eq({{id, 0, 2}}, get_extmarks(ns, 0, -1))
end) end)

View File

@ -155,9 +155,9 @@ describe('API: highlight',function()
it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function() it("nvim_buf_add_highlight to other buffer doesn't crash if undo is disabled #12873", function()
command('vsplit file') command('vsplit file')
local err, _ = pcall(meths.buf_set_option, 1, 'undofile', false) local err, _ = pcall(meths.set_option_value, 'undofile', false, { buf = 1 })
eq(true, err) eq(true, err)
err, _ = pcall(meths.buf_set_option, 1, 'undolevels', -1) err, _ = pcall(meths.set_option_value, 'undolevels', -1, { buf = 1 })
eq(true, err) eq(true, err)
err, _ = pcall(meths.buf_add_highlight, 1, -1, 'Question', 0, 0, -1) err, _ = pcall(meths.buf_add_highlight, 1, -1, 'Question', 0, 0, -1)
eq(true, err) eq(true, err)

View File

@ -1051,7 +1051,7 @@ describe('API', function()
line 3 line 3
]]) ]])
eq({0,4,1,0}, funcs.getpos('.')) -- Cursor follows the paste. eq({0,4,1,0}, funcs.getpos('.')) -- Cursor follows the paste.
eq(false, nvim('get_option', 'paste')) eq(false, nvim('get_option_value', 'paste', {}))
command('%delete _') command('%delete _')
-- Without final "\n". -- Without final "\n".
nvim('paste', 'line 1\nline 2\nline 3', true, -1) nvim('paste', 'line 1\nline 2\nline 3', true, -1)
@ -1091,7 +1091,7 @@ describe('API', function()
nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', true, -1) nvim('paste', 'line 1\r\n\r\rline 2\nline 3\rline 4\r', true, -1)
expect('line 1\n\n\nline 2\nline 3\nline 4\n') expect('line 1\n\n\nline 2\nline 3\nline 4\n')
eq({0,7,1,0}, funcs.getpos('.')) eq({0,7,1,0}, funcs.getpos('.'))
eq(false, nvim('get_option', 'paste')) eq(false, nvim('get_option_value', 'paste', {}))
end) end)
it('Replace-mode', function() it('Replace-mode', function()
-- Within single line -- Within single line
@ -1382,44 +1382,38 @@ describe('API', function()
end) end)
end) end)
describe('nvim_get_option, nvim_set_option', function() describe('nvim_get_option_value, nvim_set_option_value', function()
it('works', function() it('works', function()
ok(nvim('get_option', 'equalalways')) ok(nvim('get_option_value', 'equalalways', {}))
nvim('set_option', 'equalalways', false) nvim('set_option_value', 'equalalways', false, {})
ok(not nvim('get_option', 'equalalways')) ok(not nvim('get_option_value', 'equalalways', {}))
end) end)
it('works to get global value of local options', function() it('works to get global value of local options', function()
eq(false, nvim('get_option', 'lisp')) eq(false, nvim('get_option_value', 'lisp', {}))
eq(8, nvim('get_option', 'shiftwidth')) eq(8, nvim('get_option_value', 'shiftwidth', {}))
end) end)
it('works to set global value of local options', function() it('works to set global value of local options', function()
nvim('set_option', 'lisp', true) nvim('set_option_value', 'lisp', true, {scope='global'})
eq(true, nvim('get_option', 'lisp')) eq(true, nvim('get_option_value', 'lisp', {scope='global'}))
eq(false, helpers.curbuf('get_option', 'lisp')) eq(false, nvim('get_option_value', 'lisp', {buf=0}))
eq(nil, nvim('command_output', 'setglobal lisp?'):match('nolisp')) eq(nil, nvim('command_output', 'setglobal lisp?'):match('nolisp'))
eq('nolisp', nvim('command_output', 'setlocal lisp?'):match('nolisp')) eq('nolisp', nvim('command_output', 'setlocal lisp?'):match('nolisp'))
nvim('set_option', 'shiftwidth', 20) nvim('set_option_value', 'shiftwidth', 20, {scope='global'})
eq('20', nvim('command_output', 'setglobal shiftwidth?'):match('%d+')) eq('20', nvim('command_output', 'setglobal shiftwidth?'):match('%d+'))
eq('8', nvim('command_output', 'setlocal shiftwidth?'):match('%d+')) eq('8', nvim('command_output', 'setlocal shiftwidth?'):match('%d+'))
end) end)
it('most window-local options have no global value', function()
local status, err = pcall(nvim, 'get_option', 'foldcolumn')
eq(false, status)
ok(err:match('Invalid option name') ~= nil)
end)
it('updates where the option was last set from', function() it('updates where the option was last set from', function()
nvim('set_option', 'equalalways', false) nvim('set_option_value', 'equalalways', false, {})
local status, rv = pcall(nvim, 'command_output', local status, rv = pcall(nvim, 'command_output',
'verbose set equalalways?') 'verbose set equalalways?')
eq(true, status) eq(true, status)
ok(nil ~= string.find(rv, 'noequalalways\n'.. ok(nil ~= string.find(rv, 'noequalalways\n'..
'\tLast set from API client %(channel id %d+%)')) '\tLast set from API client %(channel id %d+%)'))
nvim('exec_lua', 'vim.api.nvim_set_option("equalalways", true)', {}) nvim('exec_lua', 'vim.api.nvim_set_option_value("equalalways", true, {})', {})
status, rv = pcall(nvim, 'command_output', status, rv = pcall(nvim, 'command_output',
'verbose set equalalways?') 'verbose set equalalways?')
eq(true, status) eq(true, status)
@ -1499,7 +1493,6 @@ describe('API', function()
end) end)
it('set window options', function() it('set window options', function()
-- Same as to nvim_win_set_option
nvim('set_option_value', 'colorcolumn', '4,3', {win=0}) nvim('set_option_value', 'colorcolumn', '4,3', {win=0})
eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'})) eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'}))
command("set modified hidden") command("set modified hidden")
@ -1508,7 +1501,6 @@ describe('API', function()
end) end)
it('set local window options', function() it('set local window options', function()
-- Different to nvim_win_set_option
nvim('set_option_value', 'colorcolumn', '4,3', {win=0, scope='local'}) nvim('set_option_value', 'colorcolumn', '4,3', {win=0, scope='local'})
eq('4,3', nvim('get_option_value', 'colorcolumn', {win = 0, scope = 'local'})) eq('4,3', nvim('get_option_value', 'colorcolumn', {win = 0, scope = 'local'}))
command("set modified hidden") command("set modified hidden")
@ -1519,11 +1511,11 @@ describe('API', function()
it('get buffer or window-local options', function() it('get buffer or window-local options', function()
nvim('command', 'new') nvim('command', 'new')
local buf = nvim('get_current_buf').id local buf = nvim('get_current_buf').id
nvim('buf_set_option', buf, 'tagfunc', 'foobar') nvim('set_option_value', 'tagfunc', 'foobar', {buf=buf})
eq('foobar', nvim('get_option_value', 'tagfunc', {buf = buf})) eq('foobar', nvim('get_option_value', 'tagfunc', {buf = buf}))
local win = nvim('get_current_win').id local win = nvim('get_current_win').id
nvim('win_set_option', win, 'number', true) nvim('set_option_value', 'number', true, {win=win})
eq(true, nvim('get_option_value', 'number', {win = win})) eq(true, nvim('get_option_value', 'number', {win = win}))
end) end)
@ -2215,7 +2207,7 @@ describe('API', function()
it('stream=job :terminal channel', function() it('stream=job :terminal channel', function()
command(':terminal') command(':terminal')
eq({id=1}, meths.get_current_buf()) eq({id=1}, meths.get_current_buf())
eq(3, meths.buf_get_option(1, 'channel')) eq(3, meths.get_option_value('channel', {buf=1}))
local info = { local info = {
stream='job', stream='job',
@ -2368,45 +2360,45 @@ describe('API', function()
end) end)
it('returns nothing with empty &runtimepath', function() it('returns nothing with empty &runtimepath', function()
meths.set_option('runtimepath', '') meths.set_option_value('runtimepath', '', {})
eq({}, meths.list_runtime_paths()) eq({}, meths.list_runtime_paths())
end) end)
it('returns single runtimepath', function() it('returns single runtimepath', function()
meths.set_option('runtimepath', 'a') meths.set_option_value('runtimepath', 'a', {})
eq({'a'}, meths.list_runtime_paths()) eq({'a'}, meths.list_runtime_paths())
end) end)
it('returns two runtimepaths', function() it('returns two runtimepaths', function()
meths.set_option('runtimepath', 'a,b') meths.set_option_value('runtimepath', 'a,b', {})
eq({'a', 'b'}, meths.list_runtime_paths()) eq({'a', 'b'}, meths.list_runtime_paths())
end) end)
it('returns empty strings when appropriate', function() it('returns empty strings when appropriate', function()
meths.set_option('runtimepath', 'a,,b') meths.set_option_value('runtimepath', 'a,,b', {})
eq({'a', '', 'b'}, meths.list_runtime_paths()) eq({'a', '', 'b'}, meths.list_runtime_paths())
meths.set_option('runtimepath', ',a,b') meths.set_option_value('runtimepath', ',a,b', {})
eq({'', 'a', 'b'}, meths.list_runtime_paths()) eq({'', 'a', 'b'}, meths.list_runtime_paths())
-- Trailing "," is ignored. Use ",," if you really really want CWD. -- Trailing "," is ignored. Use ",," if you really really want CWD.
meths.set_option('runtimepath', 'a,b,') meths.set_option_value('runtimepath', 'a,b,', {})
eq({'a', 'b'}, meths.list_runtime_paths()) eq({'a', 'b'}, meths.list_runtime_paths())
meths.set_option('runtimepath', 'a,b,,') meths.set_option_value('runtimepath', 'a,b,,', {})
eq({'a', 'b', ''}, meths.list_runtime_paths()) eq({'a', 'b', ''}, meths.list_runtime_paths())
end) end)
it('truncates too long paths', function() it('truncates too long paths', function()
local long_path = ('/a'):rep(8192) local long_path = ('/a'):rep(8192)
meths.set_option('runtimepath', long_path) meths.set_option_value('runtimepath', long_path, {})
local paths_list = meths.list_runtime_paths() local paths_list = meths.list_runtime_paths()
eq({}, paths_list) eq({}, paths_list)
end) end)
end) end)
it('can throw exceptions', function() it('can throw exceptions', function()
local status, err = pcall(nvim, 'get_option', 'invalid-option') local status, err = pcall(nvim, 'get_option_value', 'invalid-option', {})
eq(false, status) eq(false, status)
ok(err:match('Invalid option name') ~= nil) ok(err:match("Invalid 'option': 'invalid%-option'") ~= nil)
end) end)
it('does not truncate error message <1 MB #5984', function() it('does not truncate error message <1 MB #5984', function()
local very_long_name = 'A'..('x'):rep(10000)..'Z' local very_long_name = 'A'..('x'):rep(10000)..'Z'
local status, err = pcall(nvim, 'get_option', very_long_name) local status, err = pcall(nvim, 'get_option_value', very_long_name, {})
eq(false, status) eq(false, status)
eq(very_long_name, err:match('Ax+Z?')) eq(very_long_name, err:match('Ax+Z?'))
end) end)
@ -2419,7 +2411,7 @@ describe('API', function()
describe('nvim_parse_expression', function() describe('nvim_parse_expression', function()
before_each(function() before_each(function()
meths.set_option('isident', '') meths.set_option_value('isident', '', {})
end) end)
local function simplify_east_api_node(line, east_api_node) local function simplify_east_api_node(line, east_api_node)
@ -2704,9 +2696,9 @@ describe('API', function()
end) end)
it('can change buftype before visiting', function() it('can change buftype before visiting', function()
meths.set_option("hidden", false) meths.set_option_value("hidden", false, {})
eq({id=2}, meths.create_buf(true, false)) eq({id=2}, meths.create_buf(true, false))
meths.buf_set_option(2, "buftype", "nofile") meths.set_option_value("buftype", "nofile", {buf=2})
meths.buf_set_lines(2, 0, -1, true, {"test text"}) meths.buf_set_lines(2, 0, -1, true, {"test text"})
command("split | buffer 2") command("split | buffer 2")
eq({id=2}, meths.get_current_buf()) eq({id=2}, meths.get_current_buf())
@ -2749,10 +2741,10 @@ describe('API', function()
local edited_buf = 2 local edited_buf = 2
meths.buf_set_lines(edited_buf, 0, -1, true, {"some text"}) meths.buf_set_lines(edited_buf, 0, -1, true, {"some text"})
for _,b in ipairs(scratch_bufs) do for _,b in ipairs(scratch_bufs) do
eq('nofile', meths.buf_get_option(b, 'buftype')) eq('nofile', meths.get_option_value('buftype', {buf=b}))
eq('hide', meths.buf_get_option(b, 'bufhidden')) eq('hide', meths.get_option_value('bufhidden', {buf=b}))
eq(false, meths.buf_get_option(b, 'swapfile')) eq(false, meths.get_option_value('swapfile', {buf=b}))
eq(false, meths.buf_get_option(b, 'modeline')) eq(false, meths.get_option_value('modeline', {buf=b}))
end end
-- --
@ -2765,10 +2757,10 @@ describe('API', function()
{1:~ }| {1:~ }|
| |
]]) ]])
eq('nofile', meths.buf_get_option(edited_buf, 'buftype')) eq('nofile', meths.get_option_value('buftype', {buf=edited_buf}))
eq('hide', meths.buf_get_option(edited_buf, 'bufhidden')) eq('hide', meths.get_option_value('bufhidden', {buf=edited_buf}))
eq(false, meths.buf_get_option(edited_buf, 'swapfile')) eq(false, meths.get_option_value('swapfile', {buf=edited_buf}))
eq(false, meths.buf_get_option(edited_buf, 'modeline')) eq(false, meths.get_option_value('modeline', {buf=edited_buf}))
-- Scratch buffer can be wiped without error. -- Scratch buffer can be wiped without error.
command('bwipe') command('bwipe')
@ -2899,7 +2891,7 @@ describe('API', function()
it('should have information about global options', function() it('should have information about global options', function()
-- precondition: the option was changed from its default -- precondition: the option was changed from its default
-- in test setup. -- in test setup.
eq(false, meths.get_option'showcmd') eq(false, meths.get_option_value('showcmd', {}))
eq({ eq({
allows_duplicates = true, allows_duplicates = true,

View File

@ -363,22 +363,22 @@ describe('API/win', function()
end) end)
end) end)
describe('nvim_win_get_option, nvim_win_set_option', function() describe('nvim_get_option_value, nvim_set_option_value', function()
it('works', function() it('works', function()
curwin('set_option', 'colorcolumn', '4,3') nvim('set_option_value', 'colorcolumn', '4,3', {win=0})
eq('4,3', curwin('get_option', 'colorcolumn')) eq('4,3', nvim('get_option_value', 'colorcolumn', {win = 0}))
command("set modified hidden") command("set modified hidden")
command("enew") -- edit new buffer, window option is preserved command("enew") -- edit new buffer, window option is preserved
eq('4,3', curwin('get_option', 'colorcolumn')) eq('4,3', nvim('get_option_value', 'colorcolumn', {win = 0}))
-- global-local option -- global-local option
curwin('set_option', 'statusline', 'window-status') nvim('set_option_value', 'statusline', 'window-status', {win=0})
eq('window-status', curwin('get_option', 'statusline')) eq('window-status', nvim('get_option_value', 'statusline', {win=0}))
eq('', nvim('get_option', 'statusline')) eq('', nvim('get_option_value', 'statusline', {scope='global'}))
command("set modified") command("set modified")
command("enew") -- global-local: not preserved in new buffer command("enew") -- global-local: not preserved in new buffer
-- confirm local value was not copied -- confirm local value was not copied
eq('', curwin('get_option', 'statusline')) eq('', nvim('get_option_value', 'statusline', {win = 0}))
eq('', eval('&l:statusline')) eq('', eval('&l:statusline'))
end) end)
@ -386,16 +386,16 @@ describe('API/win', function()
nvim('command', 'tabnew') nvim('command', 'tabnew')
local tab1 = unpack(nvim('list_tabpages')) local tab1 = unpack(nvim('list_tabpages'))
local win1 = unpack(tabpage('list_wins', tab1)) local win1 = unpack(tabpage('list_wins', tab1))
window('set_option', win1, 'statusline', 'window-status') nvim('set_option_value', 'statusline', 'window-status', {win=win1.id})
nvim('command', 'split') nvim('command', 'split')
nvim('command', 'wincmd J') nvim('command', 'wincmd J')
nvim('command', 'wincmd j') nvim('command', 'wincmd j')
eq('window-status', window('get_option', win1, 'statusline')) eq('window-status', nvim('get_option_value', 'statusline', {win = win1.id}))
assert_alive() assert_alive()
end) end)
it('returns values for unset local options', function() it('returns values for unset local options', function()
eq(-1, curwin('get_option', 'scrolloff')) eq(-1, nvim('get_option_value', 'scrolloff', {win=0, scope='local'}))
end) end)
end) end)
@ -568,11 +568,11 @@ describe('API/win', function()
it('deletes the buffer when bufhidden=wipe', function() it('deletes the buffer when bufhidden=wipe', function()
local oldwin = meths.get_current_win() local oldwin = meths.get_current_win()
local oldbuf = meths.get_current_buf() local oldbuf = meths.get_current_buf()
local buf = meths.create_buf(true, false) local buf = meths.create_buf(true, false).id
local newwin = meths.open_win(buf, true, { local newwin = meths.open_win(buf, true, {
relative='win', row=3, col=3, width=12, height=3 relative='win', row=3, col=3, width=12, height=3
}) })
meths.buf_set_option(buf, 'bufhidden', 'wipe') meths.set_option_value('bufhidden', 'wipe', {buf=buf})
meths.win_hide(newwin) meths.win_hide(newwin)
eq({oldwin}, meths.list_wins()) eq({oldwin}, meths.list_wins())
eq({oldbuf}, meths.list_bufs()) eq({oldbuf}, meths.list_bufs())

View File

@ -141,7 +141,7 @@ describe('autocmd', function()
describe('BufLeave autocommand', function() describe('BufLeave autocommand', function()
it('can wipe out the buffer created by :edit which triggered autocmd', it('can wipe out the buffer created by :edit which triggered autocmd',
function() function()
meths.set_option('hidden', true) meths.set_option_value('hidden', true, {})
curbufmeths.set_lines(0, 1, false, { curbufmeths.set_lines(0, 1, false, {
'start of test file xx', 'start of test file xx',
'end of test file xx'}) 'end of test file xx'})

View File

@ -26,7 +26,7 @@ describe('CursorHold', function()
-- if testing with small 'updatetime' fails, double its value and test again -- if testing with small 'updatetime' fails, double its value and test again
retry(10, nil, function() retry(10, nil, function()
ut = ut * 2 ut = ut * 2
meths.set_option('updatetime', ut) meths.set_option_value('updatetime', ut, {})
feed('0') -- reset did_cursorhold feed('0') -- reset did_cursorhold
meths.set_var('cursorhold', 0) meths.set_var('cursorhold', 0)
sleep(ut / 4) sleep(ut / 4)
@ -51,12 +51,12 @@ describe('CursorHold', function()
end) end)
it("reducing 'updatetime' while waiting for CursorHold #20241", function() it("reducing 'updatetime' while waiting for CursorHold #20241", function()
meths.set_option('updatetime', 10000) meths.set_option_value('updatetime', 10000, {})
feed('0') -- reset did_cursorhold feed('0') -- reset did_cursorhold
meths.set_var('cursorhold', 0) meths.set_var('cursorhold', 0)
sleep(50) sleep(50)
eq(0, meths.get_var('cursorhold')) eq(0, meths.get_var('cursorhold'))
meths.set_option('updatetime', 20) meths.set_option_value('updatetime', 20, {})
sleep(10) sleep(10)
eq(1, meths.get_var('cursorhold')) eq(1, meths.get_var('cursorhold'))
end) end)

View File

@ -16,14 +16,14 @@ local is_os = helpers.is_os
describe('autocmd TermClose', function() describe('autocmd TermClose', function()
before_each(function() before_each(function()
clear() clear()
nvim('set_option', 'shell', testprg('shell-test')) nvim('set_option_value', 'shell', testprg('shell-test'), {})
command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=') command('set shellcmdflag=EXE shellredir= shellpipe= shellquote= shellxquote=')
end) end)
local function test_termclose_delete_own_buf() local function test_termclose_delete_own_buf()
-- The terminal process needs to keep running so that TermClose isn't triggered immediately. -- The terminal process needs to keep running so that TermClose isn't triggered immediately.
nvim('set_option', 'shell', string.format('"%s" INTERACT', testprg('shell-test'))) nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
command('autocmd TermClose * bdelete!') command('autocmd TermClose * bdelete!')
command('terminal') command('terminal')
matches('^TermClose Autocommands for "%*": Vim%(bdelete%):E937: Attempt to delete a buffer that is in use: term://', matches('^TermClose Autocommands for "%*": Vim%(bdelete%):E937: Attempt to delete a buffer that is in use: term://',
@ -51,7 +51,7 @@ describe('autocmd TermClose', function()
it('triggers when long-running terminal job gets stopped', function() it('triggers when long-running terminal job gets stopped', function()
skip(is_os('win')) skip(is_os('win'))
nvim('set_option', 'shell', is_os('win') and 'cmd.exe' or 'sh') nvim('set_option_value', 'shell', is_os('win') and 'cmd.exe' or 'sh', {})
command('autocmd TermClose * let g:test_termclose = 23') command('autocmd TermClose * let g:test_termclose = 23')
command('terminal') command('terminal')
command('call jobstop(b:terminal_job_id)') command('call jobstop(b:terminal_job_id)')
@ -60,8 +60,8 @@ describe('autocmd TermClose', function()
it('kills job trapping SIGTERM', function() it('kills job trapping SIGTERM', function()
skip(is_os('win')) skip(is_os('win'))
nvim('set_option', 'shell', 'sh') nvim('set_option_value', 'shell', 'sh', {})
nvim('set_option', 'shellcmdflag', '-c') nvim('set_option_value', 'shellcmdflag', '-c', {})
command([[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]] command([[ let g:test_job = jobstart('trap "" TERM && echo 1 && sleep 60', { ]]
.. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]]
.. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]]) .. [[ 'on_exit': {-> execute('let g:test_job_exited = 1')}}) ]])
@ -80,8 +80,8 @@ describe('autocmd TermClose', function()
it('kills PTY job trapping SIGHUP and SIGTERM', function() it('kills PTY job trapping SIGHUP and SIGTERM', function()
skip(is_os('win')) skip(is_os('win'))
nvim('set_option', 'shell', 'sh') nvim('set_option_value', 'shell', 'sh', {})
nvim('set_option', 'shellcmdflag', '-c') nvim('set_option_value', 'shellcmdflag', '-c', {})
command([[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]] command([[ let g:test_job = jobstart('trap "" HUP TERM && echo 1 && sleep 60', { ]]
.. [[ 'pty': 1,]] .. [[ 'pty': 1,]]
.. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]] .. [[ 'on_stdout': {-> execute('let g:test_job_started = 1')}, ]]

View File

@ -24,7 +24,7 @@ describe('spellfile', function()
-- │ ┌ Spell file version (#VIMSPELLVERSION) -- │ ┌ Spell file version (#VIMSPELLVERSION)
local spellheader = 'VIMspell\050' local spellheader = 'VIMspell\050'
it('errors out when prefcond section is truncated', function() it('errors out when prefcond section is truncated', function()
meths.set_option('runtimepath', testdir) meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_PREFCOND) -- ┌ Section identifier (#SN_PREFCOND)
-- │ ┌ Section flags (#SNF_REQUIRED or zero) -- │ ┌ Section flags (#SNF_REQUIRED or zero)
@ -34,12 +34,12 @@ describe('spellfile', function()
-- │ ┌ Condition length (1 byte) -- │ ┌ Condition length (1 byte)
-- │ │ ┌ Condition regex (missing!) -- │ │ ┌ Condition regex (missing!)
.. '\000\001\001') .. '\000\001\001')
meths.set_option('spelllang', 'en') meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E758: Truncated spell file', eq('Vim(set):E758: Truncated spell file',
exc_exec('set spell')) exc_exec('set spell'))
end) end)
it('errors out when prefcond regexp contains NUL byte', function() it('errors out when prefcond regexp contains NUL byte', function()
meths.set_option('runtimepath', testdir) meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_PREFCOND) -- ┌ Section identifier (#SN_PREFCOND)
-- │ ┌ Section flags (#SNF_REQUIRED or zero) -- │ ┌ Section flags (#SNF_REQUIRED or zero)
@ -54,12 +54,12 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes) -- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length -- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000') .. '\000\000\000\000\000\000\000\000\000\000\000\000')
meths.set_option('spelllang', 'en') meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', eq('Vim(set):E759: Format error in spell file',
exc_exec('set spell')) exc_exec('set spell'))
end) end)
it('errors out when region contains NUL byte', function() it('errors out when region contains NUL byte', function()
meths.set_option('runtimepath', testdir) meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_REGION) -- ┌ Section identifier (#SN_REGION)
-- │ ┌ Section flags (#SNF_REQUIRED or zero) -- │ ┌ Section flags (#SNF_REQUIRED or zero)
@ -71,12 +71,12 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes) -- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length -- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000') .. '\000\000\000\000\000\000\000\000\000\000\000\000')
meths.set_option('spelllang', 'en') meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', eq('Vim(set):E759: Format error in spell file',
exc_exec('set spell')) exc_exec('set spell'))
end) end)
it('errors out when SAL section contains NUL byte', function() it('errors out when SAL section contains NUL byte', function()
meths.set_option('runtimepath', testdir) meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
-- ┌ Section identifier (#SN_SAL) -- ┌ Section identifier (#SN_SAL)
-- │ ┌ Section flags (#SNF_REQUIRED or zero) -- │ ┌ Section flags (#SNF_REQUIRED or zero)
@ -95,15 +95,15 @@ describe('spellfile', function()
-- │ ┌ KWORDTREE tree length (4 bytes) -- │ ┌ KWORDTREE tree length (4 bytes)
-- │ │ ┌ PREFIXTREE tree length -- │ │ ┌ PREFIXTREE tree length
.. '\000\000\000\000\000\000\000\000\000\000\000\000') .. '\000\000\000\000\000\000\000\000\000\000\000\000')
meths.set_option('spelllang', 'en') meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E759: Format error in spell file', eq('Vim(set):E759: Format error in spell file',
exc_exec('set spell')) exc_exec('set spell'))
end) end)
it('errors out when spell header contains NUL bytes', function() it('errors out when spell header contains NUL bytes', function()
meths.set_option('runtimepath', testdir) meths.set_option_value('runtimepath', testdir, {})
write_file(testdir .. '/spell/en.ascii.spl', write_file(testdir .. '/spell/en.ascii.spl',
spellheader:sub(1, -3) .. '\000\000') spellheader:sub(1, -3) .. '\000\000')
meths.set_option('spelllang', 'en') meths.set_option_value('spelllang', 'en', {})
eq('Vim(set):E757: This does not look like a spell file', eq('Vim(set):E757: This does not look like a spell file',
exc_exec('set spell')) exc_exec('set spell'))
end) end)

View File

@ -40,9 +40,9 @@ end)
describe('startup', function() describe('startup', function()
it('--clean', function() it('--clean', function()
clear() clear()
ok(string.find(alter_slashes(meths.get_option('runtimepath')), funcs.stdpath('config'), 1, true) ~= nil) ok(string.find(alter_slashes(meths.get_option_value('runtimepath', {})), funcs.stdpath('config'), 1, true) ~= nil)
clear('--clean') clear('--clean')
ok(string.find(alter_slashes(meths.get_option('runtimepath')), funcs.stdpath('config'), 1, true) == nil) ok(string.find(alter_slashes(meths.get_option_value('runtimepath', {})), funcs.stdpath('config'), 1, true) == nil)
end) end)
it('--startuptime', function() it('--startuptime', function()
@ -589,7 +589,7 @@ describe('startup', function()
]] ]]
eq({'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]]) eq({'ordinary', 'FANCY', 'mittel', 'FANCY after', 'ordinary after'}, exec_lua [[ return _G.test_loadorder ]])
local rtp = meths.get_option'rtp' local rtp = meths.get_option_value('rtp', {})
ok(startswith(rtp, 'test/functional/fixtures/nvim,test/functional/fixtures/pack/*/start/*,test/functional/fixtures/start/*,test/functional/fixtures,test/functional/fixtures/middle,'), ok(startswith(rtp, 'test/functional/fixtures/nvim,test/functional/fixtures/pack/*/start/*,test/functional/fixtures/start/*,test/functional/fixtures,test/functional/fixtures/middle,'),
'startswith(…)', 'rtp='..rtp) 'startswith(…)', 'rtp='..rtp)
end) end)

View File

@ -59,7 +59,7 @@ describe('K', function()
end) end)
it('empty string falls back to :help #19298', function() it('empty string falls back to :help #19298', function()
meths.set_option('keywordprg', '') meths.set_option_value('keywordprg', '', {})
meths.buf_set_lines(0, 0, -1, true, {'doesnotexist'}) meths.buf_set_lines(0, 0, -1, true, {'doesnotexist'})
feed('K') feed('K')
eq('E149: Sorry, no help for doesnotexist', meths.get_vvar('errmsg')) eq('E149: Sorry, no help for doesnotexist', meths.get_vvar('errmsg'))

View File

@ -988,7 +988,7 @@ describe('completion', function()
return '' return ''
endfunction endfunction
]]) ]])
meths.set_option('completeopt', 'menuone,noselect') meths.set_option_value('completeopt', 'menuone,noselect', {})
meths.set_var('_complist', {{ meths.set_var('_complist', {{
word=0, word=0,
abbr=1, abbr=1,

View File

@ -55,7 +55,7 @@ describe('cmdline', function()
it('correctly clears end of the history', function() it('correctly clears end of the history', function()
-- Regression test: check absence of the memory leak when clearing end of -- Regression test: check absence of the memory leak when clearing end of
-- the history using ex_getln.c/clr_history(). -- the history using ex_getln.c/clr_history().
meths.set_option('history', 1) meths.set_option_value('history', 1, {})
eq(1, funcs.histadd(':', 'foo')) eq(1, funcs.histadd(':', 'foo'))
eq(1, funcs.histdel(':')) eq(1, funcs.histdel(':'))
eq('', funcs.histget(':', -1)) eq('', funcs.histget(':', -1))

View File

@ -8,6 +8,7 @@ local clear = helpers.clear
local funcs = helpers.funcs local funcs = helpers.funcs
local command = helpers.command local command = helpers.command
local curbufmeths = helpers.curbufmeths local curbufmeths = helpers.curbufmeths
local meths = helpers.meths
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local cmdtest = function(cmd, prep, ret1) local cmdtest = function(cmd, prep, ret1)
@ -42,7 +43,7 @@ local cmdtest = function(cmd, prep, ret1)
eq(hisline, funcs.histget(':', -2)) eq(hisline, funcs.histget(':', -2))
eq(cmd, funcs.histget(':')) eq(cmd, funcs.histget(':'))
-- Test that command-line window was launched -- Test that command-line window was launched
eq('nofile', curbufmeths.get_option('buftype')) eq('nofile', meths.get_option_value('buftype', {buf=0}))
eq('n', funcs.mode(1)) eq('n', funcs.mode(1))
feed('<CR>') feed('<CR>')
eq('c', funcs.mode(1)) eq('c', funcs.mode(1))

View File

@ -14,7 +14,7 @@ describe(':ls', function()
end) end)
it('R, F for :terminal buffers', function() it('R, F for :terminal buffers', function()
nvim('set_option', 'shell', string.format('"%s" INTERACT', testprg('shell-test'))) nvim('set_option_value', 'shell', string.format('"%s" INTERACT', testprg('shell-test')), {})
command('edit foo') command('edit foo')
command('set hidden') command('set hidden')

View File

@ -22,14 +22,14 @@ describe(':make', function()
end) end)
it('captures stderr & non zero exit code #14349', function () it('captures stderr & non zero exit code #14349', function ()
nvim('set_option', 'makeprg', testprg('shell-test')..' foo') nvim('set_option_value', 'makeprg', testprg('shell-test')..' foo', {})
local out = eval('execute("make")') local out = eval('execute("make")')
-- Error message is captured in the file and printed in the footer -- Error message is captured in the file and printed in the footer
matches('[\r\n]+.*[\r\n]+Unknown first argument%: foo[\r\n]+%(1 of 1%)%: Unknown first argument%: foo', out) matches('[\r\n]+.*[\r\n]+Unknown first argument%: foo[\r\n]+%(1 of 1%)%: Unknown first argument%: foo', out)
end) end)
it('captures stderr & zero exit code #14349', function () it('captures stderr & zero exit code #14349', function ()
nvim('set_option', 'makeprg', testprg('shell-test')) nvim('set_option_value', 'makeprg', testprg('shell-test'), {})
local out = eval('execute("make")') local out = eval('execute("make")')
-- Ensure there are no "shell returned X" messages between -- Ensure there are no "shell returned X" messages between
-- command and last line (indicating zero exit) -- command and last line (indicating zero exit)

View File

@ -18,7 +18,7 @@ describe(':*map', function()
it('are not affected by &isident', function() it('are not affected by &isident', function()
meths.set_var('counter', 0) meths.set_var('counter', 0)
command('nnoremap <C-x> :let counter+=1<CR>') command('nnoremap <C-x> :let counter+=1<CR>')
meths.set_option('isident', ('%u'):format(('>'):byte())) meths.set_option_value('isident', ('%u'):format(('>'):byte()), {})
command('nnoremap <C-y> :let counter+=1<CR>') command('nnoremap <C-y> :let counter+=1<CR>')
-- &isident used to disable keycode parsing here as well -- &isident used to disable keycode parsing here as well
feed('\24\25<C-x><C-y>') feed('\24\25<C-x><C-y>')

View File

@ -81,13 +81,13 @@ describe(':mksession', function()
local buf_count = #meths.list_bufs() local buf_count = #meths.list_bufs()
eq(2, buf_count) eq(2, buf_count)
eq('terminal', meths.buf_get_option(0, 'buftype')) eq('terminal', meths.get_option_value('buftype', { buf = 0 }))
test_terminal_session_disabled(2) test_terminal_session_disabled(2)
-- no terminal should be set. As a side effect we end up with a blank buffer -- no terminal should be set. As a side effect we end up with a blank buffer
eq('', meths.buf_get_option(meths.list_bufs()[1], 'buftype')) eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[1] }))
eq('', meths.buf_get_option(meths.list_bufs()[2], 'buftype')) eq('', meths.get_option_value('buftype', { buf = meths.list_bufs()[2] }))
end end
) )
@ -112,7 +112,7 @@ describe(':mksession', function()
it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function() it('do not restore :terminal if not set in sessionoptions, only buffer #13078', function()
command('terminal') command('terminal')
eq('terminal', meths.buf_get_option(0, 'buftype')) eq('terminal', meths.get_option_value('buftype', { buf = 0 }))
local buf_count = #meths.list_bufs() local buf_count = #meths.list_bufs()
eq(1, buf_count) eq(1, buf_count)
@ -120,7 +120,7 @@ describe(':mksession', function()
test_terminal_session_disabled(1) test_terminal_session_disabled(1)
-- no terminal should be set -- no terminal should be set
eq('', meths.buf_get_option(0, 'buftype')) eq('', meths.get_option_value('buftype', { buf = 0 }))
end) end)
it('restores tab-local working directories', function() it('restores tab-local working directories', function()
@ -249,7 +249,7 @@ describe(':mksession', function()
style = 'minimal', style = 'minimal',
} }
meths.open_win(buf, false, config) meths.open_win(buf, false, config)
local cmdheight = meths.get_option('cmdheight') local cmdheight = meths.get_option_value('cmdheight', {})
command('mksession ' .. session_file) command('mksession ' .. session_file)
-- Create a new test instance of Nvim. -- Create a new test instance of Nvim.
@ -262,7 +262,7 @@ describe(':mksession', function()
-- window was not restored. -- window was not restored.
eq(1, funcs.winnr('$')) eq(1, funcs.winnr('$'))
-- The command-line height should remain the same as it was. -- The command-line height should remain the same as it was.
eq(cmdheight, meths.get_option('cmdheight')) eq(cmdheight, meths.get_option_value('cmdheight', {}))
os.remove(tmpfile) os.remove(tmpfile)
end) end)

View File

@ -48,7 +48,7 @@ describe(':source', function()
pending("'shellslash' only works on Windows") pending("'shellslash' only works on Windows")
return return
end end
meths.set_option('shellslash', false) meths.set_option_value('shellslash', false, {})
mkdir('Xshellslash') mkdir('Xshellslash')
write_file([[Xshellslash/Xstack.vim]], [[ write_file([[Xshellslash/Xstack.vim]], [[

View File

@ -18,7 +18,7 @@ local function last_set_tests(cmd)
script_location = table.concat{current_dir, helpers.get_pathsep(), script_file} script_location = table.concat{current_dir, helpers.get_pathsep(), script_file}
write_file(script_file, [[ write_file(script_file, [[
vim.api.nvim_set_option('hlsearch', false) vim.api.nvim_set_option_value('hlsearch', false, {})
vim.bo.expandtab = true vim.bo.expandtab = true
vim.opt.number = true vim.opt.number = true
vim.api.nvim_set_keymap('n', '<leader>key1', ':echo "test"<cr>', {noremap = true}) vim.api.nvim_set_keymap('n', '<leader>key1', ':echo "test"<cr>', {noremap = true})
@ -160,7 +160,7 @@ describe('lua verbose:', function()
clear() clear()
script_file = 'test_luafile.lua' script_file = 'test_luafile.lua'
write_file(script_file, [[ write_file(script_file, [[
vim.api.nvim_set_option('hlsearch', false) vim.api.nvim_set_option_value('hlsearch', false, {})
]]) ]])
exec(':source '..script_file) exec(':source '..script_file)
end) end)

View File

@ -129,18 +129,18 @@ describe(':write', function()
eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'), eq(('Vim(write):E17: "'..funcs.fnamemodify('.', ':p:h')..'" is a directory'),
pcall_err(command, 'write .')) pcall_err(command, 'write .'))
end end
meths.set_option('writeany', true) meths.set_option_value('writeany', true, {})
-- Message from buf_write -- Message from buf_write
eq(('Vim(write):E502: "." is a directory'), pcall_err(command, 'write .')) eq(('Vim(write):E502: "." is a directory'), pcall_err(command, 'write .'))
funcs.mkdir(fname_bak) funcs.mkdir(fname_bak)
meths.set_option('backupdir', '.') meths.set_option_value('backupdir', '.', {})
meths.set_option('backup', true) meths.set_option_value('backup', true, {})
write_file(fname, 'content0') write_file(fname, 'content0')
command('edit ' .. fname) command('edit ' .. fname)
funcs.setline(1, 'TTY') funcs.setline(1, 'TTY')
eq('Vim(write):E510: Can\'t make backup file (add ! to override)', eq('Vim(write):E510: Can\'t make backup file (add ! to override)',
pcall_err(command, 'write')) pcall_err(command, 'write'))
meths.set_option('backup', false) meths.set_option_value('backup', false, {})
funcs.setfperm(fname, 'r--------') funcs.setfperm(fname, 'r--------')
eq('Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)', eq('Vim(write):E505: "Xtest-functional-ex_cmds-write" is read-only (add ! to override)',
pcall_err(command, 'write')) pcall_err(command, 'write'))

View File

@ -15,7 +15,6 @@ local clear = helpers.clear
local insert = helpers.insert local insert = helpers.insert
local command = helpers.command local command = helpers.command
local write_file = helpers.write_file local write_file = helpers.write_file
local curbufmeths = helpers.curbufmeths
local expect_exit = helpers.expect_exit local expect_exit = helpers.expect_exit
local mkdir = helpers.mkdir local mkdir = helpers.mkdir
@ -58,9 +57,9 @@ describe("'directory' option", function()
line 3 Abcdefghij line 3 Abcdefghij
end of testfile]]) end of testfile]])
meths.set_option('swapfile', true) meths.set_option_value('swapfile', true, {})
curbufmeths.set_option('swapfile', true) meths.set_option_value('swapfile', true, {buf=0})
meths.set_option('directory', '.') meths.set_option_value('directory', '.', {})
-- sanity check: files should not exist yet. -- sanity check: files should not exist yet.
eq(nil, luv.fs_stat('.Xtest1.swp')) eq(nil, luv.fs_stat('.Xtest1.swp'))
@ -72,7 +71,7 @@ describe("'directory' option", function()
-- reading the output from :!ls. -- reading the output from :!ls.
neq(nil, luv.fs_stat('.Xtest1.swp')) neq(nil, luv.fs_stat('.Xtest1.swp'))
meths.set_option('directory', './Xtest2,.') meths.set_option_value('directory', './Xtest2,.', {})
command('edit Xtest1') command('edit Xtest1')
poke_eventloop() poke_eventloop()
@ -81,10 +80,10 @@ describe("'directory' option", function()
eq({ "Xtest1.swp", "Xtest3" }, ls_dir_sorted("Xtest2")) eq({ "Xtest1.swp", "Xtest3" }, ls_dir_sorted("Xtest2"))
meths.set_option('directory', 'Xtest.je') meths.set_option_value('directory', 'Xtest.je', {})
command('bdelete') command('bdelete')
command('edit Xtest2/Xtest3') command('edit Xtest2/Xtest3')
eq(true, curbufmeths.get_option('swapfile')) eq(true, meths.get_option_value('swapfile', {buf=0}))
poke_eventloop() poke_eventloop()
eq({ "Xtest3" }, ls_dir_sorted("Xtest2")) eq({ "Xtest3" }, ls_dir_sorted("Xtest2"))

View File

@ -631,24 +631,24 @@ describe('au OptionSet', function()
it('should trigger if a boolean option be set globally', function() it('should trigger if a boolean option be set globally', function()
set_hook('autochdir') set_hook('autochdir')
nvim.set_option('autochdir', true) nvim.set_option_value('autochdir', true, {scope='global'})
eq(true, nvim.get_option('autochdir')) eq(true, nvim.get_option_value('autochdir', {scope='global'}))
expected_combination({'autochdir', 0, '', 0, 1, 'global', 'setglobal'}) expected_combination({'autochdir', 0, '', 0, 1, 'global', 'setglobal'})
end) end)
it('should trigger if a number option be set globally', function() it('should trigger if a number option be set globally', function()
set_hook('cmdheight') set_hook('cmdheight')
nvim.set_option('cmdheight', 5) nvim.set_option_value('cmdheight', 5, {scope='global'})
eq(5, nvim.get_option('cmdheight')) eq(5, nvim.get_option_value('cmdheight', {scope='global'}))
expected_combination({'cmdheight', 1, '', 1, 5, 'global', 'setglobal'}) expected_combination({'cmdheight', 1, '', 1, 5, 'global', 'setglobal'})
end) end)
it('should trigger if a string option be set globally', function() it('should trigger if a string option be set globally', function()
set_hook('ambiwidth') set_hook('ambiwidth')
nvim.set_option('ambiwidth', 'double') nvim.set_option_value('ambiwidth', 'double', {scope='global'})
eq('double', nvim.get_option('ambiwidth')) eq('double', nvim.get_option_value('ambiwidth', {scope='global'}))
expected_combination({'ambiwidth', 'single', '', 'single', 'double', 'global', 'setglobal'}) expected_combination({'ambiwidth', 'single', '', 'single', 'double', 'global', 'setglobal'})
end) end)
end) end)

View File

@ -10,7 +10,7 @@ describe('buffer', function()
before_each(function() before_each(function()
clear() clear()
meths.ui_attach(80, 24, {}) meths.ui_attach(80, 24, {})
meths.set_option('hidden', false) meths.set_option_value('hidden', false, {})
end) end)
it('deleting a modified buffer with :confirm', function() it('deleting a modified buffer with :confirm', function()

View File

@ -225,9 +225,9 @@ describe('cmdline', function()
[3] = {reverse = true}, -- TabLineFill [3] = {reverse = true}, -- TabLineFill
}) })
screen:attach() screen:attach()
meths.set_option('laststatus', 2) meths.set_option_value('laststatus', 2, {})
meths.set_option('showtabline', 2) meths.set_option_value('showtabline', 2, {})
meths.set_option('cmdheight', 1) meths.set_option_value('cmdheight', 1, {})
screen:expect([[ screen:expect([[
{2: [No Name] }{3: }| {2: [No Name] }{3: }|
^ | ^ |
@ -247,10 +247,10 @@ describe('cmdline', function()
[0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText [0] = {bold = true, foreground = Screen.colors.Blue}, -- NonText
} }
screen:attach() screen:attach()
meths.set_option('ruler', true) meths.set_option_value('ruler', true, {})
meths.set_option('rulerformat', 'longish') meths.set_option_value('rulerformat', 'longish', {})
meths.set_option('laststatus', 0) meths.set_option_value('laststatus', 0, {})
meths.set_option('winwidth', 1) meths.set_option_value('winwidth', 1, {})
feed [[<C-W>v<C-W>|<C-W>p]] feed [[<C-W>v<C-W>|<C-W>p]]
screen:expect [[ screen:expect [[
^ | ^ |

View File

@ -12,8 +12,8 @@ describe('file changed dialog', function()
before_each(function() before_each(function()
clear() clear()
meths.ui_attach(80, 24, {}) meths.ui_attach(80, 24, {})
meths.set_option('autoread', false) meths.set_option_value('autoread', false, {})
meths.set_option('fsync', true) meths.set_option_value('fsync', true, {})
end) end)
it('works', function() it('works', function()

View File

@ -361,9 +361,9 @@ describe('messages', function()
screen:attach() screen:attach()
command('cd '..nvim_dir) command('cd '..nvim_dir)
meths.set_option('shell', './shell-test') meths.set_option_value('shell', './shell-test', {})
meths.set_option('shellcmdflag', 'REP 20') meths.set_option_value('shellcmdflag', 'REP 20', {})
meths.set_option('shellxquote', '') -- win: avoid extra quotes meths.set_option_value('shellxquote', '', {}) -- win: avoid extra quotes
-- display a page and go back, results in exactly the same view -- display a page and go back, results in exactly the same view
feed([[:4 verbose echo system('foo')<CR>]]) feed([[:4 verbose echo system('foo')<CR>]])

View File

@ -12,7 +12,7 @@ describe('Vim script', function()
it('Error when if/for/while/try/function is nested too deep',function() it('Error when if/for/while/try/function is nested too deep',function()
local screen = Screen.new(80, 24) local screen = Screen.new(80, 24)
screen:attach() screen:attach()
meths.set_option('laststatus', 2) meths.set_option_value('laststatus', 2, {})
exec([[ exec([[
" Deep nesting of if ... endif " Deep nesting of if ... endif
func Test1() func Test1()

View File

@ -415,7 +415,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('opening lines', function() it('opening lines', function()
local check_events = setup_eventcheck(verify, origlines) local check_events = setup_eventcheck(verify, origlines)
-- meths.buf_set_option(0, 'autoindent', true) -- meths.set_option_value('autoindent', true, { buf = 0 })
feed 'Go' feed 'Go'
check_events { check_events {
{ "test1", "bytes", 1, 4, 7, 0, 114, 0, 0, 0, 1, 0, 1 }; { "test1", "bytes", 1, 4, 7, 0, 114, 0, 0, 0, 1, 0, 1 };
@ -428,7 +428,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('opening lines with autoindent', function() it('opening lines with autoindent', function()
local check_events = setup_eventcheck(verify, origlines) local check_events = setup_eventcheck(verify, origlines)
meths.buf_set_option(0, 'autoindent', true) meths.set_option_value('autoindent', true, { buf = 0 })
feed 'Go' feed 'Go'
check_events { check_events {
{ "test1", "bytes", 1, 4, 7, 0, 114, 0, 0, 0, 1, 0, 5 }; { "test1", "bytes", 1, 4, 7, 0, 114, 0, 0, 0, 1, 0, 5 };
@ -462,8 +462,8 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('continuing comments with fo=or', function() it('continuing comments with fo=or', function()
local check_events = setup_eventcheck(verify, {'// Comment'}) local check_events = setup_eventcheck(verify, {'// Comment'})
meths.buf_set_option(0, 'formatoptions', 'ro') meths.set_option_value('formatoptions', 'ro', { buf = 0 })
meths.buf_set_option(0, 'filetype', 'c') meths.set_option_value('filetype', 'c', { buf = 0 })
feed 'A<CR>' feed 'A<CR>'
check_events { check_events {
{ "test1", "bytes", 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 }; { "test1", "bytes", 1, 4, 0, 10, 10, 0, 0, 0, 1, 3, 4 };
@ -603,7 +603,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it('inccomand=nosplit and substitute', function() it('inccomand=nosplit and substitute', function()
local check_events = setup_eventcheck(verify, local check_events = setup_eventcheck(verify,
{"abcde", "12345"}) {"abcde", "12345"})
meths.set_option('inccommand', 'nosplit') meths.set_option_value('inccommand', 'nosplit', {})
-- linewise substitute -- linewise substitute
feed(':%s/bcd/') feed(':%s/bcd/')
@ -998,7 +998,7 @@ describe('lua: nvim_buf_attach on_bytes', function()
it("virtual edit", function () it("virtual edit", function ()
local check_events = setup_eventcheck(verify, { "", " " }) local check_events = setup_eventcheck(verify, { "", " " })
meths.set_option("virtualedit", "all") meths.set_option_value('virtualedit', "all", {})
feed [[<Right><Right>iab<ESC>]] feed [[<Right><Right>iab<ESC>]]

View File

@ -31,14 +31,12 @@ describe('nlua_expand_pat', function()
eq( eq(
{{ {{
'nvim_buf_set_lines', 'nvim_buf_set_lines',
'nvim_buf_set_option'
}, 8 }, 8
}, },
get_completions('vim.api.nvim_buf_', { get_completions('vim.api.nvim_buf_', {
vim = { vim = {
api = { api = {
nvim_buf_set_lines = true, nvim_buf_set_lines = true,
nvim_buf_set_option = true,
nvim_win_doesnt_match = true, nvim_win_doesnt_match = true,
}, },
other_key = true, other_key = true,
@ -68,14 +66,12 @@ describe('nlua_expand_pat', function()
eq( eq(
{{ {{
'nvim_buf_set_lines', 'nvim_buf_set_lines',
'nvim_buf_set_option'
}, 11 }, 11
}, },
get_completions('vim["api"].nvim_buf_', { get_completions('vim["api"].nvim_buf_', {
vim = { vim = {
api = { api = {
nvim_buf_set_lines = true, nvim_buf_set_lines = true,
nvim_buf_set_option = true,
nvim_win_doesnt_match = true, nvim_win_doesnt_match = true,
}, },
other_key = true, other_key = true,
@ -88,7 +84,6 @@ describe('nlua_expand_pat', function()
eq( eq(
{{ {{
'nvim_buf_set_lines', 'nvim_buf_set_lines',
'nvim_buf_set_option'
}, 21 }, 21
}, },
get_completions('vim["nested"]["api"].nvim_buf_', { get_completions('vim["nested"]["api"].nvim_buf_', {
@ -96,7 +91,6 @@ describe('nlua_expand_pat', function()
nested = { nested = {
api = { api = {
nvim_buf_set_lines = true, nvim_buf_set_lines = true,
nvim_buf_set_option = true,
nvim_win_doesnt_match = true, nvim_win_doesnt_match = true,
}, },
}, },
@ -121,7 +115,6 @@ describe('nlua_expand_pat', function()
eq( eq(
{{ {{
'nvim_buf_set_lines', 'nvim_buf_set_lines',
'nvim_buf_set_option'
}, 12 }, 12
}, },
get_completions('vim[MY_VAR].nvim_buf_', { get_completions('vim[MY_VAR].nvim_buf_', {
@ -129,7 +122,6 @@ describe('nlua_expand_pat', function()
vim = { vim = {
api = { api = {
nvim_buf_set_lines = true, nvim_buf_set_lines = true,
nvim_buf_set_option = true,
nvim_win_doesnt_match = true, nvim_win_doesnt_match = true,
}, },
other_key = true, other_key = true,

View File

@ -134,6 +134,6 @@ end)
describe('filetype.lua', function() describe('filetype.lua', function()
it('does not override user autocommands that set filetype #20333', function() it('does not override user autocommands that set filetype #20333', function()
clear({args={'--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md'}}) clear({args={'--clean', '--cmd', 'autocmd BufRead *.md set filetype=notmarkdown', 'README.md'}})
eq('notmarkdown', meths.buf_get_option(0, 'filetype')) eq('notmarkdown', meths.get_option_value('filetype', { buf = 0 }))
end) end)
end) end)

View File

@ -18,8 +18,8 @@ describe('vim.inspect_pos', function()
vim.api.nvim_set_current_buf(buf) vim.api.nvim_set_current_buf(buf)
vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"}) vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"})
vim.api.nvim_buf_set_lines(buf1, 0, -1, false, {"--commentline"}) vim.api.nvim_buf_set_lines(buf1, 0, -1, false, {"--commentline"})
vim.api.nvim_buf_set_option(buf, "filetype", "lua") vim.bo[buf].filetype = 'lua'
vim.api.nvim_buf_set_option(buf1, "filetype", "lua") vim.bo[buf1].filetype = 'lua'
vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = "Normal" }) vim.api.nvim_buf_set_extmark(buf, ns1, 0, 10, { hl_group = "Normal" })
vim.api.nvim_buf_set_extmark(buf, ns2, 0, 10, { hl_group = "Normal" }) vim.api.nvim_buf_set_extmark(buf, ns2, 0, 10, { hl_group = "Normal" })
vim.cmd("syntax on") vim.cmd("syntax on")
@ -97,7 +97,7 @@ describe('vim.show_pos', function()
local buf = vim.api.nvim_create_buf(true, false) local buf = vim.api.nvim_create_buf(true, false)
vim.api.nvim_set_current_buf(buf) vim.api.nvim_set_current_buf(buf)
vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"}) vim.api.nvim_buf_set_lines(0, 0, -1, false, {"local a = 123"})
vim.api.nvim_buf_set_option(buf, "filetype", "lua") vim.bo[buf].filetype = 'lua'
vim.cmd("syntax on") vim.cmd("syntax on")
return {buf, vim.show_pos(0, 0, 10)} return {buf, vim.show_pos(0, 0, 10)}
]]) ]])

View File

@ -514,7 +514,7 @@ describe('v:lua', function()
[5] = {bold = true, foreground = Screen.colors.SeaGreen4}, [5] = {bold = true, foreground = Screen.colors.SeaGreen4},
}) })
screen:attach() screen:attach()
meths.buf_set_option(0, 'omnifunc', 'v:lua.mymod.omni') meths.set_option_value('omnifunc', 'v:lua.mymod.omni', { buf = 0 })
feed('isome st<c-x><c-o>') feed('isome st<c-x><c-o>')
screen:expect{grid=[[ screen:expect{grid=[[
some stuff^ | some stuff^ |
@ -526,7 +526,7 @@ describe('v:lua', function()
{1:~ }| {1:~ }|
{4:-- Omni completion (^O^N^P) }{5:match 1 of 3} | {4:-- Omni completion (^O^N^P) }{5:match 1 of 3} |
]]} ]]}
meths.set_option('operatorfunc', 'v:lua.mymod.noisy') meths.set_option_value('operatorfunc', 'v:lua.mymod.noisy', {})
feed('<Esc>g@g@') feed('<Esc>g@g@')
eq("hey line", meths.get_current_line()) eq("hey line", meths.get_current_line())
end) end)

View File

@ -100,7 +100,7 @@ describe('print', function()
pcall_err(command, 'lua bad_custom_error()')) pcall_err(command, 'lua bad_custom_error()'))
end) end)
it('prints strings with NULs and NLs correctly', function() it('prints strings with NULs and NLs correctly', function()
meths.set_option('more', true) meths.set_option_value('more', true, {})
eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n', eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT\n',
exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]])) exec_capture([[lua print("abc \0 def\nghi\0\0\0jkl\nTEST\n\n\nT\n")]]))
eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT^@', eq('abc ^@ def\nghi^@^@^@jkl\nTEST\n\n\nT^@',

View File

@ -6,7 +6,7 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local pathsep = helpers.get_pathsep() local pathsep = helpers.get_pathsep()
local is_os = helpers.is_os local is_os = helpers.is_os
local curbufmeths = helpers.curbufmeths local meths = helpers.meths
local exec_lua = helpers.exec_lua local exec_lua = helpers.exec_lua
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
local feed = helpers.feed local feed = helpers.feed
@ -160,7 +160,7 @@ describe('vim.secure', function()
-- Cannot write file -- Cannot write file
pcall_err(command, 'write') pcall_err(command, 'write')
eq(true, curbufmeths.get_option('readonly')) eq(true, meths.get_option_value('readonly', {buf=0}))
end) end)
end) end)

View File

@ -1496,9 +1496,9 @@ describe('lua stdlib', function()
it('vim.bo', function() it('vim.bo', function()
eq('', funcs.luaeval "vim.bo.filetype") eq('', funcs.luaeval "vim.bo.filetype")
exec_lua [[ exec_lua [[
vim.api.nvim_buf_set_option(0, "filetype", "markdown") vim.api.nvim_set_option_value("filetype", "markdown", {buf = 0})
BUF = vim.api.nvim_create_buf(false, true) BUF = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(BUF, "modifiable", false) vim.api.nvim_set_option_value("modifiable", false, {buf = BUF})
]] ]]
eq(false, funcs.luaeval "vim.bo.modified") eq(false, funcs.luaeval "vim.bo.modified")
eq('markdown', funcs.luaeval "vim.bo.filetype") eq('markdown', funcs.luaeval "vim.bo.filetype")
@ -1519,9 +1519,9 @@ describe('lua stdlib', function()
it('vim.wo', function() it('vim.wo', function()
exec_lua [[ exec_lua [[
vim.api.nvim_win_set_option(0, "cole", 2) vim.api.nvim_set_option_value("cole", 2, {win=0})
vim.cmd "split" vim.cmd "split"
vim.api.nvim_win_set_option(0, "cole", 2) vim.api.nvim_set_option_value("cole", 2, {win=0})
]] ]]
eq(2, funcs.luaeval "vim.wo.cole") eq(2, funcs.luaeval "vim.wo.cole")
exec_lua [[ exec_lua [[
@ -1566,8 +1566,8 @@ describe('lua stdlib', function()
local result = exec_lua [[ local result = exec_lua [[
local result = {} local result = {}
table.insert(result, vim.api.nvim_get_option('scrolloff')) table.insert(result, vim.api.nvim_get_option_value('scrolloff', {scope='global'}))
table.insert(result, vim.api.nvim_win_get_option(0, 'scrolloff')) table.insert(result, vim.api.nvim_get_option_value('scrolloff', {win=0}))
return result return result
]] ]]
@ -1631,20 +1631,20 @@ describe('lua stdlib', function()
local result = {} local result = {}
vim.opt.makeprg = "global-local" vim.opt.makeprg = "global-local"
table.insert(result, vim.api.nvim_get_option('makeprg')) table.insert(result, vim.go.makeprg)
table.insert(result, vim.api.nvim_buf_get_option(0, 'makeprg')) table.insert(result, vim.api.nvim_get_option_value('makeprg', {buf=0}))
vim.opt_local.mp = "only-local" vim.opt_local.mp = "only-local"
table.insert(result, vim.api.nvim_get_option('makeprg')) table.insert(result, vim.go.makeprg)
table.insert(result, vim.api.nvim_buf_get_option(0, 'makeprg')) table.insert(result, vim.api.nvim_get_option_value('makeprg', {buf=0}))
vim.opt_global.makeprg = "only-global" vim.opt_global.makeprg = "only-global"
table.insert(result, vim.api.nvim_get_option('makeprg')) table.insert(result, vim.go.makeprg)
table.insert(result, vim.api.nvim_buf_get_option(0, 'makeprg')) table.insert(result, vim.api.nvim_get_option_value('makeprg', {buf=0}))
vim.opt.makeprg = "global-local" vim.opt.makeprg = "global-local"
table.insert(result, vim.api.nvim_get_option('makeprg')) table.insert(result, vim.go.makeprg)
table.insert(result, vim.api.nvim_buf_get_option(0, 'makeprg')) table.insert(result, vim.api.nvim_get_option_value('makeprg', {buf=0}))
return result return result
]] ]]
@ -2173,7 +2173,7 @@ describe('lua stdlib', function()
it('can handle isfname ,,,', function() it('can handle isfname ,,,', function()
local result = exec_lua [[ local result = exec_lua [[
vim.opt.isfname = "a,b,,,c" vim.opt.isfname = "a,b,,,c"
return { vim.opt.isfname:get(), vim.api.nvim_get_option('isfname') } return { vim.opt.isfname:get(), vim.go.isfname }
]] ]]
eq({{",", "a", "b", "c"}, "a,b,,,c"}, result) eq({{",", "a", "b", "c"}, "a,b,,,c"}, result)
@ -2183,7 +2183,7 @@ describe('lua stdlib', function()
it('can handle isfname ,^,,', function() it('can handle isfname ,^,,', function()
local result = exec_lua [[ local result = exec_lua [[
vim.opt.isfname = "a,b,^,,c" vim.opt.isfname = "a,b,^,,c"
return { vim.opt.isfname:get(), vim.api.nvim_get_option('isfname') } return { vim.opt.isfname:get(), vim.go.isfname }
]] ]]
eq({{"^,", "a", "b", "c"}, "a,b,^,,c"}, result) eq({{"^,", "a", "b", "c"}, "a,b,^,,c"}, result)
@ -2734,14 +2734,14 @@ describe('lua stdlib', function()
describe('vim.api.nvim_buf_call', function() describe('vim.api.nvim_buf_call', function()
it('can access buf options', function() it('can access buf options', function()
local buf1 = meths.get_current_buf() local buf1 = meths.get_current_buf().id
local buf2 = exec_lua [[ local buf2 = exec_lua [[
buf2 = vim.api.nvim_create_buf(false, true) buf2 = vim.api.nvim_create_buf(false, true)
return buf2 return buf2
]] ]]
eq(false, meths.buf_get_option(buf1, 'autoindent')) eq(false, meths.get_option_value('autoindent', {buf=buf1}))
eq(false, meths.buf_get_option(buf2, 'autoindent')) eq(false, meths.get_option_value('autoindent', {buf=buf2}))
local val = exec_lua [[ local val = exec_lua [[
return vim.api.nvim_buf_call(buf2, function() return vim.api.nvim_buf_call(buf2, function()
@ -2750,9 +2750,9 @@ describe('lua stdlib', function()
end) end)
]] ]]
eq(false, meths.buf_get_option(buf1, 'autoindent')) eq(false, meths.get_option_value('autoindent', {buf=buf1}))
eq(true, meths.buf_get_option(buf2, 'autoindent')) eq(true, meths.get_option_value('autoindent', {buf=buf2}))
eq(buf1, meths.get_current_buf()) eq(buf1, meths.get_current_buf().id)
eq(buf2, val) eq(buf2, val)
end) end)
@ -2771,10 +2771,10 @@ describe('lua stdlib', function()
eq(true, exec_lua([[ eq(true, exec_lua([[
local function scratch_buf_call(fn) local function scratch_buf_call(fn)
local buf = vim.api.nvim_create_buf(false, true) local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(buf, 'cindent', true) vim.api.nvim_set_option_value('cindent', true, {buf = buf})
return vim.api.nvim_buf_call(buf, function() return vim.api.nvim_buf_call(buf, function()
return vim.api.nvim_get_current_buf() == buf return vim.api.nvim_get_current_buf() == buf
and vim.api.nvim_buf_get_option(buf, 'cindent') and vim.api.nvim_get_option_value('cindent', {buf = buf})
and fn() and fn()
end) and vim.api.nvim_buf_delete(buf, {}) == nil end) and vim.api.nvim_buf_delete(buf, {}) == nil
end end
@ -2811,7 +2811,7 @@ describe('lua stdlib', function()
describe('vim.api.nvim_win_call', function() describe('vim.api.nvim_win_call', function()
it('can access window options', function() it('can access window options', function()
command('vsplit') command('vsplit')
local win1 = meths.get_current_win() local win1 = meths.get_current_win().id
command('wincmd w') command('wincmd w')
local win2 = exec_lua [[ local win2 = exec_lua [[
win2 = vim.api.nvim_get_current_win() win2 = vim.api.nvim_get_current_win()
@ -2819,8 +2819,8 @@ describe('lua stdlib', function()
]] ]]
command('wincmd p') command('wincmd p')
eq('', meths.win_get_option(win1, 'winhighlight')) eq('', meths.get_option_value('winhighlight', {win=win1}))
eq('', meths.win_get_option(win2, 'winhighlight')) eq('', meths.get_option_value('winhighlight', {win=win2}))
local val = exec_lua [[ local val = exec_lua [[
return vim.api.nvim_win_call(win2, function() return vim.api.nvim_win_call(win2, function()
@ -2829,9 +2829,9 @@ describe('lua stdlib', function()
end) end)
]] ]]
eq('', meths.win_get_option(win1, 'winhighlight')) eq('', meths.get_option_value('winhighlight', {win=win1}))
eq('Normal:Normal', meths.win_get_option(win2, 'winhighlight')) eq('Normal:Normal', meths.get_option_value('winhighlight', {win=win2}))
eq(win1, meths.get_current_win()) eq(win1, meths.get_current_win().id)
eq(win2, val) eq(win2, val)
end) end)

View File

@ -202,8 +202,8 @@ describe('startup defaults', function()
clear{args={}, args_rm={'-i'}, env=env} clear{args={}, args_rm={'-i'}, env=env}
-- Default 'shadafile' is empty. -- Default 'shadafile' is empty.
-- This means use the default location. :help shada-file-name -- This means use the default location. :help shada-file-name
eq('', meths.get_option('shadafile')) eq('', meths.get_option_value('shadafile', {}))
eq('', meths.get_option('viminfofile')) eq('', meths.get_option_value('viminfofile', {}))
-- Check that shada data (such as v:oldfiles) is saved/restored. -- Check that shada data (such as v:oldfiles) is saved/restored.
command('edit Xtest-foo') command('edit Xtest-foo')
command('write') command('write')
@ -227,13 +227,13 @@ describe('startup defaults', function()
args_rm={'runtimepath'}, args_rm={'runtimepath'},
} }
-- Defaults to &runtimepath. -- Defaults to &runtimepath.
eq(meths.get_option('runtimepath'), meths.get_option('packpath')) eq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {}))
-- Does not follow modifications to runtimepath. -- Does not follow modifications to runtimepath.
meths.command('set runtimepath+=foo') meths.command('set runtimepath+=foo')
neq(meths.get_option('runtimepath'), meths.get_option('packpath')) neq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {}))
meths.command('set packpath+=foo') meths.command('set packpath+=foo')
eq(meths.get_option('runtimepath'), meths.get_option('packpath')) eq(meths.get_option_value('runtimepath', {}), meths.get_option_value('packpath', {}))
end) end)
it('v:progpath is set to the absolute path', function() it('v:progpath is set to the absolute path', function()
@ -318,10 +318,10 @@ describe('XDG defaults', function()
USER=nil, USER=nil,
}}) }})
eq('.', meths.get_option('backupdir')) eq('.', meths.get_option_value('backupdir', {}))
eq('.', meths.get_option('viewdir')) eq('.', meths.get_option_value('viewdir', {}))
eq('.', meths.get_option('directory')) eq('.', meths.get_option_value('directory', {}))
eq('.', meths.get_option('undodir')) eq('.', meths.get_option_value('undodir', {}))
ok((funcs.tempname()):len() > 4) ok((funcs.tempname()):len() > 4)
end) end)
end) end)
@ -383,7 +383,7 @@ describe('XDG defaults', function()
.. ',' .. root_path .. ('/b'):rep(2048) .. '/nvim/after' .. ',' .. root_path .. ('/b'):rep(2048) .. '/nvim/after'
.. ',' .. root_path .. ('/a'):rep(2048) .. '/nvim/after' .. ',' .. root_path .. ('/a'):rep(2048) .. '/nvim/after'
.. ',' .. root_path .. ('/x'):rep(4096) .. '/nvim/after' .. ',' .. root_path .. ('/x'):rep(4096) .. '/nvim/after'
):gsub('\\', '/')), (meths.get_option('runtimepath')):gsub('\\', '/')) ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/'))
meths.command('set runtimepath&') meths.command('set runtimepath&')
meths.command('set backupdir&') meths.command('set backupdir&')
meths.command('set directory&') meths.command('set directory&')
@ -407,15 +407,15 @@ describe('XDG defaults', function()
.. ',' .. root_path .. ('/b'):rep(2048) .. '/nvim/after' .. ',' .. root_path .. ('/b'):rep(2048) .. '/nvim/after'
.. ',' .. root_path .. ('/a'):rep(2048) .. '/nvim/after' .. ',' .. root_path .. ('/a'):rep(2048) .. '/nvim/after'
.. ',' .. root_path .. ('/x'):rep(4096) .. '/nvim/after' .. ',' .. root_path .. ('/x'):rep(4096) .. '/nvim/after'
):gsub('\\', '/')), (meths.get_option('runtimepath')):gsub('\\', '/')) ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/'))
eq('.,' .. root_path .. ('/X'):rep(4096).. '/' .. state_dir .. '/backup//', eq('.,' .. root_path .. ('/X'):rep(4096).. '/' .. state_dir .. '/backup//',
(meths.get_option('backupdir'):gsub('\\', '/'))) (meths.get_option_value('backupdir', {}):gsub('\\', '/')))
eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/swap//', eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/swap//',
(meths.get_option('directory')):gsub('\\', '/')) (meths.get_option_value('directory', {})):gsub('\\', '/'))
eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/undo//', eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/undo//',
(meths.get_option('undodir')):gsub('\\', '/')) (meths.get_option_value('undodir', {})):gsub('\\', '/'))
eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/view//', eq(root_path .. ('/X'):rep(4096) .. '/' .. state_dir .. '/view//',
(meths.get_option('viewdir')):gsub('\\', '/')) (meths.get_option_value('viewdir', {})):gsub('\\', '/'))
end) end)
end) end)
@ -450,7 +450,7 @@ describe('XDG defaults', function()
.. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after' .. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after'
.. ',$XDG_DATA_DIRS/nvim/after' .. ',$XDG_DATA_DIRS/nvim/after'
.. ',$XDG_DATA_HOME/nvim/after' .. ',$XDG_DATA_HOME/nvim/after'
):gsub('\\', '/')), (meths.get_option('runtimepath')):gsub('\\', '/')) ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/'))
meths.command('set runtimepath&') meths.command('set runtimepath&')
meths.command('set backupdir&') meths.command('set backupdir&')
meths.command('set directory&') meths.command('set directory&')
@ -466,15 +466,15 @@ describe('XDG defaults', function()
.. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after' .. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after'
.. ',$XDG_DATA_DIRS/nvim/after' .. ',$XDG_DATA_DIRS/nvim/after'
.. ',$XDG_DATA_HOME/nvim/after' .. ',$XDG_DATA_HOME/nvim/after'
):gsub('\\', '/')), (meths.get_option('runtimepath')):gsub('\\', '/')) ):gsub('\\', '/')), (meths.get_option_value('runtimepath', {})):gsub('\\', '/'))
eq(('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'), eq(('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'),
meths.get_option('backupdir'):gsub('\\', '/')) meths.get_option_value('backupdir', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'), eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'),
meths.get_option('directory'):gsub('\\', '/')) meths.get_option_value('directory', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'), eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'),
meths.get_option('undodir'):gsub('\\', '/')) meths.get_option_value('undodir', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'),
meths.get_option('viewdir'):gsub('\\', '/')) meths.get_option_value('viewdir', {}):gsub('\\', '/'))
meths.command('set all&') meths.command('set all&')
eq(('$XDG_DATA_HOME/nvim' eq(('$XDG_DATA_HOME/nvim'
.. ',$XDG_DATA_DIRS/nvim' .. ',$XDG_DATA_DIRS/nvim'
@ -486,15 +486,15 @@ describe('XDG defaults', function()
.. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after' .. ',$XDG_CONFIG_HOME/' .. data_dir .. '/site/after'
.. ',$XDG_DATA_DIRS/nvim/after' .. ',$XDG_DATA_DIRS/nvim/after'
.. ',$XDG_DATA_HOME/nvim/after' .. ',$XDG_DATA_HOME/nvim/after'
):gsub('\\', '/'), (meths.get_option('runtimepath')):gsub('\\', '/')) ):gsub('\\', '/'), (meths.get_option_value('runtimepath', {})):gsub('\\', '/'))
eq(('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'), eq(('.,$XDG_CONFIG_HOME/' .. state_dir .. '/backup//'),
meths.get_option('backupdir'):gsub('\\', '/')) meths.get_option_value('backupdir', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'), eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/swap//'),
meths.get_option('directory'):gsub('\\', '/')) meths.get_option_value('directory', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'), eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/undo//'),
meths.get_option('undodir'):gsub('\\', '/')) meths.get_option_value('undodir', {}):gsub('\\', '/'))
eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'), eq(('$XDG_CONFIG_HOME/' .. state_dir .. '/view//'),
meths.get_option('viewdir'):gsub('\\', '/')) meths.get_option_value('viewdir', {}):gsub('\\', '/'))
eq(nil, (funcs.tempname()):match('XDG_RUNTIME_DIR')) eq(nil, (funcs.tempname()):match('XDG_RUNTIME_DIR'))
end) end)
end) end)
@ -529,7 +529,7 @@ describe('XDG defaults', function()
.. ',-\\,-\\,-' .. path_sep .. 'nvim' .. path_sep .. 'after' .. ',-\\,-\\,-' .. path_sep .. 'nvim' .. path_sep .. 'after'
.. ',\\,-\\,-\\,' .. path_sep .. 'nvim' .. path_sep .. 'after' .. ',\\,-\\,-\\,' .. path_sep .. 'nvim' .. path_sep .. 'after'
.. ',\\, \\, \\,' .. path_sep .. 'nvim' .. path_sep .. 'after' .. ',\\, \\, \\,' .. path_sep .. 'nvim' .. path_sep .. 'after'
), meths.get_option('runtimepath')) ), meths.get_option_value('runtimepath', {}))
meths.command('set runtimepath&') meths.command('set runtimepath&')
meths.command('set backupdir&') meths.command('set backupdir&')
meths.command('set directory&') meths.command('set directory&')
@ -549,15 +549,15 @@ describe('XDG defaults', function()
.. ',-\\,-\\,-' .. path_sep ..'nvim' .. path_sep ..'after' .. ',-\\,-\\,-' .. path_sep ..'nvim' .. path_sep ..'after'
.. ',\\,-\\,-\\,' .. path_sep ..'nvim' .. path_sep ..'after' .. ',\\,-\\,-\\,' .. path_sep ..'nvim' .. path_sep ..'after'
.. ',\\, \\, \\,' .. path_sep ..'nvim' .. path_sep ..'after' .. ',\\, \\, \\,' .. path_sep ..'nvim' .. path_sep ..'after'
), meths.get_option('runtimepath')) ), meths.get_option_value('runtimepath', {}))
eq('.,\\,=\\,=\\,' .. path_sep .. state_dir .. '' .. path_sep ..'backup' .. (path_sep):rep(2), eq('.,\\,=\\,=\\,' .. path_sep .. state_dir .. '' .. path_sep ..'backup' .. (path_sep):rep(2),
meths.get_option('backupdir')) meths.get_option_value('backupdir', {}))
eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'swap' .. (path_sep):rep(2), eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'swap' .. (path_sep):rep(2),
meths.get_option('directory')) meths.get_option_value('directory', {}))
eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'undo' .. (path_sep):rep(2), eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'undo' .. (path_sep):rep(2),
meths.get_option('undodir')) meths.get_option_value('undodir', {}))
eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'view' .. (path_sep):rep(2), eq('\\,=\\,=\\,' .. path_sep ..'' .. state_dir .. '' .. path_sep ..'view' .. (path_sep):rep(2),
meths.get_option('viewdir')) meths.get_option_value('viewdir', {}))
end) end)
end) end)
end) end)

View File

@ -11,7 +11,7 @@ local function should_fail(opt, value, errmsg)
feed_command('setlocal ' .. opt .. '=' .. value) feed_command('setlocal ' .. opt .. '=' .. value)
eq(errmsg, eval("v:errmsg"):match("E%d*")) eq(errmsg, eval("v:errmsg"):match("E%d*"))
feed_command('let v:errmsg = ""') feed_command('let v:errmsg = ""')
local status, err = pcall(meths.set_option, opt, value) local status, err = pcall(meths.set_option_value, opt, value, {})
eq(status, false) eq(status, false)
eq(errmsg, err:match("E%d*")) eq(errmsg, err:match("E%d*"))
eq('', eval("v:errmsg")) eq('', eval("v:errmsg"))
@ -20,8 +20,8 @@ end
local function should_succeed(opt, value) local function should_succeed(opt, value)
feed_command('setglobal ' .. opt .. '=' .. value) feed_command('setglobal ' .. opt .. '=' .. value)
feed_command('setlocal ' .. opt .. '=' .. value) feed_command('setlocal ' .. opt .. '=' .. value)
meths.set_option(opt, value) meths.set_option_value(opt, value, {})
eq(value, meths.get_option(opt)) eq(value, meths.get_option_value(opt, {}))
eq('', eval("v:errmsg")) eq('', eval("v:errmsg"))
end end
@ -29,12 +29,12 @@ describe(':setlocal', function()
before_each(clear) before_each(clear)
it('setlocal sets only local value', function() it('setlocal sets only local value', function()
eq(0, meths.get_option('iminsert')) eq(0, meths.get_option_value('iminsert', {scope='global'}))
feed_command('setlocal iminsert=1') feed_command('setlocal iminsert=1')
eq(0, meths.get_option('iminsert')) eq(0, meths.get_option_value('iminsert', {scope='global'}))
eq(-1, meths.get_option('imsearch')) eq(-1, meths.get_option_value('imsearch', {scope='global'}))
feed_command('setlocal imsearch=1') feed_command('setlocal imsearch=1')
eq(-1, meths.get_option('imsearch')) eq(-1, meths.get_option_value('imsearch', {scope='global'}))
end) end)
end) end)
@ -77,8 +77,8 @@ describe(':set validation', function()
-- If smaller than 1 this one is set to 'lines'-1 -- If smaller than 1 this one is set to 'lines'-1
feed_command('setglobal window=-10') feed_command('setglobal window=-10')
meths.set_option('window', -10) meths.set_option_value('window', -10, {})
eq(23, meths.get_option('window')) eq(23, meths.get_option_value('window', {}))
eq('', eval("v:errmsg")) eq('', eval("v:errmsg"))
-- 'scrolloff' and 'sidescrolloff' can have a -1 value when -- 'scrolloff' and 'sidescrolloff' can have a -1 value when
@ -112,8 +112,8 @@ describe(':set validation', function()
local function setto(value) local function setto(value)
feed_command('setglobal maxcombine=' .. value) feed_command('setglobal maxcombine=' .. value)
feed_command('setlocal maxcombine=' .. value) feed_command('setlocal maxcombine=' .. value)
meths.set_option('maxcombine', value) meths.set_option_value('maxcombine', value, {})
eq(6, meths.get_option('maxcombine')) eq(6, meths.get_option_value('maxcombine', {}))
eq('', eval("v:errmsg")) eq('', eval("v:errmsg"))
end end
setto(0) setto(0)

View File

@ -3,7 +3,6 @@ local clear = helpers.clear
local command = helpers.command local command = helpers.command
local eq = helpers.eq local eq = helpers.eq
local pathsep = helpers.get_pathsep() local pathsep = helpers.get_pathsep()
local curbufmeths = helpers.curbufmeths
local funcs = helpers.funcs local funcs = helpers.funcs
local meths = helpers.meths local meths = helpers.meths
@ -13,7 +12,7 @@ local function test_case(name, expected)
local filename = testdir .. pathsep .. name local filename = testdir .. pathsep .. name
command('edit ' .. filename) command('edit ' .. filename)
for opt, val in pairs(expected) do for opt, val in pairs(expected) do
eq(val, curbufmeths.get_option(opt), name) eq(val, meths.get_option_value(opt, {buf=0}), name)
end end
end end

View File

@ -21,7 +21,7 @@ before_each(function ()
-- ["mac"] = '\r', -- ["mac"] = '\r',
-- } -- }
-- local line_ending = format_line_ending[vim.api.nvim_buf_get_option(0, 'fileformat')] -- local line_ending = format_line_ending[vim.api.nvim_get_option_value('fileformat', {buf=0})]
function test_register(bufnr, id, offset_encoding, line_ending) function test_register(bufnr, id, offset_encoding, line_ending)

View File

@ -33,7 +33,9 @@ local test_rpc_server = lsp_helpers.test_rpc_server
local function get_buf_option(name, bufnr) local function get_buf_option(name, bufnr)
bufnr = bufnr or "BUFFER" bufnr = bufnr or "BUFFER"
return exec_lua(string.format("return vim.api.nvim_buf_get_option(%s, '%s')", bufnr, name)) return exec_lua(
string.format("return vim.api.nvim_get_option_value('%s', { buf = %s })", name, bufnr)
)
end end
-- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837 -- TODO(justinmk): hangs on Windows https://github.com/neovim/neovim/pull/11837
@ -356,8 +358,8 @@ describe('LSP', function()
vim.api.nvim_command('filetype plugin on') vim.api.nvim_command('filetype plugin on')
BUFFER_1 = vim.api.nvim_create_buf(false, true) BUFFER_1 = vim.api.nvim_create_buf(false, true)
BUFFER_2 = vim.api.nvim_create_buf(false, true) BUFFER_2 = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(BUFFER_1, 'filetype', 'man') vim.api.nvim_set_option_value('filetype', 'man', { buf = BUFFER_1 })
vim.api.nvim_buf_set_option(BUFFER_2, 'filetype', 'xml') vim.api.nvim_set_option_value('filetype', 'xml', { buf = BUFFER_2 })
]] ]]
-- Sanity check to ensure that some values are set after setting filetype. -- Sanity check to ensure that some values are set after setting filetype.
@ -394,9 +396,9 @@ describe('LSP', function()
client = _client client = _client
exec_lua [[ exec_lua [[
BUFFER = vim.api.nvim_create_buf(false, true) BUFFER = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(BUFFER, 'tagfunc', 'tfu') vim.api.nvim_set_option_value('tagfunc', 'tfu', { buf = BUFFER })
vim.api.nvim_buf_set_option(BUFFER, 'omnifunc', 'ofu') vim.api.nvim_set_option_value('omnifunc', 'ofu', { buf = BUFFER })
vim.api.nvim_buf_set_option(BUFFER, 'formatexpr', 'fex') vim.api.nvim_set_option_value('formatexpr', 'fex', { buf = BUFFER })
lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID) lsp.buf_attach_client(BUFFER, TEST_RPC_CLIENT_ID)
]] ]]
end; end;
@ -1166,7 +1168,7 @@ describe('LSP', function()
"testing"; "testing";
"123"; "123";
}) })
vim.api.nvim_buf_set_option(BUFFER, 'eol', false) vim.bo[BUFFER].eol = false
]] ]]
end; end;
on_init = function(_client) on_init = function(_client)
@ -2929,8 +2931,8 @@ describe('LSP', function()
describe('lsp.util.get_effective_tabstop', function() describe('lsp.util.get_effective_tabstop', function()
local function test_tabstop(tabsize, shiftwidth) local function test_tabstop(tabsize, shiftwidth)
exec_lua(string.format([[ exec_lua(string.format([[
vim.api.nvim_buf_set_option(0, 'shiftwidth', %d) vim.bo.shiftwidth = %d
vim.api.nvim_buf_set_option(0, 'tabstop', 2) vim.bo.tabstop = 2
]], shiftwidth)) ]], shiftwidth))
eq(tabsize, exec_lua('return vim.lsp.util.get_effective_tabstop()')) eq(tabsize, exec_lua('return vim.lsp.util.get_effective_tabstop()'))
end end

View File

@ -2181,8 +2181,8 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(false, curbuf('get_option', 'modified')) eq(false, nvim('get_option_value', 'modified', {buf=0}))
eq('shada', curbuf('get_option', 'filetype')) eq('shada', nvim('get_option_value', 'filetype', {buf=0}))
nvim_command('edit ' .. fname_tmp) nvim_command('edit ' .. fname_tmp)
eq({ eq({
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
@ -2191,8 +2191,8 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "b"', ' - "b"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(false, curbuf('get_option', 'modified')) eq(false, nvim('get_option_value', 'modified', {buf=0}))
eq('shada', curbuf('get_option', 'filetype')) eq('shada', nvim('get_option_value', 'filetype', {buf=0}))
eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname)) eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname))
neq({ neq({
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
@ -2201,7 +2201,7 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
neq(true, curbuf('get_option', 'modified')) neq(true, nvim('get_option_value', 'modified', {buf=0}))
end) end)
it('event FileReadCmd', function() it('event FileReadCmd', function()
@ -2217,8 +2217,8 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(true, curbuf('get_option', 'modified')) eq(true, nvim('get_option_value', 'modified', {buf=0}))
neq('shada', curbuf('get_option', 'filetype')) neq('shada', nvim('get_option_value', 'filetype', {buf=0}))
nvim_command('1,$read ' .. fname_tmp) nvim_command('1,$read ' .. fname_tmp)
eq({ eq({
'', '',
@ -2233,9 +2233,9 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "b"', ' - "b"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(true, curbuf('get_option', 'modified')) eq(true, nvim('get_option_value', 'modified', {buf=0}))
neq('shada', curbuf('get_option', 'filetype')) neq('shada', nvim('get_option_value', 'filetype', {buf=0}))
curbuf('set_option', 'modified', false) nvim('set_option_value', 'modified', false, {buf=0})
eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname)) eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname))
eq({ eq({
'', '',
@ -2250,7 +2250,7 @@ describe('plugin/shada.vim', function()
' - contents "ab"', ' - contents "ab"',
' - "b"', ' - "b"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
neq(true, curbuf('get_option', 'modified')) neq(true, nvim('get_option_value', 'modified', {buf=0}))
end) end)
it('event BufWriteCmd', function() it('event BufWriteCmd', function()
@ -2517,10 +2517,10 @@ describe('ftplugin/shada.vim', function()
it('sets options correctly', function() it('sets options correctly', function()
nvim_command('filetype plugin indent on') nvim_command('filetype plugin indent on')
nvim_command('setlocal filetype=shada') nvim_command('setlocal filetype=shada')
eq(true, curbuf('get_option', 'expandtab')) eq(true, nvim('get_option_value', 'expandtab', {buf=0}))
eq(2, curbuf('get_option', 'tabstop')) eq(2, nvim('get_option_value', 'tabstop', {buf=0}))
eq(2, curbuf('get_option', 'softtabstop')) eq(2, nvim('get_option_value', 'softtabstop', {buf=0}))
eq(2, curbuf('get_option', 'shiftwidth')) eq(2, nvim('get_option_value', 'shiftwidth', {buf=0}))
end) end)
it('sets indentkeys correctly', function() it('sets indentkeys correctly', function()

View File

@ -5,7 +5,7 @@ local command = helpers.command
local write_file = helpers.write_file local write_file = helpers.write_file
local eval = helpers.eval local eval = helpers.eval
local retry = helpers.retry local retry = helpers.retry
local curbufmeths = helpers.curbufmeths local meths = helpers.meths
local insert = helpers.insert local insert = helpers.insert
local expect = helpers.expect local expect = helpers.expect
local feed = helpers.feed local feed = helpers.feed
@ -45,7 +45,7 @@ describe('legacy perl provider', function()
-- :perldo 1; doesn't change $_, -- :perldo 1; doesn't change $_,
-- the buffer should not be changed -- the buffer should not be changed
command('normal :perldo 1;') command('normal :perldo 1;')
eq(false, curbufmeths.get_option('modified')) eq(false, meths.get_option_value('modified', {buf=0}))
-- insert some text -- insert some text
insert('abc\ndef\nghi') insert('abc\ndef\nghi')
expect([[ expect([[

View File

@ -3,7 +3,6 @@ local helpers = require('test.functional.helpers')(after_each)
local assert_alive = helpers.assert_alive local assert_alive = helpers.assert_alive
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq = helpers.eq local eq = helpers.eq
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local expect = helpers.expect local expect = helpers.expect
@ -98,7 +97,7 @@ describe(':rubydo command', function()
it('does not modify the buffer if no changes are made', function() it('does not modify the buffer if no changes are made', function()
command('normal :rubydo 42') command('normal :rubydo 42')
eq(false, curbufmeths.get_option('modified')) eq(false, meths.get_option_value('modified', {buf=0}))
end) end)
end) end)

View File

@ -1,7 +1,7 @@
-- shada buffer list saving/reading support -- shada buffer list saving/reading support
local helpers = require('test.functional.helpers')(after_each) local helpers = require('test.functional.helpers')(after_each)
local nvim_command, funcs, eq, curbufmeths = local nvim_command, funcs, eq, curbufmeths, meths =
helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths helpers.command, helpers.funcs, helpers.eq, helpers.curbufmeths, helpers.meths
local expect_exit = helpers.expect_exit local expect_exit = helpers.expect_exit
local shada_helpers = require('test.functional.shada.helpers') local shada_helpers = require('test.functional.shada.helpers')
@ -48,7 +48,7 @@ describe('shada support code', function()
reset('set shada+=%') reset('set shada+=%')
nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2) nvim_command('edit ' .. testfilename_2)
curbufmeths.set_option('buflisted', false) meths.set_option_value('buflisted', false, {buf=0})
expect_exit(nvim_command, 'qall') expect_exit(nvim_command, 'qall')
reset('set shada+=%') reset('set shada+=%')
eq(2, funcs.bufnr('$')) eq(2, funcs.bufnr('$'))
@ -60,7 +60,7 @@ describe('shada support code', function()
reset('set shada+=%') reset('set shada+=%')
nvim_command('edit ' .. testfilename) nvim_command('edit ' .. testfilename)
nvim_command('edit ' .. testfilename_2) nvim_command('edit ' .. testfilename_2)
curbufmeths.set_option('buftype', 'quickfix') meths.set_option_value('buftype', 'quickfix', {buf=0})
expect_exit(nvim_command, 'qall') expect_exit(nvim_command, 'qall')
reset('set shada+=%') reset('set shada+=%')
eq(2, funcs.bufnr('$')) eq(2, funcs.bufnr('$'))

View File

@ -106,13 +106,13 @@ describe('ShaDa support code', function()
end) end)
it('dumps and loads last search pattern with offset', function() it('dumps and loads last search pattern with offset', function()
meths.set_option('wrapscan', false) meths.set_option_value('wrapscan', false, {})
funcs.setline('.', {'foo', 'bar--'}) funcs.setline('.', {'foo', 'bar--'})
nvim_feed('gg0/a/e+1\n') nvim_feed('gg0/a/e+1\n')
eq({0, 2, 3, 0}, funcs.getpos('.')) eq({0, 2, 3, 0}, funcs.getpos('.'))
nvim_command('wshada') nvim_command('wshada')
reset() reset()
meths.set_option('wrapscan', false) meths.set_option_value('wrapscan', false, {})
funcs.setline('.', {'foo', 'bar--'}) funcs.setline('.', {'foo', 'bar--'})
nvim_feed('gg0n') nvim_feed('gg0n')
eq({0, 2, 3, 0}, funcs.getpos('.')) eq({0, 2, 3, 0}, funcs.getpos('.'))
@ -121,13 +121,13 @@ describe('ShaDa support code', function()
it('dumps and loads last search pattern with offset and backward direction', it('dumps and loads last search pattern with offset and backward direction',
function() function()
meths.set_option('wrapscan', false) meths.set_option_value('wrapscan', false, {})
funcs.setline('.', {'foo', 'bar--'}) funcs.setline('.', {'foo', 'bar--'})
nvim_feed('G$?a?e+1\n') nvim_feed('G$?a?e+1\n')
eq({0, 2, 3, 0}, funcs.getpos('.')) eq({0, 2, 3, 0}, funcs.getpos('.'))
nvim_command('wshada') nvim_command('wshada')
reset() reset()
meths.set_option('wrapscan', false) meths.set_option_value('wrapscan', false, {})
funcs.setline('.', {'foo', 'bar--'}) funcs.setline('.', {'foo', 'bar--'})
nvim_feed('G$n') nvim_feed('G$n')
eq({0, 2, 3, 0}, funcs.getpos('.')) eq({0, 2, 3, 0}, funcs.getpos('.'))

View File

@ -196,30 +196,30 @@ describe('ShaDa support code', function()
end) end)
it('is able to set &shada after &viminfo', function() it('is able to set &shada after &viminfo', function()
meths.set_option('viminfo', '\'10') meths.set_option_value('viminfo', '\'10', {})
eq('\'10', meths.get_option('viminfo')) eq('\'10', meths.get_option_value('viminfo', {}))
eq('\'10', meths.get_option('shada')) eq('\'10', meths.get_option_value('shada', {}))
meths.set_option('shada', '') meths.set_option_value('shada', '', {})
eq('', meths.get_option('viminfo')) eq('', meths.get_option_value('viminfo', {}))
eq('', meths.get_option('shada')) eq('', meths.get_option_value('shada', {}))
end) end)
it('is able to set all& after setting &shada', function() it('is able to set all& after setting &shada', function()
meths.set_option('shada', '\'10') meths.set_option_value('shada', '\'10', {})
eq('\'10', meths.get_option('viminfo')) eq('\'10', meths.get_option_value('viminfo', {}))
eq('\'10', meths.get_option('shada')) eq('\'10', meths.get_option_value('shada', {}))
nvim_command('set all&') nvim_command('set all&')
eq('!,\'100,<50,s10,h', meths.get_option('viminfo')) eq('!,\'100,<50,s10,h', meths.get_option_value('viminfo', {}))
eq('!,\'100,<50,s10,h', meths.get_option('shada')) eq('!,\'100,<50,s10,h', meths.get_option_value('shada', {}))
end) end)
it('is able to set &shada after &viminfo using :set', function() it('is able to set &shada after &viminfo using :set', function()
nvim_command('set viminfo=\'10') nvim_command('set viminfo=\'10')
eq('\'10', meths.get_option('viminfo')) eq('\'10', meths.get_option_value('viminfo', {}))
eq('\'10', meths.get_option('shada')) eq('\'10', meths.get_option_value('shada', {}))
nvim_command('set shada=') nvim_command('set shada=')
eq('', meths.get_option('viminfo')) eq('', meths.get_option_value('viminfo', {}))
eq('', meths.get_option('shada')) eq('', meths.get_option_value('shada', {}))
end) end)
it('setting &shada gives proper error message on missing number', function() it('setting &shada gives proper error message on missing number', function()
@ -237,12 +237,12 @@ describe('ShaDa support code', function()
funcs.mkdir(dirname, '', 0) funcs.mkdir(dirname, '', 0)
eq(0, funcs.filewritable(dirname)) eq(0, funcs.filewritable(dirname))
reset{shadafile=dirshada, args={'--cmd', 'set shada='}} reset{shadafile=dirshada, args={'--cmd', 'set shada='}}
meths.set_option('shada', '\'10') meths.set_option_value('shada', '\'10', {})
eq('Vim(wshada):E886: System error while opening ShaDa file ' eq('Vim(wshada):E886: System error while opening ShaDa file '
.. 'Xtest-functional-shada-shada.d/main.shada for reading to merge ' .. 'Xtest-functional-shada-shada.d/main.shada for reading to merge '
.. 'before writing it: permission denied', .. 'before writing it: permission denied',
exc_exec('wshada')) exc_exec('wshada'))
meths.set_option('shada', '') meths.set_option_value('shada', '', {})
end) end)
end) end)

View File

@ -197,7 +197,7 @@ describe(':terminal buffer', function()
it('handles loss of focus gracefully', function() it('handles loss of focus gracefully', function()
-- Change the statusline to avoid printing the file name, which varies. -- Change the statusline to avoid printing the file name, which varies.
nvim('set_option', 'statusline', '==========') nvim('set_option_value', 'statusline', '==========', {})
feed_command('set laststatus=0') feed_command('set laststatus=0')
-- Save the buffer number of the terminal for later testing. -- Save the buffer number of the terminal for later testing.

View File

@ -21,8 +21,8 @@ describe(':edit term://*', function()
before_each(function() before_each(function()
clear() clear()
meths.set_option('shell', testprg('shell-test')) meths.set_option_value('shell', testprg('shell-test'), {})
meths.set_option('shellcmdflag', 'EXE') meths.set_option_value('shellcmdflag', 'EXE', {})
end) end)
it('runs TermOpen event', function() it('runs TermOpen event', function()
@ -40,7 +40,7 @@ describe(':edit term://*', function()
local columns, lines = 20, 4 local columns, lines = 20, 4
local scr = get_screen(columns, lines) local scr = get_screen(columns, lines)
local rep = 97 local rep = 97
meths.set_option('shellcmdflag', 'REP ' .. rep) meths.set_option_value('shellcmdflag', 'REP ' .. rep, {})
command('set shellxquote=') -- win: avoid extra quotes command('set shellxquote=') -- win: avoid extra quotes
local sb = 10 local sb = 10
command('autocmd TermOpen * :setlocal scrollback='..tostring(sb) command('autocmd TermOpen * :setlocal scrollback='..tostring(sb)

View File

@ -133,8 +133,8 @@ describe(':terminal (with fake shell)', function()
screen = Screen.new(50, 4) screen = Screen.new(50, 4)
screen:attach({rgb=false}) screen:attach({rgb=false})
-- shell-test.c is a fake shell that prints its arguments and exits. -- shell-test.c is a fake shell that prints its arguments and exits.
nvim('set_option', 'shell', testprg('shell-test')) nvim('set_option_value', 'shell', testprg('shell-test'), {})
nvim('set_option', 'shellcmdflag', 'EXE') nvim('set_option_value', 'shellcmdflag', 'EXE', {})
end) end)
-- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints -- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints
@ -157,7 +157,7 @@ describe(':terminal (with fake shell)', function()
end) end)
it("with no argument, and 'shell' is set to empty string", function() it("with no argument, and 'shell' is set to empty string", function()
nvim('set_option', 'shell', '') nvim('set_option_value', 'shell', '', {})
terminal_with_fake_shell() terminal_with_fake_shell()
screen:expect([[ screen:expect([[
^ | ^ |
@ -169,7 +169,7 @@ describe(':terminal (with fake shell)', function()
it("with no argument, but 'shell' has arguments, acts like termopen()", function() it("with no argument, but 'shell' has arguments, acts like termopen()", function()
skip(is_os('win')) skip(is_os('win'))
nvim('set_option', 'shell', testprg('shell-test')..' -t jeff') nvim('set_option_value', 'shell', testprg('shell-test')..' -t jeff', {})
terminal_with_fake_shell() terminal_with_fake_shell()
screen:expect([[ screen:expect([[
^jeff $ | ^jeff $ |
@ -193,7 +193,7 @@ describe(':terminal (with fake shell)', function()
it("executes a given command through the shell, when 'shell' has arguments", function() it("executes a given command through the shell, when 'shell' has arguments", function()
skip(is_os('win')) skip(is_os('win'))
nvim('set_option', 'shell', testprg('shell-test')..' -t jeff') nvim('set_option_value', 'shell', testprg('shell-test')..' -t jeff', {})
command('set shellxquote=') -- win: avoid extra quotes command('set shellxquote=') -- win: avoid extra quotes
terminal_with_fake_shell('echo hi') terminal_with_fake_shell('echo hi')
screen:expect([[ screen:expect([[

View File

@ -11,7 +11,7 @@ describe(':terminal mouse', function()
before_each(function() before_each(function()
clear() clear()
nvim('set_option', 'statusline', '==========') nvim('set_option_value', 'statusline', '==========', {})
command('highlight StatusLine cterm=NONE') command('highlight StatusLine cterm=NONE')
command('highlight StatusLineNC cterm=NONE') command('highlight StatusLineNC cterm=NONE')
command('highlight VertSplit cterm=NONE') command('highlight VertSplit cterm=NONE')
@ -352,7 +352,7 @@ describe(':terminal mouse', function()
end) end)
it('handles terminal size when switching buffers', function() it('handles terminal size when switching buffers', function()
nvim('set_option', 'hidden', true) nvim('set_option_value', 'hidden', true, {})
feed('<c-\\><c-n><c-w><c-w>') feed('<c-\\><c-n><c-w><c-w>')
screen:expect([[ screen:expect([[
{7: 27 }line line30 | {7: 27 }line line30 |

View File

@ -8,7 +8,7 @@ local command = helpers.command
local matches = helpers.matches local matches = helpers.matches
local poke_eventloop = helpers.poke_eventloop local poke_eventloop = helpers.poke_eventloop
local retry = helpers.retry local retry = helpers.retry
local curbufmeths = helpers.curbufmeths local meths = helpers.meths
local nvim = helpers.nvim local nvim = helpers.nvim
local feed_data = thelpers.feed_data local feed_data = thelpers.feed_data
local pcall_err = helpers.pcall_err local pcall_err = helpers.pcall_err
@ -381,8 +381,8 @@ describe("'scrollback' option", function()
local function set_fake_shell() local function set_fake_shell()
-- shell-test.c is a fake shell that prints its arguments and exits. -- shell-test.c is a fake shell that prints its arguments and exits.
nvim('set_option', 'shell', testprg('shell-test')) nvim('set_option_value', 'shell', testprg('shell-test'), {})
nvim('set_option', 'shellcmdflag', 'EXE') nvim('set_option_value', 'shellcmdflag', 'EXE', {})
end end
local function expect_lines(expected, epsilon) local function expect_lines(expected, epsilon)
@ -401,7 +401,7 @@ describe("'scrollback' option", function()
screen = thelpers.screen_setup(nil, "['sh']", 30) screen = thelpers.screen_setup(nil, "['sh']", 30)
end end
curbufmeths.set_option('scrollback', 0) meths.set_option_value('scrollback', 0, {buf = 0})
feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n')) feed_data(('%s REP 31 line%s'):format(testprg('shell-test'), is_os('win') and '\r' or '\n'))
screen:expect{any='30: line '} screen:expect{any='30: line '}
retry(nil, nil, function() expect_lines(7) end) retry(nil, nil, function() expect_lines(7) end)
@ -417,7 +417,7 @@ describe("'scrollback' option", function()
screen = thelpers.screen_setup(nil, "['sh']", 30) screen = thelpers.screen_setup(nil, "['sh']", 30)
end end
curbufmeths.set_option('scrollback', 200) meths.set_option_value('scrollback', 200, {buf=0})
-- Wait for prompt. -- Wait for prompt.
screen:expect{any='%$'} screen:expect{any='%$'}
@ -426,10 +426,10 @@ describe("'scrollback' option", function()
screen:expect{any='30: line '} screen:expect{any='30: line '}
retry(nil, nil, function() expect_lines(33, 2) end) retry(nil, nil, function() expect_lines(33, 2) end)
curbufmeths.set_option('scrollback', 10) meths.set_option_value('scrollback', 10, {buf=0})
poke_eventloop() poke_eventloop()
retry(nil, nil, function() expect_lines(16) end) retry(nil, nil, function() expect_lines(16) end)
curbufmeths.set_option('scrollback', 10000) meths.set_option_value('scrollback', 10000, {buf=0})
retry(nil, nil, function() expect_lines(16) end) retry(nil, nil, function() expect_lines(16) end)
-- Terminal job data is received asynchronously, may happen before the -- Terminal job data is received asynchronously, may happen before the
-- 'scrollback' option is synchronized with the internal sb_buffer. -- 'scrollback' option is synchronized with the internal sb_buffer.
@ -484,18 +484,18 @@ describe("'scrollback' option", function()
]]) ]])
local term_height = 6 -- Actual terminal screen height, not the scrollback local term_height = 6 -- Actual terminal screen height, not the scrollback
-- Initial -- Initial
local scrollback = curbufmeths.get_option('scrollback') local scrollback = meths.get_option_value('scrollback', {buf=0})
eq(scrollback + term_height, eval('line("$")')) eq(scrollback + term_height, eval('line("$")'))
-- Reduction -- Reduction
scrollback = scrollback - 2 scrollback = scrollback - 2
curbufmeths.set_option('scrollback', scrollback) meths.set_option_value('scrollback', scrollback, {buf=0})
eq(scrollback + term_height, eval('line("$")')) eq(scrollback + term_height, eval('line("$")'))
end) end)
it('defaults to 10000 in :terminal buffers', function() it('defaults to 10000 in :terminal buffers', function()
set_fake_shell() set_fake_shell()
command('terminal') command('terminal')
eq(10000, curbufmeths.get_option('scrollback')) eq(10000, meths.get_option_value('scrollback', {buf=0}))
end) end)
it('error if set to invalid value', function() it('error if set to invalid value', function()
@ -507,7 +507,7 @@ describe("'scrollback' option", function()
it('defaults to -1 on normal buffers', function() it('defaults to -1 on normal buffers', function()
command('new') command('new')
eq(-1, curbufmeths.get_option('scrollback')) eq(-1, meths.get_option_value('scrollback', {buf=0}))
end) end)
it(':setlocal in a :terminal buffer', function() it(':setlocal in a :terminal buffer', function()
@ -516,45 +516,45 @@ describe("'scrollback' option", function()
-- _Global_ scrollback=-1 defaults :terminal to 10_000. -- _Global_ scrollback=-1 defaults :terminal to 10_000.
command('setglobal scrollback=-1') command('setglobal scrollback=-1')
command('terminal') command('terminal')
eq(10000, curbufmeths.get_option('scrollback')) eq(10000, meths.get_option_value('scrollback', {buf=0}))
-- _Local_ scrollback=-1 in :terminal forces the _maximum_. -- _Local_ scrollback=-1 in :terminal forces the _maximum_.
command('setlocal scrollback=-1') command('setlocal scrollback=-1')
retry(nil, nil, function() -- Fixup happens on refresh, not immediately. retry(nil, nil, function() -- Fixup happens on refresh, not immediately.
eq(100000, curbufmeths.get_option('scrollback')) eq(100000, meths.get_option_value('scrollback', {buf=0}))
end) end)
-- _Local_ scrollback=-1 during TermOpen forces the maximum. #9605 -- _Local_ scrollback=-1 during TermOpen forces the maximum. #9605
command('setglobal scrollback=-1') command('setglobal scrollback=-1')
command('autocmd TermOpen * setlocal scrollback=-1') command('autocmd TermOpen * setlocal scrollback=-1')
command('terminal') command('terminal')
eq(100000, curbufmeths.get_option('scrollback')) eq(100000, meths.get_option_value('scrollback', {buf=0}))
end) end)
it(':setlocal in a normal buffer', function() it(':setlocal in a normal buffer', function()
command('new') command('new')
-- :setlocal to -1. -- :setlocal to -1.
command('setlocal scrollback=-1') command('setlocal scrollback=-1')
eq(-1, curbufmeths.get_option('scrollback')) eq(-1, meths.get_option_value('scrollback', {buf=0}))
-- :setlocal to anything except -1. Currently, this just has no effect. -- :setlocal to anything except -1. Currently, this just has no effect.
command('setlocal scrollback=42') command('setlocal scrollback=42')
eq(42, curbufmeths.get_option('scrollback')) eq(42, meths.get_option_value('scrollback', {buf=0}))
end) end)
it(':set updates local value and global default', function() it(':set updates local value and global default', function()
set_fake_shell() set_fake_shell()
command('set scrollback=42') -- set global value command('set scrollback=42') -- set global value
eq(42, curbufmeths.get_option('scrollback')) eq(42, meths.get_option_value('scrollback', {buf=0}))
command('terminal') command('terminal')
eq(42, curbufmeths.get_option('scrollback')) -- inherits global default eq(42, meths.get_option_value('scrollback', {buf=0})) -- inherits global default
command('setlocal scrollback=99') command('setlocal scrollback=99')
eq(99, curbufmeths.get_option('scrollback')) eq(99, meths.get_option_value('scrollback', {buf=0}))
command('set scrollback<') -- reset to global default command('set scrollback<') -- reset to global default
eq(42, curbufmeths.get_option('scrollback')) eq(42, meths.get_option_value('scrollback', {buf=0}))
command('setglobal scrollback=734') -- new global default command('setglobal scrollback=734') -- new global default
eq(42, curbufmeths.get_option('scrollback')) -- local value did not change eq(42, meths.get_option_value('scrollback', {buf=0})) -- local value did not change
command('terminal') command('terminal')
eq(734, curbufmeths.get_option('scrollback')) eq(734, meths.get_option_value('scrollback', {buf=0}))
end) end)
end) end)
@ -578,7 +578,7 @@ describe("pending scrollback line handling", function()
local api = vim.api local api = vim.api
local buf = api.nvim_create_buf(true, true) local buf = api.nvim_create_buf(true, true)
local chan = api.nvim_open_term(buf, {}) local chan = api.nvim_open_term(buf, {})
api.nvim_win_set_option(0, "number", true) vim.wo.number = true
api.nvim_chan_send(chan, ("a\n"):rep(11) .. "a") api.nvim_chan_send(chan, ("a\n"):rep(11) .. "a")
api.nvim_win_set_buf(0, buf) api.nvim_win_set_buf(0, buf)
]] ]]

View File

@ -1458,9 +1458,9 @@ describe('TUI', function()
it('allows grid to assume wider ambiguous-width characters than host terminal #19686', function() it('allows grid to assume wider ambiguous-width characters than host terminal #19686', function()
child_session:request('nvim_buf_set_lines', 0, 0, -1, true, { (''):rep(60), (''):rep(60) }) child_session:request('nvim_buf_set_lines', 0, 0, -1, true, { (''):rep(60), (''):rep(60) })
child_session:request('nvim_win_set_option', 0, 'cursorline', true) child_session:request('nvim_set_option_value', 'cursorline', true, {win=0})
child_session:request('nvim_win_set_option', 0, 'list', true) child_session:request('nvim_set_option_value', 'list', true, {win=0})
child_session:request('nvim_win_set_option', 0, 'listchars', 'eol:$') child_session:request('nvim_set_option_value', 'listchars', 'eol:$', {win=0})
feed_data('gg') feed_data('gg')
local singlewidth_screen = [[ local singlewidth_screen = [[
{13:}{12:}| {13:}{12:}|
@ -1483,9 +1483,9 @@ describe('TUI', function()
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]] ]]
screen:expect(singlewidth_screen) screen:expect(singlewidth_screen)
child_session:request('nvim_set_option', 'ambiwidth', 'double') child_session:request('nvim_set_option_value', 'ambiwidth', 'double', {})
screen:expect(doublewidth_screen) screen:expect(doublewidth_screen)
child_session:request('nvim_set_option', 'ambiwidth', 'single') child_session:request('nvim_set_option_value', 'ambiwidth', 'single', {})
screen:expect(singlewidth_screen) screen:expect(singlewidth_screen)
child_session:request('nvim_call_function', 'setcellwidths', {{{0x2103, 0x2103, 2}}}) child_session:request('nvim_call_function', 'setcellwidths', {{{0x2103, 0x2103, 2}}})
screen:expect(doublewidth_screen) screen:expect(doublewidth_screen)

View File

@ -19,7 +19,7 @@ describe(':terminal', function()
clear() clear()
-- set the statusline to a constant value because of variables like pid -- set the statusline to a constant value because of variables like pid
-- and current directory and to improve visibility of splits -- and current directory and to improve visibility of splits
meths.set_option('statusline', '==========') meths.set_option_value('statusline', '==========', {})
command('highlight StatusLine cterm=NONE') command('highlight StatusLine cterm=NONE')
command('highlight StatusLineNC cterm=NONE') command('highlight StatusLineNC cterm=NONE')
command('highlight VertSplit cterm=NONE') command('highlight VertSplit cterm=NONE')
@ -71,7 +71,7 @@ describe(':terminal', function()
end) end)
it('does not change size if updated when not visible in any window #19665', function() it('does not change size if updated when not visible in any window #19665', function()
local channel = meths.buf_get_option(0, 'channel') local channel = meths.get_option_value('channel', { buf = 0 })
command('enew') command('enew')
sleep(100) sleep(100)
meths.chan_send(channel, 'foo') meths.chan_send(channel, 'foo')

View File

@ -178,7 +178,7 @@ end
describe('Command-line coloring', function() describe('Command-line coloring', function()
it('works', function() it('works', function()
set_color_cb('RainBowParens') set_color_cb('RainBowParens')
meths.set_option('more', false) meths.set_option_value('more', false, {})
start_prompt() start_prompt()
screen:expect([[ screen:expect([[
| |

View File

@ -265,8 +265,8 @@ describe('ui/cursor', function()
} }
-- Another cursor style. -- Another cursor style.
meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173' meths.set_option_value('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173'
..',ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') ..',ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42', {})
screen:expect(function() screen:expect(function()
local named = {} local named = {}
for _, m in ipairs(screen._mode_info) do for _, m in ipairs(screen._mode_info) do
@ -288,7 +288,7 @@ describe('ui/cursor', function()
end) end)
-- If there is no setting for guicursor, it becomes the default setting. -- If there is no setting for guicursor, it becomes the default setting.
meths.set_option('guicursor', 'n:ver35-blinkwait171-blinkoff172-blinkon173-Cursor/lCursor') meths.set_option_value('guicursor', 'n:ver35-blinkwait171-blinkoff172-blinkon173-Cursor/lCursor', {})
screen:expect(function() screen:expect(function()
for _,m in ipairs(screen._mode_info) do for _,m in ipairs(screen._mode_info) do
if m.name ~= 'normal' then if m.name ~= 'normal' then
@ -304,7 +304,7 @@ describe('ui/cursor', function()
end) end)
it("empty 'guicursor' sets cursor_shape=block in all modes", function() it("empty 'guicursor' sets cursor_shape=block in all modes", function()
meths.set_option('guicursor', '') meths.set_option_value('guicursor', '', {})
screen:expect(function() screen:expect(function()
-- Empty 'guicursor' sets enabled=false. -- Empty 'guicursor' sets enabled=false.
eq(false, screen._cursor_style_enabled) eq(false, screen._cursor_style_enabled)

View File

@ -1910,7 +1910,7 @@ describe('decorations: signs', function()
} }
ns = meths.create_namespace 'test' ns = meths.create_namespace 'test'
meths.win_set_option(0, 'signcolumn', 'auto:9') meths.set_option_value('signcolumn', 'auto:9', {win = 0})
end) end)
local example_text = [[ local example_text = [[
@ -2222,7 +2222,7 @@ l5
]]} ]]}
-- Check truncation works too -- Check truncation works too
meths.win_set_option(0, 'signcolumn', 'auto') meths.set_option_value('signcolumn', 'auto', {win = 0})
screen:expect{grid=[[ screen:expect{grid=[[
S5^l1 | S5^l1 |
@ -2233,7 +2233,7 @@ l5
it('does not set signcolumn for signs without text', function() it('does not set signcolumn for signs without text', function()
screen:try_resize(20, 3) screen:try_resize(20, 3)
meths.win_set_option(0, 'signcolumn', 'auto') meths.set_option_value('signcolumn', 'auto', {win = 0})
insert(example_text) insert(example_text)
feed 'gg' feed 'gg'
meths.buf_set_extmark(0, ns, 0, -1, {number_hl_group='Error'}) meths.buf_set_extmark(0, ns, 0, -1, {number_hl_group='Error'})

View File

@ -105,7 +105,7 @@ describe('float window', function()
it('opened with correct height', function() it('opened with correct height', function()
local height = exec_lua([[ local height = exec_lua([[
vim.api.nvim_set_option("winheight", 20) vim.go.winheight = 20
local bufnr = vim.api.nvim_create_buf(false, true) local bufnr = vim.api.nvim_create_buf(false, true)
local opts = { local opts = {
@ -127,7 +127,7 @@ describe('float window', function()
it('opened with correct width', function() it('opened with correct width', function()
local width = exec_lua([[ local width = exec_lua([[
vim.api.nvim_set_option("winwidth", 20) vim.go.winwidth = 20
local bufnr = vim.api.nvim_create_buf(false, true) local bufnr = vim.api.nvim_create_buf(false, true)
local opts = { local opts = {
@ -427,36 +427,36 @@ describe('float window', function()
it("no segfault when setting minimal style after clearing local 'fillchars' #19510", function() it("no segfault when setting minimal style after clearing local 'fillchars' #19510", function()
local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1} local float_opts = {relative = 'editor', row = 1, col = 1, width = 1, height = 1}
local float_win = meths.open_win(0, true, float_opts) local float_win = meths.open_win(0, true, float_opts)
meths.win_set_option(float_win, 'fillchars', NIL) meths.set_option_value('fillchars', NIL, {win=float_win.id})
float_opts.style = 'minimal' float_opts.style = 'minimal'
meths.win_set_config(float_win, float_opts) meths.win_set_config(float_win, float_opts)
assert_alive() assert_alive()
end) end)
it("should re-apply 'style' when present", function() it("should re-apply 'style' when present", function()
local float_opts = {style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1} local float_opts = {style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1}
local float_win = meths.open_win(0, true, float_opts) local float_win = meths.open_win(0, true, float_opts)
meths.win_set_option(float_win, 'number', true) meths.set_option_value('number', true, { win = float_win })
float_opts.row = 2 float_opts.row = 2
meths.win_set_config(float_win, float_opts) meths.win_set_config(float_win, float_opts)
eq(false, meths.win_get_option(float_win, 'number')) eq(false, meths.get_option_value('number', { win = float_win }))
end) end)
it("should not re-apply 'style' when missing", function() it("should not re-apply 'style' when missing", function()
local float_opts = {style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1} local float_opts = {style = 'minimal', relative = 'editor', row = 1, col = 1, width = 1, height = 1}
local float_win = meths.open_win(0, true, float_opts) local float_win = meths.open_win(0, true, float_opts)
meths.win_set_option(float_win, 'number', true) meths.set_option_value('number', true, { win = float_win })
float_opts.row = 2 float_opts.row = 2
float_opts.style = nil float_opts.style = nil
meths.win_set_config(float_win, float_opts) meths.win_set_config(float_win, float_opts)
eq(true, meths.win_get_option(float_win, 'number')) eq(true, meths.get_option_value('number', { win = float_win }))
end) end)
it("'scroll' is computed correctly when opening float with splitkeep=screen #20684", function() it("'scroll' is computed correctly when opening float with splitkeep=screen #20684", function()
meths.set_option('splitkeep', 'screen') meths.set_option_value('splitkeep', 'screen', {})
local float_opts = {relative = 'editor', row = 1, col = 1, width = 10, height = 10} local float_opts = {relative = 'editor', row = 1, col = 1, width = 10, height = 10}
local float_win = meths.open_win(0, true, float_opts) local float_win = meths.open_win(0, true, float_opts)
eq(5, meths.win_get_option(float_win, 'scroll')) eq(5, meths.get_option_value('scroll', {win=float_win.id}))
end) end)
describe('with only one tabpage,', function() describe('with only one tabpage,', function()
@ -4553,8 +4553,8 @@ describe('float window', function()
describe('and completion', function() describe('and completion', function()
before_each(function() before_each(function()
local buf = meths.create_buf(false,false) local buf = meths.create_buf(false,false)
local win = meths.open_win(buf, true, {relative='editor', width=12, height=4, row=2, col=5}) local win = meths.open_win(buf, true, {relative='editor', width=12, height=4, row=2, col=5}).id
meths.win_set_option(win , 'winhl', 'Normal:ErrorMsg') meths.set_option_value('winhl', 'Normal:ErrorMsg', {win=win})
if multigrid then if multigrid then
screen:expect{grid=[[ screen:expect{grid=[[
## grid 1 ## grid 1
@ -7823,7 +7823,7 @@ describe('float window', function()
local buf = meths.create_buf(false,false) local buf = meths.create_buf(false,false)
meths.buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'}) meths.buf_set_lines(buf, 0, -1, true, {'foo', 'bar', 'baz'})
local float_win = meths.open_win(buf, false, {relative='editor', width=20, height=4, row=1, col=5}) local float_win = meths.open_win(buf, false, {relative='editor', width=20, height=4, row=1, col=5})
meths.win_set_option(float_win, 'winbar', 'floaty bar') meths.set_option_value('winbar', 'floaty bar', {win=float_win.id})
if multigrid then if multigrid then
screen:expect{grid=[[ screen:expect{grid=[[
## grid 1 ## grid 1
@ -8144,7 +8144,7 @@ describe('float window', function()
]]) ]])
end end
meths.win_set_option(win, "winblend", 30) meths.set_option_value("winblend", 30, {win=win.id})
if multigrid then if multigrid then
screen:expect{grid=[[ screen:expect{grid=[[
## grid 1 ## grid 1
@ -8452,7 +8452,7 @@ describe('float window', function()
-- at least. Also check invisible EndOfBuffer region blends correctly. -- at least. Also check invisible EndOfBuffer region blends correctly.
meths.buf_set_lines(buf, 0, -1, true, {" x x x xx", " x x x x"}) meths.buf_set_lines(buf, 0, -1, true, {" x x x xx", " x x x x"})
win = meths.open_win(buf, false, {relative='editor', width=12, height=3, row=0, col=11, style='minimal'}) win = meths.open_win(buf, false, {relative='editor', width=12, height=3, row=0, col=11, style='minimal'})
meths.win_set_option(win, 'winblend', 30) meths.set_option_value('winblend', 30, {win=win.id})
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {foreground = tonumber('0xb282b2'), background = tonumber('0xffcfff')}, [1] = {foreground = tonumber('0xb282b2'), background = tonumber('0xffcfff')},
[2] = {foreground = Screen.colors.Grey0, background = tonumber('0xffcfff')}, [2] = {foreground = Screen.colors.Grey0, background = tonumber('0xffcfff')},
@ -8694,7 +8694,7 @@ describe('float window', function()
it("correctly orders multiple opened floats (current last)", function() it("correctly orders multiple opened floats (current last)", function()
local buf = meths.create_buf(false,false) local buf = meths.create_buf(false,false)
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5})
meths.win_set_option(win, "winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg") meths.set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win.id})
if multigrid then if multigrid then
screen:expect{grid=[[ screen:expect{grid=[[
@ -8739,10 +8739,10 @@ describe('float window', function()
exec_lua [[ exec_lua [[
local buf = vim.api.nvim_create_buf(false,false) local buf = vim.api.nvim_create_buf(false,false)
local win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8}) local win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8})
vim.api.nvim_win_set_option(win, "winhl", "EndOfBuffer:Normal") vim.wo[win].winhl = "EndOfBuffer:Normal"
buf = vim.api.nvim_create_buf(false,false) buf = vim.api.nvim_create_buf(false,false)
win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10}) win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10})
vim.api.nvim_win_set_option(win, "winhl", "Normal:Search,EndOfBuffer:Search") vim.wo[win].winhl = "Normal:Search,EndOfBuffer:Search"
]] ]]
if multigrid then if multigrid then
@ -8799,7 +8799,7 @@ describe('float window', function()
it("correctly orders multiple opened floats (non-current last)", function() it("correctly orders multiple opened floats (non-current last)", function()
local buf = meths.create_buf(false,false) local buf = meths.create_buf(false,false)
local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5}) local win = meths.open_win(buf, false, {relative='editor', width=20, height=2, row=2, col=5})
meths.win_set_option(win, "winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg") meths.set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win.id})
if multigrid then if multigrid then
screen:expect{grid=[[ screen:expect{grid=[[
@ -8844,10 +8844,10 @@ describe('float window', function()
exec_lua [[ exec_lua [[
local buf = vim.api.nvim_create_buf(false,false) local buf = vim.api.nvim_create_buf(false,false)
local win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10}) local win = vim.api.nvim_open_win(buf, true, {relative='editor', width=12, height=2, row=4, col=10})
vim.api.nvim_win_set_option(win, "winhl", "Normal:Search,EndOfBuffer:Search") vim.wo[win].winhl = "Normal:Search,EndOfBuffer:Search"
buf = vim.api.nvim_create_buf(false,false) buf = vim.api.nvim_create_buf(false,false)
win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8}) win = vim.api.nvim_open_win(buf, false, {relative='editor', width=16, height=2, row=3, col=8})
vim.api.nvim_win_set_option(win, "winhl", "EndOfBuffer:Normal") vim.wo[win].winhl = "EndOfBuffer:Normal"
]] ]]
if multigrid then if multigrid then
@ -8904,11 +8904,11 @@ describe('float window', function()
it('can use z-index', function() it('can use z-index', function()
local buf = meths.create_buf(false,false) local buf = meths.create_buf(false,false)
local win1 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=1, col=5, zindex=30}) local win1 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=1, col=5, zindex=30})
meths.win_set_option(win1, "winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg") meths.set_option_value("winhl", "Normal:ErrorMsg,EndOfBuffer:ErrorMsg", {win=win1.id})
local win2 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=2, col=6, zindex=50}) local win2 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=2, col=6, zindex=50})
meths.win_set_option(win2, "winhl", "Normal:Search,EndOfBuffer:Search") meths.set_option_value("winhl", "Normal:Search,EndOfBuffer:Search", {win=win2.id})
local win3 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=3, col=7, zindex=40}) local win3 = meths.open_win(buf, false, {relative='editor', width=20, height=3, row=3, col=7, zindex=40})
meths.win_set_option(win3, "winhl", "Normal:Question,EndOfBuffer:Question") meths.set_option_value("winhl", "Normal:Question,EndOfBuffer:Question", {win=win3.id})
if multigrid then if multigrid then
screen:expect{grid=[[ screen:expect{grid=[[
@ -8967,7 +8967,7 @@ describe('float window', function()
it('can use winbar', function() it('can use winbar', function()
local buf = meths.create_buf(false,false) local buf = meths.create_buf(false,false)
local win1 = meths.open_win(buf, false, {relative='editor', width=15, height=3, row=1, col=5}) local win1 = meths.open_win(buf, false, {relative='editor', width=15, height=3, row=1, col=5})
meths.win_set_option(win1, 'winbar', 'floaty bar') meths.set_option_value('winbar', 'floaty bar', {win=win1.id})
if multigrid then if multigrid then
screen:expect{grid=[[ screen:expect{grid=[[

View File

@ -967,8 +967,8 @@ describe("folded lines", function()
it("works with multibyte text", function() it("works with multibyte text", function()
-- Currently the only allowed value of 'maxcombine' -- Currently the only allowed value of 'maxcombine'
eq(6, meths.get_option('maxcombine')) eq(6, meths.get_option_value('maxcombine', {}))
eq(true, meths.get_option('arabicshape')) eq(true, meths.get_option_value('arabicshape', {}))
insert([[ insert([[
å x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢͟ العَرَبِيَّة å x̨̣̘̫̲͚͎̎͂̀̂͛͛̾͢͟ العَرَبِيَّة
möre text]]) möre text]])

View File

@ -2,7 +2,6 @@ local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen') local Screen = require('test.functional.ui.screen')
local clear = helpers.clear local clear = helpers.clear
local command = helpers.command local command = helpers.command
local curbufmeths = helpers.curbufmeths
local eq = helpers.eq local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local feed_command = helpers.feed_command local feed_command = helpers.feed_command
@ -178,8 +177,8 @@ describe(":substitute, 'inccommand' preserves", function()
feed_command("set inccommand=" .. case) feed_command("set inccommand=" .. case)
insert("as") insert("as")
feed(":%s/as/glork/<enter>") feed(":%s/as/glork/<enter>")
eq(meths.get_option('undolevels'), 139) eq(meths.get_option_value('undolevels', {scope='global'}), 139)
eq(curbufmeths.get_option('undolevels'), 34) eq(meths.get_option_value('undolevels', {buf=0}), 34)
end) end)
end end
@ -1192,7 +1191,7 @@ describe(":substitute, inccommand=split", function()
it("deactivates if 'redrawtime' is exceeded #5602", function() it("deactivates if 'redrawtime' is exceeded #5602", function()
-- prevent redraws from 'incsearch' -- prevent redraws from 'incsearch'
meths.set_option('incsearch', false) meths.set_option_value('incsearch', false, {})
-- Assert that 'inccommand' is ENABLED initially. -- Assert that 'inccommand' is ENABLED initially.
eq("split", eval("&inccommand")) eq("split", eval("&inccommand"))
-- Set 'redrawtime' to minimal value, to ensure timeout is triggered. -- Set 'redrawtime' to minimal value, to ensure timeout is triggered.
@ -2465,16 +2464,14 @@ describe(":substitute", function()
end) end)
it("inccommand=split, contraction of two subsequent NL chars", function() it("inccommand=split, contraction of two subsequent NL chars", function()
-- luacheck: push ignore 611
local text = [[ local text = [[
AAA AA AAA AA
BBB BB BBB BB
CCC CC CCC CC
]] ]]
-- luacheck: pop
-- This used to crash, but more than 20 highlight entries are required -- This used to crash, but more than 20 highlight entries are required
-- to reproduce it (so that the marktree has multiple nodes) -- to reproduce it (so that the marktree has multiple nodes)
@ -2501,16 +2498,14 @@ describe(":substitute", function()
end) end)
it("inccommand=nosplit, contraction of two subsequent NL chars", function() it("inccommand=nosplit, contraction of two subsequent NL chars", function()
-- luacheck: push ignore 611
local text = [[ local text = [[
AAA AA AAA AA
BBB BB BBB BB
CCC CC CCC CC
]] ]]
-- luacheck: pop
common_setup(screen, "nosplit", string.rep(text,10)) common_setup(screen, "nosplit", string.rep(text,10))
feed(":%s/\\n\\n/<c-v><c-m>/g") feed(":%s/\\n\\n/<c-v><c-m>/g")

View File

@ -391,7 +391,7 @@ describe("'inccommand' for user commands", function()
vim.api.nvim_create_user_command('Replace', function() end, { vim.api.nvim_create_user_command('Replace', function() end, {
nargs = '*', nargs = '*',
preview = function() preview = function()
vim.api.nvim_set_option('inccommand', 'split') vim.api.nvim_set_option_value('inccommand', 'split', {})
return 2 return 2
end, end,
}) })

View File

@ -1273,7 +1273,7 @@ vimComment xxx match /\s"[^\-:.%#=*].*$/ms=s+1,lc=1 excludenl contains=@vim
{1:~ }| {1:~ }|
| |
]]) ]])
eq(1, meths.get_option('cmdheight')) eq(1, meths.get_option_value('cmdheight', {}))
end) end)
end) end)

View File

@ -11,8 +11,8 @@ describe('ui/mouse/input', function()
before_each(function() before_each(function()
clear() clear()
meths.set_option('mouse', 'a') meths.set_option_value('mouse', 'a', {})
meths.set_option('list', true) meths.set_option_value('list', true, {})
-- NB: this is weird, but mostly irrelevant to the test -- NB: this is weird, but mostly irrelevant to the test
-- So I didn't bother to change it -- So I didn't bother to change it
command('set listchars=eol:$') command('set listchars=eol:$')
@ -64,7 +64,7 @@ describe('ui/mouse/input', function()
end) end)
it("in external ui works with unset 'mouse'", function() it("in external ui works with unset 'mouse'", function()
meths.set_option('mouse', '') meths.set_option_value('mouse', '', {})
feed('<LeftMouse><2,1>') feed('<LeftMouse><2,1>')
screen:expect{grid=[[ screen:expect{grid=[[
testing | testing |
@ -379,7 +379,7 @@ describe('ui/mouse/input', function()
end) end)
it('left click in default tabline (position 24) closes tab', function() it('left click in default tabline (position 24) closes tab', function()
meths.set_option('hidden', true) meths.set_option_value('hidden', true, {})
feed_command('%delete') feed_command('%delete')
insert('this is foo') insert('this is foo')
feed_command('silent file foo | tabnew | file bar') feed_command('silent file foo | tabnew | file bar')
@ -402,7 +402,7 @@ describe('ui/mouse/input', function()
end) end)
it('double click in default tabline (position 4) opens new tab', function() it('double click in default tabline (position 4) opens new tab', function()
meths.set_option('hidden', true) meths.set_option_value('hidden', true, {})
feed_command('%delete') feed_command('%delete')
insert('this is foo') insert('this is foo')
feed_command('silent file foo | tabnew | file bar') feed_command('silent file foo | tabnew | file bar')
@ -437,8 +437,8 @@ describe('ui/mouse/input', function()
return call('Test', a:000 + [2]) return call('Test', a:000 + [2])
endfunction endfunction
]]) ]])
meths.set_option('tabline', '%@Test@test%X-%5@Test2@test2') meths.set_option_value('tabline', '%@Test@test%X-%5@Test2@test2', {})
meths.set_option('showtabline', 2) meths.set_option_value('showtabline', 2, {})
screen:expect([[ screen:expect([[
{fill:test-test2 }| {fill:test-test2 }|
testing | testing |
@ -786,7 +786,7 @@ describe('ui/mouse/input', function()
end) end)
it('ctrl + left click will search for a tag', function() it('ctrl + left click will search for a tag', function()
meths.set_option('tags', './non-existent-tags-file') meths.set_option_value('tags', './non-existent-tags-file', {})
feed('<C-LeftMouse><0,0>') feed('<C-LeftMouse><0,0>')
screen:expect([[ screen:expect([[
{6:E433: No tags file} | {6:E433: No tags file} |
@ -1577,9 +1577,9 @@ describe('ui/mouse/input', function()
end) end)
it('getmousepos works correctly', function() it('getmousepos works correctly', function()
local winwidth = meths.get_option('winwidth') local winwidth = meths.get_option_value('winwidth', {})
-- Set winwidth=1 so that window sizes don't change. -- Set winwidth=1 so that window sizes don't change.
meths.set_option('winwidth', 1) meths.set_option_value('winwidth', 1, {})
command('tabedit') command('tabedit')
local tabpage = meths.get_current_tabpage() local tabpage = meths.get_current_tabpage()
insert('hello') insert('hello')
@ -1597,8 +1597,8 @@ describe('ui/mouse/input', function()
} }
local float = meths.open_win(meths.get_current_buf(), false, opts) local float = meths.open_win(meths.get_current_buf(), false, opts)
command('redraw') command('redraw')
local lines = meths.get_option('lines') local lines = meths.get_option_value('lines', {})
local columns = meths.get_option('columns') local columns = meths.get_option_value('columns', {})
-- Test that screenrow and screencol are set properly for all positions. -- Test that screenrow and screencol are set properly for all positions.
for row = 0, lines - 1 do for row = 0, lines - 1 do
@ -1696,7 +1696,7 @@ describe('ui/mouse/input', function()
-- Restore state and release mouse. -- Restore state and release mouse.
command('tabclose!') command('tabclose!')
meths.set_option('winwidth', winwidth) meths.set_option_value('winwidth', winwidth, {})
meths.input_mouse('left', 'release', '', 0, 0, 0) meths.input_mouse('left', 'release', '', 0, 0, 0)
end) end)

View File

@ -3555,7 +3555,7 @@ describe('ext_multigrid', function()
end) end)
it('with winbar dragging statusline with mouse works correctly', function() it('with winbar dragging statusline with mouse works correctly', function()
meths.set_option('winbar', 'Set Up The Bars') meths.set_option_value('winbar', 'Set Up The Bars', {})
command('split') command('split')
screen:expect([[ screen:expect([[
## grid 1 ## grid 1
@ -3695,7 +3695,7 @@ describe('ext_multigrid', function()
{1:~ }| {1:~ }|
{1:~ }| {1:~ }|
]]) ]])
eq(3, meths.get_option('cmdheight')) eq(3, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 1, 12, 10) meths.input_mouse('left', 'drag', '', 1, 12, 10)
screen:expect([[ screen:expect([[
@ -3730,6 +3730,6 @@ describe('ext_multigrid', function()
{1:~ }| {1:~ }|
{1:~ }| {1:~ }|
]]) ]])
eq(1, meths.get_option('cmdheight')) eq(1, meths.get_option_value('cmdheight', {}))
end) end)
end) end)

View File

@ -27,7 +27,7 @@ describe('quickfix selection highlight', function()
[12] = {foreground = Screen.colors.Brown, background = Screen.colors.Fuchsia}, [12] = {foreground = Screen.colors.Brown, background = Screen.colors.Fuchsia},
}) })
meths.set_option('errorformat', '%m %l') meths.set_option_value('errorformat', '%m %l', {})
command('syntax on') command('syntax on')
command('highlight Search guibg=Green') command('highlight Search guibg=Green')

View File

@ -828,7 +828,7 @@ local function screen_tests(linegrid)
command([[autocmd VimResized * redrawtabline]]) command([[autocmd VimResized * redrawtabline]])
command([[autocmd VimResized * lua vim.api.nvim_echo({ { 'Hello' } }, false, {})]]) command([[autocmd VimResized * lua vim.api.nvim_echo({ { 'Hello' } }, false, {})]])
command([[autocmd VimResized * let g:echospace = v:echospace]]) command([[autocmd VimResized * let g:echospace = v:echospace]])
meths.set_option('showtabline', 2) meths.set_option_value('showtabline', 2, {})
screen:expect([[ screen:expect([[
{2: + [No Name] }{3: }| {2: + [No Name] }{3: }|
resiz^e | resiz^e |
@ -1056,8 +1056,8 @@ it('CTRL-F or CTRL-B scrolls a page after UI attach/resize #20605', function()
clear() clear()
local screen = Screen.new(100, 100) local screen = Screen.new(100, 100)
screen:attach() screen:attach()
eq(100, meths.get_option('lines')) eq(100, meths.get_option_value('lines', {}))
eq(99, meths.get_option('window')) eq(99, meths.get_option_value('window', {}))
eq(99, meths.win_get_height(0)) eq(99, meths.win_get_height(0))
feed('1000o<Esc>') feed('1000o<Esc>')
eq(903, funcs.line('w0')) eq(903, funcs.line('w0'))
@ -1071,8 +1071,8 @@ it('CTRL-F or CTRL-B scrolls a page after UI attach/resize #20605', function()
eq(903, funcs.line('w0')) eq(903, funcs.line('w0'))
feed('G') feed('G')
screen:try_resize(50, 50) screen:try_resize(50, 50)
eq(50, meths.get_option('lines')) eq(50, meths.get_option_value('lines', {}))
eq(49, meths.get_option('window')) eq(49, meths.get_option_value('window', {}))
eq(49, meths.win_get_height(0)) eq(49, meths.win_get_height(0))
eq(953, funcs.line('w0')) eq(953, funcs.line('w0'))
feed('<C-B>') feed('<C-B>')

View File

@ -34,7 +34,7 @@ for _, model in ipairs(mousemodels) do
end) end)
it('works', function() it('works', function()
meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T') meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
meths.input_mouse('left', 'press', '', 0, 6, 17) meths.input_mouse('left', 'press', '', 0, 6, 17)
eq('0 1 l', eval("g:testvar")) eq('0 1 l', eval("g:testvar"))
meths.input_mouse('left', 'press', '', 0, 6, 17) meths.input_mouse('left', 'press', '', 0, 6, 17)
@ -54,7 +54,7 @@ for _, model in ipairs(mousemodels) do
end) end)
it('works for winbar', function() it('works for winbar', function()
meths.set_option('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T') meths.set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
meths.input_mouse('left', 'press', '', 0, 0, 17) meths.input_mouse('left', 'press', '', 0, 0, 17)
eq('0 1 l', eval("g:testvar")) eq('0 1 l', eval("g:testvar"))
meths.input_mouse('right', 'press', '', 0, 0, 17) meths.input_mouse('right', 'press', '', 0, 0, 17)
@ -72,8 +72,8 @@ for _, model in ipairs(mousemodels) do
it('works when there are multiple windows', function() it('works when there are multiple windows', function()
command('split') command('split')
meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T') meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
meths.set_option('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T') meths.set_option_value('winbar', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
meths.input_mouse('left', 'press', '', 0, 0, 17) meths.input_mouse('left', 'press', '', 0, 0, 17)
eq('0 1 l', eval("g:testvar")) eq('0 1 l', eval("g:testvar"))
meths.input_mouse('right', 'press', '', 0, 4, 17) meths.input_mouse('right', 'press', '', 0, 4, 17)
@ -90,23 +90,23 @@ for _, model in ipairs(mousemodels) do
vim.g.testvar = string.format("%d %d %s", minwid, clicks, button) vim.g.testvar = string.format("%d %d %s", minwid, clicks, button)
end end
]]) ]])
meths.set_option('statusline', 'Not clicky stuff %0@v:lua.clicky_func@Clicky stuff%T') meths.set_option_value('statusline', 'Not clicky stuff %0@v:lua.clicky_func@Clicky stuff%T', {})
meths.input_mouse('left', 'press', '', 0, 6, 17) meths.input_mouse('left', 'press', '', 0, 6, 17)
eq('0 1 l', eval("g:testvar")) eq('0 1 l', eval("g:testvar"))
end) end)
it('ignores unsupported click items', function() it('ignores unsupported click items', function()
command('tabnew | tabprevious') command('tabnew | tabprevious')
meths.set_option('statusline', '%2TNot clicky stuff%T') meths.set_option_value('statusline', '%2TNot clicky stuff%T', {})
meths.input_mouse('left', 'press', '', 0, 6, 0) meths.input_mouse('left', 'press', '', 0, 6, 0)
eq(1, meths.get_current_tabpage().id) eq(1, meths.get_current_tabpage().id)
meths.set_option('statusline', '%2XNot clicky stuff%X') meths.set_option_value('statusline', '%2XNot clicky stuff%X', {})
meths.input_mouse('left', 'press', '', 0, 6, 0) meths.input_mouse('left', 'press', '', 0, 6, 0)
eq(2, #meths.list_tabpages()) eq(2, #meths.list_tabpages())
end) end)
it("right click works when statusline isn't focused #18994", function() it("right click works when statusline isn't focused #18994", function()
meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T') meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
meths.input_mouse('right', 'press', '', 0, 6, 17) meths.input_mouse('right', 'press', '', 0, 6, 17)
eq('0 1 r', eval("g:testvar")) eq('0 1 r', eval("g:testvar"))
meths.input_mouse('right', 'press', '', 0, 6, 17) meths.input_mouse('right', 'press', '', 0, 6, 17)
@ -114,7 +114,7 @@ for _, model in ipairs(mousemodels) do
end) end)
it("works with modifiers #18994", function() it("works with modifiers #18994", function()
meths.set_option('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T') meths.set_option_value('statusline', 'Not clicky stuff %0@MyClickFunc@Clicky stuff%T', {})
-- Note: alternate between left and right mouse buttons to avoid triggering multiclicks -- Note: alternate between left and right mouse buttons to avoid triggering multiclicks
meths.input_mouse('left', 'press', 'S', 0, 6, 17) meths.input_mouse('left', 'press', 'S', 0, 6, 17)
eq('0 1 l(s )', eval("g:testvar")) eq('0 1 l(s )', eval("g:testvar"))
@ -143,7 +143,7 @@ for _, model in ipairs(mousemodels) do
it("works for global statusline with vertical splits #19186", function() it("works for global statusline with vertical splits #19186", function()
command('set laststatus=3') command('set laststatus=3')
meths.set_option('statusline', '%0@MyClickFunc@Clicky stuff%T %= %0@MyClickFunc@Clicky stuff%T') meths.set_option_value('statusline', '%0@MyClickFunc@Clicky stuff%T %= %0@MyClickFunc@Clicky stuff%T', {})
command('vsplit') command('vsplit')
screen:expect([[ screen:expect([[
^ | ^ |
@ -394,38 +394,38 @@ describe('global statusline', function()
end) end)
it('win_move_statusline() can reduce cmdheight to 1', function() it('win_move_statusline() can reduce cmdheight to 1', function()
eq(1, meths.get_option('cmdheight')) eq(1, meths.get_option_value('cmdheight', {}))
funcs.win_move_statusline(0, -1) funcs.win_move_statusline(0, -1)
eq(2, meths.get_option('cmdheight')) eq(2, meths.get_option_value('cmdheight', {}))
funcs.win_move_statusline(0, -1) funcs.win_move_statusline(0, -1)
eq(3, meths.get_option('cmdheight')) eq(3, meths.get_option_value('cmdheight', {}))
funcs.win_move_statusline(0, 1) funcs.win_move_statusline(0, 1)
eq(2, meths.get_option('cmdheight')) eq(2, meths.get_option_value('cmdheight', {}))
funcs.win_move_statusline(0, 1) funcs.win_move_statusline(0, 1)
eq(1, meths.get_option('cmdheight')) eq(1, meths.get_option_value('cmdheight', {}))
end) end)
it('mouse dragging can reduce cmdheight to 1', function() it('mouse dragging can reduce cmdheight to 1', function()
command('set mouse=a') command('set mouse=a')
meths.input_mouse('left', 'press', '', 0, 14, 10) meths.input_mouse('left', 'press', '', 0, 14, 10)
eq(1, meths.get_option('cmdheight')) eq(1, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 13, 10) meths.input_mouse('left', 'drag', '', 0, 13, 10)
eq(2, meths.get_option('cmdheight')) eq(2, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 12, 10) meths.input_mouse('left', 'drag', '', 0, 12, 10)
eq(3, meths.get_option('cmdheight')) eq(3, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 13, 10) meths.input_mouse('left', 'drag', '', 0, 13, 10)
eq(2, meths.get_option('cmdheight')) eq(2, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 14, 10) meths.input_mouse('left', 'drag', '', 0, 14, 10)
eq(1, meths.get_option('cmdheight')) eq(1, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 15, 10) meths.input_mouse('left', 'drag', '', 0, 15, 10)
eq(1, meths.get_option('cmdheight')) eq(1, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 0, 14, 10) meths.input_mouse('left', 'drag', '', 0, 14, 10)
eq(1, meths.get_option('cmdheight')) eq(1, meths.get_option_value('cmdheight', {}))
end) end)
it('cmdline row is correct after setting cmdheight #20514', function() it('cmdline row is correct after setting cmdheight #20514', function()
command('botright split test/functional/fixtures/bigfile.txt') command('botright split test/functional/fixtures/bigfile.txt')
meths.set_option('cmdheight', 1) meths.set_option_value('cmdheight', 1, {})
feed('L') feed('L')
screen:expect([[ screen:expect([[
| |
@ -464,7 +464,7 @@ describe('global statusline', function()
{2:test/functional/fixtures/bigfile.txt 8,1 0%}| {2:test/functional/fixtures/bigfile.txt 8,1 0%}|
| |
]]) ]])
meths.set_option('showtabline', 2) meths.set_option_value('showtabline', 2, {})
screen:expect([[ screen:expect([[
{3: }{5:2}{3: t/f/f/bigfile.txt }{4: }| {3: }{5:2}{3: t/f/f/bigfile.txt }{4: }|
| |
@ -483,7 +483,7 @@ describe('global statusline', function()
{2:test/functional/fixtures/bigfile.txt 8,1 0%}| {2:test/functional/fixtures/bigfile.txt 8,1 0%}|
| |
]]) ]])
meths.set_option('cmdheight', 0) meths.set_option_value('cmdheight', 0, {})
screen:expect([[ screen:expect([[
{3: }{5:2}{3: t/f/f/bigfile.txt }{4: }| {3: }{5:2}{3: t/f/f/bigfile.txt }{4: }|
| |
@ -502,7 +502,7 @@ describe('global statusline', function()
^0007;<control>;Cc;0;BN;;;;;N;BELL;;;; | ^0007;<control>;Cc;0;BN;;;;;N;BELL;;;; |
{2:test/functional/fixtures/bigfile.txt 8,1 0%}| {2:test/functional/fixtures/bigfile.txt 8,1 0%}|
]]) ]])
meths.set_option('cmdheight', 1) meths.set_option_value('cmdheight', 1, {})
screen:expect([[ screen:expect([[
{3: }{5:2}{3: t/f/f/bigfile.txt }{4: }| {3: }{5:2}{3: t/f/f/bigfile.txt }{4: }|
| |
@ -526,8 +526,8 @@ end)
it('statusline does not crash if it has Arabic characters #19447', function() it('statusline does not crash if it has Arabic characters #19447', function()
clear() clear()
meths.set_option('statusline', 'غً') meths.set_option_value('statusline', 'غً', {})
meths.set_option('laststatus', 2) meths.set_option_value('laststatus', 2, {})
command('redraw!') command('redraw!')
assert_alive() assert_alive()
end) end)

View File

@ -57,18 +57,18 @@ describe('title', function()
end) end)
end) end)
it('an RPC call to nvim_buf_set_option in a hidden buffer', function() it('an RPC call to nvim_set_option_value in a hidden buffer', function()
meths.buf_set_option(buf2, 'autoindent', true) meths.set_option_value('autoindent', true, { buf = buf2 })
command('redraw!') command('redraw!')
screen:expect(function() screen:expect(function()
eq(expected, screen.title) eq(expected, screen.title)
end) end)
end) end)
it('a Lua callback calling nvim_buf_set_option in a hidden buffer', function() it('a Lua callback calling nvim_set_option_value in a hidden buffer', function()
exec_lua(string.format([[ exec_lua(string.format([[
vim.schedule(function() vim.schedule(function()
vim.api.nvim_buf_set_option(%d, 'autoindent', true) vim.api.nvim_set_option_value('autoindent', true, { buf = %d })
end) end)
]], buf2)) ]], buf2))
command('redraw!') command('redraw!')

View File

@ -367,12 +367,12 @@ describe("'wildmenu'", function()
} }
-- Wildcharm? where we are going we aint't no need no wildcharm. -- Wildcharm? where we are going we aint't no need no wildcharm.
eq(0, meths.get_option'wildcharm') eq(0, meths.get_option_value('wildcharm', {}))
-- Don't mess the defaults yet (neovim is about backwards compatibility) -- Don't mess the defaults yet (neovim is about backwards compatibility)
eq(9, meths.get_option'wildchar') eq(9, meths.get_option_value('wildchar', {}))
-- Lol what is cnoremap? Some say it can define mappings. -- Lol what is cnoremap? Some say it can define mappings.
command 'set wildchar=0' command 'set wildchar=0'
eq(0, meths.get_option'wildchar') eq(0, meths.get_option_value('wildchar', {}))
command 'cnoremap <f2> <c-z>' command 'cnoremap <f2> <c-z>'
feed(':syntax <f2>') feed(':syntax <f2>')
@ -481,9 +481,9 @@ describe('command line completion', function()
end) end)
it('does not leak memory with <S-Tab> with wildmenu and only one match #19874', function() it('does not leak memory with <S-Tab> with wildmenu and only one match #19874', function()
meths.set_option('wildmenu', true) meths.set_option_value('wildmenu', true, {})
meths.set_option('wildmode', 'full') meths.set_option_value('wildmode', 'full', {})
meths.set_option('wildoptions', 'pum') meths.set_option_value('wildoptions', 'pum', {})
feed(':sign unpla<S-Tab>') feed(':sign unpla<S-Tab>')
screen:expect([[ screen:expect([[
@ -505,8 +505,8 @@ describe('command line completion', function()
end) end)
it('does not show matches with <S-Tab> without wildmenu with wildmode=full', function() it('does not show matches with <S-Tab> without wildmenu with wildmode=full', function()
meths.set_option('wildmenu', false) meths.set_option_value('wildmenu', false, {})
meths.set_option('wildmode', 'full') meths.set_option_value('wildmode', 'full', {})
feed(':sign <S-Tab>') feed(':sign <S-Tab>')
screen:expect([[ screen:expect([[
@ -519,8 +519,8 @@ describe('command line completion', function()
end) end)
it('shows matches with <S-Tab> without wildmenu with wildmode=list', function() it('shows matches with <S-Tab> without wildmenu with wildmode=list', function()
meths.set_option('wildmenu', false) meths.set_option_value('wildmenu', false, {})
meths.set_option('wildmode', 'list') meths.set_option_value('wildmode', 'list', {})
feed(':sign <S-Tab>') feed(':sign <S-Tab>')
screen:expect([[ screen:expect([[

View File

@ -31,7 +31,7 @@ describe('winbar', function()
[10] = {background = Screen.colors.LightGrey, underline = true}, [10] = {background = Screen.colors.LightGrey, underline = true},
[11] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta}, [11] = {background = Screen.colors.LightGrey, underline = true, bold = true, foreground = Screen.colors.Magenta},
}) })
meths.set_option('winbar', 'Set Up The Bars') meths.set_option_value('winbar', 'Set Up The Bars', {})
end) end)
it('works', function() it('works', function()
@ -206,7 +206,7 @@ describe('winbar', function()
insert [[ insert [[
just some just some
random text]] random text]]
meths.set_option('winbar', 'Hello, I am a ruler: %l,%c') meths.set_option_value('winbar', 'Hello, I am a ruler: %l,%c', {})
screen:expect{grid=[[ screen:expect{grid=[[
{1:Hello, I am a ruler: 2,11 }| {1:Hello, I am a ruler: 2,11 }|
just some | just some |
@ -450,7 +450,7 @@ describe('winbar', function()
| |
| |
]]) ]])
eq(3, meths.get_option('cmdheight')) eq(3, meths.get_option_value('cmdheight', {}))
meths.input_mouse('left', 'drag', '', 1, 11, 10) meths.input_mouse('left', 'drag', '', 1, 11, 10)
screen:expect([[ screen:expect([[
@ -468,7 +468,7 @@ describe('winbar', function()
{2:[No Name] }| {2:[No Name] }|
| |
]]) ]])
eq(1, meths.get_option('cmdheight')) eq(1, meths.get_option_value('cmdheight', {}))
end) end)
it('properly equalizes window height for window-local value', function() it('properly equalizes window height for window-local value', function()

View File

@ -32,8 +32,8 @@ describe('eval-API', function()
local err = exc_exec('call nvim_get_current_buf("foo")') local err = exc_exec('call nvim_get_current_buf("foo")')
eq('Vim(call):E118: Too many arguments for function: nvim_get_current_buf', err) eq('Vim(call):E118: Too many arguments for function: nvim_get_current_buf', err)
err = exc_exec('call nvim_set_option("hlsearch")') err = exc_exec('call nvim_set_option_value("hlsearch")')
eq('Vim(call):E119: Not enough arguments for function: nvim_set_option', err) eq('Vim(call):E119: Not enough arguments for function: nvim_set_option_value', err)
err = exc_exec('call nvim_buf_set_lines(1, 0, -1, [], ["list"])') err = exc_exec('call nvim_buf_set_lines(1, 0, -1, [], ["list"])')
eq('Vim(call):E5555: API call: Wrong type for argument 4 when calling nvim_buf_set_lines, expecting Boolean', err) eq('Vim(call):E5555: API call: Wrong type for argument 4 when calling nvim_buf_set_lines, expecting Boolean', err)

View File

@ -9,7 +9,6 @@ local meths = helpers.meths
local command = helpers.command local command = helpers.command
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local bufmeths = helpers.bufmeths local bufmeths = helpers.bufmeths
local winmeths = helpers.winmeths
local curbufmeths = helpers.curbufmeths local curbufmeths = helpers.curbufmeths
local curwinmeths = helpers.curwinmeths local curwinmeths = helpers.curwinmeths
local curtabmeths = helpers.curtabmeths local curtabmeths = helpers.curtabmeths
@ -189,7 +188,7 @@ describe('getbufline() function', function()
eq({}, funcs.getbufline(1, -1, 9999)) eq({}, funcs.getbufline(1, -1, 9999))
end) end)
it('returns expected lines', function() it('returns expected lines', function()
meths.set_option('hidden', true) meths.set_option_value('hidden', true, {})
command('file ' .. fname) command('file ' .. fname)
curbufmeths.set_lines(0, 1, false, {'foo\0', '\0bar', 'baz'}) curbufmeths.set_lines(0, 1, false, {'foo\0', '\0bar', 'baz'})
command('edit ' .. fname2) command('edit ' .. fname2)
@ -269,24 +268,25 @@ describe('setbufvar() function', function()
end) end)
it('may set options, including window-local and global values', function() it('may set options, including window-local and global values', function()
local buf1 = meths.get_current_buf() local buf1 = meths.get_current_buf()
eq(false, curwinmeths.get_option('number')) eq(false, meths.get_option_value('number', {win=0}))
command('split') command('split')
command('new') command('new')
eq(2, bufmeths.get_number(curwinmeths.get_buf())) eq(2, bufmeths.get_number(curwinmeths.get_buf()))
funcs.setbufvar(1, '&number', true) funcs.setbufvar(1, '&number', true)
local windows = curtabmeths.list_wins() local windows = curtabmeths.list_wins()
eq(false, winmeths.get_option(windows[1], 'number')) eq(false, meths.get_option_value('number', {win=windows[1].id}))
eq(true, winmeths.get_option(windows[2], 'number')) eq(true, meths.get_option_value('number', {win=windows[2].id}))
eq(false, winmeths.get_option(windows[3], 'number')) eq(false, meths.get_option_value('number', {win=windows[3].id}))
eq(false, winmeths.get_option(meths.get_current_win(), 'number')) eq(false, meths.get_option_value('number', {win=meths.get_current_win().id}))
eq(true, meths.get_option('hidden'))
eq(true, meths.get_option_value('hidden', {}))
funcs.setbufvar(1, '&hidden', 0) funcs.setbufvar(1, '&hidden', 0)
eq(false, meths.get_option('hidden')) eq(false, meths.get_option_value('hidden', {}))
eq(false, bufmeths.get_option(buf1, 'autoindent')) eq(false, meths.get_option_value('autoindent', {buf=buf1.id}))
funcs.setbufvar(1, '&autoindent', true) funcs.setbufvar(1, '&autoindent', true)
eq(true, bufmeths.get_option(buf1, 'autoindent')) eq(true, meths.get_option_value('autoindent', {buf=buf1.id}))
eq('Vim(call):E355: Unknown option: xxx', eq('Vim(call):E355: Unknown option: xxx',
exc_exec('call setbufvar(1, "&xxx", 0)')) exc_exec('call setbufvar(1, "&xxx", 0)'))
end) end)

View File

@ -452,8 +452,8 @@ end)
describe('confirm()', function() describe('confirm()', function()
-- oldtest: Test_confirm() -- oldtest: Test_confirm()
it('works', function() it('works', function()
meths.set_option('more', false) -- Avoid hit-enter prompt meths.set_option_value('more', false, {}) -- Avoid hit-enter prompt
meths.set_option('laststatus', 2) meths.set_option_value('laststatus', 2, {})
-- screen:expect() calls are needed to avoid feeding input too early -- screen:expect() calls are needed to avoid feeding input too early
screen:expect({any = '%[No Name%]'}) screen:expect({any = '%[No Name%]'})

View File

@ -754,7 +754,7 @@ describe('json_encode() function', function()
end) end)
it('ignores improper values in &isprint', function() it('ignores improper values in &isprint', function()
meths.set_option('isprint', '1') meths.set_option_value('isprint', '1', {})
eq(1, eval('"\1" =~# "\\\\p"')) eq(1, eval('"\1" =~# "\\\\p"'))
eq('"\\u0001"', funcs.json_encode('\1')) eq('"\\u0001"', funcs.json_encode('\1'))
end) end)

View File

@ -210,8 +210,8 @@ describe('system()', function()
end) end)
it('prints verbose information', function() it('prints verbose information', function()
nvim('set_option', 'shell', 'fake_shell') nvim('set_option_value', 'shell', 'fake_shell', {})
nvim('set_option', 'shellcmdflag', 'cmdflag') nvim('set_option_value', 'shellcmdflag', 'cmdflag', {})
screen:try_resize(72, 14) screen:try_resize(72, 14)
feed(':4verbose echo system("echo hi")<cr>') feed(':4verbose echo system("echo hi")<cr>')