]> granicus.if.org Git - vim/commitdiff
patch 9.0.0176: checking character options is duplicated and incomplete v9.0.0176
authorzeertzjq <zeertzjq@outlook.com>
Tue, 9 Aug 2022 11:53:14 +0000 (12:53 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 9 Aug 2022 11:53:14 +0000 (12:53 +0100)
Problem:    Checking character options is duplicated and incomplete.
Solution:   Move checking to check_chars_options(). (closes #10863)

src/mbyte.c
src/optionstr.c
src/proto/screen.pro
src/screen.c
src/testdir/test_options.vim
src/version.c

index 691c1608e3a1d675d49f2bfe4bfd9f6bf72cdc60..941411b4a940fd5b2341c191d58bb3658084bee8 100644 (file)
@@ -5645,31 +5645,9 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
     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));
index 331207b67ed50291675df591973a4bbcf1213308..7f5a9408c7b5cd84fa93ea7f33db4bdd9c113a46 100644 (file)
@@ -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'
index 66fc0f3da23eeb8ac2dd715cf0368e6f9d1c1503..81e5e101c1b040cea1ccc7cb15e555ed72bee2db 100644 (file)
@@ -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 : */
index 1f223f9be798ca449a92d17787df2bf912b74d18..6929501c4e406253c7cdff930a743b4dfaba28f9 100644 (file)
@@ -5155,3 +5155,28 @@ set_chars_option(win_T *wp, char_u **varp, int apply)
 
     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;
+}
index 01418bd6d69574669072957a3daa288178a71491..ba08dd7968c329887bbde97fa16f8b87232799fd 100644 (file)
@@ -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
index 39449539c539451ca61508de7fcdfb0d09573870..0334bf061ea9ac177dee661f0519328d52040356 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    176,
 /**/
     175,
 /**/