-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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: Getregion function #13998
feat: Getregion function #13998
Conversation
I think this is a nice addition. I think we should call it However, we need tests here. Including testing what happens with invalid positions, multibyte character support, tab handling, and testing failure modes if possible. |
Well, the rename is needed?
Yes. The tests are needed... |
Thank you @Shougo and the rest who helped! |
Problem: hard to get visual region using Vim script Solution: Add getregion() Vim script function (Shougo Matsushita, Jakub Łuczyński) closes: vim/vim#13998 closes: vim/vim#11579 vim/vim@3f905ab Cherry-pick changes from patch 9.1.0122, with :echom instead of :echow. Co-authored-by: Shougo Matsushita <[email protected]> Co-authored-by: Jakub Łuczyński <[email protected]>
Problem: hard to get visual region using Vim script Solution: Add getregion() Vim script function (Shougo Matsushita, Jakub Łuczyński) closes: vim/vim#13998 closes: vim/vim#11579 vim/vim@3f905ab Cherry-pick changes from patch 9.1.0122, with :echom instead of :echow. Co-authored-by: Shougo Matsushita <[email protected]> Co-authored-by: Jakub Łuczyński <[email protected]>
Problem: hard to get visual region using Vim script Solution: Add getregion() Vim script function (Shougo Matsushita, Jakub Łuczyński) closes: vim/vim#13998 closes: vim/vim#11579 vim/vim@3f905ab Cherry-pick changes from patch 9.1.0122, with :echom instead of :echow. Co-authored-by: Shougo Matsushita <[email protected]> Co-authored-by: Jakub Łuczyński <[email protected]>
Why doesn't this return a list of positions? Return text is the least useful part about a region. How can plugin authors get the positions that correspond to a visual block region (for example)? That is still an unsolved problem.
|
The functionality of this function was to be to get the buffer content of whatever those positions would define. Au contraire, getting the buffer content was an unsolved problem before, positions would need to be known before hand so I fail to see how this would be "more useful".
You can use getpos() of those positions already. Don't see why this is a problem. |
For blockwise Visual selection it'll probably need a combination of |
correct and |
You cannot easily get the dimensions of the buffer text that is described by a region. This is the code that is currently required to do that: https://github.com/neovim/neovim/blob/d35a8a9bbe385daf808984ba0fc7f07f51a96da0/runtime/lua/vim/_editor.lua#L509-L578 |
(Note that this is not as trivial as it seems once you add multibyte and ambiwidth unicode characters to the mix -- which that code can't handle fully, despite its complexity) |
Also ref neovim/neovim#21115 the initial discussion and implementation of this function. For getting text the interface is easy, but when it comes to getting buffer positions the interface gets complicated when 'virtualedit' is concerned. |
Well, I should add the option to return the range feature? |
I think range feature is good. but shouldn't add to |
correct, there was a single purpose for the We are giving already positions to the getrange() function. You are talking about dimensions of positions, which I don't understand. What exactly do you mean by that? Can you please give concrete examples? Why exactly are start and end positions not enough? Can you spell out the help documentation for what this function should do? |
For a give region defined by 2 opposite "corners", the actual buffer text bounded by those corners, depends on (1) the buffer text itself, (2) inclusive/exclusive, (3) selection type (v/V/^v), (4) multibyte. Mapping a region to buffer text is non-trivial. Perhaps name it |
Yes, but you already have those positions. So where do those positions come then from? In other words if you already have the positions, why do you need to use BTW: I have for years used a similar approach to this in one of my plugins. Set the marks |
No we don't; that's exactly what we're asking from here. (We have a hack that works in some situations, but not enough.) |
Then it's even more curious why you mention it here in the PR for |
(To be clear, I'm not the one complaining here; just trying to provide some additional context.) |
sure understood and thanks. (And to be clear, I am just trying to understand the missing pieces) |
Basically, given a pair of positions (which could be
Basically, convert a visual-block selection to an array of line-wise selections to then, say, apply highlights to. (Main use case here: highlight-on-yank as in https://github.com/machakann/vim-highlightedyank.) Especially the last points basically rely on Vim internals to be guaranteed to be correct |
"to char-wise", right?
To @chrisbra 's point, if This raises the more general question about how a buffer region is described. Currently in Vim, a buffer region is described by those 4 parameters. So we have 2 choices:
Created #14609 |
Continues of #11579
It is not only for visual mode.