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);
- }
+ 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);
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;
- }
+ 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.
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);
+ buf = tv_get_buf_from_arg(&argvars[0]);
FOR_ALL_WINDOWS(wp)
{
++winnr;
break;
}
rettv->vval.v_number = (wp != NULL ? (get_nr ? winnr : wp->w_id) : -1);
- --emsg_off;
}
/*
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;
+ argbuf = tv_get_buf_from_arg(&argvars[0]);
if (argbuf == NULL)
return;
}
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;
+ buf = tv_get_buf_from_arg(&argvars[0]);
lnum = tv_get_lnum_buf(&argvars[1], buf);
if (argvars[2].v_type == VAR_UNKNOWN)
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