0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

updated for version 7.3.1004

Problem:    No error when option could not be set.
Solution:   Report an error. (ZyX)
This commit is contained in:
Bram Moolenaar
2013-05-21 22:38:18 +02:00
parent 2a0f3d3fb2
commit c96ebe75e5
6 changed files with 55 additions and 15 deletions

View File

@@ -1520,6 +1520,25 @@ OptionsItem(OptionsObject *self, PyObject *keyObject)
} }
} }
static int
set_option_value_err(key, numval, stringval, opt_flags)
char_u *key;
int numval;
char_u *stringval;
int opt_flags;
{
char_u *errmsg;
if ((errmsg = set_option_value(key, numval, stringval, opt_flags)))
{
if (VimTryEnd())
return FAIL;
PyErr_SetVim((char *)errmsg);
return FAIL;
}
return OK;
}
static int static int
set_option_value_for(key, numval, stringval, opt_flags, opt_type, from) set_option_value_for(key, numval, stringval, opt_flags, opt_type, from)
char_u *key; char_u *key;
@@ -1532,6 +1551,7 @@ set_option_value_for(key, numval, stringval, opt_flags, opt_type, from)
win_T *save_curwin = NULL; win_T *save_curwin = NULL;
tabpage_T *save_curtab = NULL; tabpage_T *save_curtab = NULL;
buf_T *save_curbuf = NULL; buf_T *save_curbuf = NULL;
int r = 0;
VimTryStart(); VimTryStart();
switch (opt_type) switch (opt_type)
@@ -1545,16 +1565,22 @@ set_option_value_for(key, numval, stringval, opt_flags, opt_type, from)
PyErr_SetVim("Problem while switching windows."); PyErr_SetVim("Problem while switching windows.");
return -1; return -1;
} }
set_option_value(key, numval, stringval, opt_flags); r = set_option_value_err(key, numval, stringval, opt_flags);
restore_win(save_curwin, save_curtab); restore_win(save_curwin, save_curtab);
if (r == FAIL)
return -1;
break; break;
case SREQ_BUF: case SREQ_BUF:
switch_buffer(&save_curbuf, (buf_T *)from); switch_buffer(&save_curbuf, (buf_T *)from);
set_option_value(key, numval, stringval, opt_flags); r = set_option_value_err(key, numval, stringval, opt_flags);
restore_buffer(save_curbuf); restore_buffer(save_curbuf);
if (r == FAIL)
return -1;
break; break;
case SREQ_GLOBAL: case SREQ_GLOBAL:
set_option_value(key, numval, stringval, opt_flags); r = set_option_value_err(key, numval, stringval, opt_flags);
if (r == FAIL)
return -1;
break; break;
} }
return VimTryEnd(); return VimTryEnd();
@@ -1611,6 +1637,7 @@ OptionsAssItem(OptionsObject *self, PyObject *keyObject, PyObject *valObject)
if (flags & SOPT_BOOL) if (flags & SOPT_BOOL)
{ {
int istrue = PyObject_IsTrue(valObject); int istrue = PyObject_IsTrue(valObject);
if (istrue == -1) if (istrue == -1)
return -1; return -1;
r = set_option_value_for(key, istrue, NULL, r = set_option_value_for(key, istrue, NULL,

View File

@@ -3018,7 +3018,7 @@ static long_u *insecure_flag __ARGS((int opt_idx, int opt_flags));
# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags) # define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
#endif #endif
static void set_string_option_global __ARGS((int opt_idx, char_u **varp)); static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags)); static char_u *set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags)); static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
static char_u *set_chars_option __ARGS((char_u **varp)); static char_u *set_chars_option __ARGS((char_u **varp));
#ifdef FEAT_SYN_HL #ifdef FEAT_SYN_HL
@@ -5600,8 +5600,10 @@ set_string_option_global(opt_idx, varp)
/* /*
* Set a string option to a new value, and handle the effects. * Set a string option to a new value, and handle the effects.
*
* Returns NULL on success or error message on error.
*/ */
static void static char_u *
set_string_option(opt_idx, value, opt_flags) set_string_option(opt_idx, value, opt_flags)
int opt_idx; int opt_idx;
char_u *value; char_u *value;
@@ -5610,9 +5612,10 @@ set_string_option(opt_idx, value, opt_flags)
char_u *s; char_u *s;
char_u **varp; char_u **varp;
char_u *oldval; char_u *oldval;
char_u *r = NULL;
if (options[opt_idx].var == NULL) /* don't set hidden option */ if (options[opt_idx].var == NULL) /* don't set hidden option */
return; return NULL;
s = vim_strsave(value); s = vim_strsave(value);
if (s != NULL) if (s != NULL)
@@ -5624,10 +5627,11 @@ set_string_option(opt_idx, value, opt_flags)
: opt_flags); : opt_flags);
oldval = *varp; oldval = *varp;
*varp = s; *varp = s;
if (did_set_string_option(opt_idx, varp, TRUE, oldval, NULL, if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
opt_flags) == NULL) opt_flags)) == NULL)
did_set_option(opt_idx, opt_flags, TRUE); did_set_option(opt_idx, opt_flags, TRUE);
} }
return r;
} }
/* /*
@@ -8969,8 +8973,10 @@ get_option_value_strict(name, numval, stringval, opt_type, from)
/* /*
* Set the value of option "name". * Set the value of option "name".
* Use "string" for string options, use "number" for other options. * Use "string" for string options, use "number" for other options.
*
* Returns NULL on success or error message on error.
*/ */
void char_u *
set_option_value(name, number, string, opt_flags) set_option_value(name, number, string, opt_flags)
char_u *name; char_u *name;
long number; long number;
@@ -8992,11 +8998,11 @@ set_option_value(name, number, string, opt_flags)
if (sandbox > 0 && (flags & P_SECURE)) if (sandbox > 0 && (flags & P_SECURE))
{ {
EMSG(_(e_sandbox)); EMSG(_(e_sandbox));
return; return NULL;
} }
#endif #endif
if (flags & P_STRING) if (flags & P_STRING)
set_string_option(opt_idx, string, opt_flags); return set_string_option(opt_idx, string, opt_flags);
else else
{ {
varp = get_varp_scope(&(options[opt_idx]), opt_flags); varp = get_varp_scope(&(options[opt_idx]), opt_flags);
@@ -9017,19 +9023,20 @@ set_option_value(name, number, string, opt_flags)
* num option using a string. */ * num option using a string. */
EMSG3(_("E521: Number required: &%s = '%s'"), EMSG3(_("E521: Number required: &%s = '%s'"),
name, string); name, string);
return; /* do nothing as we hit an error */ return NULL; /* do nothing as we hit an error */
} }
} }
if (flags & P_NUM) if (flags & P_NUM)
(void)set_num_option(opt_idx, varp, number, return set_num_option(opt_idx, varp, number,
NULL, 0, opt_flags); NULL, 0, opt_flags);
else else
(void)set_bool_option(opt_idx, varp, (int)number, return set_bool_option(opt_idx, varp, (int)number,
opt_flags); opt_flags);
} }
} }
} }
return NULL;
} }
/* /*

View File

@@ -23,7 +23,7 @@ char_u *check_colorcolumn __ARGS((win_T *wp));
char_u *check_stl_option __ARGS((char_u *s)); char_u *check_stl_option __ARGS((char_u *s));
int get_option_value __ARGS((char_u *name, long *numval, char_u **stringval, int opt_flags)); int get_option_value __ARGS((char_u *name, long *numval, char_u **stringval, int opt_flags));
int get_option_value_strict __ARGS((char_u *name, long *numval, char_u **stringval, int opt_type, void *from)); int get_option_value_strict __ARGS((char_u *name, long *numval, char_u **stringval, int opt_type, void *from));
void set_option_value __ARGS((char_u *name, long number, char_u *string, int opt_flags)); char_u *set_option_value __ARGS((char_u *name, long number, char_u *string, int opt_flags));
char_u *get_term_code __ARGS((char_u *tname)); char_u *get_term_code __ARGS((char_u *tname));
char_u *get_highlight_default __ARGS((void)); char_u *get_highlight_default __ARGS((void));
char_u *get_encoding_default __ARGS((void)); char_u *get_encoding_default __ARGS((void));

View File

@@ -166,6 +166,7 @@ jkl
inv: -100! KeyError inv: -100! KeyError
gopts1! KeyError gopts1! KeyError
p/wopts1: 8 p/wopts1: 8
inv: -100! error
p/bopts1! KeyError p/bopts1! KeyError
inv: -100! KeyError inv: -100! KeyError
bopts1! KeyError bopts1! KeyError
@@ -184,6 +185,7 @@ jkl
inv: 'abc'! KeyError inv: 'abc'! KeyError
gopts1! KeyError gopts1! KeyError
p/wopts1: '' p/wopts1: ''
inv: 'abc'! error
p/bopts1! KeyError p/bopts1! KeyError
inv: 'abc'! KeyError inv: 'abc'! KeyError
bopts1! KeyError bopts1! KeyError

View File

@@ -155,6 +155,7 @@ jkl
inv: -100! KeyError inv: -100! KeyError
gopts1! KeyError gopts1! KeyError
p/wopts1: 8 p/wopts1: 8
inv: -100! error
p/bopts1! KeyError p/bopts1! KeyError
inv: -100! KeyError inv: -100! KeyError
bopts1! KeyError bopts1! KeyError
@@ -173,6 +174,7 @@ jkl
inv: 'abc'! KeyError inv: 'abc'! KeyError
gopts1! KeyError gopts1! KeyError
p/wopts1: b'' p/wopts1: b''
inv: 'abc'! error
p/bopts1! KeyError p/bopts1! KeyError
inv: 'abc'! KeyError inv: 'abc'! KeyError
bopts1! KeyError bopts1! KeyError

View File

@@ -728,6 +728,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1004,
/**/ /**/
1003, 1003,
/**/ /**/