Commits

ZyX_I committed 1ef9191

Added plugin/frawor/checks, made plugin/frawor/functions use it

  • Participants
  • Parent commits 5034b6a

Comments (0)

Files changed (9)

plugin/frawor.vim

 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
 

plugin/frawor/checks.vim

+"▶1 Header
+scriptencoding utf-8
+if exists('s:g._pluginloaded') || exists('g:fraworOptions._donotload') ||
+            \exists('g:fraworOptions__donotload')
+    finish
+endif
+execute frawor#Setup('0.0', {}, 1)
+"▶1 _messages
+if v:lang=~?'ru'
+    let s:g._messages={
+                \'uchecker': 'Ошибка создания проверки для дополнения %s: '.
+                \            'аргумент, описывающий проверку, '.
+                \            'не принадлежит ни к одному из известных типов',
+                \ 'ufilter': 'Ошибка создания фильтра для дополнения %s: '.
+                \            'аргумент, описывающий фильтр, '.
+                \            'не принадлежит ни к одному из известных типов',
+                \'idnotstr': 'Ошибка при обработке запроса на удаление от '.
+                \            'дополнения %s: идентификатор не является строкой',
+            \}
+else
+    let s:g._messages={
+                \'uchecker': 'Error while creating checker for plugin %s: '.
+                \            'unknown check description type',
+                \ 'ufilter': 'Error while creating filter for plugin %s: '.
+                \            'unknown filter description type',
+                \'idnotstr': 'Error while processing delete request from '.
+                \            'plugin %s: ID is not a string',
+            \}
+endif
+"▶1 addchecker
+function s:F.addchecker(plugdict, Chk)
+    let id=string(a:plugdict.features.addchecker.lastid)
+    let a:plugdict.features.addchecker.lastid+=1
+    if type(a:Chk)==2
+        if !has_key(a:plugdict.F, '_checkers')
+            let a:plugdict.F._checkers={}
+        endif
+        let a:plugdict.F._checkers[id]=a:Chk
+        return [id, 'call(s:F._checkers.'.id.', [%s], {})']
+    else
+        call s:F._frawor.throw('uchecker', a:plugdict.id)
+    endif
+endfunction
+call s:F._frawor.newfeature('addchecker', {'cons': s:F.addchecker,
+            \                              'init': {'lastid': 0}})
+"▶1 addfilter
+function s:F.addfilter(plugdict, Chk)
+    let id=string(a:plugdict.features.addfilter.lastid)
+    let a:plugdict.features.addfilter.lastid+=1
+    if type(a:Chk)==2
+        if !has_key(a:plugdict.F, '_filters')
+            let a:plugdict.F._filters={}
+        endif
+        let a:plugdict.F._filters[id]=a:Chk
+        return [id, 'call(s:F._filters.'.id.', [%s], {})']
+    else
+        call s:F._frawor.throw('ufilter', a:plugdict.id)
+    endif
+endfunction
+call s:F._frawor.newfeature('addfilter', {'cons': s:F.addfilter,
+            \                             'init': {'lastid': 0}})
+"▶1 delchecker
+function s:F.delchecker(plugdict, id)
+    if type(a:id)!=type("")
+        call s:F._frawor.throw('idnotstr', a:plugdict.id)
+    endif
+    if has_key(a:plugdict.F, '_checkers') &&
+                \has_key(a:plugdict.F._checkers, a:id)
+        unlet a:plugdict.F._checkers[a:id]
+    endif
+    if has_key(a:plugdict.g, '_checkers') &&
+                \has_key(a:plugdict.g._checkers, a:id)
+        unlet a:plugdict.g._checkers[a:id]
+    endif
+endfunction
+call s:F._frawor.newfeature('delchecker', {'cons': s:F.delchecker})
+"▶1 delfilter
+function s:F.delfilter(plugdict, id)
+    if type(a:id)!=type("")
+        call s:F._frawor.throw('idnotstr', a:plugdict.id)
+    endif
+    if has_key(a:plugdict.F, '_filters') &&
+                \has_key(a:plugdict.F._filters, a:id)
+        unlet a:plugdict.F._filters[a:id]
+    endif
+    if has_key(a:plugdict.g, '_filters') &&
+                \has_key(a:plugdict.g._filters, a:id)
+        unlet a:plugdict.g._filters[a:id]
+    endif
+endfunction
+call s:F._frawor.newfeature('delfilter', {'cons': s:F.delfilter})

plugin/frawor/functions.vim

             \exists('g:fraworOptions__donotload')
     finish
 endif
-execute frawor#Setup('0.0', {}, 1)
+execute frawor#Setup('0.0', {'plugin/frawor/checks': '0.0'}, 1)
 let s:g.sidfpref=substitute(s:Eval('expand("<sfile>")[9:-5]'), s:g._sid,'%u','')
 "▶1 _messages
 if v:lang=~?'ru'
     endif
     return fstr
 endfunction
