static argcheck_T arg3_dict_number_number[] = {arg_dict_any, arg_number, arg_number};
static argcheck_T arg3_diff[] = {arg_list_string, arg_list_string, arg_dict_any};
static argcheck_T arg3_list_string_dict[] = {arg_list_any, arg_string, arg_dict_any};
+static argcheck_T arg3_list_list_dict[] = {arg_list_any, arg_list_any, arg_dict_any};
static argcheck_T arg3_lnum_number_bool[] = {arg_lnum, arg_number, arg_bool};
static argcheck_T arg3_number[] = {arg_number, arg_number, arg_number};
static argcheck_T arg3_number_any_dict[] = {arg_number, arg_any, arg_dict_any};
ret_getreg, f_getreg},
{"getreginfo", 0, 1, FEARG_1, arg1_string,
ret_dict_any, f_getreginfo},
- {"getregion", 3, 3, FEARG_1, arg3_string,
+ {"getregion", 2, 3, FEARG_1, arg3_list_list_dict,
ret_list_string, f_getregion},
{"getregtype", 0, 1, FEARG_1, arg1_string,
ret_string, f_getregtype},
int inclusive = TRUE;
int fnum = -1;
pos_T p1, p2;
- pos_T *fp = NULL;
- char_u *pos1, *pos2, *type;
+ char_u *type;
+ char_u default_type[] = "v";
int save_virtual = -1;
int l;
int region_type = -1;
- int is_visual;
+ int is_select_exclusive;
if (rettv_list_alloc(rettv) == FAIL)
return;
- if (check_for_string_arg(argvars, 0) == FAIL
- || check_for_string_arg(argvars, 1) == FAIL
- || check_for_string_arg(argvars, 2) == FAIL)
+ if (check_for_list_arg(argvars, 0) == FAIL
+ || check_for_list_arg(argvars, 1) == FAIL
+ || check_for_opt_dict_arg(argvars, 2) == FAIL)
return;
- // NOTE: var2fpos() returns static pointer.
- fp = var2fpos(&argvars[0], TRUE, &fnum, FALSE);
- if (fp == NULL || (fnum >= 0 && fnum != curbuf->b_fnum))
+ if (list2fpos(&argvars[0], &p1, &fnum, NULL, FALSE) != OK
+ || (fnum >= 0 && fnum != curbuf->b_fnum))
return;
- p1 = *fp;
- fp = var2fpos(&argvars[1], TRUE, &fnum, FALSE);
- if (fp == NULL || (fnum >= 0 && fnum != curbuf->b_fnum))
+ if (list2fpos(&argvars[1], &p2, &fnum, NULL, FALSE) != OK
+ || (fnum >= 0 && fnum != curbuf->b_fnum))
return;
- p2 = *fp;
- pos1 = tv_get_string(&argvars[0]);
- pos2 = tv_get_string(&argvars[1]);
- type = tv_get_string(&argvars[2]);
-
- is_visual = (pos1[0] == 'v' && pos1[1] == NUL)
- || (pos2[0] == 'v' && pos2[1] == NUL);
-
- if (is_visual && !VIsual_active)
- return;
+ if (argvars[2].v_type == VAR_DICT)
+ {
+ is_select_exclusive = dict_get_bool(
+ argvars[2].vval.v_dict, "exclusive", *p_sel == 'e');
+ type = dict_get_string(
+ argvars[2].vval.v_dict, "type", FALSE);
+ if (type == NULL)
+ type = default_type;
+ }
+ else
+ {
+ is_select_exclusive = *p_sel == 'e';
+ type = default_type;
+ }
if (type[0] == 'v' && type[1] == NUL)
region_type = MCHAR;
save_virtual = virtual_op;
virtual_op = virtual_active();
+ // NOTE: Adjust is needed.
+ p1.col--;
+ p2.col--;
+
if (!LT_POS(p1, p2))
{
// swap position
if (region_type == MCHAR)
{
// handle 'selection' == "exclusive"
- if (*p_sel == 'e' && !EQUAL_POS(p1, p2))
+ if (is_select_exclusive && !EQUAL_POS(p1, p2))
{
if (p2.coladd > 0)
p2.coladd--;
oa.start = p1;
oa.end = p2;
oa.start_vcol = MIN(sc1, sc2);
- if (*p_sel == 'e' && ec1 < sc2 && 0 < sc2 && ec2 > ec1)
+ if (is_select_exclusive && ec1 < sc2 && 0 < sc2 && ec2 > ec1)
oa.end_vcol = sc2 - 1;
else
oa.end_vcol = MAX(ec1, ec2);
" Visual mode
call cursor(1, 1)
call feedkeys("\<ESC>vjl", 'tx')
- call assert_equal(['one', 'tw'], 'v'->getregion('.', 'v'))
- call assert_equal(['one', 'tw'], '.'->getregion('v', 'v'))
- call assert_equal(['o'], 'v'->getregion('v', 'v'))
- call assert_equal(['w'], '.'->getregion('.', 'v'))
- call assert_equal(['one', 'two'], '.'->getregion('v', 'V'))
- call assert_equal(['on', 'tw'], '.'->getregion('v', "\<C-v>"))
+ call assert_equal(['one', 'tw'],
+ \ 'v'->getpos()->getregion(getpos('.')))
+ call assert_equal(['one', 'tw'],
+ \ '.'->getpos()->getregion(getpos('v')))
+ call assert_equal(['o'],
+ \ 'v'->getpos()->getregion(getpos('v')))
+ call assert_equal(['w'],
+ \ '.'->getpos()->getregion(getpos('.'), #{ type: 'v' }))
+ call assert_equal(['one', 'two'],
+ \ getpos('.')->getregion(getpos('v'), #{ type: 'V' }))
+ call assert_equal(['on', 'tw'],
+ \ getpos('.')->getregion(getpos('v'), #{ type: "\<C-v>" }))
" Line visual mode
call cursor(1, 1)
call feedkeys("\<ESC>Vl", 'tx')
- call assert_equal(['one'], getregion('v', '.', 'V'))
- call assert_equal(['one'], getregion('.', 'v', 'V'))
- call assert_equal(['one'], getregion('v', 'v', 'V'))
- call assert_equal(['one'], getregion('.', '.', 'V'))
- call assert_equal(['on'], '.'->getregion('v', 'v'))
- call assert_equal(['on'], '.'->getregion('v', "\<C-v>"))
+ call assert_equal(['one'],
+ \ getregion(getpos('v'), getpos('.'), #{ type: 'V' }))
+ call assert_equal(['one'],
+ \ getregion(getpos('.'), getpos('v'), #{ type: 'V' }))
+ call assert_equal(['one'],
+ \ getregion(getpos('v'), getpos('v'), #{ type: 'V' }))
+ call assert_equal(['one'],
+ \ getregion(getpos('.'), getpos('.'), #{ type: 'V' }))
+ call assert_equal(['on'],
+ \ getpos('.')->getregion(getpos('v'), #{ type: 'v' }))
+ call assert_equal(['on'],
+ \ getpos('.')->getregion(getpos('v'), #{ type: "\<C-v>" }))
" Block visual mode
call cursor(1, 1)
call feedkeys("\<ESC>\<C-v>ll", 'tx')
- call assert_equal(['one'], getregion('v', '.', "\<C-v>"))
- call assert_equal(['one'], getregion('.', 'v', "\<C-v>"))
- call assert_equal(['o'], getregion('v', 'v', "\<C-v>"))
- call assert_equal(['e'], getregion('.', '.', "\<C-v>"))
- call assert_equal(['one'], '.'->getregion('v', 'V'))
- call assert_equal(['one'], '.'->getregion('v', 'v'))
+ call assert_equal(['one'],
+ \ getregion(getpos('v'), getpos('.'), #{ type: "\<C-v>" }))
+ call assert_equal(['one'],
+ \ getregion(getpos('.'), getpos('v'), #{ type: "\<C-v>" }))
+ call assert_equal(['o'],
+ \ getregion(getpos('v'), getpos('v'), #{ type: "\<C-v>" }))
+ call assert_equal(['e'],
+ \ getregion(getpos('.'), getpos('.'), #{ type: "\<C-v>" }))
+ call assert_equal(['one'],
+ \ '.'->getpos()->getregion(getpos('v'), #{ type: 'V' }))
+ call assert_equal(['one'],
+ \ '.'->getpos()->getregion(getpos('v'), #{ type: 'v' }))
" Using Marks
call setpos("'a", [0, 2, 3, 0])
call cursor(1, 1)
- call assert_equal(['one', 'two'], "'a"->getregion('.', 'v'))
- call assert_equal(['one', 'two'], "."->getregion("'a", 'v'))
- call assert_equal(['one', 'two'], "."->getregion("'a", 'V'))
- call assert_equal(['two'], "'a"->getregion("'a", 'V'))
- call assert_equal(['one', 'two'], "."->getregion("'a", "\<c-v>"))
+ call assert_equal(['one', 'two'],
+ \ "'a"->getpos()->getregion(getpos('.'), #{ type: 'v' }))
+ call assert_equal(['one', 'two'],
+ \ "."->getpos()->getregion(getpos("'a"), #{ type: 'v' }))
+ call assert_equal(['one', 'two'],
+ \ "."->getpos()->getregion(getpos("'a"), #{ type: 'V' }))
+ call assert_equal(['two'],
+ \ "'a"->getpos()->getregion(getpos("'a"), #{ type: 'V' }))
+ call assert_equal(['one', 'two'],
+ \ "."->getpos()->getregion(getpos("'a"), #{ type: "\<c-v>" }))
+
+ " Using List
+ call cursor(1, 1)
+ call assert_equal(['one', 'two'],
+ \ [0, 2, 3, 0]->getregion(getpos('.'), #{ type: 'v' }))
+ call assert_equal(['one', 'two'],
+ \ '.'->getpos()->getregion([0, 2, 3, 0], #{ type: 'v' }))
+ call assert_equal(['one', 'two'],
+ \ '.'->getpos()->getregion([0, 2, 3, 0], #{ type: 'V' }))
+ call assert_equal(['two'],
+ \ [0, 2, 3, 0]->getregion([0, 2, 3, 0], #{ type: 'V' }))
+ call assert_equal(['one', 'two'],
+ \ '.'->getpos()->getregion([0, 2, 3, 0], #{ type: "\<c-v>" }))
" Multiline with line visual mode
call cursor(1, 1)
call feedkeys("\<ESC>Vjj", 'tx')
- call assert_equal(['one', 'two', 'three'], getregion('v', '.', 'V'))
+ call assert_equal(['one', 'two', 'three'],
+ \ getregion(getpos('v'), getpos('.'), #{ type: 'V' }))
" Multiline with block visual mode
call cursor(1, 1)
call feedkeys("\<ESC>\<C-v>jj", 'tx')
- call assert_equal(['o', 't', 't'], getregion('v', '.', "\<C-v>"))
+ call assert_equal(['o', 't', 't'],
+ \ getregion(getpos('v'), getpos('.'), #{ type: "\<C-v>" }))
call cursor(1, 1)
call feedkeys("\<ESC>\<C-v>jj$", 'tx')
- call assert_equal(['one', 'two', 'three'], getregion('v', '.', "\<C-v>"))
+ call assert_equal(['one', 'two', 'three'],
+ \ getregion(getpos('v'), getpos('.'), #{ type: "\<C-v>" }))
" 'virtualedit'
set virtualedit=all
call cursor(1, 1)
call feedkeys("\<ESC>\<C-v>10ljj$", 'tx')
call assert_equal(['one ', 'two ', 'three '],
- \ getregion('v', '.', "\<C-v>"))
+ \ getregion(getpos('v'), getpos('.'), #{ type: "\<C-v>" }))
set virtualedit&
" Invalid position
call cursor(1, 1)
call feedkeys("\<ESC>vjj$", 'tx')
- call assert_fails("call getregion(1, 2, 'v')", 'E1174:')
- call assert_fails("call getregion('.', {}, 'v')", 'E1174:')
- call assert_equal([], getregion('', '.', 'v'))
- call assert_equal([], getregion('.', '.', ''))
- call feedkeys("\<ESC>", 'tx')
- call assert_equal([], getregion('v', '.', 'v'))
-
- " using an unset mark
- call assert_equal([], "'z"->getregion(".", 'V'))
+ call assert_fails("call getregion(1, 2)", 'E1211:')
+ call assert_fails("call getregion(getpos('.'), {})", 'E1211:')
+ call assert_equal([], getregion(getpos('.'), getpos('.'), #{ type: '' }))
+
" using the wrong type
- call assert_fails(':echo "."->getregion([],"V")', 'E1174:')
- call assert_fails(':echo "."->getregion("$", {})', 'E1174:')
- call assert_fails(':echo [0, 1, 1, 0]->getregion("$", "v")', 'E1174:')
+ call assert_fails(':echo "."->getpos()->getregion("$", [])', 'E1211:')
+
" using a mark in another buffer
new
let newbuf = bufnr()
normal! GmA
wincmd p
call assert_equal([newbuf, 10, 1, 0], getpos("'A"))
- call assert_equal([], getregion(".", "'A", 'v'))
- call assert_equal([], getregion("'A", ".", 'v'))
+ call assert_equal([], getregion(getpos('.'), getpos("'A"), #{ type: 'v' }))
+ call assert_equal([], getregion(getpos("'A"), getpos('.'), #{ type: 'v' }))
exe newbuf .. 'bwipe!'
bwipe!
call cursor(1, 3)
call feedkeys("\<Esc>\<C-v>ljj", 'xt')
call assert_equal(['cd', "\u00ab ", '34'],
- \ getregion('v', '.', "\<C-v>"))
+ \ getregion(getpos('v'), getpos('.'), #{ type: "\<C-v>" }))
call cursor(1, 4)
call feedkeys("\<Esc>\<C-v>ljj", 'xt')
call assert_equal(['de', "\U0001f1e7", '45'],
- \ getregion('v', '.', "\<C-v>"))
+ \ getregion(getpos('v'), getpos('.'), #{ type: "\<C-v>" }))
call cursor(1, 5)
call feedkeys("\<Esc>\<C-v>jj", 'xt')
- call assert_equal(['e', ' ', '5'], getregion('v', '.', "\<C-v>"))
+ call assert_equal(['e', ' ', '5'],
+ \ getregion(getpos('v'), getpos('.'), #{ type: "\<C-v>" }))
call cursor(1, 1)
call feedkeys("\<Esc>vj", 'xt')
- call assert_equal(['abcdefghijk«', "\U0001f1e6"], getregion('v', '.', "v"))
+ call assert_equal(['abcdefghijk«', "\U0001f1e6"],
+ \ getregion(getpos('v'), getpos('.'), #{ type: 'v' }))
" marks on multibyte chars
set selection=exclusive
call setpos("'a", [0, 1, 11, 0])
call setpos("'b", [0, 2, 16, 0])
call setpos("'c", [0, 2, 0, 0])
call cursor(1, 1)
- call assert_equal(['ghijk', '🇨«🇩'], getregion("'a", "'b", "\<c-v>"))
- call assert_equal(['k«', '🇦«🇧«🇨'], getregion("'a", "'b", "v"))
- call assert_equal(['k«'], getregion("'a", "'c", "v"))
+ call assert_equal(['ghijk', '🇨«🇩'],
+ \ getregion(getpos("'a"), getpos("'b"), #{ type: "\<c-v>" }))
+ call assert_equal(['k«', '🇦«🇧«🇨'],
+ \ getregion(getpos("'a"), getpos("'b"), #{ type: 'v' }))
+ call assert_equal(['k«'],
+ \ getregion(getpos("'a"), getpos("'c"), #{ type: 'v' }))
+
+ " use inclusive selection, although 'selection' is exclusive
+ call setpos("'a", [0, 1, 11, 0])
+ call setpos("'b", [0, 1, 1, 0])
+ call assert_equal(['abcdefghijk'],
+ \ getregion(getpos("'a"), getpos("'b"), #{ type: "\<c-v>", exclusive: v:false }))
+ call assert_equal(['abcdefghij'],
+ \ getregion(getpos("'a"), getpos("'b"), #{ type: "\<c-v>", exclusive: v:true }))
+ call assert_equal(['abcdefghijk'],
+ \ getregion(getpos("'a"), getpos("'b"), #{ type: 'v', exclusive: 0 }))
+ call assert_equal(['abcdefghij'],
+ \ getregion(getpos("'a"), getpos("'b"), #{ type: 'v', exclusive: 1 }))
+ call assert_equal(['abcdefghijk«'],
+ \ getregion(getpos("'a"), getpos("'b"), #{ type: 'V', exclusive: 0 }))
+ call assert_equal(['abcdefghijk«'],
+ \ getregion(getpos("'a"), getpos("'b"), #{ type: 'V', exclusive: 1 }))
bwipe!
call setline(1, ["a\tc", "x\tz", '', ''])
call cursor(1, 1)
call feedkeys("\<Esc>v2l", 'xt')
- call assert_equal(["a\t"], getregion('v', '.', 'v'))
+ call assert_equal(["a\t"],
+ \ getregion(getpos('v'), getpos('.'), #{ type: 'v' }))
call cursor(1, 1)
call feedkeys("\<Esc>v$G", 'xt')
- call assert_equal(["a\tc", "x\tz", ''], getregion('v', '.', 'v'))
+ call assert_equal(["a\tc", "x\tz", ''],
+ \ getregion(getpos('v'), getpos('.'), #{ type: 'v' }))
call cursor(1, 1)
call feedkeys("\<Esc>v$j", 'xt')
- call assert_equal(["a\tc", "x\tz"], getregion('v', '.', 'v'))
+ call assert_equal(["a\tc", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'), #{ type: 'v' }))
call cursor(1, 1)
call feedkeys("\<Esc>\<C-v>$j", 'xt')
- call assert_equal(["a\tc", "x\tz"], getregion('v', '.', "\<C-v>"))
+ call assert_equal(["a\tc", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'), #{ type: "\<C-v>" }))
call cursor(1, 1)
call feedkeys("\<Esc>\<C-v>$G", 'xt')
- call assert_equal(["a", "x", '', ''], getregion('v', '.', "\<C-v>"))
+ call assert_equal(["a", "x", '', ''],
+ \ getregion(getpos('v'), getpos('.'), #{ type: "\<C-v>" }))
call cursor(1, 1)
call feedkeys("\<Esc>wv2j", 'xt')
- call assert_equal(["c", "x\tz"], getregion('v', '.', 'v'))
+ call assert_equal(["c", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'), #{ type: 'v' }))
+ set selection&
+
+ " Exclusive selection 2
+ new
+ call setline(1, ["a\tc", "x\tz", '', ''])
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v2l", 'xt')
+ call assert_equal(["a\t"],
+ \ getregion(getpos('v'), getpos('.'), #{ exclusive: v:true }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v$G", 'xt')
+ call assert_equal(["a\tc", "x\tz", ''],
+ \ getregion(getpos('v'), getpos('.'), #{ exclusive: v:true }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>v$j", 'xt')
+ call assert_equal(["a\tc", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'), #{ exclusive: v:true }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>\<C-v>$j", 'xt')
+ call assert_equal(["a\tc", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'),
+ \ #{ exclusive: v:true, type: "\<C-v>" }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>\<C-v>$G", 'xt')
+ call assert_equal(["a", "x", '', ''],
+ \ getregion(getpos('v'), getpos('.'),
+ \ #{ exclusive: v:true, type: "\<C-v>" }))
+ call cursor(1, 1)
+ call feedkeys("\<Esc>wv2j", 'xt')
+ call assert_equal(["c", "x\tz"],
+ \ getregion(getpos('v'), getpos('.'), #{ exclusive: v:true }))
" virtualedit
+ set selection=exclusive
set virtualedit=all
call cursor(1, 1)
call feedkeys("\<Esc>2lv2lj", 'xt')
- call assert_equal([' c', 'x '], getregion('v', '.', 'v'))
+ call assert_equal([' c', 'x '],
+ \ getregion(getpos('v'), getpos('.'), #{ type: 'v' }))
call cursor(1, 1)
call feedkeys("\<Esc>2l\<C-v>2l2j", 'xt')
- call assert_equal([' ', ' ', ' '], getregion('v', '.', "\<C-v>"))
+ call assert_equal([' ', ' ', ' '],
+ \ getregion(getpos('v'), getpos('.'), #{ type: "\<C-v>" }))
set virtualedit&
set selection&