@@ -87,14 +87,6 @@ function! s:rquote(str)
8787 endif
8888endfunction
8989
90- function ! s: fnameescape (file ) abort
91- if exists (' *fnameescape' )
92- return fnameescape (a: file )
93- else
94- return escape (a: file ," \t \n *?[{`$\\ %#'\" |!<" )
95- endif
96- endfunction
97-
9890function ! s: dot_relative (path ) abort
9991 let slash = matchstr (a: path , ' ^\%(\w\:\)\=\zs[\/]' )
10092 if ! empty (slash)
@@ -107,7 +99,7 @@ function! s:dot_relative(path) abort
10799endfunction
108100
109101function ! s: mods (mods) abort
110- return s: gsub (a: mods , ' [<]mods[>]\s*| ^\s' , ' ' )
102+ return substitute (a: mods , ' ^\s' , ' ' , ' ' )
111103endfunction
112104
113105function ! s: webcat () abort
@@ -153,11 +145,7 @@ function! s:simplify(path) abort
153145endfunction
154146
155147function ! s: glob (path ) abort
156- if v: version >= 704
157- return s: fcall (' glob' , a: path , 0 , 1 )
158- else
159- return split (s: fcall (' glob' , a: path ), " \n " )
160- endif
148+ return s: fcall (' glob' , a: path , 0 , 1 )
161149endfunction
162150
163151function ! s: mkdir_p (path ) abort
@@ -199,9 +187,9 @@ endfunction
199187function ! s: push_chdir (... )
200188 if ! exists (" s:command_stack" ) | let s: command_stack = [] | endif
201189 if s: active () && (a: 0 ? getcwd () !=# rails#app ().path () : ! s: startswith (getcwd (), rails#app ().real ()))
202- let chdir = exists (" *haslocaldir " ) && haslocaldir () ? " lchdir " : " chdir "
203- call add (s: command_stack ,chdir . s: escarg (getcwd ()))
204- exe chdir . s: escarg (rails#app ().real ())
190+ let cd = haslocaldir () ? ' lcd ' : exists (' :tcd ' ) && haslocaldir (-1 ) ? ' tcd ' : ' cd '
191+ call add (s: command_stack ,cd . ' ' . s: escarg (getcwd ()))
192+ exe cd s: escarg (rails#app ().real ())
205193 else
206194 call add (s: command_stack ," " )
207195 endif
@@ -1104,26 +1092,26 @@ endfunction
11041092function ! s: Clog (bang , mods, arg) abort
11051093 let lf = rails#app ().real (' log/' . (empty (a: arg ) ? s: environment () : a: arg ) . ' .log' )
11061094 if ! filereadable (lf )
1107- return ' cgetfile ' . s: fnameescape (lf )
1095+ return ' cgetfile ' . fnameescape (lf )
11081096 endif
11091097 let [mp , efm , cc ] = [&l: mp , &l: efm , get (b: , ' current_compiler' , ' ' )]
1110- let chdir = exists (" *haslocaldir " ) && haslocaldir () ? ' lchdir ' : ' chdir '
1098+ let chdir = haslocaldir () ? ' lcd ' : exists (' :tcd ' ) && haslocaldir (-1 ) ? ' tcd ' : ' cd '
11111099 let cwd = getcwd ()
11121100 try
11131101 compiler rails
1114- exe chdir s: fnameescape (rails#app ().real ())
1115- exe ' cgetfile' s: fnameescape (lf )
1102+ exe chdir fnameescape (rails#app ().real ())
1103+ exe ' cgetfile' fnameescape (lf )
11161104 finally
11171105 let [&l: mp , &l: efm , b: current_compiler ] = [mp , efm , cc ]
11181106 if empty (cc ) | unlet ! b: current_compiler | endif
1119- exe chdir s: fnameescape (cwd)
1107+ exe chdir fnameescape (cwd)
11201108 endtry
11211109 return s: mods (a: mods ) . ' copen|$'
11221110endfunction
11231111
11241112function ! s: Plog (bang , arg) abort
11251113 let lf = rails#app ().path (' log/' . (empty (a: arg ) ? s: environment () : a: arg ) . ' .log' )
1126- return ' pedit' . (a: bang ? ' !' : ' ' ) . ' +$ ' . s: fnameescape (lf )
1114+ return ' pedit' . (a: bang ? ' !' : ' ' ) . ' +$ ' . fnameescape (lf )
11271115endfunction
11281116
11291117function ! rails#command (bang , mods, count , arg) abort
@@ -1154,16 +1142,16 @@ function! rails#command(bang, mods, count, arg) abort
11541142 let dir = matchstr (arg, ' ["'' ]\=\zs[^- "'' ][^ "'' ]\+' )
11551143 if isdirectory (dir )
11561144 let old_errorformat = &l: errorformat
1157- let chdir = exists (" *haslocaldir " ) && haslocaldir () ? ' lchdir ' : ' chdir '
1145+ let chdir = haslocaldir () ? ' lcd ' : exists (' :tcd ' ) && haslocaldir (-1 ) ? ' tcd ' : ' cd '
11581146 let cwd = getcwd ()
11591147 try
1160- exe chdir s: fnameescape (dir )
1148+ exe chdir fnameescape (dir )
11611149 let &l: errorformat = s: efm_generate
11621150 exe ' cgetfile' temp
11631151 return ' copen|cfirst'
11641152 finally
11651153 let &l: errorformat = old_errorformat
1166- exe chdir s: fnameescape (cwd)
1154+ exe chdir fnameescape (cwd)
11671155 endtry
11681156 elseif exists (' error' ) && ! error && ! empty (dir )
11691157 call s: warn (" Couldn't find app directory" )
@@ -1188,7 +1176,7 @@ function! s:TagsCommand() abort
11881176 call s: error (" ctags not found" )
11891177 return ' '
11901178 endif
1191- let cd = exists (' *haslocaldir ' ) && haslocaldir () ? ' lcd ' : ' cd'
1179+ let cd = haslocaldir () ? ' lcd ' : exists (' :tcd ' ) && haslocaldir (-1 ) ? ' tcd ' : ' cd'
11921180 let cwd = getcwd ()
11931181 try
11941182 execute cd fnameescape (rails#app ().real ())
@@ -1259,7 +1247,7 @@ function! s:qf_pre() abort
12591247 let dir = s: efm_dir ()
12601248 let cwd = getcwd ()
12611249 if ! empty (dir ) && dir !=# cwd
1262- let cd = exists (' *haslocaldir ' ) && haslocaldir () ? ' lcd ' : ' cd'
1250+ let cd = haslocaldir () ? ' lcd ' : exists (' :tcd ' ) && haslocaldir (-1 ) ? ' tcd ' : ' cd'
12631251 execute ' lcd' fnameescape (dir )
12641252 let s: qf_post = cd . ' ' . fnameescape (cwd)
12651253 endif
@@ -2434,7 +2422,7 @@ function! rails#sprockets_cfile(...) abort
24342422 if empty (file )
24352423 return eval (s: cfile_delegate (a: 0 ? a: 1 : ' ' ))
24362424 endif
2437- let escaped = s: fnameescape (file )
2425+ let escaped = fnameescape (file )
24382426 if file == # escaped
24392427 return file
24402428 else
@@ -2687,7 +2675,7 @@ endfunction
26872675
26882676function ! s: app_routes () dict abort
26892677 if self .cache.needs (' routes' )
2690- let cd = exists (' *haslocaldir ' ) && haslocaldir () ? ' lcd ' : ' cd'
2678+ let cd = haslocaldir () ? ' lcd ' : exists (' :tcd ' ) && haslocaldir (-1 ) ? ' tcd ' : ' cd'
26912679 let cwd = getcwd ()
26922680 let routes = []
26932681 let paths = {}
@@ -3432,7 +3420,7 @@ function! s:readable_open_command(cmd, argument, name, projections) dict abort
34323420 if empty (defaults)
34333421 return ' echoerr "E471: Argument required"'
34343422 else
3435- return cmd . ' ' . s: fnameescape (defaults[0 ])
3423+ return cmd . ' ' . fnameescape (defaults[0 ])
34363424 endif
34373425 endif
34383426 if djump !~# ' ^!'
@@ -3459,9 +3447,9 @@ function! s:readable_open_command(cmd, argument, name, projections) dict abort
34593447 call map (template, ' s:expand_placeholders(v:val, ph)' )
34603448 call map (template, ' s:gsub(v:val, "\t", " ")' )
34613449 let file = fnamemodify (s: simplify (file ), ' :.' )
3462- return cmd . ' ' . s: fnameescape (file ) . ' |call setline(1, ' .string (template).' )' . ' |set nomod'
3450+ return cmd . ' ' . fnameescape (file ) . ' |call setline(1, ' .string (template).' )' . ' |set nomod'
34633451 else
3464- return cmd . ' +AD ' . s: fnameescape (file )
3452+ return cmd . ' +AD ' . fnameescape (file )
34653453 endif
34663454 endif
34673455 endfor
@@ -3829,7 +3817,7 @@ function! s:ViewExtract(bang, mods, first, last, file) abort
38293817 silent exe a: last .' put =spaces . renderstr'
38303818 silent exe a: first .' ,' .a: last .' delete _'
38313819 let filetype = &filetype
3832- silent exe s: mods (a: mods ) ' split' s: fnameescape (fnamemodify (out, ' :.' ))
3820+ silent exe s: mods (a: mods ) ' split' fnameescape (fnamemodify (out, ' :.' ))
38333821 let existing_last = line (' $' )
38343822 silent $put = contents
38353823 silent exe ' 1,' . existing_last . ' delete _'
@@ -3854,7 +3842,7 @@ function! s:RubyExtract(bang, mods, root, before, name) range abort
38543842 elseif out !~# ' ^\a\a\+:' && ! isdirectory (fnamemodify (out,' :h' ))
38553843 return s: error (' No such directory' )
38563844 endif
3857- execute s: mods (a: mods ) ' split' s: fnameescape (out)
3845+ execute s: mods (a: mods ) ' split' fnameescape (out)
38583846 silent % delete_
38593847 call setline (1 , [' module ' .rails#camelize (a: name )] + a: before + content + [' end' ])
38603848endfunction
@@ -4245,19 +4233,7 @@ endfunction
42454233" Projections {{{1
42464234
42474235function ! rails#json_parse (string ) abort
4248- let string = type (a: string ) == type ([]) ? join (a: string , ' ' ) : a: string
4249- if exists (' *json_decode' )
4250- return json_decode (string )
4251- endif
4252- let [null, false, true] = [' ' , 0 , 1 ]
4253- let stripped = substitute (string ,' \C"\(\\.\|[^"\\]\)*"' ,' ' ,' g' )
4254- if stripped !~# " [^,:{}\\ [\\ ]0-9.\\ -+Eaeflnr-u \n \r \t ]"
4255- try
4256- return eval (substitute (string ," [\r \n ]" ," " ,' g' ))
4257- catch
4258- endtry
4259- endif
4260- throw " invalid JSON: " .string
4236+ return json_decode (type (a: string ) == type ([]) ? join (a: string , ' ' ) : a: string )
42614237endfunction
42624238
42634239function ! s: app_gems () dict abort
@@ -4886,7 +4862,7 @@ function! rails#sprockets_setup(type) abort
48864862 let b: undo_ftplugin = get (b: , ' undo_ftplugin' , ' exe' ) . ' |setlocal pa= sua= inc='
48874863
48884864 let map = ''
4889- let cfilemap = v: version + has ( ' patch032 ' ) >= 704 ? maparg (' <Plug><cfile>' , ' c' , 0 , 1 ) : {}
4865+ let cfilemap = maparg (' <Plug><cfile>' , ' c' , 0 , 1 )
48904866 if get (cfilemap, ' buffer' ) && cfilemap.expr && cfilemap.rhs !~# ' rails#\|Ruby'
48914867 let map = string(maparg('<Plug><cfile> ', 'c'))
48924868 endif
@@ -5020,7 +4996,7 @@ function! rails#buffer_setup() abort
50204996 let &l: errorformat = substitute (&l: errorformat , ' %\\&completion=rails#complete_\zsrails' , ' rake' , ' g' )
50214997 endif
50224998
5023- let dir = ' -dir=' . substitute (s: fnameescape (fnamemodify (self .app ().real (), ' :~' )), ' ^\\\~' , ' \~' , ' ' ) . ' '
4999+ let dir = ' -dir=' . substitute (fnameescape (fnamemodify (self .app ().real (), ' :~' )), ' ^\\\~' , ' \~' , ' ' ) . ' '
50245000
50255001 let dispatch = self .projected (' dispatch' )
50265002 if ! empty (dispatch)
0 commit comments