Source

frawor / autoload / frawor.vim

Full commit
"▶1 Header
scriptencoding utf-8
if exists('s:_.pluginloaded') || exists('g:fraworOptions._donotload') ||
            \exists('g:frawor__donotload')
    finish
endif
let s:F={}
let s:_={}
let s:_.functions=[]
function s:Eval(expr)
    return eval(a:expr)
endfunction
let s:_.functions+=['s:Eval']
"▶1 frawor#Setup      :: version, dependencies[, oneload] → vimlstr
function frawor#Setup(version, dependencies, ...)
    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))')
    let dstr=substitute(string(deps), "\n", '''."\\n".''', 'g')
    let oneload=((a:0)?(a:1 isnot 0):(1))
    return       "if !exists('s:_.pluginloaded')\n"
                \."    let s:_={}\n"
                \."    execute \"function s:Eval(expr)\\n"
                \.              "    return eval(a:expr)\\n"
                \.              "endfunction\"\n"
                \."    let s:_.functions=['s:Eval']\n"
                \."    let s:_.sid=+matchstr(s:Eval('expand(\"<sfile>\")'), "
                \.                          "'\\m\\d\\+')\n"
                \."    let s:_.sfile=expand('<sfile>:p')\n"
                \."    let s:_.functions=s:_.functions\n"
                \."    let s:_.sid=s:_.sid\n"
                \."    let s:_.sfile=s:_.sfile\n"
                \."    let s:_.p=s:\n"
                \."    call FraworRegister(".string(ver).", "
                \.                        "s:_.sid, s:_.sfile, ".dstr.", "
                \.                         oneload.", s:_, s:)\n"
                \."    let s:F={}\n"
                \."elseif s:_.pluginloaded\n"
                \."    finish\n"
                \."endif\n"
endfunction
let s:_.functions+=['frawor#Setup']
"▶1 frawor#Reload     :: Either plugdict plid → + :source
function! frawor#Reload(plid)
    for file in FraworUnload(a:plid)
        if file isnot 0
            execute 'source' fnameescape(file)
        endif
    endfor
endfunction
let s:_.functions+=['frawor#Reload']
"▶1 frawor#Lockvar    :: s:, varnamelist → + :lockvar
function frawor#Lockvar(s, nolock)
    let nolock=split(a:nolock, ',')
    for varname in filter(keys(a:s), 'index(nolock, v:val)==-1 && '.
                \                    'v:val isnot# "_"')
        lockvar! a:s[varname]
    endfor
endfunction
let s:_.functions+=['frawor#Lockvar']
"▶1 frawor#_addkey    :: key → vimlstr
function frawor#_addkey(key)
    return substitute(
                \"function s:F.add@@@(plugdict, fdict)\n".
                \"    if (!has_key(a:plugdict.g, '@@@') ||\n".
                \"                \type(a:plugdict.g.@@@)!=type([])) &&\n".
                \"                \!islocked('a:plugdict.g')\n".
                \"        let a:plugdict.g.@@@=[]\n".
                \"    endif\n".
                \"endfunction\n".
                \"call s:_.f.newfeature('del@@@', {'unloadpre': s:F.del@@@, ".
                \                                  "'register': s:F.add@@@, ".
                \                                "'ignoredeps': 1})\n".
                \"unlet s:F.add@@@\n",
                \'\V@@@', a:key, 'g')
endfunction
"▶1 Plugin registration
if !exists('*FraworRegister')
    runtime! plugin/frawor.vim
endif
call FraworRegister([1, 0], s:Eval('+matchstr(expand("<sfile>"), ''\d\+'')'),
            \       expand('<sfile>:p'), {}, 1, s:_, s:)
"▶1
call frawor#Lockvar(s:, '')
" vim: fmr=▶,▲ sw=4 ts=4 sts=4 et tw=80