aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-05-10 22:40:08 -0400
committerJan Edmund Lazo <jan.lazo@mail.utoronto.ca>2021-05-12 19:13:28 -0400
commitdad725d5e578c5dbef5a0bf503fa1b41aaf3ff6b (patch)
treefd9c07e62df7c3e9653f3076f4b14bb7602c7420 /src
parent89e29e8774ed953048ab746d4a83a6f08d850d17 (diff)
downloadrneovim-dad725d5e578c5dbef5a0bf503fa1b41aaf3ff6b.tar.gz
rneovim-dad725d5e578c5dbef5a0bf503fa1b41aaf3ff6b.tar.bz2
rneovim-dad725d5e578c5dbef5a0bf503fa1b41aaf3ff6b.zip
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. https://github.com/vim/vim/commit/8e0a8e7eb7c177807f44db6b76d8e52314248ab5
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval.c2
-rw-r--r--src/nvim/eval.lua2
-rw-r--r--src/nvim/eval/funcs.c30
3 files changed, 26 insertions, 8 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index d67db94339..5d624882a2 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -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.
///
/// @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)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 148804e54c..5ad7781a41 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -217,7 +217,7 @@ return {
len={args=1},
libcall={args=3},
libcallnr={args=3},
- line={args=1},
+ line={args={1, 2}},
line2byte={args=1},
lispindent={args=1},
list2str={args={1, 2}},
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 9d5707e649..c2e1639624 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -5540,18 +5540,36 @@ static void f_libcallnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
libcall_common(argvars, rettv, VAR_NUMBER);
}
-/*
- * "line(string)" function
- */
+// "line(string, [winid])" function
static void f_line(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
linenr_T lnum = 0;
- pos_T *fp;
+ pos_T *fp = NULL;
int fnum;
- fp = var2fpos(&argvars[0], TRUE, &fnum);
- if (fp != NULL)
+ if (argvars[1].v_type != VAR_UNKNOWN) {
+ 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;
+ }
rettv->vval.v_number = lnum;
}