mirror of
https://github.com/neovim/neovim.git
synced 2025-12-15 19:05:40 +00:00
refactor(options)!: unify set_option and set_string_option
While the interfaces for setting number and boolean options are now unified by #25394, there is still a separate `set_string_option` function that is used for setting a string option. This PR removes that function and merges it with set_option. BREAKING CHANGE: `v:option_old` is now the old global value for all global-local options, instead of just string global-local options. Local value for a global-local number/boolean option is now unset when the option is set (e.g. using `:set` or `nvim_set_option_value`) without a scope, which means they now behave the same way as string options. Ref: #25672
This commit is contained in:
@@ -1536,14 +1536,18 @@ describe('API', function()
|
||||
|
||||
-- Now try with options with a special "local is unset" value (e.g. 'undolevels')
|
||||
nvim('set_option_value', 'undolevels', 1000, {})
|
||||
eq(1000, nvim('get_option_value', 'undolevels', {scope = 'local'}))
|
||||
nvim('set_option_value', 'undolevels', 1200, {scope = 'local'})
|
||||
eq(1200, nvim('get_option_value', 'undolevels', {scope = 'local'}))
|
||||
nvim('set_option_value', 'undolevels', NIL, {scope = 'local'})
|
||||
eq(-123456, nvim('get_option_value', 'undolevels', {scope = 'local'}))
|
||||
eq(1000, nvim('get_option_value', 'undolevels', {}))
|
||||
|
||||
nvim('set_option_value', 'autoread', true, {})
|
||||
eq(true, nvim('get_option_value', 'autoread', {scope = 'local'}))
|
||||
nvim('set_option_value', 'autoread', false, {scope = 'local'})
|
||||
eq(false, nvim('get_option_value', 'autoread', {scope = 'local'}))
|
||||
nvim('set_option_value', 'autoread', NIL, {scope = 'local'})
|
||||
eq(NIL, nvim('get_option_value', 'autoread', {scope = 'local'}))
|
||||
eq(true, nvim('get_option_value', 'autoread', {}))
|
||||
end)
|
||||
|
||||
it('set window options', function()
|
||||
|
||||
@@ -260,7 +260,7 @@ describe('au OptionSet', function()
|
||||
command('setlocal tags=tagpath2')
|
||||
expected_combination({'tags', 'tagpath1', 'tagpath1', '', 'tagpath2', 'local', 'setlocal'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local string options
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa setglobal tags=tag_global')
|
||||
command('noa setlocal tags=tag_local')
|
||||
@@ -269,12 +269,12 @@ describe('au OptionSet', function()
|
||||
'tags', 'tag_global', 'tag_local', 'tag_global', 'tagpath', 'global', 'set'
|
||||
})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local string options
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa set tags=tag_global')
|
||||
command('noa setlocal tags=')
|
||||
command('set tags=tagpath')
|
||||
expected_combination({'tags', 'tag_global', '', 'tag_global', 'tagpath', 'global', 'set'})
|
||||
expected_combination({'tags', 'tag_global', 'tag_global', 'tag_global', 'tagpath', 'global', 'set'})
|
||||
end)
|
||||
|
||||
it('with string local (to buffer) option', function()
|
||||
@@ -295,7 +295,7 @@ describe('au OptionSet', function()
|
||||
command('setlocal spelllang=klingon')
|
||||
expected_combination({'spelllang', oldval, oldval, '', 'klingon', 'local', 'setlocal'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local string options
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa setglobal spelllang=spellglobal')
|
||||
command('noa setlocal spelllang=spelllocal')
|
||||
@@ -311,7 +311,7 @@ describe('au OptionSet', function()
|
||||
command('set statusline=foo')
|
||||
expected_combination({'statusline', oldval, oldval, '', 'foo', 'global', 'set'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local string options
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('set statusline&')
|
||||
expected_combination({'statusline', 'foo', 'foo', 'foo', oldval, 'global', 'set'})
|
||||
@@ -323,7 +323,7 @@ describe('au OptionSet', function()
|
||||
command('setlocal statusline=baz')
|
||||
expected_combination({'statusline', oldval, oldval, '', 'baz', 'local', 'setlocal'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local string options
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa setglobal statusline=bar')
|
||||
command('noa setlocal statusline=baz')
|
||||
@@ -364,11 +364,15 @@ describe('au OptionSet', function()
|
||||
command('setlocal cmdheight=2')
|
||||
expected_combination({'cmdheight', 1, 1, '', 2, 'local', 'setlocal'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa setglobal cmdheight=8')
|
||||
command('noa setlocal cmdheight=1') -- Sets the global(!) value
|
||||
command('set cmdheight=2')
|
||||
expected_combination({'cmdheight', 1, 1, 1, 2, 'global', 'set'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa set cmdheight=8')
|
||||
command('set cmdheight=2')
|
||||
expected_combination({'cmdheight', 8, 8, 8, 2, 'global', 'set'})
|
||||
@@ -385,11 +389,15 @@ describe('au OptionSet', function()
|
||||
command('setlocal undolevels=2')
|
||||
expected_combination({'undolevels', 1, 1, '', 2, 'local', 'setlocal'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa setglobal undolevels=8')
|
||||
command('noa setlocal undolevels=1')
|
||||
command('set undolevels=2')
|
||||
expected_combination({'undolevels', 1, 1, 8, 2, 'global', 'set'})
|
||||
expected_combination({'undolevels', 8, 1, 8, 2, 'global', 'set'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa set undolevels=8')
|
||||
command('set undolevels=2')
|
||||
expected_combination({'undolevels', 8, 8, 8, 2, 'global', 'set'})
|
||||
@@ -427,11 +435,15 @@ describe('au OptionSet', function()
|
||||
command('setlocal scrolloff=2')
|
||||
expected_combination({'scrolloff', 1, 1, '', 2, 'local', 'setlocal'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa setglobal scrolloff=8')
|
||||
command('noa setlocal scrolloff=1')
|
||||
command('set scrolloff=2')
|
||||
expected_combination({'scrolloff', 1, 1, 8, 2, 'global', 'set'})
|
||||
expected_combination({'scrolloff', 8, 1, 8, 2, 'global', 'set'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa set scrolloff=8')
|
||||
command('set scrolloff=2')
|
||||
expected_combination({'scrolloff', 8, 8, 8, 2, 'global', 'set'})
|
||||
@@ -490,11 +502,15 @@ describe('au OptionSet', function()
|
||||
command('setlocal noautoread')
|
||||
expected_combination({'autoread', true, true, '', false, 'local', 'setlocal'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa setglobal noautoread')
|
||||
command('noa setlocal autoread')
|
||||
command('set autoread')
|
||||
expected_combination({'autoread', true, true, false, true, 'global', 'set'})
|
||||
expected_combination({'autoread', false, true, false, true, 'global', 'set'})
|
||||
|
||||
-- Note: v:option_old is the old global value for global-local options.
|
||||
-- but the old local value for all other kinds of options.
|
||||
command('noa set noautoread')
|
||||
command('set autoread')
|
||||
expected_combination({'autoread', false, false, false, true, 'global', 'set'})
|
||||
|
||||
Reference in New Issue
Block a user