Commits

ZyX_I committed 9dfece2

Addded `ignoredeps' feature key, added load, unload and unloadpre keys handling into newfeature

Comments (0)

Files changed (2)

                    this feature. Function will be called when dependent plugin 
                    is loaded. If value returned by this function is not 0, then 
                    it will be assigned to plugdict.features[{fid}]
+        init       Any value. Deep copy (|deepcopy()|) of it will be assigned to 
+                   plugdict.features[{fid}]. Note that if `load' key is present, 
+                   then this key will be ignored.
         unload     Reference to a function that will take |frawor-t-plugdict| as
                    its first argument. This function will be called only once 
                    for each plugin that depends on the plugin that registers 
                    is unloaded.
         unloadpre  Just like unload, but function will be called when plugin is 
                    queued for unloading, but nothing was yet unloaded.
-        init       Any value. Deep copy (|deepcopy()|) of it will be assigned to 
-                   plugdict.features[{fid}]. Note that if `load' key is present, 
-                   then this key will be ignored.
+        ignoredeps If this key is present, then load, unload and unloadpre keys 
+                   will be called for all plugins even if they do not specify 
+                   plugin which defined this feature in dependencies (feature 
+                   definer). Key `cons' will be ignored for plugins that do not 
+                   specify feature definer in dependencies.
 
 ==============================================================================
 5. Type definitions                                             *frawor-types*

plugin/frawor.vim

     finish
 endif
 "▶1 Variable initialization
-let s:F={}
+let s:F={'_functions': {}}
 "▶2 s:g
 let s:g={}
 let s:g._pluginloaded=1
                 \ 'foptsnotdct': 'Ошибка регистрации возможности %s '.
                 \                'дополнения %s: описание возможности '.
                 \                'не является словарём',
-                \   'consnfref': 'Ошибка регистрации возможности %s '.
-                \                'дополнения %s: значение ключа «cons» '.
+                \       'nfref': 'Ошибка регистрации возможности %s '.
+                \                'дополнения %s: значение ключа «%s» '.
                 \                'не является ссылкой на функцию',
-                \   'consncall': 'Ошибка регистрации возможности %s '.
-                \                'дополнения %s: значение ключа «cons» '.
-                \                'не может быть вызвано (возможно '.
-                \                'вы пытались создать ссылку на внутренную '.
-                \                'функцию дополнения без раскрытия «s:» в '.
-                \                '«<SNR>_{N}»?)',
-                \   'loadnfref': 'Ошибка регистрации возможности %s '.
-                \                'дополнения %s: значение ключа «load» '.
-                \                'не является ссылкой на функцию',
-                \   'loadncall': 'Ошибка регистрации возможности %s '.
-                \                'дополнения %s: значение ключа «load» '.
+                \       'ncall': 'Ошибка регистрации возможности %s '.
+                \                'дополнения %s: значение ключа «%s» '.
                 \                'не может быть вызвано (возможно '.
                 \                'вы пытались создать ссылку на внутренную '.
                 \                'функцию дополнения без раскрытия «s:» в '.
                 \ 'foptsnotdct': 'Error while registering feature %s '.
                 \                'of a plugin %s: description argument '.
                 \                'is not a Dictionary',
-                \   'consnfref': 'Error while registering feature %s '.
-                \                'of a plugin %s: `cons'' fopts key is not '.
+                \       'nfref': 'Error while registering feature %s '.
+                \                'of a plugin %s: `%s'' fopts key is not '.
                 \                'a function reference',
-                \   'consncall': 'Error while registering feature %s '.
-                \                'of a plugin %s: `cons'' fopts key is not '.
-                \                'callable (perhaps you tried to create '.
-                \                'a reference to a script-local function '.
-                \                'without replacing `s:'' with `<SNR>_{N})''?)',
-                \   'loadnfref': 'Error while registering feature %s '.
-                \                'of a plugin %s: `load'' fopts key is not '.
-                \                'a function reference',
-                \   'loadncall': 'Error while registering feature %s '.
-                \                'of a plugin %s: `load'' fopts key is not '.
+                \       'ncall': 'Error while registering feature %s '.
+                \                'of a plugin %s: `%s'' fopts key is not '.
                 \                'callable (perhaps you tried to create '.
                 \                'a reference to a script-local function '.
                 \                'without replacing `s:'' with `<SNR>_{N})''?)',
 function s:F.addfeature(plugdict, feature)
     "▶2 Feature provides constructed function
     if has_key(a:feature,'cons') && !has_key(a:plugdict.F._frawor, a:feature.id)
