]> granicus.if.org Git - vim/commitdiff
patch 9.0.1223: cannot use setcellwidths() below 0x100 v9.0.1223
authorK.Takata <kentkt@csc.jp>
Fri, 20 Jan 2023 16:00:55 +0000 (16:00 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 20 Jan 2023 16:00:55 +0000 (16:00 +0000)
Problem:    Cannot use setcellwidths() below 0x100.
Solution:   Also accept characters between 0x80 and 0x100. (Ken Takata,
            closes #11834)

runtime/doc/builtin.txt
src/errors.h
src/mbyte.c
src/testdir/test_utf8.vim
src/version.c

index 3544b5df8bf1bab0dac03377f2eef5686767ec28..a888ae08970176dcc5946e170576642569fee53a 100644 (file)
@@ -7966,7 +7966,7 @@ setcellwidths({list})                                     *setcellwidths()*
                {low} and {high} can be the same, in which case this refers to
                one character.  Otherwise it is the range of characters from
                {low} to {high} (inclusive).            *E1111* *E1114*
-               Only characters with value 0x100 and higher can be used.
+               Only characters with value 0x80 and higher can be used.
 
                {width} must be either 1 or 2, indicating the character width
                in screen cells.                        *E1112*
index 3b6307f0ba5c82de8330799ae9ad6948d0341e3b..3b54f1d9f3d0789cbf62a517d2f3556daad7e119 100644 (file)
@@ -2841,8 +2841,8 @@ EXTERN char e_list_item_nr_cell_width_invalid[]
        INIT(= N_("E1112: List item %d cell width invalid"));
 EXTERN char e_overlapping_ranges_for_nr[]
        INIT(= N_("E1113: Overlapping ranges for 0x%lx"));
-EXTERN char e_only_values_of_0x100_and_higher_supported[]
-       INIT(= N_("E1114: Only values of 0x100 and higher supported"));
+EXTERN char e_only_values_of_0x80_and_higher_supported[]
+       INIT(= N_("E1114: Only values of 0x80 and higher supported"));
 EXTERN char e_assert_fails_fourth_argument[]
        INIT(= N_("E1115: \"assert_fails()\" fourth argument must be a number"));
 EXTERN char e_assert_fails_fifth_argument[]
index 6d7137ed5586ce37ca9c6f8bf3f0f03d690c11ef..57aa619990056409f8d4e6d1c676e6429271e6ac 100644 (file)
@@ -1589,19 +1589,26 @@ utf_char2cells(int c)
 #endif
     };
 
-    if (c >= 0x100)
-    {
-#if defined(FEAT_EVAL) || defined(USE_WCHAR_FUNCTIONS)
-       int     n;
-#endif
-
 #ifdef FEAT_EVAL
-       n = cw_value(c);
+    // Use the value from setcellwidths() at 0x80 and higher, unless the
+    // character is not printable.
+    if (c >= 0x80 &&
+# ifdef USE_WCHAR_FUNCTIONS
+           wcwidth(c) >= 1 &&
+# endif
+           vim_isprintc(c))
+    {
+       int n = cw_value(c);
        if (n != 0)
            return n;
+    }
 #endif
 
+    if (c >= 0x100)
+    {
 #ifdef USE_WCHAR_FUNCTIONS
+       int     n;
+
        /*
         * Assume the library function wcwidth() works better than our own
         * stuff.  It should return 1 for ambiguous width chars!
@@ -5661,9 +5668,9 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
            if (i == 0)
            {
                n1 = lili->li_tv.vval.v_number;
-               if (n1 < 0x100)
+               if (n1 < 0x80)
                {
-                   emsg(_(e_only_values_of_0x100_and_higher_supported));
+                   emsg(_(e_only_values_of_0x80_and_higher_supported));
                    vim_free(ptrs);
                    return;
                }
index d71d7ad0328f8c480ecf08f78238833ea8baac38..9ad7828d469dc31b1d74bd7906e78646a1985e0c 100644 (file)
@@ -167,6 +167,39 @@ func Test_setcellwidths()
   call assert_equal(2, strwidth("\u1339"))
   call assert_equal(1, strwidth("\u133a"))
 
+  for aw in ['single', 'double']
+    exe 'set ambiwidth=' . aw
+    " Handle \u0080 to \u009F as control chars even on MS-Windows.
+    set isprint=@,161-255
+
+    call setcellwidths([])
+    " Control chars
+    call assert_equal(4, strwidth("\u0081"))
+    call assert_equal(6, strwidth("\uFEFF"))
+    " Ambiguous width chars
+    call assert_equal((aw == 'single') ? 1 : 2, strwidth("\u00A1"))
+    call assert_equal((aw == 'single') ? 1 : 2, strwidth("\u2010"))
+
+    call setcellwidths([[0x81, 0x81, 1], [0xA1, 0xA1, 1],
+                      \ [0x2010, 0x2010, 1], [0xFEFF, 0xFEFF, 1]])
+    " Control chars
+    call assert_equal(4, strwidth("\u0081"))
+    call assert_equal(6, strwidth("\uFEFF"))
+    " Ambiguous width chars
+    call assert_equal(1, strwidth("\u00A1"))
+    call assert_equal(1, strwidth("\u2010"))
+
+    call setcellwidths([[0x81, 0x81, 2], [0xA1, 0xA1, 2],
+                      \ [0x2010, 0x2010, 2], [0xFEFF, 0xFEFF, 2]])
+    " Control chars
+    call assert_equal(4, strwidth("\u0081"))
+    call assert_equal(6, strwidth("\uFEFF"))
+    " Ambiguous width chars
+    call assert_equal(2, strwidth("\u00A1"))
+    call assert_equal(2, strwidth("\u2010"))
+  endfor
+  set ambiwidth& isprint&
+
   call setcellwidths([])
 
   call assert_fails('call setcellwidths(1)', 'E1211:')
index 22a8e8b774d482fb216a9dcfc90c1ea2086d1d3c..f15061adc2420703715478f111f0662a8c09325c 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1223,
 /**/
     1222,
 /**/