blob: 687500ebe39c99f2e7ea8e9ff0c527a31f7db944 [file] [log] [blame]
Bram Moolenaar60a795a2005-09-16 21:55:43 +00001" zip.vim: Handles browsing zipfiles
2" AUTOLOAD PORTION
Bram Moolenaar94f76b72013-07-04 22:50:40 +02003" Date: Jul 02, 2013
4" Version: 27
Bram Moolenaarff034192013-04-24 18:51:19 +02005" Maintainer: Charles E Campbell <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
Bram Moolenaar9964e462007-05-05 17:54:07 +00006" License: Vim License (see vim's :help license)
Bram Moolenaar94f76b72013-07-04 22:50:40 +02007" Copyright: Copyright (C) 2005-2013 Charles E. Campbell {{{1
Bram Moolenaar60a795a2005-09-16 21:55:43 +00008" Permission is hereby granted to use and distribute this code,
9" with or without modifications, provided that this copyright
10" notice is copied with it. Like anything else that's free,
Bram Moolenaar446cb832008-06-24 21:56:24 +000011" zip.vim and zipPlugin.vim are provided *as is* and comes with
12" no warranty of any kind, either expressed or implied. By using
13" this plugin, you agree that in no event will the copyright
Bram Moolenaar60a795a2005-09-16 21:55:43 +000014" holder be liable for any damages resulting from the use
15" of this software.
Bram Moolenaar94f76b72013-07-04 22:50:40 +020016"redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar60a795a2005-09-16 21:55:43 +000017
18" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +000019" Load Once: {{{1
Bram Moolenaar00a927d2010-05-14 23:24:24 +020020if &cp || exists("g:loaded_zip")
Bram Moolenaar60a795a2005-09-16 21:55:43 +000021 finish
22endif
Bram Moolenaar94f76b72013-07-04 22:50:40 +020023let g:loaded_zip= "v27"
Bram Moolenaar00a927d2010-05-14 23:24:24 +020024if v:version < 702
25 echohl WarningMsg
26 echo "***warning*** this version of zip needs vim 7.2"
27 echohl Normal
28 finish
29endif
30let s:keepcpo= &cpo
31set cpo&vim
Bram Moolenaar94f76b72013-07-04 22:50:40 +020032"DechoTabOn
Bram Moolenaar60a795a2005-09-16 21:55:43 +000033
Bram Moolenaardb552d602006-03-23 22:59:57 +000034let s:zipfile_escape = ' ?&;\'
Bram Moolenaar9964e462007-05-05 17:54:07 +000035let s:ERROR = 2
36let s:WARNING = 1
37let s:NOTE = 0
38
39" ---------------------------------------------------------------------
40" Global Values: {{{1
41if !exists("g:zip_shq")
Bram Moolenaar446cb832008-06-24 21:56:24 +000042 if &shq != ""
43 let g:zip_shq= &shq
44 elseif has("unix")
Bram Moolenaar9964e462007-05-05 17:54:07 +000045 let g:zip_shq= "'"
46 else
47 let g:zip_shq= '"'
48 endif
49endif
Bram Moolenaarccc18222007-05-10 18:25:20 +000050if !exists("g:zip_zipcmd")
51 let g:zip_zipcmd= "zip"
52endif
53if !exists("g:zip_unzipcmd")
54 let g:zip_unzipcmd= "unzip"
55endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +000056
57" ----------------
58" Functions: {{{1
59" ----------------
60
61" ---------------------------------------------------------------------
62" zip#Browse: {{{2
63fun! zip#Browse(zipfile)
64" call Dfunc("zip#Browse(zipfile<".a:zipfile.">)")
Bram Moolenaar94f76b72013-07-04 22:50:40 +020065 " sanity check: insure that the zipfile has "PK" as its first two letters
66 " (zipped files have a leading PK as a "magic cookie")
67 if !filereadable(a:zipfile) || readfile(a:zipfile, "", 1)[0] !~ '^PK'
68 exe "noautocmd e ".fnameescape(a:zipfile)
69" call Dret("zip#Browse : not a zipfile<".a:zipfile.">")
70 return
71" else " Decho
72" call Decho("zip#Browse: a:zipfile<".a:zipfile."> passed PK test - its a zip file")
73 endif
74
Bram Moolenaar36c31f72005-11-28 23:01:53 +000075 let repkeep= &report
76 set report=10
Bram Moolenaar60a795a2005-09-16 21:55:43 +000077
78 " sanity checks
Bram Moolenaare37d50a2008-08-06 17:06:04 +000079 if !exists("*fnameescape")
80 if &verbose > 1
81 echoerr "the zip plugin is not available (your vim doens't support fnameescape())"
82 endif
83 return
84 endif
Bram Moolenaarccc18222007-05-10 18:25:20 +000085 if !executable(g:zip_unzipcmd)
Bram Moolenaar9964e462007-05-05 17:54:07 +000086 redraw!
Bram Moolenaar60a795a2005-09-16 21:55:43 +000087 echohl Error | echo "***error*** (zip#Browse) unzip not available on your system"
Bram Moolenaar9964e462007-05-05 17:54:07 +000088" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar36c31f72005-11-28 23:01:53 +000089 let &report= repkeep
Bram Moolenaar60a795a2005-09-16 21:55:43 +000090" call Dret("zip#Browse")
91 return
92 endif
93 if !filereadable(a:zipfile)
Bram Moolenaara5792f52005-11-23 21:25:05 +000094 if a:zipfile !~# '^\a\+://'
95 " if its an url, don't complain, let url-handlers such as vim do its thing
Bram Moolenaar9964e462007-05-05 17:54:07 +000096 redraw!
Bram Moolenaara5792f52005-11-23 21:25:05 +000097 echohl Error | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None
Bram Moolenaar9964e462007-05-05 17:54:07 +000098" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaara5792f52005-11-23 21:25:05 +000099 endif
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000100 let &report= repkeep
Bram Moolenaara5792f52005-11-23 21:25:05 +0000101" call Dret("zip#Browse : file<".a:zipfile."> not readable")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000102 return
103 endif
Bram Moolenaardb552d602006-03-23 22:59:57 +0000104" call Decho("passed sanity checks")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000105 if &ma != 1
106 set ma
107 endif
Bram Moolenaarccc18222007-05-10 18:25:20 +0000108 let b:zipfile= a:zipfile
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000109
110 setlocal noswapfile
111 setlocal buftype=nofile
112 setlocal bufhidden=hide
113 setlocal nobuflisted
114 setlocal nowrap
115 set ft=tar
116
117 " give header
Bram Moolenaar251e1912011-06-19 05:09:16 +0200118 call append(0, ['" zip.vim version '.g:loaded_zip,
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100119 \ '" Browsing zipfile '.a:zipfile,
120 \ '" Select a file with cursor and press ENTER'])
Bram Moolenaar251e1912011-06-19 05:09:16 +0200121 keepj $
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000122
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000123" call Decho("exe silent r! ".g:zip_unzipcmd." -l -- ".s:Escape(a:zipfile,1))
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100124 exe "keepj sil! r! ".g:zip_unzipcmd." -Z -1 -- ".s:Escape(a:zipfile,1)
Bram Moolenaard68071d2006-05-02 22:08:30 +0000125 if v:shell_error != 0
Bram Moolenaar9964e462007-05-05 17:54:07 +0000126 redraw!
Bram Moolenaarc236c162008-07-13 17:41:49 +0000127 echohl WarningMsg | echo "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file" | echohl None
Bram Moolenaar9964e462007-05-05 17:54:07 +0000128" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar251e1912011-06-19 05:09:16 +0200129 keepj sil! %d
Bram Moolenaard68071d2006-05-02 22:08:30 +0000130 let eikeep= &ei
131 set ei=BufReadCmd,FileReadCmd
Bram Moolenaar251e1912011-06-19 05:09:16 +0200132 exe "keepj r ".fnameescape(a:zipfile)
Bram Moolenaard68071d2006-05-02 22:08:30 +0000133 let &ei= eikeep
Bram Moolenaar251e1912011-06-19 05:09:16 +0200134 keepj 1d
Bram Moolenaard68071d2006-05-02 22:08:30 +0000135" call Dret("zip#Browse")
136 return
137 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000138
139 setlocal noma nomod ro
140 noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr>
141
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000142 let &report= repkeep
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000143" call Dret("zip#Browse")
144endfun
145
146" ---------------------------------------------------------------------
147" ZipBrowseSelect: {{{2
148fun! s:ZipBrowseSelect()
Bram Moolenaarccc18222007-05-10 18:25:20 +0000149" call Dfunc("ZipBrowseSelect() zipfile<".b:zipfile."> curfile<".expand("%").">")
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000150 let repkeep= &report
151 set report=10
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000152 let fname= getline(".")
153
154 " sanity check
155 if fname =~ '^"'
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000156 let &report= repkeep
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000157" call Dret("ZipBrowseSelect")
158 return
159 endif
160 if fname =~ '/$'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000161 redraw!
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000162 echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None
Bram Moolenaar9964e462007-05-05 17:54:07 +0000163" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000164 let &report= repkeep
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000165" call Dret("ZipBrowseSelect")
166 return
167 endif
168
169" call Decho("fname<".fname.">")
170
171 " get zipfile to the new-window
Bram Moolenaarccc18222007-05-10 18:25:20 +0000172 let zipfile = b:zipfile
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000173 let curfile= expand("%")
Bram Moolenaardb552d602006-03-23 22:59:57 +0000174" call Decho("zipfile<".zipfile.">")
175" call Decho("curfile<".curfile.">")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000176
177 new
Bram Moolenaar446cb832008-06-24 21:56:24 +0000178 if !exists("g:zip_nomax") || g:zip_nomax == 0
179 wincmd _
180 endif
Bram Moolenaara5792f52005-11-23 21:25:05 +0000181 let s:zipfile_{winnr()}= curfile
Bram Moolenaarc236c162008-07-13 17:41:49 +0000182" call Decho("exe e ".fnameescape("zipfile:".zipfile.'::'.fname))
183 exe "e ".fnameescape("zipfile:".zipfile.'::'.fname)
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000184 filetype detect
185
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000186 let &report= repkeep
Bram Moolenaara5792f52005-11-23 21:25:05 +0000187" call Dret("ZipBrowseSelect : s:zipfile_".winnr()."<".s:zipfile_{winnr()}.">")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000188endfun
189
190" ---------------------------------------------------------------------
191" zip#Read: {{{2
192fun! zip#Read(fname,mode)
193" call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")")
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000194 let repkeep= &report
195 set report=10
196
Bram Moolenaard68071d2006-05-02 22:08:30 +0000197 if has("unix")
198 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\)::[^\\].*$','\1','')
199 let fname = substitute(a:fname,'zipfile:.\{-}::\([^\\].*\)$','\1','')
200 else
201 let zipfile = substitute(a:fname,'^.\{-}zipfile:\(.\{-}\)::[^\\].*$','\1','')
202 let fname = substitute(a:fname,'^.\{-}zipfile:.\{-}::\([^\\].*\)$','\1','')
Bram Moolenaarff034192013-04-24 18:51:19 +0200203 let fname = substitute(fname, '[', '[[]', 'g')
Bram Moolenaard68071d2006-05-02 22:08:30 +0000204 endif
205" call Decho("zipfile<".zipfile.">")
206" call Decho("fname <".fname.">")
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000207
Bram Moolenaarff034192013-04-24 18:51:19 +0200208 " the following code does much the same thing as
209 " exe "keepj sil! r! ".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1)
210 " but allows zipfile:... entries in quickfix lists
211 let temp = tempname()
Bram Moolenaar94f76b72013-07-04 22:50:40 +0200212" call Decho("using temp file<".temp.">")
Bram Moolenaarff034192013-04-24 18:51:19 +0200213 let fn = expand('%:p')
214 exe "sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp
215" call Decho("exe sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp)
216 sil exe 'keepalt file '.temp
217 sil keepj e!
218 sil exe 'keepalt file '.fnameescape(fn)
219 call delete(temp)
220
Bram Moolenaar251e1912011-06-19 05:09:16 +0200221 filetype detect
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000222
223 " cleanup
Bram Moolenaar94f76b72013-07-04 22:50:40 +0200224 " keepj 0d " used to be needed for the ...r! ... method
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000225 set nomod
226
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000227 let &report= repkeep
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000228" call Dret("zip#Read")
229endfun
230
231" ---------------------------------------------------------------------
232" zip#Write: {{{2
233fun! zip#Write(fname)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000234" call Dfunc("zip#Write(fname<".a:fname.">) zipfile_".winnr()."<".s:zipfile_{winnr()}.">")
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000235 let repkeep= &report
236 set report=10
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000237
238 " sanity checks
Bram Moolenaarccc18222007-05-10 18:25:20 +0000239 if !executable(g:zip_zipcmd)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000240 redraw!
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000241 echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the zip pgm" | echohl None
Bram Moolenaar9964e462007-05-05 17:54:07 +0000242" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000243 let &report= repkeep
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000244" call Dret("zip#Write")
245 return
246 endif
247 if !exists("*mkdir")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000248 redraw!
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000249 echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None
Bram Moolenaar9964e462007-05-05 17:54:07 +0000250" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000251 let &report= repkeep
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000252" call Dret("zip#Write")
253 return
254 endif
255
256 let curdir= getcwd()
257 let tmpdir= tempname()
258" call Decho("orig tempname<".tmpdir.">")
259 if tmpdir =~ '\.'
260 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e')
261 endif
262" call Decho("tmpdir<".tmpdir.">")
263 call mkdir(tmpdir,"p")
264
265 " attempt to change to the indicated directory
Bram Moolenaar9964e462007-05-05 17:54:07 +0000266 if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory")
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000267 let &report= repkeep
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000268" call Dret("zip#Write")
269 return
Bram Moolenaar9964e462007-05-05 17:54:07 +0000270 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000271" call Decho("current directory now: ".getcwd())
272
273 " place temporary files under .../_ZIPVIM_/
274 if isdirectory("_ZIPVIM_")
275 call s:Rmdir("_ZIPVIM_")
276 endif
277 call mkdir("_ZIPVIM_")
278 cd _ZIPVIM_
279" call Decho("current directory now: ".getcwd())
280
Bram Moolenaard68071d2006-05-02 22:08:30 +0000281 if has("unix")
282 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\)::[^\\].*$','\1','')
283 let fname = substitute(a:fname,'zipfile:.\{-}::\([^\\].*\)$','\1','')
284 else
285 let zipfile = substitute(a:fname,'^.\{-}zipfile:\(.\{-}\)::[^\\].*$','\1','')
286 let fname = substitute(a:fname,'^.\{-}zipfile:.\{-}::\([^\\].*\)$','\1','')
287 endif
288" call Decho("zipfile<".zipfile.">")
289" call Decho("fname <".fname.">")
Bram Moolenaarc7486e02005-12-29 22:48:26 +0000290
291 if fname =~ '/'
292 let dirpath = substitute(fname,'/[^/]\+$','','e')
Bram Moolenaarff034192013-04-24 18:51:19 +0200293 if has("win32unix") && executable("cygpath")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000294 let dirpath = substitute(system("cygpath ".s:Escape(dirpath,0)),'\n','','e')
Bram Moolenaarc7486e02005-12-29 22:48:26 +0000295 endif
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000296" call Decho("mkdir(dirpath<".dirpath.">,p)")
Bram Moolenaarc7486e02005-12-29 22:48:26 +0000297 call mkdir(dirpath,"p")
298 endif
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000299 if zipfile !~ '/'
300 let zipfile= curdir.'/'.zipfile
301 endif
302" call Decho("zipfile<".zipfile."> fname<".fname.">")
303
Bram Moolenaarc236c162008-07-13 17:41:49 +0000304 exe "w! ".fnameescape(fname)
Bram Moolenaarff034192013-04-24 18:51:19 +0200305 if has("win32unix") && executable("cygpath")
Bram Moolenaarc236c162008-07-13 17:41:49 +0000306 let zipfile = substitute(system("cygpath ".s:Escape(zipfile,0)),'\n','','e')
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000307 endif
308
Bram Moolenaar9964e462007-05-05 17:54:07 +0000309 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$'
310 let fname = substitute(fname, '[', '[[]', 'g')
311 endif
312
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000313" call Decho(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0))
314 call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0))
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000315 if v:shell_error != 0
Bram Moolenaar9964e462007-05-05 17:54:07 +0000316 redraw!
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000317 echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None
Bram Moolenaar9964e462007-05-05 17:54:07 +0000318" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaara5792f52005-11-23 21:25:05 +0000319
320 elseif s:zipfile_{winnr()} =~ '^\a\+://'
321 " support writing zipfiles across a network
322 let netzipfile= s:zipfile_{winnr()}
Bram Moolenaar9964e462007-05-05 17:54:07 +0000323" call Decho("handle writing <".zipfile."> across network as <".netzipfile.">")
Bram Moolenaara5792f52005-11-23 21:25:05 +0000324 1split|enew
325 let binkeep= &binary
326 let eikeep = &ei
327 set binary ei=all
Bram Moolenaarc236c162008-07-13 17:41:49 +0000328 exe "e! ".fnameescape(zipfile)
Bram Moolenaara5792f52005-11-23 21:25:05 +0000329 call netrw#NetWrite(netzipfile)
330 let &ei = eikeep
331 let &binary = binkeep
332 q!
333 unlet s:zipfile_{winnr()}
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000334 endif
335
336 " cleanup and restore current directory
337 cd ..
338 call s:Rmdir("_ZIPVIM_")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000339 call s:ChgDir(curdir,s:WARNING,"(zip#Write) unable to return to ".curdir."!")
340 call s:Rmdir(tmpdir)
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000341 setlocal nomod
342
Bram Moolenaar36c31f72005-11-28 23:01:53 +0000343 let &report= repkeep
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000344" call Dret("zip#Write")
345endfun
346
347" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +0000348" s:Escape: {{{2
349fun! s:Escape(fname,isfilt)
350" call Dfunc("QuoteFileDir(fname<".a:fname."> isfilt=".a:isfilt.")")
351 if exists("*shellescape")
352 if a:isfilt
353 let qnameq= shellescape(a:fname,1)
354 else
355 let qnameq= shellescape(a:fname)
356 endif
Bram Moolenaar446cb832008-06-24 21:56:24 +0000357 else
358 let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq
359 endif
360" call Dret("QuoteFileDir <".qnameq.">")
361 return qnameq
Bram Moolenaar9964e462007-05-05 17:54:07 +0000362endfun
363
364" ---------------------------------------------------------------------
365" ChgDir: {{{2
366fun! s:ChgDir(newdir,errlvl,errmsg)
367" call Dfunc("ChgDir(newdir<".a:newdir."> errlvl=".a:errlvl." errmsg<".a:errmsg.">)")
368
Bram Moolenaar9964e462007-05-05 17:54:07 +0000369 try
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000370 exe "cd ".fnameescape(a:newdir)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000371 catch /^Vim\%((\a\+)\)\=:E344/
372 redraw!
373 if a:errlvl == s:NOTE
374 echo "***note*** ".a:errmsg
375 elseif a:errlvl == s:WARNING
376 echohl WarningMsg | echo "***warning*** ".a:errmsg | echohl NONE
377 elseif a:errlvl == s:ERROR
378 echohl Error | echo "***error*** ".a:errmsg | echohl NONE
379 endif
380" call inputsave()|call input("Press <cr> to continue")|call inputrestore()
381" call Dret("ChgDir 1")
382 return 1
383 endtry
384
385" call Dret("ChgDir 0")
386 return 0
387endfun
388
389" ---------------------------------------------------------------------
Bram Moolenaarc236c162008-07-13 17:41:49 +0000390" s:Rmdir: {{{2
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000391fun! s:Rmdir(fname)
392" call Dfunc("Rmdir(fname<".a:fname.">)")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000393 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$'
Bram Moolenaarc236c162008-07-13 17:41:49 +0000394 call system("rmdir /S/Q ".s:Escape(a:fname,0))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000395 else
Bram Moolenaarc236c162008-07-13 17:41:49 +0000396 call system("/bin/rm -rf ".s:Escape(a:fname,0))
Bram Moolenaar60a795a2005-09-16 21:55:43 +0000397 endif
398" call Dret("Rmdir")
399endfun
400
401" ------------------------------------------------------------------------
402" Modelines And Restoration: {{{1
403let &cpo= s:keepcpo
404unlet s:keepcpo
Bram Moolenaarccc18222007-05-10 18:25:20 +0000405" vim:ts=8 fdm=marker