Commits

ZyX_I committed 58399e7

Fixed errors shown by tests

  • Participants
  • Parent commits c9d6c1e

Comments (0)

Files changed (1)

File plugin/frawor/functions.vim

                 \                'описания функции имеет неверную длину %u '.
                 \                '(список должен содержать один или '.
                 \                 'два элемента)',
-                \     'altnstr': 'первый элемент элемента %u значения ключа '.
+                \   'altelnstr': 'первый элемент элемента %u значения ключа '.
                 \                '«altervars» описания функции '.
                 \                'не является строкой',
                 \    'invvname': 'неверен первый элемент элемента %u '.
                 \ 'altelinvlen': 'element %u of `altervars'' value '.
                 \                'of the function description has invalid '.
                 \                'length %u while expected 1 or 2',
-                \     'altnstr': 'first element of element %u of `altervars'' '.
+                \   'altelnstr': 'first element of element %u of `altervars'' '.
                 \                'value of the function description is '.
                 \                'not a string',
                 \    'invvname': 'first element of element %u of `altervars'' '.
 "▶1 delfunction
 function s:F.delfunction(sid, Fref)
     let fstr=s:F.rewritefname(a:sid, a:Fref)
-    if string(+fstr)==#fstr
+    if string(+fstr)==#fstr || (fstr[1]!=#':' && fstr[0]=~#'\l')
         return 3
+    elseif !exists('*'.fstr)
+        return 2
     endif
     try
         execute 'delfunction '.fstr
-    catch /^Vim(delfunction):E130:/
-        " «Unknown function» error
-        return 2
     catch /^Vim(delfunction):E131:/
         " Normally you should catch this error for FraworUnload function, so 
         " it has bang
         return 0
+    catch /^Vim(delfunction):E128:/
     endtry
     return 1
 endfunction
     endif
     if has_key(a:plugdict.features, 'addextfunctions')
         for fdef in values(a:plugdict.features.addextfunctions)
-            if s:F.delfunction(a:plugdict.sid, fdef.function)
+            if s:F.delfunction(a:plugdict.sid, fdef.cons)
                 for key in ["checker", "filter"]
                     if has_key(fdef, key)
                         call call(s:F._frawor['del'.key], [fdef[key]], {})
                     endif
                 endfor
                 unlet a:plugdict.features.addextfunctions[fdef.id]
+                unlet s:g.extfunctions[fdef.id]
             endif
         endfor
     endif
 "▶1 wrapfunc
 function s:F.wrapfunc(plugdict, fopts, fdictsname, fname)
     "▶2 Check a:fopts
-    if type(d.fopts)!=type({})
-        call s:F._frawor.throw('foptsnotdict', a:fname, a:plugdict.id)
-    elseif !has_key(a:fopts, 'function')
+    if !has_key(a:fopts, 'function')
         call s:F._frawor.throw('nofunc', a:fname, a:plugdict.id)
     elseif type(a:fopts.function)!=2
         call s:F._frawor.throw('nref', a:fname, a:plugdict.id, 'functions')
             else
                 let d.carg=a:fopts[key]
             endif
-            let [id, fopts[key]]=call(s:F._frawor["add".key], [d.carg])
+            let [id, a:fopts[key]]=call(s:F._frawor["add".key], [d.carg])
             let fdef[key]=id
         endif
     endfor
         if type(a:fopts.altervars)!=type([])
             call s:F._frawor.throw('altnlst', a:fname, a:plugdict.id)
         endif
-        let fopts.altervars=map(copy(a:fopts.altervars), 'copy(v:val)')
+        let fdef.altervars=map(copy(a:fopts.altervars), 'copy(v:val)')
     endif
     "▶2 Define variables
     let args='a:000'                         " Contains name of variable that 
                                              " holds arguments
-    let indent=""
+    let indent="    "
     let fpref=a:fdictsname.'["'.a:fname.'"]' " Contains function options name
     "▲2
-    let func="function ".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".
                 call s:F._frawor.throw('altelinvlen', a:plugdict.id, a:fname, i,
                             \                         len(fdef.altervars[i]))
             elseif type(fdef.altervars[i][0])!=type("")
-                call s:F._frawor.throw('altnstr', a:plugdict.id, a:fname, i)
+                call s:F._frawor.throw('altelnstr', a:plugdict.id, a:fname, i)
             endif
             "▲3
             let element=fdef.altervars[i]
         let func.=indent."endtry\n"
     endif
     "▲2
+    let func.="endfunction"
     execute func
-    let fdef.function=((stridx(fname, '.')==-1)?(function(fname)):(eval(fname)))
+    let fdef.cons=((stridx(fname, '.')==-1)?(function(fname)):(eval(fname)))
     return fdef
 endfunction
 "▶1 addextfunctions
+let s:g.extfunctions={}
 function s:F.addextfunctions(plugdict, functions)
-    "▶2 Check a:function
-    if type(a:function)!=type({})
+    "▶2 Check a:functions
+    if type(a:functions)!=type({})
         call s:F._frawor.throw('fnotdict', a:plugdict.id)
     endif
     "▲2
     let d={}
-    for [fname, d.fopts] in items(a:function)
+    for [fname, d.fopts] in items(a:functions)
+        "▶2 Check d.fopts
+        if type(d.fopts)!=type({})
+            call s:F._frawor.throw('foptsnotdict', fname, a:plugdict.id)
+        endif
         "▶2 Replace s: prefix with <SNR>{SID}_
         if fname[:1]==#'s:'
             let fname=printf(s:g.sidfpref, a:plugdict.sid).fname[2:]
             endif
         endif
         "▲2
-        call s:F.wrapfunc(a:plugdict, d.fopts,
-                    \         'a:plugdict.features.addextfunctions', fname)
+        let fdef=s:F.wrapfunc(a:plugdict, d.fopts,
+                    \         's:g.extfunctions', fname)
+        let a:plugdict.features.addextfunctions[fdef.id]=fdef
     endfor
 endfunction
 call s:F._frawor.newfeature('addextfunctions', {'cons': s:F.addextfunctions,