Commits

ZyX_I committed c7b516f

Made p:_functions variable be similar to p:_augroups and p:_commands

  • Participants
  • Parent commits 66dab11

Comments (0)

Files changed (8)

File autoload/frawor.vim

     finish
 endif
 let s:F={}
-let s:_functions={}
+let s:_functions=[]
 function s:Eval(expr)
     return eval(a:expr)
 endfunction
-let s:_functions['s:Eval']=function('s:Eval')
+let s:_functions+=['s:Eval']
 "▶1 frawor#Setup      :: version, dependencies[, oneload] → vimlstr
 function frawor#Setup(version, dependencies, ...)
     if type(a:version)==type('')
                 \.                                              "'\\m\\d\\+')\n"
                 \."    let s:_sfile=expand('<sfile>:p')\n"
                 \."    let s:F={}\n"
-                \."    let s:_functions={'s:Eval': function('s:Eval')}\n"
+                \."    let s:_functions=['s:Eval']\n"
                 \."    call FraworRegister(".string(ver).", "
                 \.                               "s:_sid, s:_sfile, ".dstr.", "
                 \.                                oneload.", s:)\n"
                 \."    finish\n"
                 \."endif\n"
 endfunction
-let s:_functions['frawor#Setup']=function('frawor#Setup')
+let s:_functions+=['frawor#Setup']
 "▶1 frawor#Reload     :: Either plugdict plid → + :source
 function! frawor#Reload(plid)
     for file in FraworUnload(a:plid)
         endif
     endfor
 endfunction
-let s:_functions['frawor#Reload']=function('frawor#Reload')
+let s:_functions+=['frawor#Reload']
 "▶1 frawor#Lockvar    :: p:, varnamelist → + :lockvar
 function frawor#Lockvar(s, nolock)
     let nolock=split(a:nolock, ",")
         lockvar! a:s[varname]
     endfor
 endfunction
-let s:_functions['frawor#Lockvar']=function('frawor#Lockvar')
+let s:_functions+=['frawor#Lockvar']
 "▶1 Plugin registration
 if !exists('*FraworRegister')
     runtime! plugin/frawor.vim

File doc/frawor.txt

         2. It creates s:Eval function which is just a wrapper to |eval()|. 
            Useful inside mappings because they have no direct access to script 
            variables and for obtaining |<SID>| value.
-        3. It creates s:F variable containing a dictionary, s:_functions 
-           (also a dictionary) and s:_functions['s:Eval'] (contains 
-           reference to s:Eval function).
+        3. It creates s:F variable containing a dictionary, s:_functions list 
+           containng string "s:Eval".
         4. Creates s:_sid variable containing your plugin script id.
         5. If s:_sfile variable does not exist, sets it to plugin filename.
         6. Calls |FraworRegister()|, passing it transformed {version}, s:_sid, 
 3.2. plugin/frawor/functions features              *frawor-f-frawor/functions*
 
 delfunctions : unloadpre + s:_functions              *frawor-f-delfunctions*
