-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add utf8 support #24
Conversation
Hi, thanks for the effort of finding a solution here. However, I hesitate to merge this for two reasons:
|
I understand you.
|
Hmm, maintaining two branches also does not look ideal to me. Ideally, there is some niche nvim API which deals with strings which might help. Otherwise, a solution might be to just take out parts of the utf8 library which are relevant for this plugin? Not sure. 🤔 |
All right. Today I spent some time looking for find other "native" solutions. The results are not very encouraging. In Vim and Neovim regexs don't contain special "unicode classes" that starting with What's left? There are two ways that I found:
P.S. For the first way, I have thought that we could use metatable with needed string functions: "find", "gmatch", "reverse", "next_chat", "prev_char". And lua will call function that override the metatable if lua plugin |
For utf8 support was used library from luarocks.org: luautf8. It contains several string methods and utf8 specific methods implemented by the lua specification. Thanks to this, the code has not more complexity and was simplified from `col` indexing to `offset` indexing. With it methods logic was simplified. The reason why I refactored some code was byte width in utf8. In first particular range utf8 contains one byte, in second particular range utf8 contains two bytes and so it goes on. In this case indexing by `col` more complex than indexing by `offset`. Also I changed in README.md in installation section, adding luarock dependency. packer.nvim have native rocks installation, but for lazy.nvim need add `nvim_rocks` dependency that installs luarock dependency.
There solve the problem: optional `libutf8` lua library. Users who don't need UTF-8 support, because they only work with latin1 symbols, can continuously use this plugin without any problem. And they can add UTF-8 support if needed in an easy way: just add the dependency in nvim plugin manager. There is solution: adding metatable with universal string functions like "reverse", "find", "gmatch" and others. And use `pcall` method for detection of the lua accessibility plugin `luautf8`. Override string functions in metatable if plugin is exists. So there is no dependency confusion. I've also changed the README.md by restoring the "Installation" section and adding the "UTF-8 support" section.
Hi again! As you see, I did update this fork to upstream and added 'optionality' of UTF-8 plugin. Before telling my opinion, here's changes:
I'll begin from last clause:
Second clause. This detection allow us to use lightweight plugin, when UTF-8 is no need and turn on if needed. As you see in code, I implemented First clause is derived from second. But, need tests, because I'm not sure, that I moved right from 'col-based' indices to 'offset-based'. I don't see tests. Where is they? Also I don't see your issue about test. Well, there is my opinion. I used my modification (with UTF-8) of this plugin and I don't see any errors or exceptions. What do you think about this? |
Hi! Sorry for also putting this off for so long myself. Yeah, I didn't get around to add tests, partly because I maintain too many plugins (🙈), and also because there were no bug reports for any new edge cases, meaning I didn't have any reason to change the apparently stable motion mechanics.
This is a smart solution, neat! Yeah, I think with this, we can safely merge. Thanks for the work! |
@JarKz Just a minor remark: You had Normally no big deal, but in lazy.nvim, commit messages with a |
oops, you are right, fixed |
That solves #14.
For utf8 support was used library from luarocks.org: luautf8. It contains several string methods and utf8 specific methods implemented by the lua specification.
Thanks to this, the code has not more complexity and was simplified from
col
indexing tooffset
indexing. With it methods logic was simplified. The reason why I refactored some code was byte width in utf8. In first particular range utf8 contains one byte, in second particular range utf8 contains two bytes and so it goes on. In this case indexing bycol
more complex than indexing byoffset
.Also I changed in README.md in installation section, adding luarock dependency. packer.nvim have native rocks installation, but for lazy.nvim need add
nvim_rocks
dependency that installs luarock dependency.