Skip to content

Instantly share code, notes, and snippets.

@bouzuya
Created February 27, 2012 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bouzuya/1923109 to your computer and use it in GitHub Desktop.
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()
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