Commits

ZyX_I committed 197dccd

@/fwc/intfuncs: Fixed path completion (it was not able to complete ~)

Comments (0)

Files changed (5)

plugin/frawor/fwc/compiler.vim

                     \'(sort(keys('.a:ldtmp.'))))'
     endif
 endfunction
-"▶1 setmatches      :: &self(ldstr, exptype)
-function s:compiler.setmatches(ldstr, exptype)
+"▶1 setmatches      :: &self(ldstr, exptype, filter)
+function s:compiler.setmatches(ldstr, exptype, filter)
     if self.joinlists
-        call add(self.ldstrs, [a:ldstr, a:exptype])
+        call add(self.ldstrs, [a:ldstr, a:exptype, a:filter])
         return self
     else
         let vstr=self.vstrs[-1]
         call add(self.vstinf[vstr], ['let', a:ldstr])
         call filter(self.l, '!(v:val[0] is# "let" && v:val[1] is# vstr)')
-        return self.let(vstr, self.getmatcher(self.matcher, a:ldstr,
-                    \                         self.comparg, 1))
+        if a:filter
+            return self.let(vstr, self.getmatcher(self.matcher, a:ldstr,
+                        \                         self.comparg, 1))
+        else
+            return self.let(vstr, self.getmatchstr(a:ldstr, a:exptype,
+                        \                          self.getlvarid('curld')))
+        endif
     endif
 endfunction
 "▶1 newvstr         :: idx + self → varname + self
         let curldbase=self.getlvarid('curld').'_'
         let lststrs=map(remove(self.ldstrs, 0, -1),
                     \   'self.getmatchstr(v:val[0], v:val[1], curldbase.v:key)')
-        call self.setmatches(join(lststrs, '+'), type([]))
+        call self.setmatches(join(lststrs, '+'), type([]), 1)
     endif
     return self
 endfunction

plugin/frawor/fwc/intfuncs.vim

 "▶1 Path
 "▶2 getfiles
 function s:F.getfiles(arglead, filter, forcefilter)
-    let fragments=s:_r.os.path.split(a:arglead)
+    let path=expand(escape(a:arglead, '\[]*?'))
+    let fragments=s:_r.os.path.split(path)
     let globstart=''
-    if a:arglead[0] is# s:_r.os.sep
+    if path[0] is# s:_r.os.sep
         let globstart=s:_r.os.sep
     endif
-    if a:arglead[-1:] is# s:_r.os.sep && get(fragments, -1, 0) isnot# ''
+    if path[-1:] is# s:_r.os.sep && get(fragments, -1, 0) isnot# ''
         call add(fragments, '')
     endif
     while len(fragments)>1 && (fragments[0] is# '.' || fragments[0] is# '..')
         let globstart.=remove(fragments, 0).s:_r.os.sep
     endwhile
-    let startswithdot = a:arglead[0] is# '.'
+    let startswithdot = path[0] is# '.'
     if empty(fragments)
         call add(fragments, '')
     endif
                     \                      '"index(v:val, '.(ldescr-1).')!=-1 '.
                     \                      '|| (v:val[0]==-1 && '.
                     \                          'v:val[-1]<='.(ldescr).')")))',
-                    \          type([]))
+                    \          type([]), 1)
     endif
-    return self.setmatches('map('.getuserfunctionsstr.', "v:val[0]")', type([]))
+    return self.setmatches('map('.getuserfunctionsstr.', "v:val[0]")', type([]),
+                \          1)
 endfunction
 "▶1 `earg'
 " Replaces {argument} with the result of evaluating itself
     endif
 endfunction
 function s:r.in.complete(desc, idx, type)
-    return self.setmatches(self.getvar(a:desc[1]), type([]))
+    return self.setmatches(self.getvar(a:desc[1]), type([]), 1)
 endfunction
 "▶1 `key'
 let s:r.key={'args': ['var', '?omtchr']}
     return call(s:r.in.pipe, a:000+['key'], self)
 endfunction
 function s:r.key.complete(desc, idx, type)
-    return self.setmatches(self.getvar(a:desc[1]), type({}))
+    return self.setmatches(self.getvar(a:desc[1]), type({}), 1)
 endfunction
 "▶1 `take'
 " Replaces {argument} with value of the first key from {var}::Dictionary that 
     if has_key(s:idofcompletes, spec)
         let getvariantsstr=self.getfunstatvar('completers', s:F['get'.spec.'s'],
                     \                         spec.'s').'()'
-        return self.setmatches(getvariantsstr, type([]))
+        return self.setmatches(getvariantsstr, type([]), 1)
     elseif spec is# 'command'
         let intcmdsstr=self.getfunstatvar('completers', s:F.getinternalcommands,
                     \                     'commands').'()'
         let usercmdsstr=self.getfunstatvar('completers', s:F.getusercommands,
                     \                      'ucommands').'()'
-        return self.setmatches(intcmdsstr.'+'.usercmdsstr, type([]))
+        return self.setmatches(intcmdsstr.'+'.usercmdsstr, type([]), 1)
     elseif spec is# 'function'
         let userfunctionsstr='map('.self.getfunstatvar('completers',
                     \                                  s:F.getuserfunctions,
         let intfuncsstr='keys('.self.getfunstatvar('completers',
                     \                              s:F.getinternalfunctions,
                     \                              'vimfunctions').'())'
-        return self.setmatches(userfunctionsstr.'+'.intfuncsstr, type([]))
+        return self.setmatches(userfunctionsstr.'+'.intfuncsstr, type([]), 1)
     elseif spec is# 'option'
         let intoptsstr='map('.self.getfunstatvar('completers', s:F.getoptions,
                     \                            'options').'(), "v:val[0]")'
-        return self.setmatches(intoptsstr, type([]))
+        return self.setmatches(intoptsstr, type([]), 1)
     elseif spec is# 'variable'
-        return self.setmatches(s:varsstr, type([]))
+        return self.setmatches(s:varsstr, type([]), 1)
     endif
 endfunction
 "▲2
     endif
     let getfilesstr=self.getfunstatvar('completers', s:F.getfiles, 'path')
     return self.setmatches(getfilesstr.'('.self.comparg.', '.
-                \                          self.string(filter).', 1)', type([]))
+                \                          self.string(filter).', 1)', type([]),
+                \          0)
 endfunction
 "▶1 `type'
 " Checks whether {argument} has one of given types
             \'v:val=~?reg2',
             \]
 function s:r.smart.matcher(ld, str, acceptfirst)
-    if type(a:ld)==type({})
+    if empty(a:ld)
+        return []
+    elseif type(a:ld)==type({})
         if has_key(a:ld, a:str)
             return ((a:acceptfirst is 2)?([a:str]):(a:str))
         endif

plugin/frawor/fwc/topconstructs.vim

         endif
     else
         call self.addif(a:caidxstr.'=='.a:largsstr.'-1')
-                    \.setmatches(plstr, type([]))
+                    \.setmatches(plstr, type([]), 1)
                     \.break()
                 \.up()
     endif
     let curargstr=self.argstr()
     if a:type is# 'complete'
         call self.addif(a:largsstr.'-1 == '.self.getlastsub())
-                        \.setmatches(fsastr, type([]))
+                        \.setmatches(fsastr, type([]), 1)
         let savedsub=copy(self.subs[-1])
         if noact isnot 0 && len(noact)>1
             let self.onlyfirst+=1

test/fwccompletetests-os.dat

 :let dirdefghi=os.path.join(dirdef, 'ghi')
 :call writefile([], 'foo', 'b')
 :call os.makedirs(abcdefghi)
+:let $D='abc'
 `path w
   @+
   abc/ dir/ foo .bar/
 
   @/h
   /home/
+
+  @$D/
+  abc/def/
 # vim: cms=#%s fmr=▶,▲ sw=2 ts=2 sts=2 et

test/gwine/fwccompletetests-os.dat

 :let dirdefghi=os.path.join(dirdef, 'ghi')
 :call writefile([], 'foo', 'b')
 :call os.makedirs(abcdefghi)
+:let $D='abc'
 `path w
   @+
   abc\ dir\ foo
 
   @T:\
   T:\rtp\ T:\test\ T:\vimrc
+
+  @$D\
+  abc\def\
 # vim: cms=#%s fmr=▶,▲ sw=2 ts=2 sts=2 et