-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add getregionpos() #14617
Add getregionpos() #14617
Conversation
When the selection is blockwise, shouldn't there be a pair of positions for every line? They may have different |
* "getregionpos()" function | ||
*/ | ||
static void | ||
f_getregionpos(typval_T *argvars, typval_T *rettv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add tests for the new getregionpos() function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It should. But current tests are very many. It is hard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without tests, this cannot be merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add one more test similar to def Test_getregion()
in test_vim9_builtin.vim
, say Test_getregionpos()
and check for E1209
and E1211
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I have added them.
I have implemented it. Please check the implementation. |
I have added tests. NOTE: I cannot test for |
runtime/doc/builtin.txt
Outdated
Note: When the selection is blockwise, it returns a pair of | ||
positions for every line: | ||
[[{pos_start}, {pos_end}], ...] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this note is not needed now, right? because the same structure is always returned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same structure is returned. But it may be hard to understand why the positions are list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you say instead:
Same as |getregion()|, but returns a list of positions describing the buffer text
segments bound by {pos1} and {pos2}.
You can remove:
See |getregion()| for the arguments and notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. I have fixed it.
So, is this ready? Have a few people tried it out? |
I've been running with this PR applied, and it works as well as The only issue I've faced with both of these functions is that they error out ( I don't know if that is unintended behavior, though, and is easy enough to check for in scripts. |
Please check if my test itself is wrong. I wrote it in a hurry.
|
I have fixed columns error. It already exists when
I know the feature. I can change the behavior. But I think it is not useful. |
After the most recent commit, this PR works great for me – and now |
The test I mentioned above still fails. Same error ( Somewhere it is mentioned that the motivation for this API is this, which roughly translates to this test:
This test does not pass. I'm afraid this PR is not well thought through. |
The test given above doesn't fail for me with the latest commit.
|
Yes. It works for me. I think you don't build the latest version. |
The second test fails though. There is no value to Try the following. It does not highlight both lines, but only the first line. This is because getregionpos is returning
I am just a little weary of this PR. |
I found another bug.
|
It is not bug. Please see
The default It works for me. vim9script
:set shortmess=I
autocmd TextYankPost * {
if v:event.operator ==? 'y'
:echom getregionpos(getpos("'["), getpos("']"), { type: visualmode() })
endif
}
setline(1, ['abcd', 'efghij'])
:exec "normal \<c-v>"
:normal 3ljy |
Thanks, now I get ./vim -Nu NONE -S <(cat <<EOF
vim9script
:set shortmess=I
autocmd TextYankPost * {
if v:event.operator ==? 'y'
var pos = getregionpos(getpos("'["), getpos("']"), { type: visualmode() })
var m = matchaddpos('IncSearch', pos->mapnew((_, v) => [v[0][1], v[0][2], v[1][2] - v[0][2] + 1]))
timer_start(300, (_) => m->matchdelete())
endif
}
setline(1, ['abcd', 'efghij'])
:normal yj
EOF
)
Also, my other concern (see post above) about this api not adding additional value by not returning intermediate lines during 'v' and 'V' still stands. |
Visual mode was never entered in your test script, so |
OK. I get the problem. I will change the result value. |
Thanks. Modified the script. I see 2 issues:
You can use the script, visual select, and verify.
|
Hm... It seems broken. I will fix. |
I have fixed the problems. Please test. |
@justinmk does that do what you want? |
I found many problems:
I updated the test to include the
|
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
I have rebased it and fixed the conflict. |
Thanks all. I have made one minor change using |
Problem: Cannot get a list of positions describing a region (Justin M. Keyes, after v9.1.0120) Solution: Add the getregionpos() function (Shougo Matsushita) fixes: vim/vim#14609 closes: vim/vim#14617 vim/vim@b4757e6 Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com> Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Problem: Cannot get a list of positions describing a region (Justin M. Keyes, after v9.1.0120) Solution: Add the getregionpos() function (Shougo Matsushita) fixes: vim/vim#14609 closes: vim/vim#14617 vim/vim@b4757e6 Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com> Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Problem: Cannot get a list of positions describing a region (Justin M. Keyes, after v9.1.0120) Solution: Add the getregionpos() function (Shougo Matsushita) fixes: vim/vim#14609 closes: vim/vim#14617 vim/vim@b4757e6 Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com> Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
Problem: Cannot get a list of positions describing a region (Justin M. Keyes, after v9.1.0120) Solution: Add the getregionpos() function (Shougo Matsushita) fixes: vim/vim#14609 closes: vim/vim#14617 vim/vim@b4757e6 Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com> Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
For #14609