Merge pull request #9211 from bfredl/init_options

ui_options: also send when starting in --embed mode
This commit is contained in:
Björn Linse 2018-11-08 15:15:36 +01:00 committed by GitHub
commit d36afafc8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 95 additions and 81 deletions

View File

@ -1773,14 +1773,13 @@ do_set (
// Set the new value. // Set the new value.
*(char_u **)(varp) = newval; *(char_u **)(varp) = newval;
if (!starting && origval != NULL && newval != NULL) { // origval may be freed by
// origval may be freed by // did_set_string_option(), make a copy.
// did_set_string_option(), make a copy. saved_origval = (origval != NULL) ? xstrdup((char *)origval) : 0;
saved_origval = xstrdup((char *)origval);
// newval (and varp) may become invalid if the // newval (and varp) may become invalid if the
// buffer is closed by autocommands. // buffer is closed by autocommands.
saved_newval = xstrdup((char *)newval); saved_newval = (newval != NULL) ? xstrdup((char *)newval) : 0;
}
// Handle side effects, and set the global value for // Handle side effects, and set the global value for
// ":set" on local options. Note: when setting 'syntax' // ":set" on local options. Note: when setting 'syntax'
@ -1790,8 +1789,14 @@ do_set (
new_value_alloced, oldval, errbuf, opt_flags); new_value_alloced, oldval, errbuf, opt_flags);
if (errmsg == NULL) { if (errmsg == NULL) {
trigger_optionsset_string(opt_idx, opt_flags, saved_origval, if (!starting) {
saved_newval); trigger_optionsset_string(opt_idx, opt_flags, saved_origval,
saved_newval);
}
if (options[opt_idx].flags & P_UI_OPTION) {
ui_call_option_set(cstr_as_string(options[opt_idx].fullname),
STRING_OBJ(cstr_as_string(saved_newval)));
}
} }
xfree(saved_origval); xfree(saved_origval);
xfree(saved_newval); xfree(saved_newval);
@ -2382,8 +2387,8 @@ static char *set_string_option(const int opt_idx, const char *const value,
char *const oldval = *varp; char *const oldval = *varp;
*varp = s; *varp = s;
char *const saved_oldval = (starting ? NULL : xstrdup(oldval)); char *const saved_oldval = xstrdup(oldval);
char *const saved_newval = (starting ? NULL : xstrdup(s)); char *const saved_newval = xstrdup(s);
char *const r = (char *)did_set_string_option( char *const r = (char *)did_set_string_option(
opt_idx, (char_u **)varp, (int)true, (char_u *)oldval, NULL, opt_flags); opt_idx, (char_u **)varp, (int)true, (char_u *)oldval, NULL, opt_flags);
@ -2393,8 +2398,13 @@ static char *set_string_option(const int opt_idx, const char *const value,
// call autocommand after handling side effects // call autocommand after handling side effects
if (r == NULL) { if (r == NULL) {
trigger_optionsset_string(opt_idx, opt_flags, if (!starting) {
saved_oldval, saved_newval); trigger_optionsset_string(opt_idx, opt_flags, saved_oldval, saved_newval);
}
if (options[opt_idx].flags & P_UI_OPTION) {
ui_call_option_set(cstr_as_string(options[opt_idx].fullname),
STRING_OBJ(cstr_as_string(saved_newval)));
}
} }
xfree(saved_oldval); xfree(saved_oldval);
xfree(saved_newval); xfree(saved_newval);
@ -4060,10 +4070,11 @@ static char *set_bool_option(const int opt_idx, char_u *const varp,
(char_u *) options[opt_idx].fullname, (char_u *) options[opt_idx].fullname,
NULL, false, NULL); NULL, false, NULL);
reset_v_option_vars(); reset_v_option_vars();
if (options[opt_idx].flags & P_UI_OPTION) { }
ui_call_option_set(cstr_as_string(options[opt_idx].fullname),
BOOLEAN_OBJ(value)); if (options[opt_idx].flags & P_UI_OPTION) {
} ui_call_option_set(cstr_as_string(options[opt_idx].fullname),
BOOLEAN_OBJ(value));
} }
comp_col(); /* in case 'ruler' or 'showcmd' changed */ comp_col(); /* in case 'ruler' or 'showcmd' changed */
@ -4433,10 +4444,11 @@ static char *set_num_option(int opt_idx, char_u *varp, long value,
(char_u *) options[opt_idx].fullname, (char_u *) options[opt_idx].fullname,
NULL, false, NULL); NULL, false, NULL);
reset_v_option_vars(); reset_v_option_vars();
if (options[opt_idx].flags & P_UI_OPTION) { }
ui_call_option_set(cstr_as_string(options[opt_idx].fullname),
INTEGER_OBJ(value)); if (errmsg == NULL && options[opt_idx].flags & P_UI_OPTION) {
} ui_call_option_set(cstr_as_string(options[opt_idx].fullname),
INTEGER_OBJ(value));
} }
comp_col(); /* in case 'columns' or 'ls' changed */ comp_col(); /* in case 'columns' or 'ls' changed */
@ -4465,10 +4477,6 @@ static void trigger_optionsset_string(int opt_idx, int opt_flags,
apply_autocmds(EVENT_OPTIONSET, apply_autocmds(EVENT_OPTIONSET,
(char_u *)options[opt_idx].fullname, NULL, false, NULL); (char_u *)options[opt_idx].fullname, NULL, false, NULL);
reset_v_option_vars(); reset_v_option_vars();
if (options[opt_idx].flags & P_UI_OPTION) {
ui_call_option_set(cstr_as_string(options[opt_idx].fullname),
STRING_OBJ(cstr_as_string(newval)));
}
} }
} }

