aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.lua13
-rw-r--r--src/nvim/eval/funcs.c32
2 files changed, 32 insertions, 13 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 2984ce29c6..94c9af50d4 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -4359,11 +4359,13 @@ M.funcs = {
args = { 2, 3 },
base = 1,
desc = [=[
- Returns the list of strings from {pos1} to {pos2} in current
+ Returns the list of strings from {pos1} to {pos2} from a
buffer.
{pos1} and {pos2} must both be |List|s with four numbers.
- See |getpos()| for the format of the list.
+ See |getpos()| for the format of the list. It's possible
+ to specify positions from a different buffer, but please
+ note the limitations at |getregion-notes|
The optional argument {opts} is a Dict and supports the
following items:
@@ -4384,6 +4386,7 @@ M.funcs = {
This function is useful to get text starting and ending in
different columns, such as a |charwise-visual| selection.
+ *getregion-notes*
Note that:
- Order of {pos1} and {pos2} doesn't matter, it will always
return content from the upper left position to the lower
@@ -4393,8 +4396,12 @@ M.funcs = {
- If the region is blockwise and it starts or ends in the
middle of a multi-cell character, it is not included but
its selected part is substituted with spaces.
- - If {pos1} or {pos2} is not current in the buffer, an empty
+ - If {pos1} and {pos2} are not in the same buffer, an empty
list is returned.
+ - {pos1} and {pos2} must belong to a |bufloaded()| buffer.
+ - It is evaluated in current window context, this makes a
+ different if a buffer is displayed in a different window and
+ 'virtualedit' or 'list' is set
Examples: >
:xnoremap <CR>
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 605170610c..67443b66bc 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -2827,16 +2827,12 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
return;
}
- int fnum = -1;
- pos_T p1;
- if (list2fpos(&argvars[0], &p1, &fnum, NULL, false) != OK
- || (fnum >= 0 && fnum != curbuf->b_fnum)) {
- return;
- }
-
- pos_T p2;
- if (list2fpos(&argvars[1], &p2, &fnum, NULL, false) != OK
- || (fnum >= 0 && fnum != curbuf->b_fnum)) {
+ int fnum1 = -1;
+ int fnum2 = -1;
+ pos_T p1, p2;
+ if (list2fpos(&argvars[0], &p1, &fnum1, NULL, false) != OK
+ || list2fpos(&argvars[1], &p2, &fnum2, NULL, false) != OK
+ || fnum1 != fnum2) {
return;
}
@@ -2866,6 +2862,18 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
return;
}
+ buf_T *save_curbuf = curbuf;
+
+ if (fnum1 != 0) {
+ buf_T *findbuf = buflist_findnr(fnum1);
+ // buffer not loaded
+ if (findbuf == NULL || findbuf->b_ml.ml_mfp == NULL) {
+ return;
+ }
+ save_curbuf = curbuf;
+ curbuf = findbuf;
+ }
+
const TriState save_virtual = virtual_op;
virtual_op = virtual_active();
@@ -2948,6 +2956,10 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
tv_list_append_allocated_string(rettv->vval.v_list, akt);
}
+ if (curbuf != save_curbuf) {
+ curbuf = save_curbuf;
+ }
+
virtual_op = save_virtual;
}