To: vim_dev@googlegroups.com Subject: Patch 9.0.1212 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1212 Problem: Cannot read back what setcellwidths() has done. Solution: Add getcellwidths(). (Kota Kato, closes #11837) Files: runtime/doc/builtin.txt, runtime/doc/usr_41.txt, src/evalfunc.c, src/mbyte.c, src/proto/mbyte.pro, src/testdir/test_utf8.vim *** ../vim-9.0.1211/runtime/doc/builtin.txt 2023-01-12 21:07:58.636905098 +0000 --- runtime/doc/builtin.txt 2023-01-17 18:17:59.187496137 +0000 *************** *** 211,216 **** --- 211,217 ---- 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,3267 **** --- 3263,3275 ---- < 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 *************** *** 7940,7968 **** setcellwidths({list}) *setcellwidths()* Specify overrides for cell widths of character ranges. This ! tells Vim how wide characters are, counted in screen cells. ! This overrides 'ambiwidth'. Example: > ! setcellwidths([[0xad, 0xad, 1], ! \ [0x2194, 0x2199, 2]]) ! ! < *E1109* *E1110* *E1111* *E1112* *E1113* *E1114* ! The {list} argument is a list of lists with each three ! numbers. These three numbers are [low, high, width]. "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). "width" is either 1 or 2, indicating ! the character width in screen cells. ! An error is given if the argument is invalid, also when a ! range overlaps with another. Only characters with value 0x100 and higher can be used. If the new value causes 'fillchars' or 'listchars' to become invalid it is rejected and an error is given. ! To clear the overrides pass an empty list: > setcellwidths([]); < You can use the script $VIMRUNTIME/tools/emoji_list.vim to see ! the effect for known emoji characters. setcharpos({expr}, {list}) *setcharpos()* Same as |setpos()| but uses the specified column number as the --- 7953,7990 ---- setcellwidths({list}) *setcellwidths()* Specify overrides for cell widths of character ranges. This ! tells Vim how wide characters are when displayed in the ! terminal, counted in screen cells. The values override ! 'ambiwidth'. Example: > ! call setcellwidths([ ! \ [0x111, 0x111, 1], ! \ [0x2194, 0x2199, 2], ! \ ]) ! ! < The {list} argument is a List of Lists with each three ! numbers: [{low}, {high}, {width}]. *E1109* *E1110* ! {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. + {width} must be either 1 or 2, indicating the character width + in screen cells. *E1112* + An error is given if the argument is invalid, also when a + range overlaps with another. *E1113* + If the new value causes 'fillchars' or 'listchars' to become invalid it is rejected and an error is given. ! To clear the overrides pass an empty {list}: > setcellwidths([]); + < You can use the script $VIMRUNTIME/tools/emoji_list.vim to see ! the effect for known emoji characters. Move the cursor ! through the text to check if the cell widths of your terminal ! match with what Vim knows about each emoji. If it doesn't ! look right you need to adjust the {list} argument. ! setcharpos({expr}, {list}) *setcharpos()* Same as |setpos()| but uses the specified column number as the *** ../vim-9.0.1211/runtime/doc/usr_41.txt 2022-12-20 20:01:09.620090910 +0000 --- runtime/doc/usr_41.txt 2023-01-17 18:19:47.207470777 +0000 *************** *** 756,761 **** --- 757,763 ---- 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 *** ../vim-9.0.1211/src/evalfunc.c 2023-01-15 18:17:08.785655216 +0000 --- src/evalfunc.c 2023-01-17 18:15:00.083549100 +0000 *************** *** 1953,1958 **** --- 1953,1960 ---- 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, *** ../vim-9.0.1211/src/mbyte.c 2023-01-14 12:32:24.219984103 +0000 --- src/mbyte.c 2023-01-17 18:21:56.163445402 +0000 *************** *** 5746,5751 **** --- 5746,5770 ---- } 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) { if (check_for_string_arg(argvars, 0) == FAIL *** ../vim-9.0.1211/src/proto/mbyte.pro 2022-06-27 23:15:14.000000000 +0100 --- src/proto/mbyte.pro 2023-01-17 18:20:37.819460241 +0000 *************** *** 86,90 **** --- 86,91 ---- 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 : */ *** ../vim-9.0.1211/src/testdir/test_utf8.vim 2023-01-10 16:02:41.248313354 +0000 --- src/testdir/test_utf8.vim 2023-01-17 18:15:00.083549100 +0000 *************** *** 199,204 **** --- 199,224 ---- 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 *** ../vim-9.0.1211/src/version.c 2023-01-16 20:47:53.889287080 +0000 --- src/version.c 2023-01-17 18:16:44.155516500 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1212, /**/ -- How To Keep A Healthy Level Of Insanity: 4. Put your garbage can on your desk and label it "in". /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///