summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYegappan Lakshmanan <yegappan@yahoo.com>2023-02-13 16:10:04 +0000
committerBram Moolenaar <Bram@vim.org>2023-02-13 16:10:04 +0000
commit32ff96ef018eb1a5bea0953648b4892a6ee71658 (patch)
treec3a1a5383526dccb92ce5b9289f0a8f42c0f748b
parent5ceb8157bc4608eeff4b7453da31ebe65f08a862 (diff)
downloadvim-git-32ff96ef018eb1a5bea0953648b4892a6ee71658.tar.gz
patch 9.0.1307: setting 'formatoptions' with :let doesn't check for errorsv9.0.1307
Problem: Setting 'formatoptions' with :let doesn't check for errors. Solution: Pass "errbuf" to set_string_option(). (Yegappan Lakshmanan, closes #11974, closes #11972)
-rw-r--r--src/option.c7
-rw-r--r--src/optionstr.c5
-rw-r--r--src/proto/optionstr.pro2
-rw-r--r--src/testdir/test_options.vim40
-rw-r--r--src/version.c2
5 files changed, 51 insertions, 5 deletions
diff --git a/src/option.c b/src/option.c
index ee9c9e33b..c2f002867 100644
--- a/src/option.c
+++ b/src/option.c
@@ -5135,6 +5135,7 @@ set_option_value(
int opt_idx;
char_u *varp;
long_u flags;
+ static char errbuf[80];
opt_idx = findoption(name);
if (opt_idx < 0)
@@ -5177,7 +5178,7 @@ set_option_value(
}
#endif
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);
if (varp != NULL) // hidden option is not changed
@@ -5202,8 +5203,10 @@ set_option_value(
}
}
if (flags & P_NUM)
+ {
return set_num_option(opt_idx, varp, number,
- NULL, 0, opt_flags);
+ errbuf, sizeof(errbuf), opt_flags);
+ }
else
return set_bool_option(opt_idx, varp, (int)number, opt_flags);
}
diff --git a/src/optionstr.c b/src/optionstr.c
index 7dfb7b7ff..6c9fd3ab3 100644
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -487,7 +487,8 @@ set_string_option_direct_in_buf(
set_string_option(
int opt_idx,
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 **varp;
@@ -540,7 +541,7 @@ set_string_option(
saved_newval = vim_strsave(s);
}
#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)
did_set_option(opt_idx, opt_flags, TRUE, value_checked);
diff --git a/src/proto/optionstr.pro b/src/proto/optionstr.pro
index e75e3dcdb..d4f96be40 100644
--- a/src/proto/optionstr.pro
+++ b/src/proto/optionstr.pro
@@ -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_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);
-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);
int check_ff_value(char_u *p);
void save_clear_shm_value(void);
diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim
index 30828e2da..ff8372786 100644
--- a/src/testdir/test_options.vim
+++ b/src/testdir/test_options.vim
@@ -483,6 +483,8 @@ func Test_set_errors()
call assert_fails('set fileencoding=latin1', 'E21:')
set modifiable&
call assert_fails('set t_#-&', 'E522:')
+ call assert_fails('let &formatoptions = "?"', 'E539:')
+ call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
endfunc
func Test_set_encoding()
@@ -1465,5 +1467,43 @@ func Test_endoffile_default()
call delete('Xtestout')
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
diff --git a/src/version.c b/src/version.c
index f3877e429..ee9bf2866 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1307,
+/**/
1306,
/**/
1305,