Patch 8.2.1562
Problem: Vim9: error when using "%" where a buffer is expected.
Solution: Add tv_get_buf_from_arg(). (closes #6814)
Files: src/typval.c, src/proto/typval.pro, src/evalbuffer.c,
src/testdir/test_vim9_func.vim
*** ../vim-8.2.1561/src/typval.c 2020-08-22 15:06:29.420409081 +0200
--- src/typval.c 2020-09-01 22:54:44.230657278 +0200
***************
*** 1562,1565 ****
--- 1562,1584 ----
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
*** ../vim-8.2.1561/src/proto/typval.pro 2020-08-18 19:11:34.486104966
+0200
--- src/proto/typval.pro 2020-09-01 23:02:48.813274971 +0200
***************
*** 29,32 ****
--- 29,33 ----
linenr_T tv_get_lnum(typval_T *argvars);
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_from_arg(typval_T *tv);
/* vim: set ft=c : */
*** ../vim-8.2.1561/src/evalbuffer.c 2020-08-30 21:26:53.351220687 +0200
--- src/evalbuffer.c 2020-09-01 23:05:11.676921908 +0200
***************
*** 364,379 ****
if (tv->v_type == VAR_UNKNOWN)
buf = curbuf;
else
! {
! ++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;
if (buf != NULL && buf->b_fname != NULL)
rettv->vval.v_string = vim_strsave(buf->b_fname);
--- 364,370 ----
if (tv->v_type == VAR_UNKNOWN)
buf = curbuf;
else
! buf = tv_get_buf_from_arg(tv);
rettv->v_type = VAR_STRING;
if (buf != NULL && buf->b_fname != NULL)
rettv->vval.v_string = vim_strsave(buf->b_fname);
***************
*** 394,406 ****
if (argvars[0].v_type == VAR_UNKNOWN)
buf = curbuf;
else
! {
! 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
// new buffer.
--- 385,391 ----
if (argvars[0].v_type == VAR_UNKNOWN)
buf = curbuf;
else
! buf = tv_get_buf_from_arg(&argvars[0]);
// If the buffer isn't found and the second argument is not zero create a
// new buffer.
***************
*** 425,433 ****
int winnr = 0;
buf_T *buf;
! (void)tv_get_number(&argvars[0]); // issue errmsg if type error
! ++emsg_off;
! buf = tv_get_buf(&argvars[0], TRUE);
FOR_ALL_WINDOWS(wp)
{
++winnr;
--- 410,416 ----
int winnr = 0;
buf_T *buf;
! buf = tv_get_buf_from_arg(&argvars[0]);
FOR_ALL_WINDOWS(wp)
{
++winnr;
***************
*** 435,441 ****
break;
}
rettv->vval.v_number = (wp != NULL ? (get_nr ? winnr : wp->w_id) : -1);
- --emsg_off;
}
/*
--- 418,423 ----
***************
*** 662,671 ****
else if (argvars[0].v_type != VAR_UNKNOWN)
{
// Information about one buffer. Argument specifies the buffer
! (void)tv_get_number(&argvars[0]); // issue errmsg if type error
! ++emsg_off;
! argbuf = tv_get_buf(&argvars[0], FALSE);
! --emsg_off;
if (argbuf == NULL)
return;
}
--- 644,650 ----
else if (argvars[0].v_type != VAR_UNKNOWN)
{
// Information about one buffer. Argument specifies the buffer
! argbuf = tv_get_buf_from_arg(&argvars[0]);
if (argbuf == NULL)
return;
}
***************
*** 752,761 ****
linenr_T end;
buf_T *buf;
! (void)tv_get_number(&argvars[0]); // issue errmsg if type error
! ++emsg_off;
! buf = tv_get_buf(&argvars[0], FALSE);
! --emsg_off;
lnum = tv_get_lnum_buf(&argvars[1], buf);
if (argvars[2].v_type == VAR_UNKNOWN)
--- 731,737 ----
linenr_T end;
buf_T *buf;
! buf = tv_get_buf_from_arg(&argvars[0]);
lnum = tv_get_lnum_buf(&argvars[1], buf);
if (argvars[2].v_type == VAR_UNKNOWN)
*** ../vim-8.2.1561/src/testdir/test_vim9_func.vim 2020-08-30
23:24:17.223401357 +0200
--- src/testdir/test_vim9_func.vim 2020-09-01 23:02:25.785340765 +0200
***************
*** 1443,1448 ****
--- 1443,1453 ----
close
enddef
+ def Test_gebufinfo()
+ let bufinfo = getbufinfo(bufnr())
+ assert_equal(bufinfo, getbufinfo('%'))
+ enddef
+
def Fibonacci(n: number): number
if n < 2
return n
*** ../vim-8.2.1561/src/version.c 2020-09-01 21:20:11.918075824 +0200
--- src/version.c 2020-09-01 23:03:21.321182052 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1562,
/**/
--
PRINCE: He's come to rescue me, father.
LAUNCELOT: (embarrassed) Well, let's not jump to conclusions ...
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202009012106.081L6S9O3415699%40masaka.moolenaar.net.