mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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.
8e0a8e7eb7
This commit is contained in:
parent
89e29e8774
commit
dad725d5e5
@ -7617,7 +7617,7 @@ char *save_tv_as_string(typval_T *tv, ptrdiff_t *const len, bool endnl)
|
|||||||
/// @param[out] ret_fnum Set to fnum for marks.
|
/// @param[out] ret_fnum Set to fnum for marks.
|
||||||
///
|
///
|
||||||
/// @return Pointer to position or NULL in case of error (e.g. invalid type).
|
/// @return Pointer to position or NULL in case of error (e.g. invalid type).
|
||||||
pos_T *var2fpos(const typval_T *const tv, const int dollar_lnum,
|
pos_T *var2fpos(const typval_T *const tv, const bool dollar_lnum,
|
||||||
int *const ret_fnum)
|
int *const ret_fnum)
|
||||||
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
|
@ -217,7 +217,7 @@ return {
|
|||||||
len={args=1},
|
len={args=1},
|
||||||
libcall={args=3},
|
libcall={args=3},
|
||||||
libcallnr={args=3},
|
libcallnr={args=3},
|
||||||
line={args=1},
|
line={args={1, 2}},
|
||||||
line2byte={args=1},
|
line2byte={args=1},
|
||||||
lispindent={args=1},
|
lispindent={args=1},
|
||||||
list2str={args={1, 2}},
|
list2str={args={1, 2}},
|
||||||
|
@ -5540,18 +5540,36 @@ static void f_libcallnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
|||||||
libcall_common(argvars, rettv, VAR_NUMBER);
|
libcall_common(argvars, rettv, VAR_NUMBER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// "line(string, [winid])" function
|
||||||
* "line(string)" function
|
|
||||||
*/
|
|
||||||
static void f_line(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
static void f_line(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||||
{
|
{
|
||||||
linenr_T lnum = 0;
|
linenr_T lnum = 0;
|
||||||
pos_T *fp;
|
pos_T *fp = NULL;
|
||||||
int fnum;
|
int fnum;
|
||||||
|
|
||||||
fp = var2fpos(&argvars[0], TRUE, &fnum);
|
if (argvars[1].v_type != VAR_UNKNOWN) {
|
||||||
if (fp != NULL)
|
tabpage_T *tp;
|
||||||
|
win_T *save_curwin;
|
||||||
|
tabpage_T *save_curtab;
|
||||||
|
|
||||||
|
// use window specified in the second argument
|
||||||
|
win_T *wp = win_id2wp_tp(&argvars[1], &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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fp != NULL) {
|
||||||
lnum = fp->lnum;
|
lnum = fp->lnum;
|
||||||
|
}
|
||||||
rettv->vval.v_number = lnum;
|
rettv->vval.v_number = lnum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,7 @@ describe('NULL', function()
|
|||||||
null_expr_test('does not crash col()', 'col(L)', 0, 0)
|
null_expr_test('does not crash col()', 'col(L)', 0, 0)
|
||||||
null_expr_test('does not crash virtcol()', 'virtcol(L)', 0, 0)
|
null_expr_test('does not crash virtcol()', 'virtcol(L)', 0, 0)
|
||||||
null_expr_test('does not crash line()', 'line(L)', 0, 0)
|
null_expr_test('does not crash line()', 'line(L)', 0, 0)
|
||||||
|
null_expr_test('does not crash line() with window id', 'line(L, 1000)', 0, 0)
|
||||||
null_expr_test('does not crash count()', 'count(L, 1)', 0, 0)
|
null_expr_test('does not crash count()', 'count(L, 1)', 0, 0)
|
||||||
null_expr_test('does not crash cursor()', 'cursor(L)', 'E474: Invalid argument', -1)
|
null_expr_test('does not crash cursor()', 'cursor(L)', 'E474: Invalid argument', -1)
|
||||||
null_expr_test('does not crash map()', 'map(L, "v:val")', 0, {})
|
null_expr_test('does not crash map()', 'map(L, "v:val")', 0, {})
|
||||||
|
@ -64,10 +64,13 @@ describe('float window', function()
|
|||||||
|
|
||||||
it('win_execute() should work' , function()
|
it('win_execute() should work' , function()
|
||||||
local buf = meths.create_buf(false, false)
|
local buf = meths.create_buf(false, false)
|
||||||
meths.buf_set_lines(buf, 0, -1, true, {'the floatwin'})
|
meths.buf_set_lines(buf, 0, -1, true, {'the floatwin', 'abc', 'def'})
|
||||||
local win = meths.open_win(buf, false, {relative='win', width=16, height=1, row=0, col=10})
|
local win = meths.open_win(buf, false, {relative='win', width=16, height=1, row=0, col=10})
|
||||||
local line = funcs.win_execute(win, 'echo getline(1)')
|
local line = funcs.win_execute(win, 'echo getline(1)')
|
||||||
eq('\nthe floatwin', line)
|
eq('\nthe floatwin', line)
|
||||||
|
eq('\n1', funcs.win_execute(win, 'echo line(".",'..win.id..')'))
|
||||||
|
eq('\n3', funcs.win_execute(win, 'echo line("$",'..win.id..')'))
|
||||||
|
eq('\n0', funcs.win_execute(win, 'echo line("$", 123456)'))
|
||||||
funcs.win_execute(win, 'bwipe!')
|
funcs.win_execute(win, 'bwipe!')
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user