Commits

ZyX_I committed eabf79d

Improved frawor/functions checker/filter handling

Comments (0)

Files changed (1)

plugin/frawor/functions.vim

         return function(fstr)
     endif
 endfunction
+"▶1 delfunction
+function s:F.delfunction(sid, Fref)
+    let fstr=s:F.rewritefname(a:sid, a:Fref)
+    if string(+fstr)==#fstr
+        continue
+    endif
+    try
+        execute 'delfunction '.fstr
+    catch /^Vim(delfunction):E130:/
+        " Ignore «Unknown function» error
+    catch /^Vim(delfunction):E131:/
+        " Normally you should catch this error for FraworUnload function, so 
+        " it has bang
+    endtry
+endfunction
 "▶1 delfunctions
 function s:F.delfunctions(plugdict)
     let d={}
         if type(d.Function)!=2
             continue
         endif
-        let fstr=s:F.rewritefname(a:plugdict.sid, d.Function)
-        if string(+fstr)==#fstr
-            continue
-        endif
-        try
-            execute 'delfunction '.fstr
-        catch /^Vim(delfunction):E130:/
-            " Ignore «Unknown function» error
-        catch /^Vim(delfunction):E131:/
-            " Normally you should catch this error for FraworUnload function, so 
-            " it has bang
-        endtry
+        call s:F.delfunction(a:plugdict.sid, d.Functon)
+    endfor
+    for fdef in values(a:plugdict.features.addextfunctions)
+        call s:F.delfunction(a:plugdict.sid, fdef.function)
+        for key in ["checker", "filter"]
+            if has_key(fdef, key)
+                call s:F._frawor['del'.key](fdef[key])
+            endif
+        endfor
     endfor
 endfunction
 call s:F._frawor.newfeature('delfunctions', {'unloadpre': s:F.delfunctions,
     elseif type(a:fopts.function)!=2
     endif
     "▲2
+    "▶2 Replace s: prefix with <SNR>{SID}_
+    let fname=a:fname
+    if fname[:1]==#'s:'
+        let fname=printf(s:g.sidfpref, a:plugdict.sid).fname[2:]
+    endif
+    "▲2
     let fdicts=eval(a:fdictsname)
-    let fdef  =   {"id": a:fname,
+    let fdef  =   {"id":   fname,
                 \"plid": a:plugdict.id}
     let fdicts[fdef.id]=fdef
     "▶2 Add 'function', 'checker' and 'filter' keys
                 let d.carg=a:fopts[key]
             endif
             let [id, fopts[key]]=call(s:F._frawor["add".key], [d.carg])
-            call add(a:plugdict.features.addextfunctions[key], id)
+            let fdef[key]=id
         endif
     endfor
     "▶2 Add 'altervars' key
     let indent=""
     let fpref=a:fdictsname.'["'.a:fname.'"]' " Contains function options name
     "▲2
-    let func="function ".a:fname."(...)\n"   " Contains function string
+    let func="function ".fname."(...)\n"   " Contains function string
     "▶2 Process `altervars' key
     if has_key(fdef, 'altervars')
         let func.=indent."let d={}\n".
         let func.=indent."endtry\n"
     endif
     "▲2
+    execute func
+    let fdef.function=((stridx(fname, '.')==-1)?(function(fname)):(eval(fname)))
     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)
                         \                  fdicts[fname].plid)
         endif
         "▲2
-        call s:F.wrapfunc(a:plugdict, d.fopts, 's:g.functions', fname)
+        call s:F.wrapfunc(a:plugdict, d.fopts,
+                    \         'a:plugdict.features.addextfunctions', fname)
     endfor
 endfunction
 call s:F._frawor.newfeature('addextfunctions', {'cons': s:F.addextfunctions,
-            \                                   'init': {'checker': [],
-            \                                             'filter': []},
+            \                                   'init': {},
             \                                 'unload': s:F.delcnf})
 
 "▶1