forked from aniani/vim
patch 8.1.1967: line() only works for the current window
Problem: Line() only works for the current window. Solution: Add an optional argument for the window to use.
This commit is contained in:
@@ -634,7 +634,7 @@ static funcentry_T global_functions[] =
|
|||||||
{"len", 1, 1, FEARG_1, f_len},
|
{"len", 1, 1, FEARG_1, f_len},
|
||||||
{"libcall", 3, 3, FEARG_3, f_libcall},
|
{"libcall", 3, 3, FEARG_3, f_libcall},
|
||||||
{"libcallnr", 3, 3, FEARG_3, f_libcallnr},
|
{"libcallnr", 3, 3, FEARG_3, f_libcallnr},
|
||||||
{"line", 1, 1, FEARG_1, f_line},
|
{"line", 1, 2, FEARG_1, f_line},
|
||||||
{"line2byte", 1, 1, FEARG_1, f_line2byte},
|
{"line2byte", 1, 1, FEARG_1, f_line2byte},
|
||||||
{"lispindent", 1, 1, FEARG_1, f_lispindent},
|
{"lispindent", 1, 1, FEARG_1, f_lispindent},
|
||||||
{"list2str", 1, 2, FEARG_1, f_list2str},
|
{"list2str", 1, 2, FEARG_1, f_list2str},
|
||||||
@@ -1154,14 +1154,18 @@ tv_get_lnum(typval_T *argvars)
|
|||||||
{
|
{
|
||||||
typval_T rettv;
|
typval_T rettv;
|
||||||
linenr_T lnum;
|
linenr_T lnum;
|
||||||
|
int save_type;
|
||||||
|
|
||||||
lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL);
|
lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL);
|
||||||
if (lnum == 0) /* no valid number, try using line() */
|
if (lnum == 0) /* no valid number, try using line() */
|
||||||
{
|
{
|
||||||
rettv.v_type = VAR_NUMBER;
|
rettv.v_type = VAR_NUMBER;
|
||||||
|
save_type = argvars[1].v_type;
|
||||||
|
argvars[1].v_type = VAR_UNKNOWN;
|
||||||
f_line(argvars, &rettv);
|
f_line(argvars, &rettv);
|
||||||
lnum = (linenr_T)rettv.vval.v_number;
|
lnum = (linenr_T)rettv.vval.v_number;
|
||||||
clear_tv(&rettv);
|
clear_tv(&rettv);
|
||||||
|
argvars[1].v_type = save_type;
|
||||||
}
|
}
|
||||||
return lnum;
|
return lnum;
|
||||||
}
|
}
|
||||||
@@ -6658,16 +6662,40 @@ f_libcallnr(typval_T *argvars, typval_T *rettv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "line(string)" function
|
* "line(string, [winid])" function
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
f_line(typval_T *argvars, typval_T *rettv)
|
f_line(typval_T *argvars, typval_T *rettv)
|
||||||
{
|
{
|
||||||
linenr_T lnum = 0;
|
linenr_T lnum = 0;
|
||||||
pos_T *fp;
|
pos_T *fp = NULL;
|
||||||
int fnum;
|
int fnum;
|
||||||
|
int id;
|
||||||
|
tabpage_T *tp;
|
||||||
|
win_T *wp;
|
||||||
|
win_T *save_curwin;
|
||||||
|
tabpage_T *save_curtab;
|
||||||
|
|
||||||
|
if (argvars[1].v_type != VAR_UNKNOWN)
|
||||||
|
{
|
||||||
|
// use window specified in the second argument
|
||||||
|
id = (int)tv_get_number(&argvars[1]);
|
||||||
|
wp = win_id2wp_tp(id, &tp);
|
||||||
|
if (wp != NULL && tp != NULL)
|
||||||
|
{
|
||||||
|
if (switch_win_noblock(&save_curwin, &save_curtab, wp, tp, TRUE)
|
||||||
|
== OK)
|
||||||
|
{
|
||||||
|
check_cursor();
|
||||||
|
fp = var2fpos(&argvars[0], TRUE, &fnum);
|
||||||
|
}
|
||||||
|
restore_win_noblock(save_curwin, save_curtab, TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
// use current window
|
||||||
|
fp = var2fpos(&argvars[0], TRUE, &fnum);
|
||||||
|
|
||||||
fp = var2fpos(&argvars[0], TRUE, &fnum);
|
|
||||||
if (fp != NULL)
|
if (fp != NULL)
|
||||||
lnum = fp->lnum;
|
lnum = fp->lnum;
|
||||||
rettv->vval.v_number = lnum;
|
rettv->vval.v_number = lnum;
|
||||||
|
@@ -346,6 +346,10 @@ func Test_popup_firstline()
|
|||||||
redraw
|
redraw
|
||||||
call assert_equal(11, popup_getoptions(winid).firstline)
|
call assert_equal(11, popup_getoptions(winid).firstline)
|
||||||
call assert_equal(11, popup_getpos(winid).firstline)
|
call assert_equal(11, popup_getpos(winid).firstline)
|
||||||
|
" check line() works with popup window
|
||||||
|
call assert_equal(11, line('.', winid))
|
||||||
|
call assert_equal(50, line('$', winid))
|
||||||
|
call assert_equal(0, line('$', 123456))
|
||||||
|
|
||||||
" Normal command changes what is displayed but not "firstline"
|
" Normal command changes what is displayed but not "firstline"
|
||||||
call win_execute(winid, "normal! \<c-y>")
|
call win_execute(winid, "normal! \<c-y>")
|
||||||
|
@@ -761,6 +761,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1967,
|
||||||
/**/
|
/**/
|
||||||
1966,
|
1966,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user