Mercurial > vim
comparison src/option.c @ 12188:d2e367d9de1f v8.0.0974
patch 8.0.0974: resetting a string option does not trigger OptionSet
commit https://github.com/vim/vim/commit/8efa026a25b95de5598535ef62505282a8584a4b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 20 15:47:20 2017 +0200
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.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 20 Aug 2017 16:00:04 +0200 |
parents | 36456f237c59 |
children | 497b78526358 |
comparison
equal
deleted
inserted
replaced
12187:0ebbce47179c | 12188:d2e367d9de1f |
---|---|
4349 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); | 4349 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); |
4350 apply_autocmds(EVENT_OPTIONSET, | 4350 apply_autocmds(EVENT_OPTIONSET, |
4351 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL); | 4351 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL); |
4352 reset_v_option_vars(); | 4352 reset_v_option_vars(); |
4353 } | 4353 } |
4354 vim_free(oldval); | |
4355 vim_free(newval); | |
4356 } | 4354 } |
4357 #endif | 4355 #endif |
4358 | 4356 |
4359 /* | 4357 /* |
4360 * Parse 'arg' for option settings. | 4358 * Parse 'arg' for option settings. |
4816 errmsg = set_num_option(opt_idx, varp, value, | 4814 errmsg = set_num_option(opt_idx, varp, value, |
4817 errbuf, sizeof(errbuf), opt_flags); | 4815 errbuf, sizeof(errbuf), opt_flags); |
4818 } | 4816 } |
4819 else if (opt_idx >= 0) /* string */ | 4817 else if (opt_idx >= 0) /* string */ |
4820 { | 4818 { |
4821 char_u *save_arg = NULL; | 4819 char_u *save_arg = NULL; |
4822 char_u *s = NULL; | 4820 char_u *s = NULL; |
4823 char_u *oldval = NULL; /* previous value if *varp */ | 4821 char_u *oldval = NULL; /* previous value if *varp */ |
4824 char_u *newval; | 4822 char_u *newval; |
4825 char_u *origval = NULL; | 4823 char_u *origval = NULL; |
4826 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 4824 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
4827 char_u *saved_origval = NULL; | 4825 char_u *saved_origval = NULL; |
4828 char_u *saved_newval = NULL; | 4826 char_u *saved_newval = NULL; |
4829 #endif | 4827 #endif |
4830 unsigned newlen; | 4828 unsigned newlen; |
4831 int comma; | 4829 int comma; |
4832 int bs; | 4830 int bs; |
4833 int new_value_alloced; /* new string option | 4831 int new_value_alloced; /* new string option |
4834 was allocated */ | 4832 was allocated */ |
4835 | 4833 |
4836 /* When using ":set opt=val" for a global option | 4834 /* When using ":set opt=val" for a global option |
4837 * with a local value the local value will be | 4835 * with a local value the local value will be |
4838 * reset, use the global value here. */ | 4836 * reset, use the global value here. */ |
4841 varp = options[opt_idx].var; | 4839 varp = options[opt_idx].var; |
4842 | 4840 |
4843 /* The old value is kept until we are sure that the | 4841 /* The old value is kept until we are sure that the |
4844 * new value is valid. */ | 4842 * new value is valid. */ |
4845 oldval = *(char_u **)varp; | 4843 oldval = *(char_u **)varp; |
4844 | |
4845 /* When setting the local value of a global | |
4846 * option, the old value may be the global value. */ | |
4847 if (((int)options[opt_idx].indir & PV_BOTH) | |
4848 && (opt_flags & OPT_LOCAL)) | |
4849 origval = *(char_u **)get_varp( | |
4850 &options[opt_idx]); | |
4851 else | |
4852 origval = oldval; | |
4853 | |
4846 if (nextchar == '&') /* set to default val */ | 4854 if (nextchar == '&') /* set to default val */ |
4847 { | 4855 { |
4848 newval = options[opt_idx].def_val[ | 4856 newval = options[opt_idx].def_val[ |
4849 ((flags & P_VI_DEF) || cp_val) | 4857 ((flags & P_VI_DEF) || cp_val) |
4850 ? VI_DEFAULT : VIM_DEFAULT]; | 4858 ? VI_DEFAULT : VIM_DEFAULT]; |
4955 || varp == (char_u *)&p_bdir)) | 4963 || varp == (char_u *)&p_bdir)) |
4956 { | 4964 { |
4957 ++arg; | 4965 ++arg; |
4958 } | 4966 } |
4959 | 4967 |
4960 /* When setting the local value of a global | |
4961 * option, the old value may be the global value. */ | |
4962 if (((int)options[opt_idx].indir & PV_BOTH) | |
4963 && (opt_flags & OPT_LOCAL)) | |
4964 origval = *(char_u **)get_varp( | |
4965 &options[opt_idx]); | |
4966 else | |
4967 origval = oldval; | |
4968 | |
4969 /* | 4968 /* |
4970 * Copy the new string into allocated memory. | 4969 * Copy the new string into allocated memory. |
4971 * Can't use set_string_option_direct(), because | 4970 * Can't use set_string_option_direct(), because |
4972 * we need to remove the backslashes. | 4971 * we need to remove the backslashes. |
4973 */ | 4972 */ |
5167 if (save_arg != NULL) /* number for 'whichwrap' */ | 5166 if (save_arg != NULL) /* number for 'whichwrap' */ |
5168 arg = save_arg; | 5167 arg = save_arg; |
5169 new_value_alloced = TRUE; | 5168 new_value_alloced = TRUE; |
5170 } | 5169 } |
5171 | 5170 |
5172 /* Set the new value. */ | 5171 /* |
5172 * Set the new value. | |
5173 */ | |
5173 *(char_u **)(varp) = newval; | 5174 *(char_u **)(varp) = newval; |
5174 | 5175 |
5175 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 5176 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
5176 if (!starting | 5177 if (!starting |
5177 # ifdef FEAT_CRYPT | 5178 # ifdef FEAT_CRYPT |
5193 * or 'filetype' autocommands may be triggered that can | 5194 * or 'filetype' autocommands may be triggered that can |
5194 * cause havoc. */ | 5195 * cause havoc. */ |
5195 errmsg = did_set_string_option(opt_idx, (char_u **)varp, | 5196 errmsg = did_set_string_option(opt_idx, (char_u **)varp, |
5196 new_value_alloced, oldval, errbuf, opt_flags); | 5197 new_value_alloced, oldval, errbuf, opt_flags); |
5197 | 5198 |
5199 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
5200 if (errmsg == NULL) | |
5201 trigger_optionsset_string(opt_idx, opt_flags, | |
5202 saved_origval, saved_newval); | |
5203 vim_free(saved_origval); | |
5204 vim_free(saved_newval); | |
5205 #endif | |
5198 /* If error detected, print the error message. */ | 5206 /* If error detected, print the error message. */ |
5199 if (errmsg != NULL) | 5207 if (errmsg != NULL) |
5200 { | |
5201 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
5202 vim_free(saved_origval); | |
5203 vim_free(saved_newval); | |
5204 #endif | |
5205 goto skip; | 5208 goto skip; |
5206 } | |
5207 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | |
5208 trigger_optionsset_string(opt_idx, opt_flags, | |
5209 saved_origval, saved_newval); | |
5210 #endif | |
5211 } | 5209 } |
5212 else /* key code option */ | 5210 else /* key code option */ |
5213 { | 5211 { |
5214 char_u *p; | 5212 char_u *p; |
5215 | 5213 |
6012 opt_flags)) == NULL) | 6010 opt_flags)) == NULL) |
6013 did_set_option(opt_idx, opt_flags, TRUE); | 6011 did_set_option(opt_idx, opt_flags, TRUE); |
6014 | 6012 |
6015 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 6013 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
6016 /* call autocommand after handling side effects */ | 6014 /* call autocommand after handling side effects */ |
6017 trigger_optionsset_string(opt_idx, opt_flags, | 6015 if (r == NULL) |
6016 trigger_optionsset_string(opt_idx, opt_flags, | |
6018 saved_oldval, saved_newval); | 6017 saved_oldval, saved_newval); |
6018 vim_free(saved_oldval); | |
6019 vim_free(saved_newval); | |
6019 #endif | 6020 #endif |
6020 } | 6021 } |
6021 return r; | 6022 return r; |
6022 } | 6023 } |
6023 | 6024 |