mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.1562: Vim9: error when using "%" where a buffer is expected
Problem: Vim9: error when using "%" where a buffer is expected. Solution: Add tv_get_buf_from_arg(). (closes #6814)
This commit is contained in:
@@ -364,16 +364,7 @@ f_bufname(typval_T *argvars, typval_T *rettv)
|
|||||||
if (tv->v_type == VAR_UNKNOWN)
|
if (tv->v_type == VAR_UNKNOWN)
|
||||||
buf = curbuf;
|
buf = curbuf;
|
||||||
else
|
else
|
||||||
{
|
buf = tv_get_buf_from_arg(tv);
|
||||||
++emsg_off;
|
|
||||||
buf = tv_get_buf(tv, FALSE);
|
|
||||||
--emsg_off;
|
|
||||||
if (buf == NULL
|
|
||||||
&& tv->v_type != VAR_NUMBER
|
|
||||||
&& tv->v_type != VAR_STRING)
|
|
||||||
// issue errmsg for type error
|
|
||||||
(void)tv_get_number(tv);
|
|
||||||
}
|
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = VAR_STRING;
|
||||||
if (buf != NULL && buf->b_fname != NULL)
|
if (buf != NULL && buf->b_fname != NULL)
|
||||||
rettv->vval.v_string = vim_strsave(buf->b_fname);
|
rettv->vval.v_string = vim_strsave(buf->b_fname);
|
||||||
@@ -394,13 +385,7 @@ f_bufnr(typval_T *argvars, typval_T *rettv)
|
|||||||
if (argvars[0].v_type == VAR_UNKNOWN)
|
if (argvars[0].v_type == VAR_UNKNOWN)
|
||||||
buf = curbuf;
|
buf = curbuf;
|
||||||
else
|
else
|
||||||
{
|
buf = tv_get_buf_from_arg(&argvars[0]);
|
||||||
if (argvars[0].v_type != VAR_STRING)
|
|
||||||
(void)tv_get_number(&argvars[0]); // issue errmsg if type error
|
|
||||||
++emsg_off;
|
|
||||||
buf = tv_get_buf(&argvars[0], FALSE);
|
|
||||||
--emsg_off;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the buffer isn't found and the second argument is not zero create a
|
// If the buffer isn't found and the second argument is not zero create a
|
||||||
// new buffer.
|
// new buffer.
|
||||||
@@ -425,9 +410,7 @@ buf_win_common(typval_T *argvars, typval_T *rettv, int get_nr)
|
|||||||
int winnr = 0;
|
int winnr = 0;
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
|
|
||||||
(void)tv_get_number(&argvars[0]); // issue errmsg if type error
|
buf = tv_get_buf_from_arg(&argvars[0]);
|
||||||
++emsg_off;
|
|
||||||
buf = tv_get_buf(&argvars[0], TRUE);
|
|
||||||
FOR_ALL_WINDOWS(wp)
|
FOR_ALL_WINDOWS(wp)
|
||||||
{
|
{
|
||||||
++winnr;
|
++winnr;
|
||||||
@@ -435,7 +418,6 @@ buf_win_common(typval_T *argvars, typval_T *rettv, int get_nr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rettv->vval.v_number = (wp != NULL ? (get_nr ? winnr : wp->w_id) : -1);
|
rettv->vval.v_number = (wp != NULL ? (get_nr ? winnr : wp->w_id) : -1);
|
||||||
--emsg_off;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -662,10 +644,7 @@ f_getbufinfo(typval_T *argvars, typval_T *rettv)
|
|||||||
else if (argvars[0].v_type != VAR_UNKNOWN)
|
else if (argvars[0].v_type != VAR_UNKNOWN)
|
||||||
{
|
{
|
||||||
// Information about one buffer. Argument specifies the buffer
|
// Information about one buffer. Argument specifies the buffer
|
||||||
(void)tv_get_number(&argvars[0]); // issue errmsg if type error
|
argbuf = tv_get_buf_from_arg(&argvars[0]);
|
||||||
++emsg_off;
|
|
||||||
argbuf = tv_get_buf(&argvars[0], FALSE);
|
|
||||||
--emsg_off;
|
|
||||||
if (argbuf == NULL)
|
if (argbuf == NULL)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -752,10 +731,7 @@ f_getbufline(typval_T *argvars, typval_T *rettv)
|
|||||||
linenr_T end;
|
linenr_T end;
|
||||||
buf_T *buf;
|
buf_T *buf;
|
||||||
|
|
||||||
(void)tv_get_number(&argvars[0]); // issue errmsg if type error
|
buf = tv_get_buf_from_arg(&argvars[0]);
|
||||||
++emsg_off;
|
|
||||||
buf = tv_get_buf(&argvars[0], FALSE);
|
|
||||||
--emsg_off;
|
|
||||||
|
|
||||||
lnum = tv_get_lnum_buf(&argvars[1], buf);
|
lnum = tv_get_lnum_buf(&argvars[1], buf);
|
||||||
if (argvars[2].v_type == VAR_UNKNOWN)
|
if (argvars[2].v_type == VAR_UNKNOWN)
|
||||||
|
@@ -29,4 +29,5 @@ int eval_env_var(char_u **arg, typval_T *rettv, int evaluate);
|
|||||||
linenr_T tv_get_lnum(typval_T *argvars);
|
linenr_T tv_get_lnum(typval_T *argvars);
|
||||||
linenr_T tv_get_lnum_buf(typval_T *argvars, buf_T *buf);
|
linenr_T tv_get_lnum_buf(typval_T *argvars, buf_T *buf);
|
||||||
buf_T *tv_get_buf(typval_T *tv, int curtab_only);
|
buf_T *tv_get_buf(typval_T *tv, int curtab_only);
|
||||||
|
buf_T *tv_get_buf_from_arg(typval_T *tv);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
@@ -1443,6 +1443,11 @@ def Test_bufname()
|
|||||||
close
|
close
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_gebufinfo()
|
||||||
|
let bufinfo = getbufinfo(bufnr())
|
||||||
|
assert_equal(bufinfo, getbufinfo('%'))
|
||||||
|
enddef
|
||||||
|
|
||||||
def Fibonacci(n: number): number
|
def Fibonacci(n: number): number
|
||||||
if n < 2
|
if n < 2
|
||||||
return n
|
return n
|
||||||
|
19
src/typval.c
19
src/typval.c
@@ -1562,4 +1562,23 @@ tv_get_buf(typval_T *tv, int curtab_only)
|
|||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Like tv_get_buf() but give an error message is the type is wrong.
|
||||||
|
*/
|
||||||
|
buf_T *
|
||||||
|
tv_get_buf_from_arg(typval_T *tv)
|
||||||
|
{
|
||||||
|
buf_T *buf;
|
||||||
|
|
||||||
|
++emsg_off;
|
||||||
|
buf = tv_get_buf(tv, FALSE);
|
||||||
|
--emsg_off;
|
||||||
|
if (buf == NULL
|
||||||
|
&& tv->v_type != VAR_NUMBER
|
||||||
|
&& tv->v_type != VAR_STRING)
|
||||||
|
// issue errmsg for type error
|
||||||
|
(void)tv_get_number(tv);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // FEAT_EVAL
|
#endif // FEAT_EVAL
|
||||||
|
@@ -754,6 +754,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 */
|
||||||
|
/**/
|
||||||
|
1562,
|
||||||
/**/
|
/**/
|
||||||
1561,
|
1561,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user