Commits

ZyX_I  committed acba1e0

@/fwc: Added onlyfirst support to next completion compilation function, improved nullact optimizer

  • Participants
  • Parent commits 0e23fe4

Comments (0)

Files changed (2)

File plugin/frawor/fwc/topconstructs.vim

     let addedsavemsgs=a:addedsavemsgs
     let hasnext=s:F.hasnext(a:adescr, 'next')
     if a:type is 'complete'
-        call self.addif(a:largsstr.'>='.self.getlastsub())
+        let condition=a:largsstr.'>='.self.getlastsub()
+        if self.onlyfirst
+            let condition=a:largsstr.'-1 == '.self.getlastsub()
+        endif
+        call self.addif(condition)
                     \.compilearg(a:adescr.next[0], a:idx.'.(next)')
                 \.up()
         if hasnext
     endif
     return self.conclose()
 endfunction
-"▶2 optimizenullact :: &self
+"▶2 optimizenullact :: &self(caidxstr)
 " XXX low-level hacks here
-function s:r.actions.optimizenullact()
+function s:r.actions.optimizenullact(caidxstr)
     if len(self.l)==2 && self.l[1][0] is 'if'
                 \&& (len(self.l[1])==3 ||
                 \    (len(self.l[1])==4 && self.l[-1] is 'endif'))
                 \&& self.l[1][1] is self.stack[-2][1]
         call extend(self.l, self.l[1][2])
         call remove(self.l, 1)
+    elseif len(self.l)==3 && self.l[1][0] is 'let'
+                \&& self.l[1][2] is a:caidxstr
+                \&& self.l[2][0] is 'if'
+                \&& (len(self.l[2])==3 ||
+                \    (len(self.l[2])==4 && self.l[-1] is 'endif'))
+                \&& len(self.stack[-2])==3
+                \&& self.stack[-2][0] is 'if'
+                \&& self.l[2][1][:(-1-len(self.l[1][1]))] is
+                \   self.stack[-2][1][:(-1-len(a:caidxstr))]
+        call extend(self.l, self.l[2][2])
+        call remove(self.l, 1, 2)
     endif
     return self
 endfunction
     endif
     let curargstr=self.argstr()
     if a:type is 'complete'
-        call self.addif(self.getlargsstr().'-1 == '.self.getlastsub())
+        call self.addif(a:largsstr.'-1 == '.self.getlastsub())
                         \.addmatches(fsastr, type([]))
         let savedsub=copy(self.subs[-1])
         if noact isnot 0 && len(noact)>1
             let self.onlyfirst+=1
             call self.compadescr(noact[1], idx.'.nullact').out()
-            call call(s:r.actions.optimizenullact, [], self)
+            call call(s:r.actions.optimizenullact, [a:caidxstr], self)
             let self.onlyfirst-=1
         endif
         let self.subs[-1]=savedsub

File test/fwccompletetests.dat

 
   @d+
   =s:list2
+
+`<abc in list
++ -   +in list2>
+  @+
+  =["abc"]+s:list2
 #▶2 {next}+{actions}
 `+ in list
 +<abc in list2