Skip to content

Commit 66bb9ae

Browse files
kat0hbrammool
authored andcommitted
patch 9.0.1212: cannot read back what setcellwidths() has done
Problem: Cannot read back what setcellwidths() has done. Solution: Add getcellwidths(). (Kota Kato, closes #11837)
1 parent f7d1c6e commit 66bb9ae

7 files changed

Lines changed: 54 additions & 1 deletion

File tree

runtime/doc/builtin.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ getbufline({buf}, {lnum} [, {end}])
211211
getbufoneline({buf}, {lnum}) String line {lnum} of buffer {buf}
212212
getbufvar({buf}, {varname} [, {def}])
213213
any variable {varname} in buffer {buf}
214+
getcellwidths() List get character cell width overrides
214215
getchangelist([{buf}]) List list of change list items
215216
getchar([expr]) Number or String
216217
get one character from the user
@@ -3262,6 +3263,13 @@ getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
32623263
< Can also be used as a |method|: >
32633264
GetBufnr()->getbufvar(varname)
32643265
<
3266+
getcellwidths() *getcellwidths()*
3267+
Returns a |List| of cell widths of character ranges overridden
3268+
by |setcellwidths()|. The format is equal to the argument of
3269+
|setcellwidths()|. If no character ranges have their cell
3270+
widths overridden, an empty List is returned.
3271+
3272+
32653273
getchangelist([{buf}]) *getchangelist()*
32663274
Returns the |changelist| for the buffer {buf}. For the use
32673275
of {buf}, see |bufname()| above. If buffer {buf} doesn't
@@ -9969,7 +9977,7 @@ typename({expr}) *typename()*
99699977
Return a string representation of the type of {expr}.
99709978
Example: >
99719979
echo typename([1, 2, 3])
9972-
list<number>
9980+
< list<number> ~
99739981

99749982

99759983
undofile({name}) *undofile()*

runtime/doc/usr_41.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ String manipulation: *string-functions*
757757
strwidth() size of string when displayed
758758
strdisplaywidth() size of string when displayed, deals with tabs
759759
setcellwidths() set character cell width overrides
760+
getcellwidths() get character cell width overrides
760761
substitute() substitute a pattern match with a string
761762
submatch() get a specific match in ":s" and substitute()
762763
strpart() get part of a string using byte index

src/evalfunc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,8 @@ static funcentry_T global_functions[] =
19531953
ret_string, f_getbufoneline},
19541954
{"getbufvar", 2, 3, FEARG_1, arg3_buffer_string_any,
19551955
ret_any, f_getbufvar},
1956+
{"getcellwidths", 0, 0, 0, NULL,
1957+
ret_list_any, f_getcellwidths},
19561958
{"getchangelist", 0, 1, FEARG_1, arg1_buffer,
19571959
ret_list_any, f_getchangelist},
19581960
{"getchar", 0, 1, 0, arg1_bool,

src/mbyte.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5745,6 +5745,25 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
57455745
redraw_all_later(UPD_CLEAR);
57465746
}
57475747

5748+
void
5749+
f_getcellwidths(typval_T *argvars UNUSED, typval_T *rettv)
5750+
{
5751+
if (rettv_list_alloc(rettv) == FAIL)
5752+
return;
5753+
5754+
for (size_t i = 0; i < cw_table_size; i++)
5755+
{
5756+
list_T *entry = list_alloc();
5757+
if (entry == NULL)
5758+
break;
5759+
list_append_number(entry, (varnumber_T)cw_table[i].first);
5760+
list_append_number(entry, (varnumber_T)cw_table[i].last);
5761+
list_append_number(entry, (varnumber_T)cw_table[i].width);
5762+
5763+
list_append_list(rettv->vval.v_list, entry);
5764+
}
5765+
}
5766+
57485767
void
57495768
f_charclass(typval_T *argvars, typval_T *rettv UNUSED)
57505769
{

src/proto/mbyte.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,6 @@ int convert_input_safe(char_u *ptr, int len, int maxlen, char_u **restp, int *re
8686
char_u *string_convert(vimconv_T *vcp, char_u *ptr, int *lenp);
8787
char_u *string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp, int *unconvlenp);
8888
void f_setcellwidths(typval_T *argvars, typval_T *rettv);
89+
void f_getcellwidths(typval_T *argvars, typval_T *rettv);
8990
void f_charclass(typval_T *argvars, typval_T *rettv);
9091
/* vim: set ft=c : */

src/testdir/test_utf8.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,26 @@ func Test_setcellwidths()
199199
call setcellwidths([])
200200
endfunc
201201

202+
func Test_getcellwidths()
203+
call setcellwidths([])
204+
call assert_equal([], getcellwidths())
205+
206+
let widthlist = [
207+
\ [0x1330, 0x1330, 2],
208+
\ [9999, 10000, 1],
209+
\ [0x1337, 0x1339, 2],
210+
\]
211+
let widthlistsorted = [
212+
\ [0x1330, 0x1330, 2],
213+
\ [0x1337, 0x1339, 2],
214+
\ [9999, 10000, 1],
215+
\]
216+
call setcellwidths(widthlist)
217+
call assert_equal(widthlistsorted, getcellwidths())
218+
219+
call setcellwidths([])
220+
endfunc
221+
202222
func Test_setcellwidths_dump()
203223
CheckRunVimInTerminal
204224

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1212,
698700
/**/
699701
1211,
700702
/**/

0 commit comments

Comments
 (0)