Commits

ZyX_I  committed c9ddc27

Added FraworLoad and FraworUnload functions

  • Participants
  • Parent commits 839f1eb

Comments (0)

Files changed (2)

File doc/frawor.txt

 ==============================================================================
 2. Functionality provided                               *frawor-functionality*
 
-Frawor provides the only global function |FraworRegister()| (and 
-|frawor#Setup()| that is wrapper around |FraworRegister()| and just 
-hides some work) that will register your plugin in the framework thus granting 
-access to required features. Almost all features are defined in 
-plugin/frawor/*.vim files.
-
 ------------------------------------------------------------------------------
 2.1. Functions                                              *frawor-functions*
 
         frawor#Setup extension, it won't work with FraworRegister.
         Note: you must |:execute| frawor#Setup, not |:call| it.
 
+FraworLoad({plugin})                                            *FraworLoad()*
+        Load {plugin}. {plugin} argument may be either a plugin ID or plugin 
+        dictionary.
+
+FraworUnload({plugin})                                        *FraworUnload()*
+        Unload {plugin}. {plugin} argument may be either a plugin ID or plugin 
+        dictionary.
+
 ------------------------------------------------------------------------------
 2.2. Commands                                                *frawor-commands*
 

File plugin/frawor.vim

                 \                '«<SNR>_{N}»?)',
                 \  'unotloaded': 'Невозможно выгрузить незагруженное '.
                 \                'дополнение %s',
+                \ 'invplugdict': 'Неправильный словарь с описанием дополнения',
+                \  'invloadarg': 'Неверный тип аргумента FraworLoad',
+                \   'notloaded': 'Дополнение %s не загружено',
+                \'invunloadarg': 'Неверный тип аргумента FraworUnload',
             \}
 else
     let s:g._messages={
                 \                'without replacing `s:'' with `<SNR>_{N})''?)',
                 \  'unotloaded': 'Unable to unload plugin %s that '.
                 \                'is not loaded',
+                \ 'invplugdict': 'Plugin description dictionary is not valid',
+                \  'invloadarg': 'Wrong type of FraworLoad argument',
+                \   'notloaded': 'Plugin %s is not loaded',
+                \'invunloadarg': 'Wrong type of FraworUnload argument',
             \}
 endif
 "▶1 s:Eval
 function s:Eval(expr)
     return eval(a:expr)
 endfunction
+let s:F._functions['s:Eval']=function('s:Eval')
 "▶1 compareversions
 function s:F.compareversions(a, b)
     let len=max([len(a:a), len(a:b)])
 endfunction
 "▶1 loadplugin
 function s:F.loadplugin(plid)
-    if has_key(s:g.loading, a:plid)
-        return 2
+    "▶2 Get plugdict
+    if type(a:plid)==type("")
+        if has_key(s:g.loading, a:plid)
+            return 2
+        endif
+        if !has_key(s:g.pls, a:plid)
+            execute 'runtime! '.fnameescape(a:plid.'.vim')
+        endif
+        if !has_key(s:g.pls, a:plid)
+            return 0
+        endif
+        let plugdict=s:g.pls[a:plid]
+    elseif type(a:plid)==type({})
+        if has_key(a:plid, 'id') && type(a:plid.id)==type("") ||
+                    \s:g.pls[a:plid.id] is a:plid
+            let plugdict=a:plid
+        else
+            call s:F._frawor.throw('inva:plid')
+        endif
+    else
+        call s:F._frawor.throw('invloadarg')
     endif
-    if !has_key(s:g.pls, a:plid)
-        execute 'runtime! '.fnameescape(a:plid.'.vim')
-    endif
-    if !has_key(s:g.pls, a:plid)
-        return 0
-    endif
-    let plugdict=s:g.pls[a:plid]
+    "▲2
     if plugdict.status!=2
         let s:g.loading[a:plid]=1
         let d={}
             "▶2 Adding features to already loaded plugins
             if has_key(plugdict.features, 'newfeature')
                 for feature in values(plugdict.features.newfeature)
-                    call map(((has_key(feature, 'ignoredeps'))?
+                    call map(filter(((has_key(feature, 'ignoredeps'))?
                                 \       (values(s:g.pls)):
                                 \       (map(keys(get(s:g.dependents,
                                 \                     a:plid, {})),
                                 \            's:g.pls[v:val]'))),
+                                \   'v:val.status==2'),
                                 \'s:F.addfeature(v:val, feature)')
                 endfor
             endif
 endfunction
 "▶1 unloadplugin
 function s:F.unloadplugin(plid)
-    let plugdict=s:g.pls[a:plid]
+    "▶2 Get plugdict
+    if type(a:plid)==type("")
+        if has_key(s:g.pls, a:plid)
+            let plugdict=s:g.pls[a:plid]
+        else
+            call s:F._frawor.throw('notloaded', a:plid)
+        endif
+    elseif type(a:plid)==type({})
+        if has_key(a:plid, 'id') && type(a:plid.id)==type("") ||
+                    \s:g.pls[a:plid.id] is a:plid
+            let plugdict=a:plid
+        else
+            call s:F._frawor.throw('inva:plid')
+        endif
+    else
+        call s:F._frawor.throw('invunloadarg')
+    endif
+    "▲2
     if plugdict.status!=0
         let ordered=s:F.getorderegdeps(plugdict)
         let tosource=map(reverse(copy(ordered)), 'v:val.file')
             call map(keys(plugdict.F), 'remove(plugdict.F, v:val)')
             unlockvar plugdict.status
             let plugdict.status=0
+            lockvar! plugdict.status
             unlet s:g.pls[plugdict.id]
         endfor
         return tosource
     return call(s:F.newplugin, a:000, {})
 endfunction
 let s:F._functions.FraworRegister=function('FraworRegister')
+"▶1 FraworLoad
+function FraworLoad(...)
+    return call(s:F.loadplugin, a:000, {})
+endfunction
+let s:F._functions.FraworLoad=function('FraworLoad')
+"▶1 FraworUnload
+function FraworUnload(...)
+    return call(s:F.unloadplugin, a:000, {})
+endfunction
+let s:F._functions.FraworUnload=function('FraworUnload')
 "▶1 isfunc
 function s:F.isfunc(Func, key, fid, plid)
     if type(a:Func)!=2