0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 9.0.1307: setting 'formatoptions' with :let doesn't check for errors

Problem:    Setting 'formatoptions' with :let doesn't check for errors.
Solution:   Pass "errbuf" to set_string_option(). (Yegappan Lakshmanan,
            closes #11974, closes #11972)
This commit is contained in:
Yegappan Lakshmanan
2023-02-13 16:10:04 +00:00
committed by Bram Moolenaar
parent 5ceb8157bc
commit 32ff96ef01
5 changed files with 51 additions and 5 deletions

View File

@@ -5135,6 +5135,7 @@ set_option_value(
int opt_idx; int opt_idx;
char_u *varp; char_u *varp;
long_u flags; long_u flags;
static char errbuf[80];
opt_idx = findoption(name); opt_idx = findoption(name);
if (opt_idx < 0) if (opt_idx < 0)
@@ -5177,7 +5178,7 @@ set_option_value(
} }
#endif #endif
if (flags & P_STRING) if (flags & P_STRING)
return set_string_option(opt_idx, string, opt_flags); return set_string_option(opt_idx, string, opt_flags, errbuf);
varp = get_varp_scope(&(options[opt_idx]), opt_flags); varp = get_varp_scope(&(options[opt_idx]), opt_flags);
if (varp != NULL) // hidden option is not changed if (varp != NULL) // hidden option is not changed
@@ -5202,8 +5203,10 @@ set_option_value(
} }
} }
if (flags & P_NUM) if (flags & P_NUM)
{
return set_num_option(opt_idx, varp, number, return set_num_option(opt_idx, varp, number,
NULL, 0, opt_flags); errbuf, sizeof(errbuf), opt_flags);
}
else else
return set_bool_option(opt_idx, varp, (int)number, opt_flags); return set_bool_option(opt_idx, varp, (int)number, opt_flags);
} }

View File

@@ -487,7 +487,8 @@ set_string_option_direct_in_buf(
set_string_option( set_string_option(
int opt_idx, int opt_idx,
char_u *value, char_u *value,
int opt_flags) // OPT_LOCAL and/or OPT_GLOBAL int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
char *errbuf)
{ {
char_u *s; char_u *s;
char_u **varp; char_u **varp;
@@ -540,7 +541,7 @@ set_string_option(
saved_newval = vim_strsave(s); saved_newval = vim_strsave(s);
} }
#endif #endif
if ((errmsg = did_set_string_option(opt_idx, varp, oldval, NULL, if ((errmsg = did_set_string_option(opt_idx, varp, oldval, errbuf,
opt_flags, &value_checked)) == NULL) opt_flags, &value_checked)) == NULL)
did_set_option(opt_idx, opt_flags, TRUE, value_checked); did_set_option(opt_idx, opt_flags, TRUE, value_checked);

View File

@@ -8,7 +8,7 @@ void check_string_option(char_u **pp);
void set_string_option_direct(char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); void set_string_option_direct(char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid);
void set_string_option_direct_in_win(win_T *wp, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); void set_string_option_direct_in_win(win_T *wp, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid);
void set_string_option_direct_in_buf(buf_T *buf, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid); void set_string_option_direct_in_buf(buf_T *buf, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid);
char *set_string_option(int opt_idx, char_u *value, int opt_flags); char *set_string_option(int opt_idx, char_u *value, int opt_flags, char *errbuf);
char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *errbuf, int opt_flags, int *value_checked); char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char *errbuf, int opt_flags, int *value_checked);
int check_ff_value(char_u *p); int check_ff_value(char_u *p);
void save_clear_shm_value(void); void save_clear_shm_value(void);

View File

@@ -483,6 +483,8 @@ func Test_set_errors()
call assert_fails('set fileencoding=latin1', 'E21:') call assert_fails('set fileencoding=latin1', 'E21:')
set modifiable& set modifiable&
call assert_fails('set t_#-&', 'E522:') call assert_fails('set t_#-&', 'E522:')
call assert_fails('let &formatoptions = "?"', 'E539:')
call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
endfunc endfunc
func Test_set_encoding() func Test_set_encoding()
@@ -1465,5 +1467,43 @@ func Test_endoffile_default()
call delete('Xtestout') call delete('Xtestout')
endfunc endfunc
" Test for setting the 'lines' and 'columns' options to a minimum value
func Test_set_min_lines_columns()
let save_lines = &lines
let save_columns = &columns
let after =<< trim END
set nomore
let msg = []
let v:errmsg = ''
silent! let &columns=0
call add(msg, v:errmsg)
silent! set columns=0
call add(msg, v:errmsg)
silent! call setbufvar('', '&columns', 0)
call add(msg, v:errmsg)
"call writefile(msg, 'XResultsetminlines')
silent! let &lines=0
call add(msg, v:errmsg)
silent! set lines=0
call add(msg, v:errmsg)
silent! call setbufvar('', '&lines', 0)
call add(msg, v:errmsg)
call writefile(msg, 'XResultsetminlines')
qall!
END
if RunVim([], after, '')
call assert_equal(['E594: Need at least 12 columns',
\ 'E594: Need at least 12 columns: columns=0',
\ 'E594: Need at least 12 columns',
\ 'E593: Need at least 2 lines',
\ 'E593: Need at least 2 lines: lines=0',
\ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
endif
call delete('XResultsetminlines')
let &lines = save_lines
let &columns = save_columns
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -695,6 +695,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 */
/**/
1307,
/**/ /**/
1306, 1306,
/**/ /**/