patch 8.1.0362: cannot get the script line number when executing a function
Problem: Cannot get the script line number when executing a function.
Solution: Store the line number besides the script ID. (Ozaki Kiichi,
closes #3362) Also display the line number with ":verbose set".
diff --git a/src/userfunc.c b/src/userfunc.c
index a8ea303..78a2ecc 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -302,7 +302,8 @@
fp->uf_varargs = TRUE;
fp->uf_flags = flags;
fp->uf_calls = 0;
- fp->uf_script_ID = current_SID;
+ fp->uf_script_ctx = current_sctx;
+ fp->uf_script_ctx.sc_lnum += sourcing_lnum - newlines.ga_len;
pt->pt_func = fp;
pt->pt_refcount = 1;
@@ -505,11 +506,11 @@
i = 3;
if (eval_fname_sid(name)) /* "<SID>" or "s:" */
{
- if (current_SID <= 0)
+ if (current_sctx.sc_sid <= 0)
*error = ERROR_SCRIPT;
else
{
- sprintf((char *)fname_buf + 3, "%ld_", (long)current_SID);
+ sprintf((char *)fname_buf + 3, "%ld_", (long)current_sctx.sc_sid);
i = (int)STRLEN(fname_buf);
}
}
@@ -690,7 +691,7 @@
{
char_u *save_sourcing_name;
linenr_T save_sourcing_lnum;
- scid_T save_current_SID;
+ sctx_T save_current_sctx;
int using_sandbox = FALSE;
funccall_T *fc;
int save_did_emsg;
@@ -944,8 +945,8 @@
}
#endif
- save_current_SID = current_SID;
- current_SID = fp->uf_script_ID;
+ save_current_sctx = current_sctx;
+ current_sctx = fp->uf_script_ctx;
save_did_emsg = did_emsg;
did_emsg = FALSE;
@@ -1026,7 +1027,7 @@
vim_free(sourcing_name);
sourcing_name = save_sourcing_name;
sourcing_lnum = save_sourcing_lnum;
- current_SID = save_current_SID;
+ current_sctx = save_current_sctx;
#ifdef FEAT_PROFILE
if (do_profiling == PROF_YES)
script_prof_restore(&wait_start);
@@ -1574,7 +1575,7 @@
MSG_PUTS(" closure");
msg_clr_eos();
if (p_verbose > 0)
- last_set_msg(fp->uf_script_ID);
+ last_set_msg(fp->uf_script_ctx);
}
/*
@@ -1757,12 +1758,12 @@
|| eval_fname_sid(*pp))
{
/* It's "s:" or "<SID>" */
- if (current_SID <= 0)
+ if (current_sctx.sc_sid <= 0)
{
EMSG(_(e_usingsid));
goto theend;
}
- sprintf((char *)sid_buf, "%ld_", (long)current_SID);
+ sprintf((char *)sid_buf, "%ld_", (long)current_sctx.sc_sid);
lead += (int)STRLEN(sid_buf);
}
}
@@ -2454,7 +2455,8 @@
flags |= FC_SANDBOX;
fp->uf_flags = flags;
fp->uf_calls = 0;
- fp->uf_script_ID = current_SID;
+ fp->uf_script_ctx = current_sctx;
+ fp->uf_script_ctx.sc_lnum += sourcing_lnum - newlines.ga_len - 1;
goto ret_free;
erret: