Commits

ZyX_I committed 800765a

@/functions: Fixed 3-tuple function key value handling
Added test for it

  • Participants
  • Parent commits b1df018

Comments (0)

Files changed (8)

File autoload/frawor/functions.vim

                     \                 '|| v:val<0'))
             call s:_f.throw('1nver', a:fname, a:plugdict.id)
         endif
-        call a:plugdict.g._f.require(a:funopts.function[0],
-                    \                a:funopts.function[1], 1)
-        if !has_key(s:aufunctions, a:funopts.function[0])
-            call s:_f.throw('nodep', a:fname, a:plugdict.id,
-                        \   a:funopts.function[0])
-        elseif !has_key(s:aufunctions[a:funopts.function[0]].functions,
-                    \   a:funopts.function[2])
+        let dplid=a:plugdict.g._f.require(a:funopts.function[0],
+                    \                     a:funopts.function[1], 1, 1)
+        if !has_key(s:aufunctions, dplid)
+            call s:_f.throw('nodep', a:fname, a:plugdict.id, dplid)
+        elseif !has_key(s:aufunctions[dplid].functions, a:funopts.function[2])
             call s:_f.throw('nofun', a:fname, a:plugdict.id,
-                        \   a:funopts.function[2], a:funopts.function[0])
+                        \   a:funopts.function[2], dplid)
         endif
-        let funopts=s:aufunctions[a:funopts.function[0]].functions
-        let fundefext=s:F.fundef(s:aufunctions[a:funopts.function[0]].plugdict,
-                    \            funopts, fundefext, a:fname)
+        let funopts=s:aufunctions[dplid].functions[a:funopts.function[2]]
+        let fundefext=s:F.fundef(s:aufunctions[dplid].plugdict, funopts,
+                    \            fundefext, a:fname)
         call extend(decdeps, fundefext.decdeps)
-        let sid=s:aufunctions[a:funopts.function[0]].sid
+        let sid=s:aufunctions[dplid].sid
     else
         let sid=a:plugdict.sid
     endif
                 \'plid': a:plugdict.id,}
     let fdicts.nextid+=1
     let fdicts[fundef.id]=fundef
-    "▶2 Add `function' key
     let fundef=s:F.fundef(a:plugdict, a:funopts, fundef, a:fname)
-    "▲2
-    let decs=map(filter(keys(a:funopts), 'v:val[0] is# "@"'),
+    let decs=map(filter(keys(fundef), 'v:val[0] is# "@"'),
                 \'s:_r.getdecorator(v:val[1:])')
     if empty(decs) && fname is# 'fundef.cons'
         let fundef.cons=fundef.function
             let decplugdict=fundef.decdeps[decorator.id]
             "▶2 Check existance of decorator definer in dependencies
             if !has_key(decplugdict.dependencies, decorator.plid)
-                call s:_f.throw('decndep', a:fname, a:plugdict.id,
-                            \              decorator.id)
+                call s:_f.throw('decndep', a:fname, a:plugdict.id, decorator.id)
             endif
             "▲2
             call add(fblocks, decorator.func(decplugdict, fname,
-                        \                    a:funopts['@'.decorator.id]))
+                        \                    fundef['@'.decorator.id]))
             "▶2 Check decorator return value
             if type(fblocks[-1])!=type([])
                         \|| len(fblocks[-1])!=6

File doc/frawor.txt

         `Frawor:{plid}:{msgid}:{message}' where {message} is a value returned 
         by |frawor-f-warn|. Semicolon and backslash in {plid} and {msgid} will 
         be escaped.
-require : function ({plid}, {dversion}, {throw}) → 0..2     *frawor-f-require*
+                                                             *frawor-f-require*
+require : function ({plid}, {dversion}, {throw}[, {plidreturn}]) → 0..2 | plid
         Loads plugin {plid} and makes it dependency of the caller, also 
         running all its features. {throw} argument determines what should be 
         done if frawor failed to load requested plugin: if it is 1, then 
         `Frawor:plugin/frawor:reqfailed' exception will be thrown, otherwise 
         0 will be returned. 2 is returned when requested dependency was 
         already added and 1 indicates that dependency was successfully loaded.
