Mercurial > vim
annotate runtime/autoload/tar.vim @ 3757:3b62d8f36cdf v7.3.637
updated for version 7.3.637
Problem: Cannot catch the error caused by a foldopen when there is no fold.
(ZyX, Issue 48)
Solution: Do not break out of the loop early when inside try/catch.
(Christian Brabandt) Except when there is a syntax error.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 23 Aug 2012 18:43:10 +0200 |
parents | af1e8a1714c2 |
children | 22fa3049e934 |
rev | line source |
---|---|
557 | 1 " tar.vim: Handles browsing tarfiles |
2 " AUTOLOAD PORTION | |
3281 | 3 " Date: Jan 17, 2012 |
4 " Version: 28 | |
1125 | 5 " Maintainer: Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM> |
557 | 6 " License: Vim License (see vim's :help license) |
446 | 7 " |
557 | 8 " Contains many ideas from Michael Toren's <tar.vim> |
446 | 9 " |
2908 | 10 " Copyright: Copyright (C) 2005-2011 Charles E. Campbell, Jr. {{{1 |
557 | 11 " Permission is hereby granted to use and distribute this code, |
12 " with or without modifications, provided that this copyright | |
13 " notice is copied with it. Like anything else that's free, | |
1624 | 14 " tar.vim and tarPlugin.vim are provided *as is* and comes |
15 " with no warranty of any kind, either expressed or implied. | |
16 " By using this plugin, you agree that in no event will the | |
17 " copyright holder be liable for any damages resulting from | |
18 " the use of this software. | |
2034 | 19 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
557 | 20 " --------------------------------------------------------------------- |
1125 | 21 " Load Once: {{{1 |
2034 | 22 if &cp || exists("g:loaded_tar") |
23 finish | |
24 endif | |
3281 | 25 let g:loaded_tar= "v28" |
2034 | 26 if v:version < 702 |
27 echohl WarningMsg | |
28 echo "***warning*** this version of tar needs vim 7.2" | |
29 echohl Normal | |
30 finish | |
31 endif | |
557 | 32 let s:keepcpo= &cpo |
33 set cpo&vim | |
819 | 34 "call Decho("loading autoload/tar.vim") |
557 | 35 |
36 " --------------------------------------------------------------------- | |
37 " Default Settings: {{{1 | |
38 if !exists("g:tar_browseoptions") | |
39 let g:tar_browseoptions= "Ptf" | |
40 endif | |
41 if !exists("g:tar_readoptions") | |
42 let g:tar_readoptions= "OPxf" | |
43 endif | |
819 | 44 if !exists("g:tar_cmd") |
45 let g:tar_cmd= "tar" | |
46 endif | |
557 | 47 if !exists("g:tar_writeoptions") |
48 let g:tar_writeoptions= "uf" | |
49 endif | |
2908 | 50 if !exists("g:netrw_cygwin") |
51 if has("win32") || has("win95") || has("win64") || has("win16") | |
52 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' | |
53 let g:netrw_cygwin= 1 | |
54 else | |
55 let g:netrw_cygwin= 0 | |
56 endif | |
57 else | |
58 let g:netrw_cygwin= 0 | |
59 endif | |
60 endif | |
2034 | 61 if !exists("g:tar_copycmd") |
62 if !exists("g:netrw_localcopycmd") | |
63 if has("win32") || has("win95") || has("win64") || has("win16") | |
64 if g:netrw_cygwin | |
65 let g:netrw_localcopycmd= "cp" | |
66 else | |
67 let g:netrw_localcopycmd= "copy" | |
68 endif | |
69 elseif has("unix") || has("macunix") | |
70 let g:netrw_localcopycmd= "cp" | |
71 else | |
72 let g:netrw_localcopycmd= "" | |
73 endif | |
74 endif | |
75 let g:tar_copycmd= g:netrw_localcopycmd | |
76 endif | |
77 if !exists("g:tar_extractcmd") | |
78 let g:tar_extractcmd= "tar -xf" | |
79 endif | |
1624 | 80 |
81 " set up shell quoting character | |
1125 | 82 if !exists("g:tar_shq") |
1624 | 83 if exists("&shq") && &shq != "" |
84 let g:tar_shq= &shq | |
85 elseif has("win32") || has("win95") || has("win64") || has("win16") | |
86 if exists("g:netrw_cygwin") && g:netrw_cygwin | |
87 let g:tar_shq= "'" | |
88 else | |
89 let g:tar_shq= '"' | |
90 endif | |
91 else | |
1125 | 92 let g:tar_shq= "'" |
93 endif | |
1624 | 94 " call Decho("g:tar_shq<".g:tar_shq.">") |
1125 | 95 endif |
557 | 96 |
97 " ---------------- | |
98 " Functions: {{{1 | |
99 " ---------------- | |
446 | 100 |
527 | 101 " --------------------------------------------------------------------- |
557 | 102 " tar#Browse: {{{2 |
103 fun! tar#Browse(tarfile) | |
104 " call Dfunc("tar#Browse(tarfile<".a:tarfile.">)") | |
569 | 105 let repkeep= &report |
106 set report=10 | |
446 | 107 |
557 | 108 " sanity checks |
819 | 109 if !executable(g:tar_cmd) |
1125 | 110 redraw! |
819 | 111 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' |
569 | 112 let &report= repkeep |
557 | 113 " call Dret("tar#Browse") |
114 return | |
115 endif | |
116 if !filereadable(a:tarfile) | |
819 | 117 " call Decho('a:tarfile<'.a:tarfile.'> not filereadable') |
557 | 118 if a:tarfile !~# '^\a\+://' |
119 " if its an url, don't complain, let url-handlers such as vim do its thing | |
1125 | 120 redraw! |
557 | 121 echohl Error | echo "***error*** (tar#Browse) File not readable<".a:tarfile.">" | echohl None |
122 endif | |
569 | 123 let &report= repkeep |
557 | 124 " call Dret("tar#Browse : file<".a:tarfile."> not readable") |
125 return | |
126 endif | |
127 if &ma != 1 | |
128 set ma | |
129 endif | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
130 let b:tarfile= a:tarfile |
446 | 131 |
557 | 132 setlocal noswapfile |
133 setlocal buftype=nofile | |
134 setlocal bufhidden=hide | |
135 setlocal nobuflisted | |
136 setlocal nowrap | |
137 set ft=tar | |
446 | 138 |
557 | 139 " give header |
819 | 140 " call Decho("printing header") |
1624 | 141 let lastline= line("$") |
142 call setline(lastline+1,'" tar.vim version '.g:loaded_tar) | |
143 call setline(lastline+2,'" Browsing tarfile '.a:tarfile) | |
144 call setline(lastline+3,'" Select a file with cursor and press ENTER') | |
2908 | 145 keepj $put ='' |
3281 | 146 keepj sil! 0d |
2908 | 147 keepj $ |
446 | 148 |
819 | 149 let tarfile= a:tarfile |
150 if has("win32") && executable("cygpath") | |
151 " assuming cygwin | |
2034 | 152 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
819 | 153 endif |
857 | 154 let curlast= line("$") |
819 | 155 if tarfile =~# '\.\(gz\|tgz\)$' |
2034 | 156 " call Decho("1: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
2908 | 157 exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
1624 | 158 elseif tarfile =~# '\.lrp' |
2034 | 159 " call Decho("2: exe silent r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - ") |
2908 | 160 exe "sil! r! cat -- ".shellescape(tarfile,1)."|gzip -d -c -|".g:tar_cmd." -".g:tar_browseoptions." - " |
3281 | 161 elseif tarfile =~# '\.\(bz2\|tbz\|tb2\)$' |
2034 | 162 " call Decho("3: exe silent r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
2908 | 163 exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
3281 | 164 elseif tarfile =~# '\.\(lzma\|tlz\)$' |
2034 | 165 " call Decho("3: exe silent r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") |
2908 | 166 exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
2426 | 167 elseif tarfile =~# '\.\(xz\|txz\)$' |
168 " call Decho("3: exe silent r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - ") | |
2908 | 169 exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_browseoptions." - " |
557 | 170 else |
1702 | 171 if tarfile =~ '^\s*-' |
2034 | 172 " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. |
1702 | 173 let tarfile = substitute(tarfile, '-', './-', '') |
174 endif | |
2034 | 175 " call Decho("4: exe silent r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,0)) |
2908 | 176 exe "sil! r! ".g:tar_cmd." -".g:tar_browseoptions." ".shellescape(tarfile,1) |
557 | 177 endif |
819 | 178 if v:shell_error != 0 |
1125 | 179 redraw! |
857 | 180 echohl WarningMsg | echo "***warning*** (tar#Browse) please check your g:tar_browseoptions<".g:tar_browseoptions.">" |
181 " call Dret("tar#Browse : a:tarfile<".a:tarfile.">") | |
182 return | |
183 endif | |
1125 | 184 if line("$") == curlast || ( line("$") == (curlast + 1) && getline("$") =~ '\c\%(warning\|error\|inappropriate\|unrecognized\)') |
185 redraw! | |
857 | 186 echohl WarningMsg | echo "***warning*** (tar#Browse) ".a:tarfile." doesn't appear to be a tar file" | echohl None |
2908 | 187 keepj sil! %d |
857 | 188 let eikeep= &ei |
189 set ei=BufReadCmd,FileReadCmd | |
1668 | 190 exe "r ".fnameescape(a:tarfile) |
857 | 191 let &ei= eikeep |
2908 | 192 keepj sil! 1d |
857 | 193 " call Dret("tar#Browse : a:tarfile<".a:tarfile.">") |
819 | 194 return |
195 endif | |
446 | 196 |
557 | 197 setlocal noma nomod ro |
198 noremap <silent> <buffer> <cr> :call <SID>TarBrowseSelect()<cr> | |
199 | |
569 | 200 let &report= repkeep |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
201 " call Dret("tar#Browse : b:tarfile<".b:tarfile.">") |
527 | 202 endfun |
203 | |
204 " --------------------------------------------------------------------- | |
557 | 205 " TarBrowseSelect: {{{2 |
206 fun! s:TarBrowseSelect() | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
207 " call Dfunc("TarBrowseSelect() b:tarfile<".b:tarfile."> curfile<".expand("%").">") |
569 | 208 let repkeep= &report |
209 set report=10 | |
557 | 210 let fname= getline(".") |
211 " call Decho("fname<".fname.">") | |
212 | |
1702 | 213 if !exists("g:tar_secure") && fname =~ '^\s*-\|\s\+-' |
214 redraw! | |
2034 | 215 echohl WarningMsg | echo '***warning*** (tar#BrowseSelect) rejecting tarfile member<'.fname.'> because of embedded "-"' |
1702 | 216 " call Dret('tar#BrowseSelect : rejecting tarfile member<'.fname.'> because of embedded "-"') |
217 return | |
218 endif | |
219 | |
557 | 220 " sanity check |
221 if fname =~ '^"' | |
569 | 222 let &report= repkeep |
557 | 223 " call Dret("TarBrowseSelect") |
224 return | |
225 endif | |
226 | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
227 " about to make a new window, need to use b:tarfile |
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
228 let tarfile= b:tarfile |
557 | 229 let curfile= expand("%") |
819 | 230 if has("win32") && executable("cygpath") |
231 " assuming cygwin | |
2034 | 232 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
819 | 233 endif |
557 | 234 |
235 new | |
1624 | 236 if !exists("g:tar_nomax") || g:tar_nomax == 0 |
237 wincmd _ | |
238 endif | |
557 | 239 let s:tblfile_{winnr()}= curfile |
1624 | 240 call tar#Read("tarfile:".tarfile.'::'.fname,1) |
557 | 241 filetype detect |
242 | |
569 | 243 let &report= repkeep |
557 | 244 " call Dret("TarBrowseSelect : s:tblfile_".winnr()."<".s:tblfile_{winnr()}.">") |
245 endfun | |
246 | |
247 " --------------------------------------------------------------------- | |
248 " tar#Read: {{{2 | |
249 fun! tar#Read(fname,mode) | |
250 " call Dfunc("tar#Read(fname<".a:fname.">,mode=".a:mode.")") | |
569 | 251 let repkeep= &report |
252 set report=10 | |
1624 | 253 let tarfile = substitute(a:fname,'tarfile:\(.\{-}\)::.*$','\1','') |
254 let fname = substitute(a:fname,'tarfile:.\{-}::\(.*\)$','\1','') | |
819 | 255 if has("win32") && executable("cygpath") |
256 " assuming cygwin | |
2034 | 257 let tarfile=substitute(system("cygpath -u ".shellescape(tarfile,0)),'\n$','','e') |
819 | 258 endif |
259 " call Decho("tarfile<".tarfile.">") | |
260 " call Decho("fname<".fname.">") | |
557 | 261 |
2034 | 262 if fname =~ '\.bz2$' && executable("bzcat") |
263 let decmp= "|bzcat" | |
264 let doro = 1 | |
265 elseif fname =~ '\.gz$' && executable("zcat") | |
1624 | 266 let decmp= "|zcat" |
267 let doro = 1 | |
2034 | 268 elseif fname =~ '\.lzma$' && executable("lzcat") |
269 let decmp= "|lzcat" | |
1624 | 270 let doro = 1 |
2426 | 271 elseif fname =~ '\.xz$' && executable("xzcat") |
272 let decmp= "|xzcat" | |
273 let doro = 1 | |
1624 | 274 else |
275 let decmp="" | |
276 let doro = 0 | |
2426 | 277 if fname =~ '\.bz2$\|\.gz$\|\.lzma$\|\.xz$\|\.zip$\|\.Z$' |
1624 | 278 setlocal bin |
279 endif | |
280 endif | |
281 | |
1702 | 282 if exists("g:tar_secure") |
283 let tar_secure= " -- " | |
284 else | |
285 let tar_secure= " " | |
286 endif | |
2034 | 287 if tarfile =~# '\.bz2$' |
288 " call Decho("7: exe silent r! bzip2 -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) | |
2908 | 289 exe "sil! r! bzip2 -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
2034 | 290 elseif tarfile =~# '\.\(gz\|tgz\)$' |
291 " call Decho("5: exe silent r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd.' -'.g:tar_readoptions.' - '.tar_secure.shellescape(fname,1)) | |
2908 | 292 exe "sil! r! gzip -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
1624 | 293 elseif tarfile =~# '\.lrp$' |
2034 | 294 " call Decho("6: exe silent r! cat ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) |
2908 | 295 exe "sil! r! cat -- ".shellescape(tarfile,1)." | gzip -d -c - | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
2034 | 296 elseif tarfile =~# '\.lzma$' |
297 " call Decho("7: exe silent r! lzma -d -c ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) | |
2908 | 298 exe "sil! r! lzma -d -c -- ".shellescape(tarfile,1)."| ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
2426 | 299 elseif tarfile =~# '\.\(xz\|txz\)$' |
300 " call Decho("3: exe silent r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp) | |
2908 | 301 exe "sil! r! xz --decompress --stdout -- ".shellescape(tarfile,1)." | ".g:tar_cmd." -".g:tar_readoptions." - ".tar_secure.shellescape(fname,1).decmp |
557 | 302 else |
1702 | 303 if tarfile =~ '^\s*-' |
2034 | 304 " A file name starting with a dash is taken as an option. Prepend ./ to avoid that. |
1702 | 305 let tarfile = substitute(tarfile, '-', './-', '') |
306 endif | |
2034 | 307 " call Decho("8: exe silent r! ".g:tar_cmd." -".g:tar_readoptions.tar_secure.shellescape(tarfile,1)." ".shellescape(fname,1).decmp) |
308 exe "silent r! ".g:tar_cmd." -".g:tar_readoptions.shellescape(tarfile,1)." ".tar_secure.shellescape(fname,1).decmp | |
557 | 309 endif |
1624 | 310 |
311 if doro | |
312 " because the reverse process of compressing changed files back into the tarball is not currently supported | |
313 setlocal ro | |
314 endif | |
315 | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
316 let b:tarfile= a:fname |
1668 | 317 exe "file tarfile::".fnameescape(fname) |
557 | 318 |
319 " cleanup | |
2908 | 320 keepj sil! 0d |
557 | 321 set nomod |
322 | |
569 | 323 let &report= repkeep |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
324 " call Dret("tar#Read : b:tarfile<".b:tarfile.">") |
557 | 325 endfun |
326 | |
327 " --------------------------------------------------------------------- | |
328 " tar#Write: {{{2 | |
329 fun! tar#Write(fname) | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
330 " call Dfunc("tar#Write(fname<".a:fname.">) b:tarfile<".b:tarfile."> tblfile_".winnr()."<".s:tblfile_{winnr()}.">") |
569 | 331 let repkeep= &report |
332 set report=10 | |
557 | 333 |
1702 | 334 if !exists("g:tar_secure") && a:fname =~ '^\s*-\|\s\+-' |
335 redraw! | |
2034 | 336 echohl WarningMsg | echo '***warning*** (tar#Write) rejecting tarfile member<'.a:fname.'> because of embedded "-"' |
1702 | 337 " call Dret('tar#Write : rejecting tarfile member<'.fname.'> because of embedded "-"') |
338 return | |
339 endif | |
340 | |
527 | 341 " sanity checks |
819 | 342 if !executable(g:tar_cmd) |
1125 | 343 redraw! |
819 | 344 echohl Error | echo '***error*** (tar#Browse) "'.g:tar_cmd.'" not available on your system' |
569 | 345 let &report= repkeep |
527 | 346 " call Dret("tar#Write") |
347 return | |
348 endif | |
349 if !exists("*mkdir") | |
1125 | 350 redraw! |
557 | 351 echohl Error | echo "***error*** (tar#Write) sorry, mkdir() doesn't work on your system" | echohl None |
569 | 352 let &report= repkeep |
527 | 353 " call Dret("tar#Write") |
354 return | |
355 endif | |
356 | |
357 let curdir= getcwd() | |
358 let tmpdir= tempname() | |
359 " call Decho("orig tempname<".tmpdir.">") | |
360 if tmpdir =~ '\.' | |
361 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') | |
362 endif | |
363 " call Decho("tmpdir<".tmpdir.">") | |
364 call mkdir(tmpdir,"p") | |
365 | |
366 " attempt to change to the indicated directory | |
367 try | |
1624 | 368 exe "cd ".fnameescape(tmpdir) |
527 | 369 catch /^Vim\%((\a\+)\)\=:E344/ |
1125 | 370 redraw! |
557 | 371 echohl Error | echo "***error*** (tar#Write) cannot cd to temporary directory" | Echohl None |
569 | 372 let &report= repkeep |
527 | 373 " call Dret("tar#Write") |
374 return | |
375 endtry | |
376 " call Decho("current directory now: ".getcwd()) | |
446 | 377 |
557 | 378 " place temporary files under .../_ZIPVIM_/ |
379 if isdirectory("_ZIPVIM_") | |
380 call s:Rmdir("_ZIPVIM_") | |
527 | 381 endif |
557 | 382 call mkdir("_ZIPVIM_") |
383 cd _ZIPVIM_ | |
527 | 384 " call Decho("current directory now: ".getcwd()) |
385 | |
2535
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
386 let tarfile = substitute(b:tarfile,'tarfile:\(.\{-}\)::.*$','\1','') |
31e51111bd14
Runtime file updates. Fix tar plugin window split.
Bram Moolenaar <bram@vim.org>
parents:
2426
diff
changeset
|
387 let fname = substitute(b:tarfile,'tarfile:.\{-}::\(.*\)$','\1','') |
557 | 388 |
389 " handle compressed archives | |
2034 | 390 if tarfile =~# '\.bz2' |
391 call system("bzip2 -d -- ".shellescape(tarfile,0)) | |
392 let tarfile = substitute(tarfile,'\.bz2','','e') | |
393 let compress= "bzip2 -- ".shellescape(tarfile,0) | |
394 " call Decho("compress<".compress.">") | |
395 elseif tarfile =~# '\.gz' | |
396 call system("gzip -d -- ".shellescape(tarfile,0)) | |
557 | 397 let tarfile = substitute(tarfile,'\.gz','','e') |
2034 | 398 let compress= "gzip -- ".shellescape(tarfile,0) |
399 " call Decho("compress<".compress.">") | |
557 | 400 elseif tarfile =~# '\.tgz' |
2034 | 401 call system("gzip -d -- ".shellescape(tarfile,0)) |
557 | 402 let tarfile = substitute(tarfile,'\.tgz','.tar','e') |
2034 | 403 let compress= "gzip -- ".shellescape(tarfile,0) |
557 | 404 let tgz = 1 |
1702 | 405 " call Decho("compress<".compress.">") |
2426 | 406 elseif tarfile =~# '\.xz' |
407 call system("xz -d -- ".shellescape(tarfile,0)) | |
408 let tarfile = substitute(tarfile,'\.xz','','e') | |
409 let compress= "xz -- ".shellescape(tarfile,0) | |
410 " call Decho("compress<".compress.">") | |
411 elseif tarfile =~# '\.lzma' | |
412 call system("lzma -d -- ".shellescape(tarfile,0)) | |
413 let tarfile = substitute(tarfile,'\.lzma','','e') | |
414 let compress= "lzma -- ".shellescape(tarfile,0) | |
415 " call Decho("compress<".compress.">") | |
527 | 416 endif |
1624 | 417 " call Decho("tarfile<".tarfile.">") |
527 | 418 |
419 if v:shell_error != 0 | |
1125 | 420 redraw! |
557 | 421 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".tarfile." with ".fname | echohl None |
527 | 422 else |
557 | 423 |
424 " call Decho("tarfile<".tarfile."> fname<".fname.">") | |
425 | |
624 | 426 if fname =~ '/' |
427 let dirpath = substitute(fname,'/[^/]\+$','','e') | |
428 if executable("cygpath") | |
2034 | 429 let dirpath = substitute(system("cygpath ".shellescape(dirpath, 0)),'\n','','e') |
624 | 430 endif |
431 call mkdir(dirpath,"p") | |
432 endif | |
557 | 433 if tarfile !~ '/' |
434 let tarfile= curdir.'/'.tarfile | |
435 endif | |
1702 | 436 if tarfile =~ '^\s*-' |
437 " A file name starting with a dash may be taken as an option. Prepend ./ to avoid that. | |
438 let tarfile = substitute(tarfile, '-', './-', '') | |
439 endif | |
557 | 440 " call Decho("tarfile<".tarfile."> fname<".fname.">") |
441 | |
1702 | 442 if exists("g:tar_secure") |
443 let tar_secure= " -- " | |
444 else | |
445 let tar_secure= " " | |
446 endif | |
1624 | 447 exe "w! ".fnameescape(fname) |
557 | 448 if executable("cygpath") |
2034 | 449 let tarfile = substitute(system("cygpath ".shellescape(tarfile,0)),'\n','','e') |
557 | 450 endif |
451 | |
452 " delete old file from tarfile | |
2034 | 453 " call Decho("system(".g:tar_cmd." --delete -f ".shellescape(tarfile,0)." -- ".shellescape(fname,0).")") |
454 call system(g:tar_cmd." --delete -f ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) | |
557 | 455 if v:shell_error != 0 |
1125 | 456 redraw! |
1624 | 457 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None |
557 | 458 else |
459 | |
460 " update tarfile with new file | |
2034 | 461 " call Decho(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) |
462 call system(g:tar_cmd." -".g:tar_writeoptions." ".shellescape(tarfile,0).tar_secure.shellescape(fname,0)) | |
557 | 463 if v:shell_error != 0 |
1125 | 464 redraw! |
1624 | 465 echohl Error | echo "***error*** (tar#Write) sorry, unable to update ".fnameescape(tarfile)." with ".fnameescape(fname) | echohl None |
557 | 466 elseif exists("compress") |
467 " call Decho("call system(".compress.")") | |
468 call system(compress) | |
469 if exists("tgz") | |
470 " call Decho("rename(".tarfile.".gz,".substitute(tarfile,'\.tar$','.tgz','e').")") | |
471 call rename(tarfile.".gz",substitute(tarfile,'\.tar$','.tgz','e')) | |
472 endif | |
473 endif | |
474 endif | |
475 | |
476 " support writing tarfiles across a network | |
477 if s:tblfile_{winnr()} =~ '^\a\+://' | |
478 " call Decho("handle writing <".tarfile."> across network to <".s:tblfile_{winnr()}.">") | |
479 let tblfile= s:tblfile_{winnr()} | |
480 1split|enew | |
2034 | 481 let binkeep= &l:binary |
557 | 482 let eikeep = &ei |
483 set binary ei=all | |
1668 | 484 exe "e! ".fnameescape(tarfile) |
557 | 485 call netrw#NetWrite(tblfile) |
2034 | 486 let &ei = eikeep |
487 let &l:binary = binkeep | |
557 | 488 q! |
489 unlet s:tblfile_{winnr()} | |
490 endif | |
527 | 491 endif |
492 | |
493 " cleanup and restore current directory | |
494 cd .. | |
557 | 495 call s:Rmdir("_ZIPVIM_") |
1668 | 496 exe "cd ".fnameescape(curdir) |
527 | 497 setlocal nomod |
498 | |
569 | 499 let &report= repkeep |
527 | 500 " call Dret("tar#Write") |
501 endfun | |
502 | |
503 " --------------------------------------------------------------------- | |
2034 | 504 " s:Rmdir: {{{2 |
527 | 505 fun! s:Rmdir(fname) |
506 " call Dfunc("Rmdir(fname<".a:fname.">)") | |
507 if has("unix") | |
2034 | 508 call system("/bin/rm -rf -- ".shellescape(a:fname,0)) |
527 | 509 elseif has("win32") || has("win95") || has("win64") || has("win16") |
510 if &shell =~? "sh$" | |
2034 | 511 call system("/bin/rm -rf -- ".shellescape(a:fname,0)) |
527 | 512 else |
2034 | 513 call system("del /S ".shellescape(a:fname,0)) |
527 | 514 endif |
515 endif | |
516 " call Dret("Rmdir") | |
517 endfun | |
518 | |
1624 | 519 " --------------------------------------------------------------------- |
2034 | 520 " tar#Vimuntar: installs a tarball in the user's .vim / vimfiles directory {{{2 |
521 fun! tar#Vimuntar(...) | |
522 " call Dfunc("tar#Vimuntar() a:0=".a:0." a:1<".(exists("a:1")? a:1 : "-n/a-").">") | |
523 let tarball = expand("%") | |
524 " call Decho("tarball<".tarball.">") | |
525 let tarbase = substitute(tarball,'\..*$','','') | |
526 " call Decho("tarbase<".tarbase.">") | |
527 let tarhome = expand("%:p") | |
528 if has("win32") || has("win95") || has("win64") || has("win16") | |
529 let tarhome= substitute(tarhome,'\\','/','g') | |
530 endif | |
531 let tarhome= substitute(tarhome,'/[^/]*$','','') | |
532 " call Decho("tarhome<".tarhome.">") | |
533 let tartail = expand("%:t") | |
534 " call Decho("tartail<".tartail.">") | |
535 let curdir = getcwd() | |
536 " call Decho("curdir <".curdir.">") | |
537 " set up vimhome | |
538 if a:0 > 0 && a:1 != "" | |
539 let vimhome= a:1 | |
540 else | |
541 let vimhome= vimball#VimballHome() | |
542 endif | |
543 " call Decho("vimhome<".vimhome.">") | |
544 | |
545 " call Decho("curdir<".curdir."> vimhome<".vimhome.">") | |
546 if simplify(curdir) != simplify(vimhome) | |
547 " copy (possibly compressed) tarball to .vim/vimfiles | |
548 " call Decho(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) | |
549 call system(netrw#WinPath(g:tar_copycmd)." ".shellescape(tartail)." ".shellescape(vimhome)) | |
550 " call Decho("exe cd ".fnameescape(vimhome)) | |
551 exe "cd ".fnameescape(vimhome) | |
552 endif | |
553 " call Decho("getcwd<".getcwd().">") | |
554 | |
555 " if necessary, decompress the tarball; then, extract it | |
556 if tartail =~ '\.tgz' | |
557 if executable("gunzip") | |
558 silent exe "!gunzip ".shellescape(tartail) | |
559 elseif executable("gzip") | |
560 silent exe "!gzip -d ".shellescape(tartail) | |
1668 | 561 else |
2034 | 562 echoerr "unable to decompress<".tartail."> on this sytem" |
563 if simplify(curdir) != simplify(tarhome) | |
564 " remove decompressed tarball, restore directory | |
565 " call Decho("delete(".tartail.".tar)") | |
566 call delete(tartail.".tar") | |
567 " call Decho("exe cd ".fnameescape(curdir)) | |
568 exe "cd ".fnameescape(curdir) | |
569 endif | |
570 " call Dret("tar#Vimuntar") | |
571 return | |
1668 | 572 endif |
1624 | 573 else |
2034 | 574 call vimball#Decompress(tartail,0) |
1624 | 575 endif |
2034 | 576 let extractcmd= netrw#WinPath(g:tar_extractcmd) |
577 " call Decho("system(".extractcmd." ".shellescape(tarbase.".tar").")") | |
578 call system(extractcmd." ".shellescape(tarbase.".tar")) | |
579 | |
580 " set up help | |
581 if filereadable("doc/".tarbase.".txt") | |
582 " call Decho("exe helptags ".getcwd()."/doc") | |
583 exe "helptags ".getcwd()."/doc" | |
584 endif | |
585 | |
586 if simplify(tarhome) != simplify(vimhome) | |
587 " remove decompressed tarball, restore directory | |
588 call delete(vimhome."/".tarbase.".tar") | |
589 exe "cd ".fnameescape(curdir) | |
590 endif | |
591 | |
592 " call Dret("tar#Vimuntar") | |
1624 | 593 endfun |
594 | |
2034 | 595 " ===================================================================== |
557 | 596 " Modelines And Restoration: {{{1 |
597 let &cpo= s:keepcpo | |
598 unlet s:keepcpo | |
1624 | 599 " vim:ts=8 fdm=marker |