Skip to content
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

neovim: use vim.fn.getregionpos() to replace buffer_get_selection() #2406

Open
fidgetingbits opened this issue Jun 13, 2024 · 3 comments
Open
Labels
app-neovim Issues related to neovim support

Comments

@fidgetingbits
Copy link
Collaborator

There is recently a new function in neovim called getregionpos which I believe will be better to use than the existing buffer_get_selection(). Also has the benefit of existing tests in neovim, etc. One thing I'm not sure about will be the 'reverse' part, but I suspect it will still be easier to just use vim.fn.getregionpos() and work out the reverse flag.

See vim/vim#14617

We will have to wait at least for 0.11 release (October 31, 2024) for it to be available though.

@saidelike saidelike added the app-neovim Issues related to neovim support label Jun 13, 2024
@saidelike
Copy link
Collaborator

Maybe i misread https://github.com/vim/vim/pull/14617/files#diff-ef8946d89919ad628b9ac65c49d3067e4e017b0980cac70eb25d832a59ef677dR4332 but is it the same?

  • getregionpos() takes arguments but buffer_get_selection() does not
getregionpos({pos1}, {pos2} [, {opts}])            *getregionpos()*
		Same as |getregion()|, but returns a list of positions
		describing the buffer text segments bound by {pos1} and
		{pos2}.
		The segments are a pair of positions for every line:
                    [[{pos_start}, {pos_end}], ...]

		The position is a |List| with four numbers:
		    [bufnum, lnum, col, off]
		"bufnum" is the buffer number.
		"lnum" and "col" are the position in the buffer.  The first
		column is 1.
		The "off" number is zero, unless 'virtualedit' is used.  Then
		it is the offset in screen columns from the start of the
		character.  E.g., a position within a <Tab> or after the last
		character.

		Can also be used as a |method|: >
			getpos('.')->getregionpos(getpos("'a"))
<

@fidgetingbits
Copy link
Collaborator Author

fidgetingbits commented Jun 13, 2024

It's not identical. My thinking is that you would call it with something like vim.fn.getpos("'>") and vim.fn.getpos("'>") as the visual selection start/end positions to get back most of the coordinates you are currently trying to compute yourself. Probably the majority of buffer_get_selection()'s logic would be replaced by a call to vim.fn.getregionpos(). But ya, would need to test to make sure it can be used.

@fidgetingbits
Copy link
Collaborator Author

fidgetingbits commented Jun 26, 2024

I didn't even try to use getregionpos() in the end, as it was already simple enough without:

saidelike#9

Once that PR is merged can close this issue imo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app-neovim Issues related to neovim support
Projects
None yet
Development

No branches or pull requests

2 participants