ZyX_I avatar ZyX_I committed a6a3be9

@/commands: Made it able to delay FWC completion function compilation until plugin is loaded

Comments (0)

Files changed (8)

                      |FWC-o-onlystrings| option will be enabled and "complete" 
                      string will be added to list. If list contains two 
                      strings, then it will be passed to fwc.compile 
-                     unmodified.
+                     unmodified. Like with dictionary, compilation will be 
+                     done only after plugin is loaded.
         splitfunc, rsplitfunc
                   Defines function that will split command-line into a list of 
                   arguments. `splitfunc' is for FWC completion, `rsplitfunc' 

plugin/frawor.vim

 "▶1
 call frawor#Lockvar(s:, 'dependents,features,f,selfdeps,loading,shadow,pls,'.
             \           'rtpcache,dircache')
+" TODO feature redefinition
 " vim: fmr=▶,▲ sw=4 ts=4 sts=4 et tw=80

plugin/frawor/commands.vim

     endif
     return fstr
 endfunction
-"▶1 wrapfunc     :: cmd, fname, fdict → + :function
-function s:F.wrapfunc(cmd, fname, fdict)
-    let a:cmd.f[a:fname[2:]]=call(a:cmd.wrapfunc, [a:fdict], {})
+"▶1 wrapfunc     :: cmd, fname, fdescr → + :function
+function s:F.wrapfunc(cmd, fname, fdescr)
+    if type(a:fdescr)==type({})
+        let a:cmd.f[a:fname[2:]]=call(a:cmd.wrapfunc, [a:fdescr], {})
+        let args='a:000'
+    else
+        let lcomp=len(a:fdescr)
+        if lcomp==1
+            if type(a:fdescr[0])!=type('')
+                call s:_f.throw('1nstr', a:cmd.id, a:cmd.plid)
+            endif
+            let compargs=['-onlystrings '.a:fdescr[0], 'complete']
+        elseif lcomp==2
+            let compargs=a:fdescr
+        else
+            call s:_f.throw('invclen', a:cmd.id, a:cmd.plid)
+        endif
+        let compargs+=[a:cmd.g]
+        unlet a:cmd.g
+        let [a:cmd.f[a:fname[2:]], a:cmd.FWCid]=
+                    \call(s:_f.fwc.compile, compargs, {})
+        let args     = '[call(s:F.splitfunc, '.
+                    \        'a:000'.
+                    \        ((a:cmd.sp is 0)?
+                    \           (', '):
+                    \           ('+[s:commands.'.a:cmd.id.'.sp], ')).
+                    \        '{}).curargs]'
+    endif
     execute      "function ".a:fname."(...)\n"
                 \"    return call(s:commands.".a:cmd.id.".f.".a:fname[2:].", ".
-                \                "a:000, {})\n".
+                \                 args.", {})\n".
                 \"endfunction"
 endfunction
 "▶1 add_commands :: {f} → + p:_commands
 "▶1 command feature
 let s:F.command={}
 let s:commands={}
+"▶2 addfunc      :: cmd, fdescr → + cmd | :function
+function s:F.addfunc(cmd, plstatus, fdescr)
+    if a:plstatus!=2
+        let fpattern='*'.(s:_sid).'_'.(a:cmd.compfname[2:])
+        let augname=s:compaugprefix.(a:cmd.id)
+        call s:_f.augroup.add(augname, [['FuncUndefined', fpattern, 0,
+                    \                   [s:F.loadplugin, a:cmd]]])
+        call add(a:cmd.augs, augname)
+        call add(a:cmd.funs, [a:cmd.compfname, a:fdescr])
+    else
+        call s:F.wrapfunc(a:cmd, a:cmd.compfname, a:fdescr)
+    endif
+endfunction
 "▶2 loadplugin   :: cmd → + FraworLoad(), :au!
 function s:F.loadplugin(cmd)
     call FraworLoad(a:cmd.plid)
                     let cmdstring.='-complete=customlist,'.(cmd.compfname).' '
                 "▶5 Use function described by dictionary
                 elseif tcomplete==type({})
