aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval/userfunc.c2
-rw-r--r--src/nvim/ex_eval.c21
-rw-r--r--src/nvim/ex_eval_defs.h6
-rw-r--r--src/nvim/runtime.c4
4 files changed, 24 insertions, 9 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 83be330592..c527c70be0 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -1015,7 +1015,7 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett
sandbox++;
}
- estack_push_ufunc(ETYPE_UFUNC, fp, 1);
+ estack_push_ufunc(fp, 1);
if (p_verbose >= 12) {
++no_wait_return;
verbose_enter_scroll();
diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c
index 0d10be2a97..66c782d12e 100644
--- a/src/nvim/ex_eval.c
+++ b/src/nvim/ex_eval.c
@@ -275,6 +275,11 @@ bool cause_errthrow(const char *mesg, bool severe, bool *ignore)
(*msg_list)->throw_msg = tmsg;
}
}
+
+ // Get the source name and lnum now, it may change before
+ // reaching do_errthrow().
+ elem->sfile = estack_sfile();
+ elem->slnum = SOURCING_LNUM;
}
return true;
}
@@ -289,6 +294,7 @@ static void free_msglist(msglist_T *l)
while (messages != NULL) {
next = messages->next;
xfree(messages->msg);
+ xfree(messages->sfile);
xfree(messages);
messages = next;
}
@@ -478,11 +484,18 @@ static int throw_exception(void *value, except_type_T type, char *cmdname)
}
excp->type = type;
- excp->throw_name = estack_sfile();
- if (excp->throw_name == NULL) {
- excp->throw_name = xstrdup("");
+ if (type == ET_ERROR && ((msglist_T *)value)->sfile != NULL) {
+ msglist_T *entry = (msglist_T *)value;
+ excp->throw_name = entry->sfile;
+ entry->sfile = NULL;
+ excp->throw_lnum = entry->slnum;
+ } else {
+ excp->throw_name = estack_sfile();
+ if (excp->throw_name == NULL) {
+ excp->throw_name = xstrdup("");
+ }
+ excp->throw_lnum = SOURCING_LNUM;
}
- excp->throw_lnum = SOURCING_LNUM;
if (p_verbose >= 13 || debug_break_level > 0) {
int save_msg_silent = msg_silent;
diff --git a/src/nvim/ex_eval_defs.h b/src/nvim/ex_eval_defs.h
index 75150d6da4..9da0c9ad12 100644
--- a/src/nvim/ex_eval_defs.h
+++ b/src/nvim/ex_eval_defs.h
@@ -38,11 +38,13 @@ enum {
/// A list of error messages that can be converted to an exception. "throw_msg"
/// is only set in the first element of the list. Usually, it points to the
/// original message stored in that element, but sometimes it points to a later
-/// message in the list. See cause_errthrow() below.
+/// message in the list. See cause_errthrow().
typedef struct msglist msglist_T;
struct msglist {
- char *msg; ///< original message
+ char *msg; ///< original message, allocated
char *throw_msg; ///< msg to throw: usually original one
+ char *sfile; ///< value from estack_sfile(), allocated
+ linenr_T slnum; ///< line number for "sfile"
msglist_T *next; ///< next of several messages in a row
};
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
index c9b5051a30..8299f8ec45 100644
--- a/src/nvim/runtime.c
+++ b/src/nvim/runtime.c
@@ -80,9 +80,9 @@ estack_T *estack_push(etype_T type, char *name, linenr_T lnum)
}
/// Add a user function to the execution stack.
-void estack_push_ufunc(etype_T type, ufunc_T *ufunc, linenr_T lnum)
+void estack_push_ufunc(ufunc_T *ufunc, linenr_T lnum)
{
- estack_T *entry = estack_push(type,
+ estack_T *entry = estack_push(ETYPE_UFUNC,
(char *)(ufunc->uf_name_exp != NULL
? ufunc->uf_name_exp : ufunc->uf_name),
lnum);