From d89144626e7429d9c499875ed426a6223f9013be Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 20 May 2024 06:15:58 +0800 Subject: vim-patch:9.1.0394: Cannot get a list of positions describing a region 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 https://github.com/vim/vim/commit/b4757e627e6c83d1c8e5535d4887a82d6a5efdd0 Co-authored-by: Shougo Matsushita Co-authored-by: Justin M. Keyes --- runtime/doc/builtin.txt | 17 +++++++++++++++++ runtime/doc/usr_41.txt | 1 + runtime/lua/vim/_meta/vimfn.lua | 22 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) (limited to 'runtime') diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index bbbabea2a4..0f0e33b54e 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -2969,6 +2969,23 @@ getregion({pos1}, {pos2} [, {opts}]) *getregion()* \ getpos('v'), getpos('.'), #{ type: mode() }) < +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: > + [[{start_pos}, {end_pos}], ...] +< + 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 or after the last + character. + getregtype([{regname}]) *getregtype()* The result is a String, which is type of register {regname}. The value will be one of: diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index 9515548cc5..ab2eecdfaf 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -794,6 +794,7 @@ Cursor and mark position: *cursor-functions* *mark-functions* Working with text in the current buffer: *text-functions* getline() get a line or list of lines from the buffer getregion() get a region of text from the buffer + getregionpos() get a list of positions for a region setline() replace a line in the buffer append() append line or list of lines in the buffer indent() indent of a specific line diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua index 853f354275..fbcdd52116 100644 --- a/runtime/lua/vim/_meta/vimfn.lua +++ b/runtime/lua/vim/_meta/vimfn.lua @@ -3581,6 +3581,28 @@ function vim.fn.getreginfo(regname) end --- @return string[] function vim.fn.getregion(pos1, pos2, opts) end +--- 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: > +--- [[{start_pos}, {end_pos}], ...] +--- < +--- 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 or after the last +--- character. +--- +--- @param pos1 table +--- @param pos2 table +--- @param opts? table +--- @return integer[][][] +function vim.fn.getregionpos(pos1, pos2, opts) end + --- The result is a String, which is type of register {regname}. --- The value will be one of: --- "v" for |charwise| text -- cgit From e0259b9466a0dd62b74d4aa195b3c5e6c7a183d0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 20 May 2024 20:50:32 +0800 Subject: vim-patch:9.1.0423: getregionpos() wrong with blockwise mode and multibyte Problem: getregionpos() wrong with blockwise mode and multibyte. Solution: Use textcol and textlen instead of start_vcol and end_vcol. Handle coladd properly (zeertzjq). Also remove unnecessary buflist_findnr() in add_regionpos_range(), as getregionpos() has already switched buffer. closes: vim/vim#14805 https://github.com/vim/vim/commit/c95e64f41f7f6d1bdc95b047ae9b369743c8637b --- runtime/doc/builtin.txt | 10 ++++++---- runtime/lua/vim/_meta/vimfn.lua | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 0f0e33b54e..e0921cf477 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -2981,10 +2981,12 @@ getregionpos({pos1}, {pos2} [, {opts}]) *getregionpos()* "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 or after the last - character. + If the "off" number of a starting position is non-zero, it is + the offset in screen columns from the start of the character. + E.g., a position within a or after the last character. + If the "off" number of an ending position is non-zero, it is + the character's number of cells included in the selection, + otherwise the whole character is included. getregtype([{regname}]) *getregtype()* The result is a String, which is type of register {regname}. diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua index fbcdd52116..dee65a40c7 100644 --- a/runtime/lua/vim/_meta/vimfn.lua +++ b/runtime/lua/vim/_meta/vimfn.lua @@ -3592,10 +3592,12 @@ function vim.fn.getregion(pos1, pos2, opts) end --- "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 or after the last ---- character. +--- If the "off" number of a starting position is non-zero, it is +--- the offset in screen columns from the start of the character. +--- E.g., a position within a or after the last character. +--- If the "off" number of an ending position is non-zero, it is +--- the character's number of cells included in the selection, +--- otherwise the whole character is included. --- --- @param pos1 table --- @param pos2 table -- cgit