Proposal: Make "screenchar()" handle unicode composing characters#4059
Proposal: Make "screenchar()" handle unicode composing characters#4059ichizok wants to merge 7 commits intovim:masterfrom
Conversation
src/evalfunc.c
Outdated
| return; | ||
| for (; *p != NUL; p += utf_ptr2len(p)) | ||
| list_append_number(rettv->vval.v_list, | ||
| (varnumber_T)utf_ptr2char(p)); |
There was a problem hiding this comment.
With this, the returned value will include all characters of the given string - not only the first one plus composing characters. If this is really what we wanit, I think it would be nice to warn about this more clearly in the documentation.
src/evalfunc.c
Outdated
| c = tv_get_number(&li->li_tv); | ||
| if (i > 0 && !utf_iscomposing(c)) | ||
| break; | ||
| len += utf_char2bytes(c, &buf[len]); |
There was a problem hiding this comment.
Here, nr2char() stops on encountering a character that is not composing, but char2nr(str, 1, 1) does not stop in such a situation. IOW, I am not sure if it's good to have an asymetry: char2nr("AB", 1, 1) gives [65, 66], but nr2char([65, 66], 1) gives only "A".
runtime/doc/eval.txt
Outdated
| When {expr} is a List of number values, and with 'encoding' is | ||
| "utf-8" or {utf8} set to 1, return Unicode character which is | ||
| the result of combining the values in {expr} as Unicode | ||
| codepoints up to 'maxcombline'. |
|
I propose to add the following features for handling unicode composing characters.
char2nr(expr [, utf8 [, list]])
* Add a new optional argument "list": when set it to 1 the result is a List of number values
* e.g. char2nr("\uXXXX\uYYYY", 1, 1) == [0xXXXX, 0xYYYY] (\uYYYY is a composing characters)
I don't like having an argument that causes the return type to be
different. It would be better to add a new function for that.
Perhaps str2list(), although it might be done with a loop.
nr2char(expr [, utf8])
* Accept a List of number values as "expr"
* e.g. nr2char([0xXXXX, 0xYYYY], 1) == "\uXXXX\uYYYY" (\uYYYY is a composing characters)
That would be list2str() then. "2char" is not the right name anyway,
but that's an old problem.
screenchar(row, col [, list])
* Add a new optional argument "list": when set it to 1 the result is a List of number values
* e.g. screenchar(1, 1, 1) == [0xXXXX, 0xYYYY] (\uYYYY is a composing characters)
It would be good to also have the option to get the string, which
represents the character, and any composing characters. This is
especially useful when getting the character for several positions
and concatenating them.
…--
Time is an illusion. Lunchtime doubly so.
-- Ford Prefect, in Douglas Adams'
"The Hitchhiker's Guide to the Galaxy"
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
44930dd to
a17f2c3
Compare
|
Updated the patch:
|
What interface do you expect? I want an example. |
Codecov Report
@@ Coverage Diff @@
## master #4059 +/- ##
==========================================
- Coverage 79.21% 79.2% -0.01%
==========================================
Files 105 105
Lines 141147 141199 +52
==========================================
+ Hits 111813 111842 +29
- Misses 29334 29357 +23
Continue to review full report at Codecov.
|
|
How about |
|
Or codes2str, str2codes |
|
I think: |
Problem: Cannot get composing characters from the screen.
Solution: Add screenchars() and screenstring(). (partly by Ozaki Kiichi,
closes vim/vim#4059)
vim/vim@2912abb
I propose to add the following features for handling unicode composing characters.
char2nr(expr [, utf8 [, list]])str2list(expr [, utf8])
nr2char(expr [, utf8])list2str(list [, utf8])
screenchar(row, col [, list])