Commits

ZyX_I committed 8d94651

@/fwc: Partial {prefixes} section completion implementation: it does not support list prefixes

Comments (0)

Files changed (4)

plugin/frawor/fwc/compiler.vim

                     \.let('@$@pmessages', '[]')
                     \.try()
         call t.compadescr(tree)
+        call t
                 \.up().finally()
                     \.for('@$@targs', '@$@messages')
                         \.call('call(@%@.F.warn, @$@targs, {})').up()

plugin/frawor/fwc/topconstructs.vim

     let lists=filter(copy(a:adescr.prefixes), 'v:val[1].list')
     let haslist=!empty(lists)
     let lastliststr=self.getlvarid('lastlist')
-    let addtry=s:F.hasnext(a:adescr, 'prefixes')
-    "▶3 Add messages saving if required
-    if addtry
-        if !addedsavemsgs
-            call self.addsavemsgs()
-            let addedsavemsgs=1
+    let hasnext=s:F.hasnext(a:adescr, 'prefixes')
+    if self.type is 'check' || self.type is 'filter'
+        "▶3 Add messages saving if required
+        if hasnext
+            if !addedsavemsgs
+                call self.addsavemsgs()
+                let addedsavemsgs=1
+            endif
+            call self.try().pushms('throw')
         endif
-        call self.try().pushms('throw')
+        "▶3 Initialize variables inside constructed function
+            call self.let(prefdictstr, '{}')
+                        \.call('insert('.base.', '.prefdictstr.', '.
+                        \                self.getsub(nextsub).')')
+                        \.increment(a:caidxstr)
+                        \.increment(a:largsstr)
+        "▶3 Add default values
+        for [prefix, prefopts, defval; dummylist] in defaults
+            call self.let(prefdictstr.self.getsubs([prefix]),
+                        \ self.getvar(defval))
+        endfor
+        "▲3
+        call self.while('len('.base.')>'.a:caidxstr)
+    else
+        call self.while(a:caidxstr.'<'.a:largsstr)
     endif
-    "▶3 Initialize variables inside constructed function
-    call self.let(prefdictstr, '{}')
-                \.call('insert('.base.', '.prefdictstr.', '.
-                \                self.getsub(nextsub).')')
-                \.increment(a:caidxstr)
-                \.increment(a:largsstr)
-    "▶3 Add default values
-    for [prefix, prefopts, defval; dummylist] in defaults
-        call self.let(prefdictstr.self.getsubs([prefix]),
-                    \ self.getvar(defval))
-    endfor
-    "▲3
-    call self.while('len('.base.')>'.a:caidxstr)
     "▶3 Get `astr' variable
-    if haslist
-        call self.if('type('.self.argstr().')=='.type(''))
-    elseif !self.o.onlystrings
-        call self.addtypecond([type('')], idx)
+    if self.type is 'check' || self.type is 'filter'
+        if !self.o.onlystrings
+            if haslist
+                call self.if('type('.self.argstr().')=='.type(''))
+            else
+                call self.addtypecond([type('')], idx)
+            endif
+        endif
+    else
+        call self.addif(a:caidxstr.'=='.a:largsstr.'-1')
+                    \.addmatches(plstr, type([]))
+                    \.break()
+                \.up()
     endif
     call self.let(astr, self.getmatcher(get(a:adescr, 'prefixesmatcher',
                 \                           s:prefdefmatcher), plstr,
                 \                       self.argstr(), 0))
-    let removestr='remove('.base.', '.a:caidxstr.')'
-    if addtry
-        let argorigstr=self.getd('argorig')
-    endif
-    if haslist
-        call self.up().else().let(astr, 0).up().endif()
-                    \.if(astr.' isnot 0')
+    if self.type is 'check' || self.type is 'filter'
+        let removestr='remove('.base.', '.a:caidxstr.')'
+        if hasnext
+            let argorigstr=self.getd('argorig')
+        endif
+        if !self.o.onlystrings
+            if haslist
+                call self.up().else().let(astr, 0).up().endif()
+                            \.if(astr.' isnot 0')
+            else
+                call self.nextthrow(astr.' is 0', 'pnf', idx, self.argstr())
+            endif
+        elseif haslist
+            call self.if(astr.' isnot 0')
+        endif
+        call self.increment(a:largsstr, -1)
+        if hasnext
+            call self.let(argorigstr, removestr)
+        else
+            call self.call(removestr)
+        endif
+        if haslist
+            call self.up().endif()
+        endif
     else
-        call self.nextthrow(astr.' is 0', 'pnf', idx, self.argstr())
-    endif
-    call self.increment(a:largsstr, -1)
-    if addtry
-        call self.let(argorigstr, removestr)
-    else
-        call self.call(removestr)
-    endif
-    if haslist
-        call self.up().endif()
+        call self.increment(a:caidxstr, 1)
+                    \.addif(astr.' is 0')
+                        \.break()
+                    \.up()
     endif
     "▲3
     for [prefix, prefopts; args] in a:adescr.prefixes
         "▲3
         let prefstr=prefdictstr.self.getsubs([prefix])
         let prefixstr=self.string(prefix)
+        if self.type is 'complete' && !prefopts.argnum
+            continue
+        endif
         "▶3 Construct prefix condition
         let cond=astr.' is '.prefixstr
         if prefopts.list
         endif
         call self.addif(cond)
         "▶3 Process prefix arguments
-        for i in range(1, prefopts.argnum)
-            call self.compilearg(args[i-1], idx.self.string(prefix))
-                        \.incsub()
-        endfor
+        if self.type is 'check' || self.type is 'filter'
+            for i in range(1, prefopts.argnum)
+                call self.compilearg(args[i-1], idx.self.string(prefix))
+                            \.incsub()
+            endfor
+            if prefopts.argnum>0
+                call self.increment(a:largsstr, -prefopts.argnum)
+            endif
+        else
+            call self.let(lastliststr, prefopts.list?(prefixstr):0)
+            let idxdiffstr=self.getlvarid('idxdiff')
+            call self.if(a:caidxstr.'+'.prefopts.argnum.'<'.a:largsstr)
+                        \.increment(a:caidxstr, prefopts.argnum)
+                    \.else()
+                        \.let(idxdiffstr, a:largsstr.'-'.a:caidxstr)
+            for i in range(1, prefopts.argnum)
+                call self.addif(idxdiffstr.'=='.i)
+                            \.compilearg(args[i-1], idx.self.string(prefix))
+                            \.break()
+                        \.up()
+            endfor
+            call self.up().up()
+        endif
         "▶3 Move prefix arguments to prefix dictionary
-        if prefopts.argnum>0
-            call self.increment(a:largsstr, -prefopts.argnum)
-        endif
-        if prefopts.list
+        if self.type is 'complete'
+            call self.up()
+        elseif prefopts.list
             let removestr='remove('.base.', '.a:caidxstr.', '.
                         \           a:caidxstr.'+'.(prefopts.argnum-1).')'
             let cond='has_key('.prefdictstr.', '.prefixstr.')'
         let self.subs[-1]=[a:caidxstr]
         call self.up()
         "▶3 Process `no{prefix}'
-        if prefopts.alt
-            call self.addif(astr.' is '.self.string('no'.prefix))
-                        \.let(prefstr, 0)
-                        \.up()
+        if self.type is 'check' || self.type is 'filter'
+            if prefopts.alt
+                call self.addif(astr.' is '.self.string('no'.prefix))
+                            \.let(prefstr, 0)
+                            \.up()
+            endif
         endif
         "▲3
     endfor
     call self.up()
-    if addtry
-        call self.unlet(argorigstr).up().up().addrestmsgs(1).popms()
-            \.catch(s:cfreg)
-                \.if('exists('.string(argorigstr).')')
-                    \.call('insert('.base.', '.argorigstr.', '.a:caidxstr.')')
-                    \.increment(a:largsstr)
+    if self.type is 'check' || self.type is 'filter'
+        if hasnext
+            call self.unlet(argorigstr).up().up().addrestmsgs(1).popms()
+                \.catch(s:cfreg)
+                    \.if('exists('.string(argorigstr).')')
+                        \.call('insert('.base.','.argorigstr.','.a:caidxstr.')')
+                        \.increment(a:largsstr)
+                    \.up()
                 \.up()
-            \.up()
+        else
+            call self.up()
+        endif
     else
         call self.up()
     endif
 ::: Section <Built-in completion functions/if>
 ::: Section <Different sections/{required}>
 ::: Section <Different sections/{optional}>
+::: Section <Different sections/{prefixes}>
 ::: Section <Different sections/{next}>
 ::: Section <Different sections/{actions}>
 ::: Section <Different sections/{next}+{actions}>

test/fwccompletetests.dat

 
   @- -+
   =sort(keys(s:dict))
+#▶2 {prefixes}
+`{   abc  in list
++    def  in list2
++   !ghi
++ +2*jkl  key dict in list2}
+  @+
+  abc def ghi noghi jkl
+
+  @a b+
+  abc def ghi noghi jkl
+
+  @j 1 2+
+  abc def ghi noghi jkl
+
+  @a+
+  =s:list
+
+  @j+
+  =sort(keys(s:dict))
+
+  @j 1+
+  =s:list2
+
+  # @j 1 2 3+
+  # =s:list2
+
+  @n
+  noghi
 #▶2 {next}
 `+ in list
   @+