-        Deletes all non-anonymous functions in s:_functions dictionary 
-        before plugin is unloaded. It is |frawor-fk-ignoredeps| feature, so 
-        you don't need specify plugin/frawor/functions in your dependencies.
+             + register + s:_functions
+        Deletes all non-anonymous functions in s:_functions list before plugin 
+        is unloaded. It is |frawor-fk-ignoredeps| feature, so you don't need 
+        specify plugin/frawor/functions in your dependencies.
         Usage (assuming that you executed |frawor#Setup()|): >
             function Foo()
                 " some code here
             endfunction
-            let s:_functions.Foo=function("Foo")
+            let s:_functions+=['Foo']
 <                                                   *frawor-f-addextfunctions*
-addextfunctions : function ({ {funcname}: {funcdescr} }) + s:_functions
+addextfunctions : function ({ {funcname}: {funcdescr} })
                 + unload
         Adds external functions. Each {funcname} must be a valid function name 
         (names that start with s: are also supported, though it is probably 
-        better to just use `let s:_functions['s:Func']=function('s:Func')' 
-        after each plugin-local function definition). This feature will throw 
-        an error if function is already defined. {funcdescr} is described in 
+        better to just use `let s:_functions+=['s:Func']' after each 
+        plugin-local function definition). This feature will throw an error if 
+        function is already defined. {funcdescr} is described in 
         |frawor-t-funcdescr|.
                                                            *frawor-f-wrapfunc*
 wrapfunc : function ({funcdescr})
                                   used by |frawor-f-delaugroups|.
 *s:_commands*      frawor/commands  List of strings containing command names. 
                                   Is used by |frawor-f-delcommands|.
-*s:_functions*     frawor/functions Dictionary containing references to global 
-                                  and script-local functions as values. Is 
+*s:_functions*     frawor/functions List containing references to global and 
+                                  script-local functions or their names. Is 
                                   used by |frawor-f-delfunctions| and set by 
                                   |frawor#Setup()|.
 *s:_r*             frawor/resources Dictionary containing resources posted by 

File plugin/frawor.vim

 endif
 "▶1 Variable initialization
 let s:F={}
-let s:_functions={}
+let s:_functions=[]
 "▶2 s:
 let s:selfdeps={}
 let s:pls={} " Plugin dictionaries
 function s:Eval(expr)
     return eval(a:expr)
 endfunction
-let s:_functions['s:Eval']=function('s:Eval')
+let s:_functions+=['s:Eval']
 "▶1 expandplid      :: String → plid
 let s:prefixes={
             \'@/': 'plugin/frawor/',
 endfunction
 "▶1 getordereddeps  :: plugdict + s:dependents → [plugdict]
 function s:F.getordereddeps(plugdict)
-    let deps=sort(s:F.getdeps(a:plugdict, {}), s:_functions['s:DepComp'])
+    let deps=sort(s:F.getdeps(a:plugdict, {}), function('s:DepComp'))
     let ordered=[]
     let withdeps=[]
     call map(deps, 'add(((empty(get(s:dependents, v:val.id, {})))?'.
                 \       (1):
                 \       (-1))))
 endfunction
-let s:_functions['s:DepComp']=function('s:DepComp')
+let s:_functions+=['s:DepComp']
 "▶1 unloadplugin    :: Either plugdict plid + … → [filename]
 " Returns a list of files that should be sourced to load plugin back
 function s:F.unloadplugin(plid)
 function FraworRegister(...)
     return call(s:F.newplugin, a:000, {})
 endfunction
-let s:_functions.FraworRegister=function('FraworRegister')
+let s:_functions+=['FraworRegister']
 "▶1 FraworLoad
 function FraworLoad(...)
     return call(s:F.loadplugin, a:000, {})
 endfunction
-let s:_functions.FraworLoad=function('FraworLoad')
+let s:_functions+=['FraworLoad']
 "▶1 FraworUnload
 function! FraworUnload(...)
     return call(s:F.unloadplugin, a:000, {})
 endfunction
-let s:_functions.FraworUnload=function('FraworUnload')
+let s:_functions+=['FraworUnload']
 "▶1 isfunc          :: funcref, key, fid, plid → + throw
 function s:F.isfunc(Func, key, fid, plid)
     if type(a:Func)!=2

File plugin/frawor/functions.vim

 endif
 "▶1 rewritefname    :: sid, Funcref → funcname
 function s:F.rewritefname(sid, Fref)
-    let fstr=string(a:Fref)[10:-3]
+    if type(a:Fref)==2
+        let fstr=string(a:Fref)[10:-3]
+    else
+        let fstr=a:Fref
+    endif
     if fstr[:1]==#'s:'
         let fstr='<SNR>'.a:sid.'_'.fstr[2:]
     elseif fstr[:4]==#'<SID>'
 endfunction
 "▶1 delextfunctions :: {f} + p:_functions → + p:_functions, …
 function s:F.delextfunctions(plugdict, fdict)
