# HG changeset patch # User Bram Moolenaar # Date 1660046405 -7200 # Node ID 6b8aaf16af99ba105202a842d92a9b1295094111 # Parent 4e3501a00ec7a2ac2cbc6cbc036cbccd5ddee92c patch 9.0.0176: checking character options is duplicated and incomplete Commit: https://github.com/vim/vim/commit/8ca29b6a3599b82b8822b7697cad63d0244c2d59 Author: zeertzjq Date: Tue Aug 9 12:53:14 2022 +0100 patch 9.0.0176: checking character options is duplicated and incomplete Problem: Checking character options is duplicated and incomplete. Solution: Move checking to check_chars_options(). (closes https://github.com/vim/vim/issues/10863) diff --git a/src/mbyte.c b/src/mbyte.c --- a/src/mbyte.c +++ b/src/mbyte.c @@ -5645,31 +5645,9 @@ f_setcellwidths(typval_T *argvars, typva cw_table = table; cw_table_size = l->lv_len; - // Check that the new value does not conflict with 'fillchars' or - // 'listchars'. - if (set_chars_option(curwin, &p_fcs, FALSE) != NULL) - error = e_conflicts_with_value_of_fillchars; - else if (set_chars_option(curwin, &p_lcs, FALSE) != NULL) - error = e_conflicts_with_value_of_listchars; - else - { - tabpage_T *tp; - win_T *wp; - - FOR_ALL_TAB_WINDOWS(tp, wp) - { - if (set_chars_option(wp, &wp->w_p_lcs, FALSE) != NULL) - { - error = e_conflicts_with_value_of_listchars; - break; - } - if (set_chars_option(wp, &wp->w_p_fcs, FALSE) != NULL) - { - error = e_conflicts_with_value_of_fillchars; - break; - } - } - } + // Check that the new value does not conflict with 'listchars' or + // 'fillchars'. + error = check_chars_options(); if (error != NULL) { emsg(_(error)); diff --git a/src/optionstr.c b/src/optionstr.c --- a/src/optionstr.c +++ b/src/optionstr.c @@ -866,24 +866,8 @@ did_set_string_option( { if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK) errmsg = e_invalid_argument; - else if (set_chars_option(curwin, &p_fcs, FALSE) != NULL) - errmsg = e_conflicts_with_value_of_fillchars; else - { - tabpage_T *tp; - win_T *wp; - - FOR_ALL_TAB_WINDOWS(tp, wp) - { - if (set_chars_option(wp, &wp->w_p_lcs, FALSE) != NULL) - { - errmsg = e_conflicts_with_value_of_listchars; - goto ambw_end; - } - } - } -ambw_end: - {} + errmsg = check_chars_options(); } // 'background' diff --git a/src/proto/screen.pro b/src/proto/screen.pro --- a/src/proto/screen.pro +++ b/src/proto/screen.pro @@ -56,4 +56,5 @@ int number_width(win_T *wp); int screen_screencol(void); int screen_screenrow(void); char *set_chars_option(win_T *wp, char_u **varp, int apply); +char *check_chars_options(void); /* vim: set ft=c : */ diff --git a/src/screen.c b/src/screen.c --- a/src/screen.c +++ b/src/screen.c @@ -5155,3 +5155,28 @@ set_chars_option(win_T *wp, char_u **var return NULL; // no error } + +/* + * Check all global and local values of 'listchars' and 'fillchars'. + * Return an untranslated error messages if any of them is invalid, NULL + * otherwise. + */ + char * +check_chars_options(void) +{ + tabpage_T *tp; + win_T *wp; + + if (set_chars_option(curwin, &p_lcs, FALSE) != NULL) + return e_conflicts_with_value_of_listchars; + if (set_chars_option(curwin, &p_fcs, FALSE) != NULL) + return e_conflicts_with_value_of_fillchars; + FOR_ALL_TAB_WINDOWS(tp, wp) + { + if (set_chars_option(wp, &wp->w_p_lcs, FALSE) != NULL) + return e_conflicts_with_value_of_listchars; + if (set_chars_option(wp, &wp->w_p_fcs, FALSE) != NULL) + return e_conflicts_with_value_of_fillchars; + } + return NULL; +} diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim --- a/src/testdir/test_options.vim +++ b/src/testdir/test_options.vim @@ -466,9 +466,17 @@ func Test_set_errors() call assert_fails('set sessionoptions=curdir,sesdir', 'E474:') call assert_fails('set foldmarker={{{,', 'E474:') call assert_fails('set sessionoptions=sesdir,curdir', 'E474:') - call assert_fails('set listchars=trail:· ambiwidth=double', 'E834:') + setlocal listchars=trail:· + call assert_fails('set ambiwidth=double', 'E834:') + setlocal listchars=trail:- + setglobal listchars=trail:· + call assert_fails('set ambiwidth=double', 'E834:') set listchars& - call assert_fails('set fillchars=stl:· ambiwidth=double', 'E835:') + setlocal fillchars=stl:· + call assert_fails('set ambiwidth=double', 'E835:') + setlocal fillchars=stl:- + setglobal fillchars=stl:· + call assert_fails('set ambiwidth=double', 'E835:') set fillchars& call assert_fails('set fileencoding=latin1,utf-8', 'E474:') set nomodifiable diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -736,6 +736,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 176, +/**/ 175, /**/ 174,