Commits

ZyX_I committed 00cf850

Added s:g.f: cache of feature options

  • Participants
  • Parent commits 4048c16

Comments (0)

Files changed (2)

plugin/frawor.vim

 let s:g.pls={} " Plugin dictionaries
 let s:g.loading={}
 let s:g.features={}
+let s:g.f={
+            \'cons':      {},
+            \'load':      {},
+            \'unload':    {},
+            \'unloadpre': {},
+        \}
 let s:g.dependents={}
 "▶2 Messages
 if v:lang=~?'ru'
                 \'runtimepath': plugdict.runtimepath,
             \}
     let s:g.pls[plid]=plugdict
+    "▲2
     if a:oneload
         call s:F.loadplugin(plid)
     endif
     return r
 endfunction
+"▶1 addcons
+function s:F.addcons(plugdict)
+    for feature in values(s:g.f.cons)
+        if has_key(a:plugdict.dependencies, feature.plid)
+            execute  'function a:plugdict.F._frawor.'.feature.id."(...)\n".
+                        \'    return call(s:g.features.'.feature.id.'.cons, '.
+                        \                '['.a:plugdict.intprefix.']+a:000, '.
+                        \                "{})\n".
+                        \'endfunction'
+        endif
+    endfor
+endfunction
+"▶1 runfeatures
+function s:F.runfeatures(plugdict, key)
+    for feature in values(s:g.f[a:key])
+        if has_key(a:plugdict.dependencies, feature.plid) ||
+                    \has_key(feature, 'ignoredeps')
+            " XXX can't use feature[a:key](a:plugdict) due to the vim bug
+            call call(feature[a:key], [a:plugdict], {})
+        endif
+    endfor
+    " XXX required in order not to copy list
+    return a:plugdict
+endfunction
+"▶1 initfeatures
+function s:F.initfeatures(plugdict)
+    for feature in values(s:g.f.load)
+        if has_key(a:plugdict.dependencies, feature.plid) ||
+                    \has_key(feature, 'ignoredeps')
+            if has_key(feature, 'load')
+                let d={}
+                let d.Result=feature.load(a:plugdict)
+                let a:plugdict.features[feature.id]=
+                            \((d.Result is 0)?({}):(d.Result))
+            elseif has_key(feature, 'init')
+                let a:plugdict.features[feature.id]=deepcopy(feature.init)
+            endif
+        endif
+    endfor
+endfunction
 "▶1 addfeature
 function s:F.addfeature(plugdict, feature)
     "▶2 Feature provides constructed function
     endwhile
     return ordered
 endfunction
-"▶1 runfeatures
-function s:F.runfeatures(plugdict, key)
-    for feature in values(s:g.features)
-        if has_key(feature, a:key) && (has_key(a:plugdict.dependencies,
-                    \                          feature.plid) ||
-                    \                  has_key(feature, 'ignoredeps'))
-            " XXX can't use feature[a:key](a:plugdict) due to the vim bug
-            call call(feature[a:key], [a:plugdict], {})
-        endif
-    endfor
-    " XXX required in order not to copy list
-    return a:plugdict
-endfunction
 "▶1 unloadplugin
 function s:F.unloadplugin(plid)
     "▶2 Get plugdict
             \  'id': 'newfeature',
             \'init': {},
         \}
+let s:g.f.cons.newfeature=s:g.features.newfeature
+let s:g.f.load.newfeature=s:g.features.newfeature
+let s:g.f.unload.newfeature=s:g.features.newfeature
 function s:g.features.newfeature.cons(plugdict, fid, fopts)
     if type(a:fid)!=type("")
         call s:F._frawor.throw('fidnotstr', a:plugdict.id)
         if has_key(a:fopts, key)
             call s:F.isfunc(a:fopts[key], key, a:fid, feature.plid)
             let feature[key]=a:fopts[key]
+            let s:g.f[key][a:fid]=feature
         endif
     endfor
     if has_key(a:fopts, 'ignoredeps')
         let feature.ignoredeps=1
     endif
+    if has_key(a:fopts, 'init')
+        let feature.init=a:fopts.init
+        let s:g.f.load[a:fid]=feature
+    endif
     let a:plugdict.features.newfeature[a:fid]=feature
     let s:g.features[a:fid]=feature
     if has_key(feature, 'ignoredeps')
             endfor
         endif
         unlet s:g.features[feature.id]
+        for featdict in values(s:g.f)
+            if has_key(featdict, feature.id)
+                unlet featdict[feature.id]
+            endif
+        endfor
     endfor
 endfunction
 "▶1 Plugin registration
 endfunction
 call s:F._frawor.newfeature('throw', {'cons': s:F.throw})
 
+"▶1
+runtime! plugin/frawor/*.vim
 " vim: fmr=▶,▲ sw=4 ts=4 sts=4 et tw=80
 

test/reload-frawor.ok

 unloadpre: plugin/frawor
 unload: plugin/frawor/functions
 unload: plugin/ignoredeps-feature
+load: plugin/frawor/functions
 load: plugin/frawor
 load: plugin/writefile-feature
-load: plugin/ignoredeps-feature
-load: plugin/frawor/functions
+load: plugin/ignoredeps-feature