aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-01-18 06:50:22 +0800
committerGitHub <noreply@github.com>2023-01-18 06:50:22 +0800
commitf4e03cbdbc88bd0c1095918df11450c98b729988 (patch)
treef098b79045d4175491f4f2dda32044c817b0e1fd /src
parent20b7be2d1024b6e9eac68e0cb92cf663e95e51ca (diff)
downloadrneovim-f4e03cbdbc88bd0c1095918df11450c98b729988.tar.gz
rneovim-f4e03cbdbc88bd0c1095918df11450c98b729988.tar.bz2
rneovim-f4e03cbdbc88bd0c1095918df11450c98b729988.zip
vim-patch:9.0.1212: cannot read back what setcellwidths() has done (#21867)
Problem: Cannot read back what setcellwidths() has done. Solution: Add getcellwidths(). (Kota Kato, closes vim/vim#11837) https://github.com/vim/vim/commit/66bb9ae70f7371456ed76518076d2a344f8ab417 Co-authored-by: Kota Kato <github@kat0h.com>
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.lua1
-rw-r--r--src/nvim/mbyte.c15
-rw-r--r--src/nvim/testdir/test_utf8.vim20
3 files changed, 36 insertions, 0 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 14be6aba73..c17a44b990 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -148,6 +148,7 @@ return {
getbufline={args={2, 3}, base=1},
getbufoneline={args=2, base=1},
getbufvar={args={2, 3}, base=1},
+ getcellwidths={},
getchangelist={args={0, 1}, base=1},
getchar={args={0, 1}},
getcharmod={},
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index b5274b9695..68e8a3269b 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -2795,6 +2795,21 @@ void f_setcellwidths(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
redraw_all_later(UPD_NOT_VALID);
}
+/// "getcellwidths()" function
+void f_getcellwidths(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
+{
+ tv_list_alloc_ret(rettv, (ptrdiff_t)cw_table_size);
+
+ for (size_t i = 0; i < cw_table_size; i++) {
+ list_T *entry = tv_list_alloc(3);
+ tv_list_append_number(entry, (varnumber_T)cw_table[i].first);
+ tv_list_append_number(entry, (varnumber_T)cw_table[i].last);
+ tv_list_append_number(entry, (varnumber_T)cw_table[i].width);
+
+ tv_list_append_list(rettv->vval.v_list, entry);
+ }
+}
+
void f_charclass(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
if (tv_check_for_string_arg(argvars, 0) == FAIL
diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim
index 9146cf7ab3..255f179fc9 100644
--- a/src/nvim/testdir/test_utf8.vim
+++ b/src/nvim/testdir/test_utf8.vim
@@ -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