-                    let fpattern='*'.(s:_sid).'_'.(cmd.compfname[2:])
                     if !exists('*a:plugdict.g._f.wrapfunc')
                         call s:_f.throw('nowrapfunc', a:cid, a:plugdict.id)
                     endif
                     let cmd.wrapfunc=a:plugdict.g._f.wrapfunc
-                    if a:plugdict.status!=2
-                        let augname=s:compaugprefix.(cmd.id)
-                        call s:_f.augroup.add(augname,
-                                    \         [['FuncUndefined', fpattern, 0,
-                                    \           [s:F.loadplugin, cmd]]])
-                        call add(cmd.augs, augname)
-                        call add(cmd.funs, [cmd.compfname, d.complete])
-                    else
-                        call s:F.wrapfunc(cmd, cmd.compfname, d.complete)
-                    endif
+                    call s:F.addfunc(cmd, a:plugdict.status, d.complete)
                     let cmdstring.='-complete=customlist,'.(cmd.compfname).' '
                 "▶5 Use FWC string
                 elseif tcomplete==type([])
-                    let lcomp=len(d.complete)
-                    if lcomp==1
-                        if type(d.complete[0])!=type('')
-                            call s:_f.throw('1nstr', a:cid, a:plugdict.id)
-                        endif
-                        let compargs=['-onlystrings '.d.complete[0], 'complete']
-                    elseif lcomp==2
-                        let compargs=d.complete
-                    else
-                        call s:_f.throw('invclen', a:cid, a:plugdict.id)
-                    endif
-                    let compargs+=[a:plugdict.g]
-                    let [cmd.compfunc, cmd.FWCid]=
-                                \call(s:_f.fwc.compile, compargs, {})
-                    let intfname = 's:commands.'.cmd.id.'.compfunc'
-                    let args     = '[call(s:F.splitfunc, '.
-                                \        'a:000'.
-                                \        ((cmd.sp is 0)?
-                                \           (', '):
-                                \           ('+[s:commands.'.cmd.id.'.sp], ')).
-                                \        '{}).curargs]'
-                    execute      "function ".cmd.compfname."(...)\n".
-                                \"    return call(".intfname.",".args.",{})\n".
-                                \"endfunction"
+                    let cmd.g=a:plugdict.g
+                    call s:F.addfunc(cmd, a:plugdict.status, d.complete)
                     let cmdstring.='-complete=customlist,'.(cmd.compfname).' '
                 "▶5 Use something else
                 elseif tcomplete==type('')

plugin/frawor/fwc/compiler.vim

     return [FWC.f, id]
 endfunction
 "▶2 fwc.del         :: {f}, FWCid
-function s:F.removefunc(plugdict, fdict, FWCid)
+function s:F.fwc.del(plugdict, fdict, FWCid)
     "▶3 Check arguments
     if type(a:FWCid)!=type('')
         call s:_f.throw('donstr', a:plugdict.id)

plugin/frawor/resources.vim

 call s:_f.newfeature('addresource', {'load': s:F.addresource, 'ignoredeps': 1,})
 "▶1
 call frawor#Lockvar(s:, 'postedress,plugresources')
+" TODO resources redefinition
 " vim: fmr=▶,▲ sw=4 ts=4 sts=4 et tw=80

test/commands-completion-twoload.in

 :source test.vim
 :set wc=<Tab> wcm=<Tab>
 :Abc a	
+:Def g	
 :call FraworUnload(g:testfile[:-5])
 :source test.vim
 :Abc b	
+:Def d	

test/commands-completion-twoload.ok

 Second load
 <<< messages
 aa
+ghi
 >>> messages
 First load
 Second load
 <<< messages
-bb
+bb
+def

test/rtp/plugin/commands-completion-twoload.vim

     let s:rdict={}
     call s:_f.command.add('Abc', 'call WriteFile(<q-args>)',
                 \         {'complete': s:rdict, 'nargs': '1'})
+    let s:rlist=[]
+    call s:_f.command.add('Def', 'call WriteFile(<q-args>)',
+                \         {'complete': s:rlist, 'nargs': '1'})
     echom 'First load'
     finish
 elseif s:_pluginloaded
 function s:rdict.function(a, c, p)
     return [a:a.a:a]
 endfunction
+let s:list=['def', 'ghi']
+let s:rlist+=['in list']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.