By throwing an exception you should be able to obtain the full (functions) callstack. I've described part the process in a section of the documentation of my library plugin along with the related functions I provide to decode v:throwpoint
. IIRC, there is another Q/A where I delved more in details about how its works... Found it! And also here.
There are a few limitations: it only returns calling functions. If your function is called only through commands or mappings, you won't see anything useful. It's also extremely slow: do not abuse of the feature.
EDIT: it seems that v:throwpoint
and Vim 8.2.1297 expand('<stack>')
return a string (almost) in the same format. Split it at ..
. Then each element will contain a function name (and may a line number). From there the best way to know where it's defined is with verbose function {funcname}
. The difficulty is that the message will be localized, and sometimes anonymous functions have already been garbage collected (or why I don't use them any more).
My library already takes care of all these issues. I'll eventually upgrade it to use expand('<stack>')
whenever it's possible as I expect better performances.