+        If {plidreturn} is present and is 1 then.
 newfeature : function ({fid}, {fopts})                   *frawor-f-newfeature*
            + unload
         Registers plugin feature with id {fid} ({fid} must contain only 
     0.3: Added isftplugin key to |frawor-t-plugdict|,
          adjusted the way plugin type is determined.
     1.0: Removed twoload feature and s:_loading variable.
+    1.1: Added {plidreturn} argument to |frawor-f-require|.
 @/mappings:
     0.1: Added possibility to specify dictionaries in `strfunc' and `func' 
          keys.

File frawor-addon-info.txt

         "test/rtp/plugin/plid-expansion.vim",
         "test/rtp/plugin/plid-expansion/exptest.vim",
         "test/rtp/plugin/plugin-depends-on-plugin-with-feature.vim",
+        "test/rtp/plugin/plugin-with-autoload-function.vim",
         "test/rtp/plugin/plugin-with-dependencies.vim",
         "test/rtp/plugin/plugin-with-feature-1.vim",
         "test/rtp/plugin/plugin-with-feature-2.vim",

File plugin/frawor.vim

                 \                'быть непустым списком '.
                 \                'целых неотрицательных чисел',
                 \  'thrownbool': 'Ошибка добавления зависимости %s '.
-                \                'дополнения %s: последний аргумент '.
+                \                'дополнения %s: последний обязательный '.
+                \                'аргумент должен быть нулём или единицей',
+                \  'plidrnbool': 'Ошибка добавления зависимости %s '.
+                \                'дополнения %s: необязательный аргумент '.
                 \                'должен быть нулём или единицей',
             \}
 else
                 \                'to plugin %s: plugin version should be '.
                 \                'a non-empty list of non-negative integers',
                 \  'thrownbool': 'Error while adding dependency %s '.
-                \                'to plugin %s: last argument should be '.
+                \                'to plugin %s: last required argument '.
+                \                'should be either 0 or 1',
+                \  'plidrnbool': 'Error while adding dependency %s '.
+                \                'to plugin %s: optional argument should be '.
                 \                'either 0 or 1',
             \}
 endif
 let s:features[s:newfeature.id]=s:newfeature
 let s:featordered.all+=[s:newfeature]
 "▶1 Plugin registration
-call s:F.newplugin([1, 0], s:Eval('+matchstr(expand("<sfile>"), ''\d\+'')'),
+call s:F.newplugin([1, 1], s:Eval('+matchstr(expand("<sfile>"), ''\d\+'')'),
             \      expand('<sfile>:p'), {}, s:)
 let s:shadow[s:_frawor.id].features.newfeature.newfeature=s:newfeature
 unlet s:newfeature
 endfunction
 call s:_f.newfeature('throw', {'cons': s:F.throw})
 "▶1 require feature :: {f}, plid, version, throw → + plugdict
-function s:F.require(plugdict, fdict, dplid, dversion, throw)
+function s:F.require(plugdict, fdict, dplid, dversion, throw, ...)
     "▶2 Check arguments
     if type(a:dplid)!=type('') || empty(a:dplid)
         call s:_f.throw('plidnstr', a:plugdict.id)
         call s:_f.throw('invplversion', a:dplid, a:plugdict.id)
     elseif type(a:throw)!=type(0)
         call s:_f.throw('thrownbool', a:dplid, a:plugdict.id)
+    elseif a:0 && type(a:1)!=type(0)
+        call s:_f.throw('plidrnbool', a:dplid, a:plugdict.id)
     endif
     "▲2
     let dplid=s:F.expandplid(a:dplid, a:plugdict.id)
     if has_key(a:plugdict.dependencies, dplid)
-        return 2
+        return (a:0 && a:1 ? dplid : 2)
     endif
     "▶2 Add dependency
     unlockvar 1 a:plugdict.dependencies
                                 \'v:val.load(a:plugdict, fdicts[v:val.name])')
                 endif
                 call s:F.runfeatures(a:plugdict, 'depadd', dplid)
-                return 1
+                return (a:0 && a:1 ? dplid : 1)
             endif
         else
             if a:throw
         endif
     endfor
     call s:F.runfeatures(a:plugdict, 'depadd', dplid)
-    return 1
+    return (a:0 && a:1 ? dplid : 1)
 endfunction
 call s:_f.newfeature('require', {'cons': s:F.require})
 "▶1 Load modules with ignoredeps features

File test/plugin-requesting-autoload-function.in

+:let &rtp.=",".escape($TESTDIR, ',\').'/rtp'
+:let g:testfile="plugin/".g:curtest.".vim"
+:source test.vim

File test/plugin-requesting-autoload-function.ok

+In tracerun for fundef.cons
+Calling fundef.cons
+Finished fundef.cons

File test/rtp/plugin/plugin-requesting-autoload-function.vim

+execute frawor#Setup('0.0', {'@/functions': '0.1'})
+let s:F.func=s:_f.wrapfunc({'function': ['@plugin-with-autoload-function', [0, 0], 'tracedfunc']})
+call s:F.func()

File test/rtp/plugin/plugin-with-autoload-function.vim

 execute frawor#Setup('0.0', {'@/functions': '0.1',
             \               '@/decorators': '0.0',
             \'@plugin-with-autoload-function': '0.0'})
-function s:F.tracerun(plugdict, fname)
+function s:F.tracerun(plugdict, fname, ...)
     call WriteFile('In tracerun for '.a:fname)
     return [0, '@@@', 0, ['try',
                 \           'call WriteFile("Calling '.a:fname.'")'],
     return a:0 == 1 ? a:1 : a:000
 endfunction
 call s:_f.adddecorator('tracerun', s:F.tracerun)
-let s:_autoload={
-            \'tracedfunc': {'function': s:F.func, '@tracerun': []},
-        \}
+let s:_aufunctions.tracedfunc={'function': s:F.func, '@tracerun': []}