Source

frawor / autoload / frawor.vim

"▶1 Header
scriptencoding utf-8
if exists('s:_pluginloaded') || exists('g:fraworOptions._donotload') ||
            \exists('g:frawor__donotload')
    finish
endif
let s:F={}
let s:_functions={}
function s:Eval(expr)
    return eval(a:expr)
endfunction
let s:_functions['s:Eval']=function('s:Eval')
"▶1 expandplid     :: String → String
function s:F.expandplid(str)
    return substitute(substitute(substitute(substitute(substitute(a:str,
                \'^@$', 'plugin/frawor',  ''),
                \'^@@', '@',              ''),
                \'^@/', 'plugin/frawor/', ''),
                \'^@:', 'ftplugin/',      ''),
                \'^@',  'plugin/',        '')
endfunction
"▶1 frawor#Setup   :: version, dependencies, oneload → vimlstr
function frawor#Setup(version, dependencies, oneload)
    if type(a:version)==type("")
        let ver=map(split(a:version, '\.'), '+v:val')
    else
        let ver=a:version
    endif
    let deps=map(copy(a:dependencies),
                \'((type(v:val)==type(""))?'.
                \   '(map(split(v:val, "\\."), "+v:val")):'.
                \   '(v:val))')
    for key in keys(deps)
        let deps[s:F.expandplid(key)]=remove(deps, key)
    endfor
    let dstr=substitute(string(deps), "\n", '''."\\n".''', 'g')
    let oneload=(!!a:oneload)
    return       'execute "function s:Eval(expr)\n'.
                \         '    return eval(a:expr)\n'.
                \         "endfunction\"\n".
                \"let s:_sid=+matchstr(s:Eval('expand(\"<sfile>\")'), ".
                \                                               "'\\d\\+')\n".
                \"let s:_realsfile=expand('<sfile>:p')\n".
                \"if !exists('s:_sfile')\n".
                \"    let s:_sfile=s:_realsfile\n".
                \"endif\n".
                \"let s:F={}\n".
                \"let s:_functions={'s:Eval': function('s:Eval')}\n".
                \"call FraworRegister(".string(ver).", ".
                \                               "s:_sid, s:_sfile, ".dstr.", ".
                \                                oneload.", s:)"
endfunction
let s:_functions['frawor#Setup']=function('frawor#Setup')
"▶1 frawor#Reload  :: Either plugdict plid → + :source
function! frawor#Reload(plid)
    for file in FraworUnload(s:F.expandplid(a:plid))
        if file isnot 0
            execute 'source' fnameescape(file)
        endif
    endfor
endfunction
let s:_functions['frawor#Reload']=function('frawor#Reload')
"▶1 frawor#Lockvar :: p:, varnamelist → + :lockvar
function frawor#Lockvar(s, nolock)
    let nolock=split(a:nolock, ",")
    for varname in filter(keys(a:s), 'index(nolock, v:val)==-1')
        lockvar! a:s[varname]
    endfor
endfunction
let s:_functions['frawor#Lockvar']=function('frawor#Lockvar')
"▶1 Plugin registration
if !exists('*FraworRegister')
    runtime! plugin/frawor.vim
endif
call FraworRegister([0, 0], s:Eval('+matchstr(expand("<sfile>"), ''\d\+'')'),
            \       expand('<sfile>:p'), {}, 1, s:)
"▶1
call frawor#Lockvar(s:, '')
" vim: fmr=▶,▲ sw=4 ts=4 sts=4 et tw=80