convert <SNR>##_ to a filename

5 views
Skip to first unread message

Ernie Rael

unread,
Feb 25, 2023, 1:26:43 PM2/25/23
to vim...@googlegroups.com

I'm playing around with putting a stacktrace in a log file. I probably want to include the script file name. Example stacktrace is

<SNR>31_Baz[1]
<SNR>31_Bar[1]
function <SNR>31_Foo[1]
script /home/err/play/xxx.vim[27]

I tried

expand("<SNR>31")

I see ":scriptnames", and I just found scriptnames-dictionary, so I guess that's the route to take. I suppose if I encounter a <SNR> that's not in cached dictionary, I should run it again. Unless of course there's some builtin support since scriptnames-dictionary was written that I can't find.

Is a patch to eval.txt of interest to use a vim9 function instead?

-ernie

Bram Moolenaar

unread,
Feb 25, 2023, 5:23:52 PM2/25/23
to vim...@googlegroups.com, Ernie Rael
There actually is getscriptinfo(). Have a look at it, parsing the
output of :scriptnames might not be needed.

I'll mention getscriptinfo() in a couple of places, it is not so easy to
find.

--
Rule #1: Don't give somebody a tool that he's going to hurt himself with.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Ernie Rael

unread,
Feb 25, 2023, 6:07:01 PM2/25/23
to vim...@googlegroups.com
On 23/02/25 2:23 PM, Bram Moolenaar wrote:
> Ernie Rael wrote:
>
>> I'm playing around with putting a stacktrace in a log file. I probably
>> want to include the script file name. Example stacktrace is
>>
>> <SNR>31_Baz[1]
>> <SNR>31_Bar[1]
>> function <SNR>31_Foo[1]
>> script /home/err/play/xxx.vim[27]
>>
>> I tried
>>
>> expand("<SNR>31")
>>
>> I see ":scriptnames", and I just found scriptnames-dictionary, so I
>> guess that's the route to take. I suppose if I encounter a <SNR> that's
>> not in cached dictionary, I should run it again. Unless of course
>> there's some builtin support since scriptnames-dictionary was written
>> that I can't find.
>>
>> Is a patch to eval.txt of interest to use a vim9 function instead?
> There actually is getscriptinfo(). Have a look at it, parsing the
> output of :scriptnames might not be needed.
>
> I'll mention getscriptinfo() in a couple of places, it is not so easy to
> find.
>
Thanks, perfect. Update PR#12062 to use getscriptinfo().

-ernie

Reply all
Reply to author
Forward
0 new messages