-    let d={}
     if has_key(a:plugdict.g, '_functions') &&
-                \type(a:plugdict.g._functions)==type({})
+                \type(a:plugdict.g._functions)==type([])
+        let d={}
         unlockvar a:plugdict.g._functions
-        for [key, d.Function] in items(a:plugdict.g._functions)
-            if type(d.Function)!=2
+        for d.Function in a:plugdict.g._functions
+            if type(d.Function)!=2 && type(d.Function)!=type('')
                 continue
             endif
-            if s:F.delfunction(a:plugdict.sid, d.Function)
-                unlet a:plugdict.g._functions[key]
-            endif
+            call s:F.delfunction(a:plugdict.sid, d.Function)
         endfor
     endif
 endfunction
+"▶1 add_functions   :: {f} → + p:_functions
+function s:F.add_functions(plugdict, fdict)
+    if !has_key(a:plugdict.g, '_functions') ||
+                \type(a:plugdict.g._functions)!=type([])
+        let a:plugdict.g._functions=[]
+    endif
+endfunction
 call s:_f.newfeature('delfunctions', {'unloadpre': s:F.delextfunctions,
+            \                          'register': s:F.add_functions,
             \                        'ignoredeps': 1})
 "▶1 decsort
 function s:Decsort(a, b)
     endif
     return ((a>b)?(-1):(1))
 endfunction
-let s:_functions['s:Decsort']=function('s:Decsort')
+let s:_functions+=['s:Decsort']
 "▶1 beatycode       :: function::[String] → function::[String]
 let s:indents={
             \         'if': [ 0, 1],
         endif
         call extend(fblocks[-1], [decorator.id, decorator.pref], 0)
     endfor
-    call sort(fblocks, s:_functions['s:Decsort'])
+    call sort(fblocks, function('s:Decsort'))
     let end=[]
     let d={}
     let fvar="_.F"

File plugin/frawor/mappings.vim

     endif
     call call(s:F.maprun, mrargs, {})
 endfunction
-let s:_functions['s:opfunc']=function('s:opfunc')
+let s:_functions+=['s:opfunc']
 "▶1 getchar       :: + {input} → String
 function s:F.getchar()
     let r=getchar()

File test/rtp/plugin/augroup.vim

 function s:Entered(...)
     call WriteFile(join(a:000).': '.expand('<amatch>'))
 endfunction
-let s:_functions['s:Entered']=function('s:Entered')
+let s:_functions+=['s:Entered']
 function s:F.entered(...)
     return call('s:Entered', a:000)
 endfunction

File test/rtp/plugin/global-function.vim

 function TestFunction()
     echo 1
 endfunction
-let s:_functions.TestFunction=function("TestFunction")
+let s:_functions+=['TestFunction']
 
 function s:testFunction()
     echo 2
 endfunction
-let s:_functions["s:testFunction"]=function("s:testFunction")
+let s:_functions+=['s:testFunction']

File test/rtp/plugin/strfunc-mappings.vim

     call WriteFile('args: ('.string(a:000)[1:-2].')')
     return ""
 endfunction
-let s:_functions['MapFunc']=function('MapFunc')
+let s:_functions+=['MapFunc']
 
 call s:_f.mapgroup.add('Strfunc', {'1': {'rhs': ["%lhs", "%str"],
             \                        'strfunc': s:F.strfunc,
-            \                           'func': s:_functions.MapFunc,
+            \                           'func': function('MapFunc'),
             \                            'lhs': 'a',},
             \                      '2': {'rhs': {'function':
-            \                                    s:_functions.MapFunc},
+            \                                    function('MapFunc')},
             \                        'strfunc': s:F.strfunc,
             \                           'args': ["%lhs", "%str"],
             \                            'lhs': 'b',},