+                \&& has_key(a:plugdict.dependencies, a:feature.plid)
         execute  'function a:plugdict.F._frawor.'.a:feature.id."(...)\n".
                     \'    return call(s:g.features.'.a:feature.id.'.cons, '.
                     \                '['.a:plugdict.intprefix."]+a:000, {})\n".
                 else
                     call s:F._frawor.throw('reqfailed', dplid, a:plid)
                 endif
-                if has_key(s:g.pls[dplid].features, 'newfeature')
-                    call map(values(s:g.pls[dplid].features.newfeature),
-                                \'s:F.addfeature(plugdict, v:val)')
+            endfor
+            "▶2 Running features
+            for feature in values(s:g.features)
+                if has_key(plugdict.dependencies, feature.plid) ||
+                            \has_key(feature, 'ignoredeps')
+                    call s:F.addfeature(plugdict, feature)
                 endif
             endfor
             "▲2
             let plugdict.status=2
             lockvar! plugdict.status
             "▶2 Adding features to already loaded plugins
-            if has_key(s:g.dependents, a:plid) &&
-                        \has_key(plugdict.features, 'newfeature')
-                for rplugdict in map(keys(s:g.dependents[a:plid]),
-                            \        's:g.pls[v:val]')
-                    call map(values(plugdict.features.newfeature),
-                                \'s:F.addfeature(rplugdict, v:val)')
+            if has_key(plugdict.features, 'newfeature')
+                for feature in values(plugdict.features.newfeature)
+                    call map(((has_key(feature, 'ignoredeps'))?
+                                \       (values(s:g.pls)):
+                                \       (map(keys(get(s:g.dependents,
+                                \                     a:plid, {})),
+                                \            's:g.pls[v:val]'))),
+                                \'s:F.addfeature(v:val, feature)')
                 endfor
             endif
             "▲2
 "▶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)
+        if has_key(feature, a:key) && (has_key(a:plugdict.dependencies,
+                    \                          feature.plid) ||
+                    \                  has_key(feature, 'ignoredeps'))
             call feature[a:key](a:plugdict)
         endif
     endfor
 endfunction
 let s:F._functions.FraworRegister=function('FraworRegister')
 "▶1 isfunc
-function s:F.isfunc(Func, msgpref, fid, plid)
+function s:F.isfunc(Func, key, fid, plid)
     if type(a:Func)!=2
-        call s:F._frawor.throw(a:msgpref.'nfref', a:fid, a:plid)
+        call s:F._frawor.throw('nfref', a:fid, a:plid, a:key)
     elseif !exists('*a:Func')
-        call s:F._frawor.throw(a:msgpref.'ncall', a:fid, a:plid)
+        call s:F._frawor.throw('ncall', a:fid, a:plid, a:key)
     endif
 endfunction
 "▶1 features.newfeature.cons
 let s:g.features.newfeature={
+            \'plid': 'plugin/frawor',
             \  'id': 'newfeature',
             \'init': {},
         \}
     let feature={}
     let feature.plid=a:plugdict.id
     let feature.id=a:fid
-    if has_key(a:fopts, 'cons')
-        call s:F.isfunc(a:fopts.cons, 'cons', a:fid, feature.plid)
-        let feature.cons=a:fopts.cons
-    endif
-    if has_key(a:fopts, 'load')
-        call s:F.isfunc(a:fopts.load, 'load', a:fid, feature.plid)
-        let feature.load=a:fopts.load
+    for key in ['cons', 'load', 'unload', 'unloadpre']
+        if has_key(a:fopts, key)
+            call s:F.isfunc(a:fopts[key], key, a:fid, feature.plid)
+            let feature[key]=a:fopts[key]
+        endif
+    endfor
+    if has_key(a:fopts, 'ignoredeps')
+        let feature.ignoredeps=1
     endif
     let a:plugdict.features.newfeature[a:fid]=feature
     let s:g.features[a:fid]=feature
 let s:g._frawor=s:F.newplugin([0, 0],
             \       s:Eval('+matchstr(expand("<sfile>"), ''\d\+'')'),
             \       expand('<sfile>:p'), {}, 1, s:g, s:F)
-call s:F.addfeature(s:g.pls[s:g._frawor.id], s:g.features.newfeature)
 let s:g.pls[s:g._frawor.id].features.newfeature.newfeature=
             \                                           s:g.features.newfeature
 "▶1 warn feature