+"▶1 refunction
+function s:F.refunction(sid, Fref, throwargs)
+    let fstr=s:F.rewritefname(a:sid, a:Fref)
+    if string(+fstr)==#fstr
+        return a:Fref
+    else
+        if !exists('*'.fstr)
+            call call(s:F._frawor.throw, a:throwargs, {})
+        endif
+        return function(fstr)
+    endif
+endfunction
 "▶1 delfunctions
 function s:F.delfunctions(plugdict)
     let d={}
         call s:F._frawor.throw('foptsnotdict', a:fname, a:plugdict.id)
     elseif !has_key(a:fopts, 'function')
         call s:F._frawor.throw('nofunc', a:fname, a:plugdict.id)
+    elseif type(a:fopts.function)!=2
     endif
     "▲2
     let fdicts=eval(a:fdictsname)
                 \"plid": a:plugdict.id}
     let fdicts[fdef.id]=fdef
     "▶2 Add 'function', 'checker' and 'filter' keys
-    for key in ["function", "checker", "filter"]
+    let fdef.function=s:F.refunction(a:plugdict.sid, a:fopts.function,
+                \                    ['uref', a:plugdict.id, 'function',
+                \                             a:fname])
+    let d={}
+    for key in ["checker", "filter"]
         if has_key(a:fopts, key)
-            if type(a:fopts[key])!=2
-                call s:F._frawor.throw('nref', a:fname, a:plugdict.id, key)
+            if type(a:fopts[key])==2
+                let d.carg=s:F.refunction(a:plugdict.sid, a:fopts[key],
+                            \             ['uref', a:plugdict.id, key,
+                            \                      a:fname])
+            else
+                let d.carg=a:fopts[key]
             endif
-            let fstr=s:F.rewritefname(a:plugdict.sid, a:fopts[key])
-            if string(+fstr)!=#fstr
-                if !exists('*'.fstr)
-                    call s:F._frawor.throw('uref', a:plugdict.id, key, a:fname)
-                endif
-                let fdef[key]=function(fstr)
-            else
-                let fdef[key]=a:fopts[key]
-            endif
+            let [id, fopts[key]]=call(s:F._frawor["add".key], [d.carg])
+            call add(a:plugdict.features.addextfunctions[key], id)
         endif
     endfor
     "▶2 Add 'altervars' key
     endif
     "▶2 Process 'checker' and 'filter' keys
     if has_key(fdef, 'checker')
-        let func.=indent."if !call(".fpref.".checker, [".args."], {})\n".
+        let func.=indent."if !".printf(fdef.checker, args)."\n".
                     \indent."    call s:F._frawor.throw('checkfailed', ".
                     \                                   fpref.".id, ".
                     \                                   fpref.".plid)\n".
                     \"endif\n"
     endif
     if has_key(fdef, 'filter')
-        let func.=indent."let args=call(".fpref.".filter, [".args."], {})\n".
+        let func.=indent."let args=".printf(fdef.filter, args)."\n".
                     \indent."if type(args)!=".type([])."\n".
                     \indent."    call s:F._frawor.throw('filterfailed', ".
                     \                                   fpref.".id, ".
     "▲2
     return fdef
 endfunction
+"▶1 delcnf
+function s:F.delcnf(plugdict)
+    for key in ["checker", "filter"]
+        let idlist=a:plugdict.features.addextfunctions[key]
+        while !empty(idlist)
+            call s:F._frawor['del'.key](remove(idlist, 0))
+        endwhile
+    endfor
+endfunction
 "▶1 addextfunctions
 let s:g.functions={}
 function s:F.addextfunctions(plugdict, functions)
         call s:F.wrapfunc(a:plugdict, d.fopts, 's:g.functions', fname)
     endfor
 endfunction
-call s:F._frawor.newfeature('addextfunctions', {'cons': s:F.addextfunctions})
+call s:F._frawor.newfeature('addextfunctions', {'cons': s:F.addextfunctions,
+            \                                   'init': {'checker': [],
+            \                                             'filter': []},
+            \                                 'unload': s:F.delcnf})
 

test/global-functions-reload.ok

 1      echo 1
    endfunction
 
-   function <SNR>6_testFunction()
+   function <SNR>7_testFunction()
 1      echo 2
    endfunction
 
 1      echo 1
    endfunction
 
-   function <SNR>6_testFunction()
+   function <SNR>7_testFunction()
 1      echo 2
    endfunction

test/ignoredeps-feature.ok

 load: plugin/frawor/functions
+load: plugin/frawor/checks
 load: plugin/frawor
 load: plugin/writefile-feature
 load: plugin/ignoredeps-feature

test/reload-frawor.ok

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

test/reload-ignoredeps.ok

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

test/reload-writefile.ok

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

test/unload-self.ok

 load: plugin/frawor/functions
+load: plugin/frawor/checks
 load: plugin/unload-self-feature
 load: plugin/frawor
 load: plugin/unload-self