View File

@ -1,85 +1,85 @@
local global_helpers = require('test.helpers')
local helpers = require('test.functional.helpers')(after_each) 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 eq = helpers.eq local eq = helpers.eq
local shallowcopy = global_helpers.shallowcopy
describe('ui receives option updates', function() describe('ui receives option updates', function()
local screen local screen
before_each(function() local function reset(opts, ...)
clear() local defaults = {
ambiwidth='single',
arabicshape=true,
emoji=true,
guifont='',
guifontset='',
guifontwide='',
linespace=0,
showtabline=1,
termguicolors=false,
ext_cmdline=false,
ext_popupmenu=false,
ext_tabline=false,
ext_wildmenu=false,
ext_linegrid=false,
ext_hlstate=false,
}
clear(...)
screen = Screen.new(20,5) screen = Screen.new(20,5)
end) screen:attach(opts)
-- NB: UI test suite can be run in both "linegrid" and legacy grid mode.
-- In both cases check that the received value is the one requested.
defaults.ext_linegrid = screen._options.ext_linegrid or false
return defaults
end
after_each(function() after_each(function()
screen:detach() screen:detach()
end) end)
local defaults = {
ambiwidth='single',
arabicshape=true,
emoji=true,
guifont='',
guifontset='',
guifontwide='',
linespace=0,
showtabline=1,
termguicolors=false,
ext_cmdline=false,
ext_popupmenu=false,
ext_tabline=false,
ext_wildmenu=false,
ext_linegrid=false,
ext_hlstate=false,
}
it("for defaults", function() it("for defaults", function()
screen:attach() local expected = reset()
-- NB: UI test suite can be run in both "linegrid" and legacy grid mode.
-- In both cases check that the received value is the one requested.
defaults.ext_linegrid = screen._options.ext_linegrid or false
screen:expect(function() screen:expect(function()
eq(defaults, screen.options) eq(expected, screen.options)
end) end)
end) end)
it("when setting options", function() it("when setting options", function()
screen:attach() local expected = reset()
defaults.ext_linegrid = screen._options.ext_linegrid or false local defaults = shallowcopy(expected)
local changed = {}
for k,v in pairs(defaults) do
changed[k] = v
end
command("set termguicolors") command("set termguicolors")
changed.termguicolors = true expected.termguicolors = true
screen:expect(function() screen:expect(function()
eq(changed, screen.options) eq(expected, screen.options)
end) end)
command("set guifont=Comic\\ Sans") command("set guifont=Comic\\ Sans")
changed.guifont = "Comic Sans" expected.guifont = "Comic Sans"
screen:expect(function() screen:expect(function()
eq(changed, screen.options) eq(expected, screen.options)
end) end)
command("set showtabline=0") command("set showtabline=0")
changed.showtabline = 0 expected.showtabline = 0
screen:expect(function() screen:expect(function()
eq(changed, screen.options) eq(expected, screen.options)
end) end)
command("set linespace=13") command("set linespace=13")
changed.linespace = 13 expected.linespace = 13
screen:expect(function() screen:expect(function()
eq(changed, screen.options) eq(expected, screen.options)
end) end)
command("set linespace=-11") command("set linespace=-11")
changed.linespace = -11 expected.linespace = -11
screen:expect(function() screen:expect(function()
eq(changed, screen.options) eq(expected, screen.options)
end) end)
command("set all&") command("set all&")
@ -89,29 +89,35 @@ describe('ui receives option updates', function()
end) end)
it('with UI extensions', function() it('with UI extensions', function()
local changed = {} local expected = reset({ext_cmdline=true, ext_wildmenu=true})
for k,v in pairs(defaults) do
changed[k] = v
end
screen:attach({ext_cmdline=true, ext_wildmenu=true}) expected.ext_cmdline = true
defaults.ext_linegrid = screen._options.ext_linegrid or false expected.ext_wildmenu = true
changed.ext_cmdline = true
changed.ext_wildmenu = true
screen:expect(function() screen:expect(function()
eq(changed, screen.options) eq(expected, screen.options)
end) end)
screen:set_option('ext_popupmenu', true) screen:set_option('ext_popupmenu', true)
changed.ext_popupmenu = true expected.ext_popupmenu = true
screen:expect(function() screen:expect(function()
eq(changed, screen.options) eq(expected, screen.options)
end) end)
screen:set_option('ext_wildmenu', false) screen:set_option('ext_wildmenu', false)
changed.ext_wildmenu = false expected.ext_wildmenu = false
screen:expect(function() screen:expect(function()
eq(changed, screen.options) eq(expected, screen.options)
end) end)
end) end)
local function startup_test(headless)
local expected = reset(nil,{headless=headless,args={'--cmd', 'set guifont=Comic\\ Sans\\ 12'}})
expected.guifont = "Comic Sans 12"
screen:expect(function()
eq(expected, screen.options)
end)
end
it('from startup options with --headless', function() startup_test(true) end)
it('from startup options with --embed', function() startup_test(false) end)
end) end)