diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-08-13 11:29:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-13 11:29:38 +0800 |
commit | 754892e59dc3ab65a92d22f315e88b716bc26d1d (patch) | |
tree | 7defed25672c3fa12fac8ad4f1a263efb679d8c5 /src | |
parent | 6f14c5d2ddbefea51920762769eec217d19a9ed9 (diff) | |
download | rneovim-754892e59dc3ab65a92d22f315e88b716bc26d1d.tar.gz rneovim-754892e59dc3ab65a92d22f315e88b716bc26d1d.tar.bz2 rneovim-754892e59dc3ab65a92d22f315e88b716bc26d1d.zip |
vim-patch:8.2.{1536,1540}: charclass() (#19748)
vim-patch:8.2.1536: cannot get the class of a character; emoji widths are wrong
Problem: Cannot get the class of a character; emoji widths are wrong in
some environments.
Solution: Add charclass(). Update some emoji widths. Add script to check
emoji widths.
https://github.com/vim/vim/commit/4e4473c927167fd24e5c8df90e0e8035080cf2da
Use latest charclass() docs from Vim.
Rewrite DoIt() in emoji_list.vim in Lua.
Omit emoji table updates:
- emoji_width update looks wrong as these added ranges are only double-width when followed by 0xFE0F.
- Other updates are too old.
vim-patch:8.2.1540: the user cannot try out emoji character widths
Problem: The user cannot try out emoji character widths.
Solution: Move the emoji script to the runtime/tools directory.
https://github.com/vim/vim/commit/98945560c1ae6e2ddee820a7de718a36e3f4b6e5
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.lua | 1 | ||||
-rw-r--r-- | src/nvim/mbyte.c | 21 | ||||
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 7 |
3 files changed, 24 insertions, 5 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index a2272f0c98..e4e9b34ec6 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -72,6 +72,7 @@ return { chanclose={args={1, 2}}, chansend={args=2}, char2nr={args={1, 2}, base=1}, + charclass={args=1, base=1}, charcol={args=1, base=1}, charidx={args={2, 3}, base=1}, chdir={args=1, base=1}, diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index e4d2d35c1b..378a08131d 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1182,6 +1182,11 @@ int utf_class_tab(const int c, const uint64_t *const chartab) return 1; // punctuation } + // emoji + if (intable(emoji_all, ARRAY_SIZE(emoji_all), c)) { + return 3; + } + // binary search in table while (top >= bot) { mid = (bot + top) / 2; @@ -1194,11 +1199,6 @@ int utf_class_tab(const int c, const uint64_t *const chartab) } } - // emoji - if (intable(emoji_all, ARRAY_SIZE(emoji_all), c)) { - return 3; - } - // most other characters are "word" characters return 2; } @@ -2858,3 +2858,14 @@ void f_setcellwidths(typval_T *argvars, typval_T *rettv, FunPtr fptr) xfree(cw_table_save); redraw_all_later(NOT_VALID); } + +void f_charclass(typval_T *argvars, typval_T *rettv, FunPtr fptr) +{ + if (argvars[0].v_type != VAR_STRING + || argvars[0].vval.v_string == NULL + || *argvars[0].vval.v_string == NUL) { + emsg(_(e_stringreq)); + return; + } + rettv->vval.v_number = mb_get_class((const char_u *)argvars[0].vval.v_string); +} diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index c11e7b4fea..e0e0c1ca38 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1769,6 +1769,13 @@ func Test_char2nr() call assert_equal(12354, char2nr('あ', 1)) endfunc +func Test_charclass() + call assert_equal(0, charclass(' ')) + call assert_equal(1, charclass('.')) + call assert_equal(2, charclass('x')) + call assert_equal(3, charclass("\u203c")) +endfunc + func Test_eventhandler() call assert_equal(0, eventhandler()) endfunc |