Commits

ZyX_I  committed 993bbbe

@/fwc: Added completion of built-in function names (!!!unstable: help file parsing)

  • Participants
  • Parent commits 41d7305

Comments (0)

Files changed (3)

File plugin/frawor/fwc/intfuncs.vim

                 \'[v:val[0]]+split(v:val[1], ", ")')
 endfunction
 " TODO get internal functions (from help?)
+function s:F.getinternalfunctions()
+    if exists('s:vimintfuncs')
+        return copy(s:vimintfuncs)
+    endif
+    let s:vimintfuncs={}
+    let helpfile=s:_r.os.path.join($VIMRUNTIME, 'doc', 'eval.txt')
+    if !filereadable(helpfile)
+        return copy(s:vimintfuncs)
+    endif
+    let help=readfile(helpfile)
+    let ruler=repeat('=', 78)
+    let section=''
+    while !empty(help)
+        if remove(help, 0) is ruler
+            if remove(help, 0)[:19] is '4. Builtin Functions'
+                while !empty(help)
+                    let line=remove(help, 0)
+                    if empty(line) && !empty(s:vimintfuncs)
+                        break
+                    endif
+                    let match=matchlist(line, '\v(\w+)\((.{-})\)')
+                    if empty(match)
+                        continue
+                    endif
+                    let fname=match[1]
+                    let fargs=substitute(match[2], '\s', '', 'g')
+                    let lengths=[]
+                    if stridx(fargs, '...')!=-1
+                        call add(lengths, -1)
+                    endif
+                    let bidx=stridx(fargs, '[')
+                    if bidx!=-1
+                        while bidx!=-1
+                            call add(lengths, len(split(fargs[:(bidx)], ','))
+                                        \                  +get(lengths, -1, 0))
+                            let fargs=fargs[(bidx+1):]
+                            let bidx=stridx(fargs, '[')
+                        endwhile
+                    else
+                        call add(lengths, len(split(fargs, ',')))
+                    endif
+                    let s:vimintfuncs[fname]=lengths
+                endwhile
+                call filter(s:vimintfuncs, 'exists("*".v:key)')
+                break
+            endif
+        endif
+    endwhile
+    lockvar s:vimintfuncs
+    return copy(s:vimintfuncs)
+endfunction
 "▲1
 "Filters/checkers --------------------------------------------------------------
 "▶1 `func', `eval'
     let getuserfunctionsstr=self.getfunstatvar('completers',
                 \                              s:F.getuserfunctions,
                 \                              'userfunctions').'()'
+    let getintfuncsstr=self.getfunstatvar('completers',s:F.getinternalfunctions,
+                \                         'vimfunctions').'()'
     if a:desc[1][0] is 'list'
         " XXX a:desc[1] contains one more items then required, as well as output 
         " of getuserfunctions
         return self.addmatches('map(filter('.getuserfunctionsstr.
                     \          ', "len(v:val)=='.ldescr.' || '.
                     \             '(len(v:val)<='.(ldescr+1).' && '.
-                    \              'v:val[-1] is ''...'')"), "v:val[0]")',
+                    \              'v:val[-1] is ''...'')"), "v:val[0]")+'.
+                    \          'sort(keys(filter('.getintfuncsstr.', '.
+                    \                      '"index(v:val, '.(ldescr-1).')!=-1 '.
+                    \                      '|| (v:val[0]==-1 && '.
+                    \                          'v:val[-1]<='.(ldescr).')")))',
                     \          type([]))
     endif
     return self.addmatches('map('.getuserfunctionsstr.', "v:val[0]")', type([]))

File test/fwccomplete-redir.ok

+>>> messages
+::: Section <run>
+<<< messages

File test/fwccompletetests-withredir.dat

   @T
   ToList
 
-  @f
+  @#R
   frawor#Reload
 
 `run [1 2 3]
   @f
   frawor#Setup
 
+`run [1 2 3 4 5 6 7 8]
+  @p
+  printf
+
 # vim: cms=#%s fmr=▶,▲ sw=2 ts=2 sts=2 et