1
0
forked from aniani/vim

patch 7.4.786

Problem:    It is not possible for a plugin to adjust to a changed setting.
Solution:   Add the OptionSet autocommand event. (Christian Brabandt)
This commit is contained in:
Bram Moolenaar
2015-07-17 17:38:22 +02:00
parent 34d72d4b6c
commit 537443018d
16 changed files with 354 additions and 5 deletions

View File

@@ -4592,9 +4592,12 @@ do_set(arg, opt_flags)
{
char_u *save_arg = NULL;
char_u *s = NULL;
char_u *oldval; /* previous value if *varp */
char_u *oldval = NULL; /* previous value if *varp */
char_u *newval;
char_u *origval;
char_u *origval = NULL;
#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
char_u *saved_origval = NULL;
#endif
unsigned newlen;
int comma;
int bs;
@@ -4914,6 +4917,14 @@ do_set(arg, opt_flags)
/* Set the new value. */
*(char_u **)(varp) = newval;
#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
if (!starting && options[opt_idx].indir != PV_KEY
&& origval != NULL)
/* origval may be freed by
* did_set_string_option(), make a copy. */
saved_origval = vim_strsave(origval);
#endif
/* Handle side effects, and set the global value for
* ":set" on local options. */
errmsg = did_set_string_option(opt_idx, (char_u **)varp,
@@ -4922,6 +4933,24 @@ do_set(arg, opt_flags)
/* If error detected, print the error message. */
if (errmsg != NULL)
goto skip;
#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
if (saved_origval != NULL)
{
char_u buf_type[7];
sprintf((char *)buf_type, "%s",
(opt_flags & OPT_LOCAL) ? "local" : "global");
set_vim_var_string(VV_OPTION_NEW, newval, -1);
set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
apply_autocmds(EVENT_OPTIONSET,
(char_u *)options[opt_idx].fullname,
NULL, FALSE, NULL);
reset_v_option_vars();
vim_free(saved_origval);
}
#endif
}
else /* key code option */
{
@@ -5668,6 +5697,9 @@ set_string_option(opt_idx, value, opt_flags)
char_u *s;
char_u **varp;
char_u *oldval;
#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
char_u *saved_oldval = NULL;
#endif
char_u *r = NULL;
if (options[opt_idx].var == NULL) /* don't set hidden option */
@@ -5683,9 +5715,30 @@ set_string_option(opt_idx, value, opt_flags)
: opt_flags);
oldval = *varp;
*varp = s;
#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
if (!starting && options[opt_idx].indir != PV_KEY)
saved_oldval = vim_strsave(oldval);
#endif
if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
opt_flags)) == NULL)
did_set_option(opt_idx, opt_flags, TRUE);
/* call autocomamnd after handling side effects */
#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
if (saved_oldval != NULL)
{
char_u buf_type[7];
sprintf((char *)buf_type, "%s",
(opt_flags & OPT_LOCAL) ? "local" : "global");
set_vim_var_string(VV_OPTION_NEW, s, -1);
set_vim_var_string(VV_OPTION_OLD, oldval, -1);
set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
reset_v_option_vars();
vim_free(saved_oldval);
}
#endif
}
return r;
}
@@ -8230,8 +8283,25 @@ set_bool_option(opt_idx, varp, value, opt_flags)
* End of handling side effects for bool options.
*/
/* after handling side effects, call autocommand */
options[opt_idx].flags |= P_WAS_SET;
#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
if (!starting)
{
char_u buf_old[2], buf_new[2], buf_type[7];
snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
sprintf((char *)buf_type, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
reset_v_option_vars();
}
#endif
comp_col(); /* in case 'ruler' or 'showcmd' changed */
if (curwin->w_curswant != MAXCOL
&& (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
@@ -8767,6 +8837,21 @@ set_num_option(opt_idx, varp, value, errbuf, errbuflen, opt_flags)
options[opt_idx].flags |= P_WAS_SET;
#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
if (!starting && errmsg == NULL)
{
char_u buf_old[11], buf_new[11], buf_type[7];
snprintf((char *)buf_old, 10, "%ld", old_value);
snprintf((char *)buf_new, 10, "%ld", value);
snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
reset_v_option_vars();
}
#endif
comp_col(); /* in case 'columns' or 'ls' changed */
if (curwin->w_curswant != MAXCOL
&& (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)