summaryrefslogtreecommitdiffstats
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-17 22:55:25 +0200
committerChristian Brabandt <cb@256bit.org>2023-08-17 22:55:25 +0200
commit825cf813fa0fddf085fcbd3194781e875320ff63 (patch)
tree8c97b2ff072b1021d804514d5aa49e642e665bda /src/evalfunc.c
parentb0efa49ed179d3aa1fa0358d4c3c6d35a0efb291 (diff)
patch 9.0.1728: missing winid argument for virtcol()v9.0.1728
Problem: missing winid argument for virtcol() Solution: Add a {winid} argument to virtcol() Other functions col(), charcol() and virtcol2col() support a {winid} argument, so it makes sense for virtcol() to also support than. Also add test for virtcol2col() with 'showbreak' and {winid}. closes: #12633 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index ef0414c689..c0710da119 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -1070,7 +1070,6 @@ static argcheck_T arg2_string_dict[] = {arg_string, arg_dict_any};
static argcheck_T arg2_string_list_number[] = {arg_string, arg_list_number};
static argcheck_T arg2_string_number[] = {arg_string, arg_number};
static argcheck_T arg2_string_or_list_dict[] = {arg_string_or_list_any, arg_dict_any};
-static argcheck_T arg2_string_or_list_bool[] = {arg_string_or_list_any, arg_bool};
static argcheck_T arg2_string_or_list_number[] = {arg_string_or_list_any, arg_number};
static argcheck_T arg2_string_string_or_number[] = {arg_string, arg_string_or_nr};
static argcheck_T arg3_any_list_dict[] = {NULL, arg_list_any, arg_dict_any};
@@ -1094,6 +1093,7 @@ static argcheck_T arg3_string_bool_bool[] = {arg_string, arg_bool, arg_bool};
static argcheck_T arg3_string_number_bool[] = {arg_string, arg_number, arg_bool};
static argcheck_T arg3_string_number_number[] = {arg_string, arg_number, arg_number};
static argcheck_T arg3_string_or_dict_bool_dict[] = {arg_string_or_dict_any, arg_bool, arg_dict_any};
+static argcheck_T arg3_string_or_list_bool_number[] = {arg_string_or_list_any, arg_bool, arg_number};
static argcheck_T arg3_string_string_bool[] = {arg_string, arg_string, arg_bool};
static argcheck_T arg3_string_string_dict[] = {arg_string, arg_string, arg_dict_any};
static argcheck_T arg3_string_string_number[] = {arg_string, arg_string, arg_number};
@@ -1569,7 +1569,7 @@ ret_virtcol(int argcount,
type_T **decl_type)
{
// Assume that if the second argument is passed it's non-zero
- if (argcount == 2)
+ if (argcount > 1)
{
*decl_type = &t_list_any;
return &t_list_number;
@@ -2806,7 +2806,7 @@ static funcentry_T global_functions[] =
ret_number, f_utf16idx},
{"values", 1, 1, FEARG_1, arg1_dict_any,
ret_list_member, f_values},
- {"virtcol", 1, 2, FEARG_1, arg2_string_or_list_bool,
+ {"virtcol", 1, 3, FEARG_1, arg3_string_or_list_bool_number,
ret_virtcol, f_virtcol},
{"virtcol2col", 3, 3, FEARG_1, arg3_number,
ret_number, f_virtcol2col},
@@ -10737,7 +10737,7 @@ f_type(typval_T *argvars, typval_T *rettv)
}
/*
- * "virtcol(string, bool)" function
+ * "virtcol({expr}, [, {list} [, {winid}]])" function
*/
static void
f_virtcol(typval_T *argvars, typval_T *rettv)
@@ -10745,15 +10745,35 @@ f_virtcol(typval_T *argvars, typval_T *rettv)
colnr_T vcol_start = 0;
colnr_T vcol_end = 0;
pos_T *fp;
- int fnum = curbuf->b_fnum;
+ switchwin_T switchwin;
+ int winchanged = FALSE;
int len;
if (in_vim9script()
&& (check_for_string_or_list_arg(argvars, 0) == FAIL
|| (argvars[1].v_type != VAR_UNKNOWN
- && check_for_bool_arg(argvars, 1) == FAIL)))
+ && (check_for_bool_arg(argvars, 1) == FAIL
+ || check_for_opt_number_arg(argvars, 2) == FAIL))))
return;
+ if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN)
+ {
+ tabpage_T *tp;
+ win_T *wp;
+
+ // use the window specified in the third argument
+ wp = win_id2wp_tp((int)tv_get_number(&argvars[2]), &tp);
+ if (wp == NULL || tp == NULL)
+ goto theend;
+
+ if (switch_win_noblock(&switchwin, wp, tp, TRUE) != OK)
+ goto theend;
+
+ check_cursor();
+ winchanged = TRUE;
+ }
+
+ int fnum = curbuf->b_fnum;
fp = var2fpos(&argvars[0], FALSE, &fnum, FALSE);
if (fp != NULL && fp->lnum <= curbuf->b_ml.ml_line_count
&& fnum == curbuf->b_fnum)
@@ -10772,6 +10792,7 @@ f_virtcol(typval_T *argvars, typval_T *rettv)
++vcol_end;
}
+theend:
if (argvars[1].v_type != VAR_UNKNOWN && tv_get_bool(&argvars[1]))
{
if (rettv_list_alloc(rettv) == OK)
@@ -10784,6 +10805,9 @@ f_virtcol(typval_T *argvars, typval_T *rettv)
}
else
rettv->vval.v_number = vcol_end;
+
+ if (winchanged)
+ restore_win_noblock(&switchwin, TRUE);
}
/*