vim-patch:8.0.0974: resetting a string option does not trigger OptionSet

Problem:    Resetting a string option does not trigger OptionSet. (Rick Howe)
Solution:   Set the origval.

8efa026a25
This commit is contained in:
Justin M. Keyes 2018-02-02 02:38:10 +01:00
parent fd58863eb6
commit e578d586f2
2 changed files with 37 additions and 18 deletions

View File

@ -1515,6 +1515,16 @@ do_set (
/* The old value is kept until we are sure that the
* new value is valid. */
oldval = *(char_u **)varp;
// When setting the local value of a global
// option, the old value may be the global value.
if (((int)options[opt_idx].indir & PV_BOTH) && (opt_flags
& OPT_LOCAL)) {
origval = *(char_u **)get_varp(&options[opt_idx]);
} else {
origval = oldval;
}
if (nextchar == '&') { /* set to default val */
newval = options[opt_idx].def_val[
((flags & P_VI_DEF) || cp_val)
@ -1610,15 +1620,6 @@ do_set (
++arg;
}
/* When setting the local value of a global
* option, the old value may be the global value. */
if (((int)options[opt_idx].indir & PV_BOTH)
&& (opt_flags & OPT_LOCAL))
origval = *(char_u **)get_varp(
&options[opt_idx]);
else
origval = oldval;
/*
* Copy the new string into allocated memory.
* Can't use set_string_option_direct(), because
@ -1788,7 +1789,7 @@ do_set (
new_value_alloced = TRUE;
}
/* Set the new value. */
// Set the new value.
*(char_u **)(varp) = newval;
if (!starting && origval != NULL && newval != NULL) {
@ -1807,15 +1808,18 @@ do_set (
errmsg = did_set_string_option(opt_idx, (char_u **)varp,
new_value_alloced, oldval, errbuf, opt_flags);
if (errmsg == NULL) {
trigger_optionsset_string(opt_idx, opt_flags, saved_origval,
saved_newval);
}
xfree(saved_origval);
xfree(saved_newval);
// If error detected, print the error message.
if (errmsg != NULL) {
xfree(saved_origval);
xfree(saved_newval);
goto skip;
}
trigger_optionsset_string(opt_idx, opt_flags, saved_origval,
saved_newval);
} else {
// key code option(FIXME(tarruda): Show a warning or something
// similar)
@ -2407,8 +2411,12 @@ static char *set_string_option(const int opt_idx, const char *const value,
}
// call autocommand after handling side effects
trigger_optionsset_string(opt_idx, opt_flags,
saved_oldval, saved_newval);
if (r == NULL) {
trigger_optionsset_string(opt_idx, opt_flags,
saved_oldval, saved_newval);
}
xfree(saved_oldval);
xfree(saved_newval);
return r;
}
@ -4458,8 +4466,6 @@ static void trigger_optionsset_string(int opt_idx, int opt_flags,
STRING_OBJ(cstr_as_string(newval)));
}
}
xfree(oldval);
xfree(newval);
}
/*

View File

@ -550,6 +550,19 @@ func Test_OptionSet()
call assert_equal([['key', 'invalid', 'invalid1', 'invalid']], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 18: Setting string option"
let oldval = &tags
let g:options=[['tags', oldval, 'tagpath', 'global']]
set tags=tagpath
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" 1l: Resetting string option"
let g:options=[['tags', 'tagpath', oldval, 'global']]
set tags&
call assert_equal([], g:options)
call assert_equal(g:opt[0], g:opt[1])
" Cleanup
au! OptionSet
for opt in ['nu', 'ai', 'acd', 'ar', 'bs', 'backup', 'cul', 'cp']