mirror of
https://github.com/neovim/neovim.git
synced 2025-10-07 02:16:31 +00:00
vim-patch:9.0.1728: missing winid argument for virtcol() (#24770)
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: vim/vim#12633
825cf813fa
This commit is contained in:
@@ -11893,7 +11893,7 @@ M.funcs = {
|
||||
signature = 'values({dict})',
|
||||
},
|
||||
virtcol = {
|
||||
args = { 1, 2 },
|
||||
args = { 1, 3 },
|
||||
base = 1,
|
||||
desc = [=[
|
||||
The result is a Number, which is the screen column of the file
|
||||
@@ -11927,10 +11927,13 @@ M.funcs = {
|
||||
returns the cursor position. Differs from |'<| in
|
||||
that it's updated right away.
|
||||
|
||||
If {list} is present and non-zero then virtcol() returns a List
|
||||
with the first and last screen position occupied by the
|
||||
If {list} is present and non-zero then virtcol() returns a
|
||||
List with the first and last screen position occupied by the
|
||||
character.
|
||||
|
||||
With the optional {winid} argument the values are obtained for
|
||||
that window instead of the current window.
|
||||
|
||||
Note that only marks in the current file can be used.
|
||||
Examples: >vim
|
||||
" With text "foo^Lbar" and cursor on the "^L":
|
||||
@@ -11942,15 +11945,15 @@ M.funcs = {
|
||||
" With text " there", with 't at 'h':
|
||||
|
||||
echo virtcol("'t") " returns 6
|
||||
<Techo he first column is 1. 0 is returned for an error.
|
||||
A echo more advanced example that echoes the maximum length of
|
||||
<The first column is 1. 0 or [0, 0] is returned for an error.
|
||||
A more advanced example that echoes the maximum length of
|
||||
all lines: >vim
|
||||
echo max(map(range(1, line('$')), "virtcol([v:val, '$'])"))
|
||||
|
||||
]=],
|
||||
name = 'virtcol',
|
||||
params = { { 'expr', 'any' }, { 'list', 'any' } },
|
||||
signature = 'virtcol({expr} [, {list}])',
|
||||
params = { { 'expr', 'any' }, { 'list', 'any' }, { 'winid', 'integer' } },
|
||||
signature = 'virtcol({expr} [, {list} [, {winid}]])',
|
||||
},
|
||||
virtcol2col = {
|
||||
args = 3,
|
||||
|
@@ -8748,13 +8748,31 @@ static void f_type(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
rettv->vval.v_number = n;
|
||||
}
|
||||
|
||||
/// "virtcol(string, bool)" function
|
||||
/// "virtcol({expr}, [, {list} [, {winid}]])" function
|
||||
static void f_virtcol(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
{
|
||||
colnr_T vcol_start = 0;
|
||||
colnr_T vcol_end = 0;
|
||||
int fnum = curbuf->b_fnum;
|
||||
switchwin_T switchwin;
|
||||
bool winchanged = false;
|
||||
|
||||
if (argvars[1].v_type != VAR_UNKNOWN && argvars[2].v_type != VAR_UNKNOWN) {
|
||||
// use the window specified in the third argument
|
||||
tabpage_T *tp;
|
||||
win_T *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;
|
||||
pos_T *fp = var2fpos(&argvars[0], false, &fnum, false);
|
||||
if (fp != NULL && fp->lnum <= curbuf->b_ml.ml_line_count
|
||||
&& fnum == curbuf->b_fnum) {
|
||||
@@ -8772,6 +8790,7 @@ static void f_virtcol(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
vcol_end++;
|
||||
}
|
||||
|
||||
theend:
|
||||
if (argvars[1].v_type != VAR_UNKNOWN && tv_get_bool(&argvars[1])) {
|
||||
tv_list_alloc_ret(rettv, 2);
|
||||
tv_list_append_number(rettv->vval.v_list, vcol_start);
|
||||
@@ -8779,6 +8798,10 @@ static void f_virtcol(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
} else {
|
||||
rettv->vval.v_number = vcol_end;
|
||||
}
|
||||
|
||||
if (winchanged) {
|
||||
restore_win_noblock(&switchwin, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// "visualmode()" function
|
||||
|
Reference in New Issue
Block a user