diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-10-11 00:24:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-11 00:24:52 +0800 |
commit | 26c653718097955dc4dfbeb45ab602c8dbe9dea5 (patch) | |
tree | 9ae12e34472a4aa6dae4cfb381a0648705b1351d /src/nvim/eval | |
parent | 8781213f00a22e20abeb4282204e900db799f4b5 (diff) | |
parent | 62a0c9f8c24b9115155cd4551976353ace3e2c5e (diff) | |
download | rneovim-26c653718097955dc4dfbeb45ab602c8dbe9dea5.tar.gz rneovim-26c653718097955dc4dfbeb45ab602c8dbe9dea5.tar.bz2 rneovim-26c653718097955dc4dfbeb45ab602c8dbe9dea5.zip |
Merge pull request #20574 from zeertzjq/vim-8.2.2184
vim-patch:8.2.{1465,2184,2670,2671},9.0.{0712,partial:0715}
Diffstat (limited to 'src/nvim/eval')
-rw-r--r-- | src/nvim/eval/funcs.c | 19 | ||||
-rw-r--r-- | src/nvim/eval/typval.c | 4 |
2 files changed, 15 insertions, 8 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index f2ef8e5cdd..a326c44371 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -1270,7 +1270,7 @@ static void f_ctxsize(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// Otherwise use the column number as a byte offset. static void set_cursorpos(typval_T *argvars, typval_T *rettv, bool charcol) { - long line, col; + long lnum, col; long coladd = 0; bool set_curswant = true; @@ -1284,7 +1284,7 @@ static void set_cursorpos(typval_T *argvars, typval_T *rettv, bool charcol) return; } - line = pos.lnum; + lnum = pos.lnum; col = pos.col; coladd = pos.coladd; if (curswant >= 0) { @@ -1293,10 +1293,15 @@ static void set_cursorpos(typval_T *argvars, typval_T *rettv, bool charcol) } } else if ((argvars[0].v_type == VAR_NUMBER || argvars[0].v_type == VAR_STRING) && (argvars[1].v_type == VAR_NUMBER || argvars[1].v_type == VAR_STRING)) { - line = tv_get_lnum(argvars); + lnum = tv_get_lnum(argvars); + if (lnum < 0) { + semsg(_(e_invarg2), tv_get_string(&argvars[0])); + } else if (lnum == 0) { + lnum = curwin->w_cursor.lnum; + } col = (long)tv_get_number_chk(&argvars[1], NULL); if (charcol) { - col = buf_charidx_to_byteidx(curbuf, (linenr_T)line, (int)col) + 1; + col = buf_charidx_to_byteidx(curbuf, (linenr_T)lnum, (int)col) + 1; } if (argvars[2].v_type != VAR_UNKNOWN) { coladd = (long)tv_get_number_chk(&argvars[2], NULL); @@ -1305,11 +1310,11 @@ static void set_cursorpos(typval_T *argvars, typval_T *rettv, bool charcol) emsg(_(e_invarg)); return; } - if (line < 0 || col < 0 || coladd < 0) { + if (lnum < 0 || col < 0 || coladd < 0) { return; // type error; errmsg already given } - if (line > 0) { - curwin->w_cursor.lnum = (linenr_T)line; + if (lnum > 0) { + curwin->w_cursor.lnum = (linenr_T)lnum; } if (col > 0) { curwin->w_cursor.col = (colnr_T)col - 1; diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 961c963170..a0b06aaaf4 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -3750,9 +3750,11 @@ varnumber_T tv_get_number_chk(const typval_T *const tv, bool *const ret_error) linenr_T tv_get_lnum(const typval_T *const tv) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { + const int did_emsg_before = did_emsg; linenr_T lnum = (linenr_T)tv_get_number_chk(tv, NULL); - if (lnum == 0) { // No valid number, try using same function as line() does. + if (lnum <= 0 && did_emsg_before == did_emsg && tv->v_type != VAR_NUMBER) { int fnum; + // No valid number, try using same function as line() does. pos_T *const fp = var2fpos(tv, true, &fnum, false); if (fp != NULL) { lnum = fp->lnum; |