Created
February 27, 2012 11:15
-
-
Save bouzuya/1923109 to your computer and use it in GitHub Desktop.
vim s:snr() & s:sid() & s:parse_script_names() & s:path_to_snr()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:snr() | |
let sfile = expand('<sfile>') | |
return matchstr(sfile, '<SNR>\zs\d\+\ze_snr$') | |
endfunction | |
function! s:sid() | |
let snr = s:snr() | |
return printf('<SNR>%s_', snr) | |
endfunction | |
function! s:parse_script_names() | |
redir => _ | |
silent! scriptnames | |
redir END | |
let scripts = split(_, '\n') | |
cal map(scripts, 'matchlist(v:val, ''^\s*\(\d*\):\s*\(\S*\)\s*$'')') | |
call filter(scripts, '!empty(v:val)') | |
return map(scripts, '{''snr'': v:val[1], ''path'': v:val[2]}') | |
endfunction | |
function! s:path_to_snr(path) | |
let scripts = s:parse_script_names() | |
call filter(scripts, 'expand(v:val.path) ==# a:path') | |
return empty(scripts) ? '' : scripts[0].snr | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment