Commits

ZyX_I  committed ebcfecc

@/fwc: Implemented {actions} section completion

  • Participants
  • Parent commits 266544f

Comments (0)

Files changed (6)

File plugin/frawor/fwc/compiler.vim

     endif
     return r
 endfunction
-"▶1 getmatcher      :: matchercontext, ldstr, strstr + self → String
-function s:compiler.getmatcher(matcher, ldstr, strstr)
+"▶1 getmatcher      :: matchercontext, ldstr, strstr, iscomp + self → String
+function s:compiler.getmatcher(matcher, ldstr, strstr, iscomp)
     let mname=a:matcher[1][1]
     if !has_key(s:_r.FWC_intfuncs[mname], 'matcher')
         call s:_f.throw('umatcher', mname)
                     \           'self.string(v:val)'),
                     \    ', ')
     endif
-    if self.type is 'check' || self.type is 'filter'
+    if a:iscomp
+        let r.=', 2)'
+    else
         let r.=', '.a:matcher[1][-1].')'
-    else
-        let r.=', 2)'
     endif
     return r
 endfunction
         return self
     else
         return self.increment('@-@', self.getmatcher(self.matcher, a:ldstr,
-                    \                                self.comparg))
+                    \                                self.comparg, 1))
     endif
 endfunction
 "▶1 addjoinedmtchs  :: &self
     endfor
     "▶2 Check for processed argument length
     " XXX a:0 is checked here
-    if !a:0 && type(self.subs[-1])==type([])
+    if !a:0 && type(self.subs[-1])==type([]) && self.type isnot 'complete'
         let largsstr=self.getlargsstr()
         let proclen=self.getlastsub()
         call self.addif(proclen.' isnot '.largsstr)

File plugin/frawor/fwc/intfuncs.vim

     else
         let matchstr=self.getlvarid('match')
         return self.addtypecond([type('')], a:idx)
-                    \.let(matchstr,self.getmatcher(a:desc[2],
-                    \                              self.getvar(a:desc[1]),
-                    \                              curargstr))
+                    \.let(matchstr, self.getmatcher(a:desc[2],
+                    \                               self.getvar(a:desc[1]),
+                    \                               curargstr, 0))
                     \.nextthrow(matchstr.' is 0',
                     \           'nmatch', a:idx, curargstr)
                     \.let(curargstr, matchstr)
     let matchstr=self.getlvarid('match')
     call self.addtypecond([type('')], a:idx)
                 \.let(matchstr, self.getmatcher(a:desc[2], varstr,
-                \                               curargstr))
+                \                               curargstr, 0))
                 \.nextthrow(matchstr.' is 0', 'nmatch', a:idx, curargstr)
                 \.let(curargstr, varstr.'['.matchstr.']')
     let self.typechanged=1

File plugin/frawor/fwc/topconstructs.vim

     endif
     call self.let(astr, self.getmatcher(get(a:adescr, 'prefixesmatcher',
                 \                           s:prefdefmatcher), plstr,
-                \                       self.argstr()))
+                \                       self.argstr(), 0))
     let removestr='remove('.base.', '.a:caidxstr.')'
     if addtry
         let argorigstr=self.getd('argorig')
     let actions=filter(copy(a:adescr.actions), 'v:val[0] isnot 0')
     let noact=get(filter(copy(a:adescr.actions), 'v:val[0] is 0'), 0, 0)
     let fsastr=self.getfunstatvar('actions', map(copy(actions), 'v:val[0]'))
-    if noact isnot 0
+    if noact isnot 0 && self.type isnot 'complete'
         call self.try().pushms('throw')
     endif
     let idx=a:idx.'(actions)'
-    if !self.o.onlystrings
+    if !self.o.onlystrings && self.type isnot 'complete'
         call self.addtypecond([type('')], idx)
     endif
     let curargstr=self.argstr()
+    if self.type is 'complete'
+        call self.addif(self.getlargsstr().'-1 == '.self.getlastsub())
+                        \.addmatches(fsastr, type([]))
+        let savedsub=copy(self.subs[-1])
+        if noact isnot 0 && len(noact)>1
+            call self.compadescr(noact[1], idx.'.nullact')
+        endif
+        let self.subs[-1]=savedsub
+        call self.up().else()
+    endif
     call self.let(actionstr, self.getmatcher(get(a:adescr, 'actionsmatcher',
                 \                                s:actdefmatcher),
-                \                            fsastr, curargstr))
-                \.nextthrow(actionstr.' is 0', 'anf', idx, curargstr)
-                \.let(curargstr, actionstr)
+                \                            fsastr, curargstr, 0))
+    if self.type isnot 'complete'
+        call self.nextthrow(actionstr.' is 0', 'anf', idx, curargstr)
+    endif
+    if self.type is 'filter'
+        call self.let(curargstr, actionstr)
+    endif
     unlet curargstr
     call self.incsub()
     let astartsub=copy(self.subs[-1])
-    for action in actions
-        call self.addif(actionstr.' is '.self.string(action[0]))
-        if len(action)>1
-            call self.compadescr(action[1],idx.'.'.self.string(action[0]))
+    for [actstr; actargs] in actions
+        call self.addif(actionstr.' is '.self.string(actstr))
+        if !empty(actargs)
+            call self.compadescr(actargs[0], idx.'.'.self.string(actstr))
         endif
         call self.let(a:caidxstr, self.getlastsub()).up()
         let self.subs[-1]=copy(astartsub)
     endfor
     if noact isnot 0
-        call self.popms().catch(s:cfreg)
+        if self.type is 'complete'
+            call self.else()
+        else
+            call self.popms().catch(s:cfreg)
+        endif
         call self.incsub(-1)
         if len(noact)>1
             call self.compadescr(noact[1], idx.'.nullact')
         call self.up().up()
     endif
     let self.subs[-1]=[a:caidxstr]
+    if self.type is 'complete'
+        call self.up().up()
+    endif
     return [[a:caidxstr], a:addedsavemsgs]
 endfunction
 "▶1 _order

File test/fwccomplete.ok

 ::: Section <Built-in completion functions/either>
 ::: Section <Built-in completion functions/first>
 ::: Section <Different sections/{required}>
+::: Section <Different sections/{actions}>
 <<< messages

File test/fwccompletetests.dat

 
   @b+
   =s:list2
+#▶2 {actions}
+`<abc in list
++ dbf in list2
++ gh (in list2  key dict)>
+  @+
+  abc dbf gh
+
+  @b
+  abc dbf
+
+  @a+
+  =s:list
+
+  @d+
+  =s:list2
+
+  @g+
+  =s:list2
+
+  @g a+
+  =sort(keys(s:dict))
+
+`<abc in list
++ dbf in list2
++ gh (in list2  key dict)
++ - (key dict  in list)>
+  @+
+  =["abc", "dbf", "gh"]+sort(keys(s:dict))
+
+  @a+
+  =s:list
+
+  @x+
+  =s:list
 # vim: cms=#%s fmr=▶,▲ sw=2 ts=2 sts=2 et

File test/rtp/plugin/fwccomplete.vim

     elseif line[0] is '`'
         let FWC=line[1:]
         continue
+    elseif line[0] is '+'
+        let FWC.=line[1:]
+        continue
     elseif line[0] is '!'
         let FWCtype=line[1:]
         continue