diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-02-14 08:29:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-14 08:29:05 +0800 |
commit | 20c9f4b3521fa7ab5c5997c0ec1a3df2b5bd0dbe (patch) | |
tree | 092e42d145c081172935e256f5fef7b429c3dfc2 /src | |
parent | fc9ece617bbf5fbdc74eed33c63641c550b4b314 (diff) | |
download | rneovim-20c9f4b3521fa7ab5c5997c0ec1a3df2b5bd0dbe.tar.gz rneovim-20c9f4b3521fa7ab5c5997c0ec1a3df2b5bd0dbe.tar.bz2 rneovim-20c9f4b3521fa7ab5c5997c0ec1a3df2b5bd0dbe.zip |
vim-patch:9.0.1307: setting 'formatoptions' with :let doesn't check for errors (#22252)
Problem: Setting 'formatoptions' with :let doesn't check for errors.
Solution: Pass "errbuf" to set_string_option(). (Yegappan Lakshmanan,
closes vim/vim#11974, closes vim/vim#11972)
https://github.com/vim/vim/commit/32ff96ef018eb1a5bea0953648b4892a6ee71658
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/option.c | 6 | ||||
-rw-r--r-- | src/nvim/optionstr.c | 5 | ||||
-rw-r--r-- | src/nvim/testdir/test_options.vim | 41 |
3 files changed, 48 insertions, 4 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 26466c2869..5ece5e4e5d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3084,6 +3084,8 @@ char *set_option_value(const char *const name, const long number, const char *co const int opt_flags) FUNC_ATTR_NONNULL_ARG(1) { + static char errbuf[80]; + if (is_tty_option(name)) { return NULL; // Fail silently; many old vimrcs set t_xx options. } @@ -3106,7 +3108,7 @@ char *set_option_value(const char *const name, const long number, const char *co if (s == NULL || opt_flags & OPT_CLEAR) { s = ""; } - return set_string_option(opt_idx, s, opt_flags); + return set_string_option(opt_idx, s, opt_flags, errbuf, sizeof(errbuf)); } char_u *varp = (char_u *)get_varp_scope(&(options[opt_idx]), opt_flags); @@ -3144,7 +3146,7 @@ char *set_option_value(const char *const name, const long number, const char *co } } if (flags & P_NUM) { - return set_num_option(opt_idx, varp, numval, NULL, 0, opt_flags); + return set_num_option(opt_idx, varp, numval, errbuf, sizeof(errbuf), opt_flags); } return set_bool_option(opt_idx, (char *)varp, (int)numval, opt_flags); } diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 5f8514b1a6..f903ad3d09 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -410,7 +410,8 @@ void set_string_option_direct_in_win(win_T *wp, const char *name, int opt_idx, c /// #OPT_GLOBAL. /// /// @return NULL on success, an untranslated error message on error. -char *set_string_option(const int opt_idx, const char *const value, const int opt_flags) +char *set_string_option(const int opt_idx, const char *const value, const int opt_flags, + char *const errbuf, const size_t errbuflen) FUNC_ATTR_NONNULL_ARG(2) FUNC_ATTR_WARN_UNUSED_RESULT { vimoption_T *opt = get_option(opt_idx); @@ -442,7 +443,7 @@ char *set_string_option(const int opt_idx, const char *const value, const int op int value_checked = false; char *const errmsg = did_set_string_option(opt_idx, varp, oldval, - NULL, 0, + errbuf, errbuflen, opt_flags, &value_checked); if (errmsg == NULL) { did_set_option(opt_idx, opt_flags, true, value_checked); diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index f51de94bac..43cc3632e6 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -434,6 +434,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 CheckWasSet(name) @@ -1300,5 +1302,44 @@ 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 laststatus=1 + 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 |