]> granicus.if.org Git - vim/commitdiff
patch 9.0.1212: cannot read back what setcellwidths() has done v9.0.1212
authorKota Kato <github@kat0h.com>
Tue, 17 Jan 2023 18:31:56 +0000 (18:31 +0000)
committerBram Moolenaar <Bram@vim.org>
Tue, 17 Jan 2023 18:31:56 +0000 (18:31 +0000)
Problem:    Cannot read back what setcellwidths() has done.
Solution:   Add getcellwidths(). (Kota Kato, closes #11837)

runtime/doc/builtin.txt
runtime/doc/usr_41.txt
src/evalfunc.c
src/mbyte.c
src/proto/mbyte.pro
src/testdir/test_utf8.vim
src/version.c

index f202da0585138e78a2dd278851a6522d69fb2aa5..3544b5df8bf1bab0dac03377f2eef5686767ec28 100644 (file)
@@ -211,6 +211,7 @@ getbufline({buf}, {lnum} [, {end}])
 getbufoneline({buf}, {lnum})   String  line {lnum} of buffer {buf}
 getbufvar({buf}, {varname} [, {def}])
                                any     variable {varname} in buffer {buf}
+getcellwidths()                        List    get character cell width overrides
 getchangelist([{buf}])         List    list of change list items
 getchar([expr])                        Number or String
                                        get one character from the user
@@ -3262,6 +3263,13 @@ getbufvar({buf}, {varname} [, {def}])                            *getbufvar()*
 <              Can also be used as a |method|: >
                        GetBufnr()->getbufvar(varname)
 <
+getcellwidths()                                                *getcellwidths()*
+               Returns a |List| of cell widths of character ranges overridden
+               by |setcellwidths()|.  The format is equal to the argument of
+               |setcellwidths()|.  If no character ranges have their cell
+               widths overridden, an empty List is returned.
+
+
 getchangelist([{buf}])                                 *getchangelist()*
                Returns the |changelist| for the buffer {buf}. For the use
                of {buf}, see |bufname()| above. If buffer {buf} doesn't
@@ -9969,7 +9977,7 @@ typename({expr})                                  *typename()*
                Return a string representation of the type of {expr}.
                Example: >
                        echo typename([1, 2, 3])
-                       list<number>
+<                      list<number> ~
 
 
 undofile({name})                                       *undofile()*
index 559707737cfe379891651a7dd41f7867fd405acf..7a706af3cb657a19b2f0c8fb65ded81aa03c4931 100644 (file)
@@ -757,6 +757,7 @@ String manipulation:                                        *string-functions*
        strwidth()              size of string when displayed
        strdisplaywidth()       size of string when displayed, deals with tabs
        setcellwidths()         set character cell width overrides
+       getcellwidths()         get character cell width overrides
        substitute()            substitute a pattern match with a string
        submatch()              get a specific match in ":s" and substitute()
        strpart()               get part of a string using byte index
index 7639af8b24e9af6e4a9ef07cbe3585a751e40c52..923a75024a8c814fdc990c6012dafc41fc00d6ac 100644 (file)
@@ -1953,6 +1953,8 @@ static funcentry_T global_functions[] =
                        ret_string,         f_getbufoneline},
     {"getbufvar",      2, 3, FEARG_1,      arg3_buffer_string_any,
                        ret_any,            f_getbufvar},
+    {"getcellwidths",  0, 0, 0,            NULL,
+                       ret_list_any,       f_getcellwidths},
     {"getchangelist",  0, 1, FEARG_1,      arg1_buffer,
                        ret_list_any,       f_getchangelist},
     {"getchar",                0, 1, 0,            arg1_bool,
index 07cd9c6e6421756d395599d09c10eb07e087bc62..4f6c8502afd8d8230eaa5efc79a6c4604c6564eb 100644 (file)
@@ -5745,6 +5745,25 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
     redraw_all_later(UPD_CLEAR);
 }
 
+    void
+f_getcellwidths(typval_T *argvars UNUSED, typval_T *rettv)
+{
+    if (rettv_list_alloc(rettv) == FAIL)
+       return;
+
+    for (size_t i = 0; i < cw_table_size; i++)
+    {
+       list_T *entry = list_alloc();
+       if (entry == NULL)
+           break;
+       list_append_number(entry, (varnumber_T)cw_table[i].first);
+       list_append_number(entry, (varnumber_T)cw_table[i].last);
+       list_append_number(entry, (varnumber_T)cw_table[i].width);
+
+       list_append_list(rettv->vval.v_list, entry);
+    }
+}
+
     void
 f_charclass(typval_T *argvars, typval_T *rettv UNUSED)
 {
index c429adcf8a157c428ac0219f0858667fd4dbe17b..1bd3aa0bbe3ab30a2a33a5d2d0dbd433faf0dbe9 100644 (file)
@@ -86,5 +86,6 @@ int convert_input_safe(char_u *ptr, int len, int maxlen, char_u **restp, int *re
 char_u *string_convert(vimconv_T *vcp, char_u *ptr, int *lenp);
 char_u *string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp, int *unconvlenp);
 void f_setcellwidths(typval_T *argvars, typval_T *rettv);
+void f_getcellwidths(typval_T *argvars, typval_T *rettv);
 void f_charclass(typval_T *argvars, typval_T *rettv);
 /* vim: set ft=c : */
index 935af7ebf72700fbbc57e4c5d959f8ab343c0814..d71d7ad0328f8c480ecf08f78238833ea8baac38 100644 (file)
@@ -199,6 +199,26 @@ func Test_setcellwidths()
   call setcellwidths([])
 endfunc
 
+func Test_getcellwidths()
+  call setcellwidths([])
+  call assert_equal([], getcellwidths())
+
+  let widthlist = [
+        \ [0x1330, 0x1330, 2],
+        \ [9999, 10000, 1],
+        \ [0x1337, 0x1339, 2],
+        \]
+  let widthlistsorted = [
+        \ [0x1330, 0x1330, 2],
+        \ [0x1337, 0x1339, 2],
+        \ [9999, 10000, 1],
+        \]
+  call setcellwidths(widthlist)
+  call assert_equal(widthlistsorted, getcellwidths())
+
+  call setcellwidths([])
+endfunc
+
 func Test_setcellwidths_dump()
   CheckRunVimInTerminal
 
index a38801961534a8ca318f3f76ebc80bbbd4275017..3496b3af8927849773c9e4e7c1620bb5a521493b 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1212,
 /**/
     1211,
 /**/