Mercurial > vim
annotate runtime/autoload/zip.vim @ 25802:5ef704de7709 v8.2.3436
patch 8.2.3436: check for optional bool type has confusing return type
Commit: https://github.com/vim/vim/commit/a29856fcdc41541c607437629c1c1f45951100a4
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 13 21:36:27 2021 +0200
patch 8.2.3436: check for optional bool type has confusing return type
Problem: Check for optional bool type has confusing return type.
Solution: Explicitly return OK.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 13 Sep 2021 21:45:04 +0200 |
parents | 11b656e74444 |
children | 624439a39432 |
rev | line source |
---|---|
530 | 1 " zip.vim: Handles browsing zipfiles |
2 " AUTOLOAD PORTION | |
19099 | 3 " Date: Jan 07, 2020 |
22723 | 4 " Version: 31 |
19099 | 5 " Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> |
1121 | 6 " License: Vim License (see vim's :help license) |
19099 | 7 " Copyright: Copyright (C) 2005-2019 Charles E. Campbell {{{1 |
530 | 8 " 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, | |
1621 | 11 " 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 | |
530 | 14 " holder be liable for any damages resulting from the use |
15 " of this software. | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
16 "redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
530 | 17 |
18 " --------------------------------------------------------------------- | |
1121 | 19 " Load Once: {{{1 |
2152 | 20 if &cp || exists("g:loaded_zip") |
21 finish | |
22 endif | |
22723 | 23 let g:loaded_zip= "v31" |
2152 | 24 if v:version < 702 |
25 echohl WarningMsg | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
26 echo "***warning*** this version of zip needs vim 7.2 or later" |
2152 | 27 echohl Normal |
28 finish | |
29 endif | |
530 | 30 let s:keepcpo= &cpo |
31 set cpo&vim | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
32 "DechoTabOn |
530 | 33 |
798 | 34 let s:zipfile_escape = ' ?&;\' |
1121 | 35 let s:ERROR = 2 |
36 let s:WARNING = 1 | |
37 let s:NOTE = 0 | |
38 | |
39 " --------------------------------------------------------------------- | |
40 " Global Values: {{{1 | |
41 if !exists("g:zip_shq") | |
1621 | 42 if &shq != "" |
43 let g:zip_shq= &shq | |
44 elseif has("unix") | |
1121 | 45 let g:zip_shq= "'" |
46 else | |
47 let g:zip_shq= '"' | |
48 endif | |
49 endif | |
1214 | 50 if !exists("g:zip_zipcmd") |
51 let g:zip_zipcmd= "zip" | |
52 endif | |
53 if !exists("g:zip_unzipcmd") | |
54 let g:zip_unzipcmd= "unzip" | |
55 endif | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
56 if !exists("g:zip_extractcmd") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
57 let g:zip_extractcmd= g:zip_unzipcmd |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
58 endif |
530 | 59 |
60 " ---------------- | |
61 " Functions: {{{1 | |
62 " ---------------- | |
63 | |
64 " --------------------------------------------------------------------- | |
65 " zip#Browse: {{{2 | |
66 fun! zip#Browse(zipfile) | |
67 " call Dfunc("zip#Browse(zipfile<".a:zipfile.">)") | |
22723 | 68 " sanity check: insure that the zipfile has "PK" as its first two letters |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
69 " (zipped files have a leading PK as a "magic cookie") |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
70 if !filereadable(a:zipfile) || readfile(a:zipfile, "", 1)[0] !~ '^PK' |
19099 | 71 exe "noswapfile noautocmd noswapfile e ".fnameescape(a:zipfile) |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
72 " call Dret("zip#Browse : not a zipfile<".a:zipfile.">") |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
73 return |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
74 " else " Decho |
19116 | 75 " call Decho("zip#Browse: a:zipfile<".a:zipfile."> passed PK test - it's a zip file") |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
76 endif |
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
77 |
568 | 78 let repkeep= &report |
79 set report=10 | |
530 | 80 |
81 " sanity checks | |
1698 | 82 if !exists("*fnameescape") |
83 if &verbose > 1 | |
25773 | 84 echoerr "the zip plugin is not available (your vim doesn't support fnameescape())" |
1698 | 85 endif |
86 return | |
87 endif | |
1214 | 88 if !executable(g:zip_unzipcmd) |
1121 | 89 redraw! |
530 | 90 echohl Error | echo "***error*** (zip#Browse) unzip not available on your system" |
1121 | 91 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 92 let &report= repkeep |
530 | 93 " call Dret("zip#Browse") |
94 return | |
95 endif | |
96 if !filereadable(a:zipfile) | |
557 | 97 if a:zipfile !~# '^\a\+://' |
19116 | 98 " if it's an url, don't complain, let url-handlers such as vim do its thing |
1121 | 99 redraw! |
557 | 100 echohl Error | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None |
1121 | 101 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
557 | 102 endif |
568 | 103 let &report= repkeep |
557 | 104 " call Dret("zip#Browse : file<".a:zipfile."> not readable") |
530 | 105 return |
106 endif | |
798 | 107 " call Decho("passed sanity checks") |
530 | 108 if &ma != 1 |
109 set ma | |
110 endif | |
1214 | 111 let b:zipfile= a:zipfile |
530 | 112 |
113 setlocal noswapfile | |
114 setlocal buftype=nofile | |
115 setlocal bufhidden=hide | |
116 setlocal nobuflisted | |
117 setlocal nowrap | |
118 set ft=tar | |
119 | |
120 " give header | |
2908 | 121 call append(0, ['" zip.vim version '.g:loaded_zip, |
3281 | 122 \ '" Browsing zipfile '.a:zipfile, |
123 \ '" Select a file with cursor and press ENTER']) | |
2908 | 124 keepj $ |
530 | 125 |
1698 | 126 " call Decho("exe silent r! ".g:zip_unzipcmd." -l -- ".s:Escape(a:zipfile,1)) |
3281 | 127 exe "keepj sil! r! ".g:zip_unzipcmd." -Z -1 -- ".s:Escape(a:zipfile,1) |
857 | 128 if v:shell_error != 0 |
1121 | 129 redraw! |
1668 | 130 echohl WarningMsg | echo "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file" | echohl None |
1121 | 131 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
2908 | 132 keepj sil! %d |
857 | 133 let eikeep= &ei |
134 set ei=BufReadCmd,FileReadCmd | |
2908 | 135 exe "keepj r ".fnameescape(a:zipfile) |
857 | 136 let &ei= eikeep |
2908 | 137 keepj 1d |
857 | 138 " call Dret("zip#Browse") |
139 return | |
140 endif | |
530 | 141 |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
142 " Maps associated with zip plugin |
530 | 143 setlocal noma nomod ro |
19099 | 144 noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr> |
145 noremap <silent> <buffer> x :call zip#Extract()<cr> | |
146 if &mouse != "" | |
147 noremap <silent> <buffer> <leftmouse> <leftmouse>:call <SID>ZipBrowseSelect()<cr> | |
148 endif | |
530 | 149 |
568 | 150 let &report= repkeep |
530 | 151 " call Dret("zip#Browse") |
152 endfun | |
153 | |
154 " --------------------------------------------------------------------- | |
155 " ZipBrowseSelect: {{{2 | |
156 fun! s:ZipBrowseSelect() | |
1214 | 157 " call Dfunc("ZipBrowseSelect() zipfile<".b:zipfile."> curfile<".expand("%").">") |
568 | 158 let repkeep= &report |
159 set report=10 | |
530 | 160 let fname= getline(".") |
161 | |
162 " sanity check | |
163 if fname =~ '^"' | |
568 | 164 let &report= repkeep |
530 | 165 " call Dret("ZipBrowseSelect") |
166 return | |
167 endif | |
168 if fname =~ '/$' | |
1121 | 169 redraw! |
530 | 170 echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None |
1121 | 171 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 172 let &report= repkeep |
530 | 173 " call Dret("ZipBrowseSelect") |
174 return | |
175 endif | |
176 | |
177 " call Decho("fname<".fname.">") | |
178 | |
179 " get zipfile to the new-window | |
1214 | 180 let zipfile = b:zipfile |
19099 | 181 let curfile = expand("%") |
798 | 182 " call Decho("zipfile<".zipfile.">") |
183 " call Decho("curfile<".curfile.">") | |
530 | 184 |
19099 | 185 noswapfile new |
1621 | 186 if !exists("g:zip_nomax") || g:zip_nomax == 0 |
187 wincmd _ | |
188 endif | |
557 | 189 let s:zipfile_{winnr()}= curfile |
1668 | 190 " call Decho("exe e ".fnameescape("zipfile:".zipfile.'::'.fname)) |
19099 | 191 exe "noswapfile e ".fnameescape("zipfile:".zipfile.'::'.fname) |
530 | 192 filetype detect |
193 | |
568 | 194 let &report= repkeep |
557 | 195 " call Dret("ZipBrowseSelect : s:zipfile_".winnr()."<".s:zipfile_{winnr()}.">") |
530 | 196 endfun |
197 | |
198 " --------------------------------------------------------------------- | |
199 " zip#Read: {{{2 | |
200 fun! zip#Read(fname,mode) | |
201 " call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")") | |
568 | 202 let repkeep= &report |
203 set report=10 | |
204 | |
857 | 205 if has("unix") |
206 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\)::[^\\].*$','\1','') | |
207 let fname = substitute(a:fname,'zipfile:.\{-}::\([^\\].*\)$','\1','') | |
208 else | |
209 let zipfile = substitute(a:fname,'^.\{-}zipfile:\(.\{-}\)::[^\\].*$','\1','') | |
210 let fname = substitute(a:fname,'^.\{-}zipfile:.\{-}::\([^\\].*\)$','\1','') | |
4339 | 211 let fname = substitute(fname, '[', '[[]', 'g') |
857 | 212 endif |
213 " call Decho("zipfile<".zipfile.">") | |
214 " call Decho("fname <".fname.">") | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
215 " sanity check |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
216 if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
217 redraw! |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
218 echohl Error | echo "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program" | echohl None |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
219 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
220 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
221 " call Dret("zip#Write") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
222 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
223 endif |
530 | 224 |
4339 | 225 " the following code does much the same thing as |
226 " exe "keepj sil! r! ".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1) | |
227 " but allows zipfile:... entries in quickfix lists | |
228 let temp = tempname() | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
229 " call Decho("using temp file<".temp.">") |
4339 | 230 let fn = expand('%:p') |
231 exe "sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp | |
232 " call Decho("exe sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp) | |
233 sil exe 'keepalt file '.temp | |
234 sil keepj e! | |
235 sil exe 'keepalt file '.fnameescape(fn) | |
236 call delete(temp) | |
237 | |
2908 | 238 filetype detect |
530 | 239 |
240 " cleanup | |
5130
71e066e10a47
updated for version 7.3.1308
Bram Moolenaar <bram@vim.org>
parents:
4339
diff
changeset
|
241 " keepj 0d " used to be needed for the ...r! ... method |
530 | 242 set nomod |
243 | |
568 | 244 let &report= repkeep |
530 | 245 " call Dret("zip#Read") |
246 endfun | |
247 | |
248 " --------------------------------------------------------------------- | |
249 " zip#Write: {{{2 | |
250 fun! zip#Write(fname) | |
819 | 251 " call Dfunc("zip#Write(fname<".a:fname.">) zipfile_".winnr()."<".s:zipfile_{winnr()}.">") |
568 | 252 let repkeep= &report |
253 set report=10 | |
530 | 254 |
255 " sanity checks | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
256 if !executable(substitute(g:zip_zipcmd,'\s\+.*$','','')) |
1121 | 257 redraw! |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
258 echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program" | echohl None |
1121 | 259 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 260 let &report= repkeep |
530 | 261 " call Dret("zip#Write") |
262 return | |
263 endif | |
264 if !exists("*mkdir") | |
1121 | 265 redraw! |
530 | 266 echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None |
1121 | 267 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
568 | 268 let &report= repkeep |
530 | 269 " call Dret("zip#Write") |
270 return | |
271 endif | |
272 | |
273 let curdir= getcwd() | |
274 let tmpdir= tempname() | |
275 " call Decho("orig tempname<".tmpdir.">") | |
276 if tmpdir =~ '\.' | |
277 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') | |
278 endif | |
279 " call Decho("tmpdir<".tmpdir.">") | |
280 call mkdir(tmpdir,"p") | |
281 | |
282 " attempt to change to the indicated directory | |
1121 | 283 if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory") |
568 | 284 let &report= repkeep |
530 | 285 " call Dret("zip#Write") |
286 return | |
1121 | 287 endif |
530 | 288 " call Decho("current directory now: ".getcwd()) |
289 | |
290 " place temporary files under .../_ZIPVIM_/ | |
291 if isdirectory("_ZIPVIM_") | |
292 call s:Rmdir("_ZIPVIM_") | |
293 endif | |
294 call mkdir("_ZIPVIM_") | |
295 cd _ZIPVIM_ | |
296 " call Decho("current directory now: ".getcwd()) | |
297 | |
857 | 298 if has("unix") |
299 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\)::[^\\].*$','\1','') | |
300 let fname = substitute(a:fname,'zipfile:.\{-}::\([^\\].*\)$','\1','') | |
301 else | |
302 let zipfile = substitute(a:fname,'^.\{-}zipfile:\(.\{-}\)::[^\\].*$','\1','') | |
303 let fname = substitute(a:fname,'^.\{-}zipfile:.\{-}::\([^\\].*\)$','\1','') | |
304 endif | |
305 " call Decho("zipfile<".zipfile.">") | |
306 " call Decho("fname <".fname.">") | |
623 | 307 |
308 if fname =~ '/' | |
309 let dirpath = substitute(fname,'/[^/]\+$','','e') | |
4339 | 310 if has("win32unix") && executable("cygpath") |
1668 | 311 let dirpath = substitute(system("cygpath ".s:Escape(dirpath,0)),'\n','','e') |
623 | 312 endif |
819 | 313 " call Decho("mkdir(dirpath<".dirpath.">,p)") |
623 | 314 call mkdir(dirpath,"p") |
315 endif | |
530 | 316 if zipfile !~ '/' |
317 let zipfile= curdir.'/'.zipfile | |
318 endif | |
319 " call Decho("zipfile<".zipfile."> fname<".fname.">") | |
320 | |
1668 | 321 exe "w! ".fnameescape(fname) |
4339 | 322 if has("win32unix") && executable("cygpath") |
1668 | 323 let zipfile = substitute(system("cygpath ".s:Escape(zipfile,0)),'\n','','e') |
530 | 324 endif |
325 | |
1121 | 326 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$' |
327 let fname = substitute(fname, '[', '[[]', 'g') | |
328 endif | |
329 | |
1698 | 330 " call Decho(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) |
331 call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) | |
530 | 332 if v:shell_error != 0 |
1121 | 333 redraw! |
530 | 334 echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None |
1121 | 335 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() |
557 | 336 |
337 elseif s:zipfile_{winnr()} =~ '^\a\+://' | |
338 " support writing zipfiles across a network | |
339 let netzipfile= s:zipfile_{winnr()} | |
1121 | 340 " call Decho("handle writing <".zipfile."> across network as <".netzipfile.">") |
557 | 341 1split|enew |
342 let binkeep= &binary | |
343 let eikeep = &ei | |
344 set binary ei=all | |
19099 | 345 exe "noswapfile e! ".fnameescape(zipfile) |
557 | 346 call netrw#NetWrite(netzipfile) |
347 let &ei = eikeep | |
348 let &binary = binkeep | |
349 q! | |
350 unlet s:zipfile_{winnr()} | |
530 | 351 endif |
352 | |
353 " cleanup and restore current directory | |
354 cd .. | |
355 call s:Rmdir("_ZIPVIM_") | |
1121 | 356 call s:ChgDir(curdir,s:WARNING,"(zip#Write) unable to return to ".curdir."!") |
357 call s:Rmdir(tmpdir) | |
530 | 358 setlocal nomod |
359 | |
568 | 360 let &report= repkeep |
530 | 361 " call Dret("zip#Write") |
362 endfun | |
363 | |
364 " --------------------------------------------------------------------- | |
10211
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
365 " zip#Extract: extract a file from a zip archive {{{2 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
366 fun! zip#Extract() |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
367 " call Dfunc("zip#Extract()") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
368 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
369 let repkeep= &report |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
370 set report=10 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
371 let fname= getline(".") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
372 " call Decho("fname<".fname.">") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
373 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
374 " sanity check |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
375 if fname =~ '^"' |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
376 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
377 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
378 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
379 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
380 if fname =~ '/$' |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
381 redraw! |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
382 echohl Error | echo "***error*** (zip#Extract) Please specify a file, not a directory" | echohl None |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
383 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
384 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
385 return |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
386 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
387 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
388 " extract the file mentioned under the cursor |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
389 " call Decho("system(".g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell).")") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
390 call system(g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell)) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
391 " call Decho("zipfile<".b:zipfile.">") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
392 if v:shell_error != 0 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
393 echohl Error | echo "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!" | echohl NONE |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
394 elseif !filereadable(fname) |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
395 echohl Error | echo "***error*** attempted to extract ".fname." but it doesn't appear to be present!" |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
396 else |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
397 echo "***note*** successfully extracted ".fname |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
398 endif |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
399 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
400 " restore option |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
401 let &report= repkeep |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
402 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
403 " call Dret("zip#Extract") |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
404 endfun |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
405 |
b7da8d4c594c
commit https://github.com/vim/vim/commit/d07969093a9b3051511c478d71c36de6fc33c0d6
Christian Brabandt <cb@256bit.org>
parents:
5130
diff
changeset
|
406 " --------------------------------------------------------------------- |
1668 | 407 " s:Escape: {{{2 |
408 fun! s:Escape(fname,isfilt) | |
409 " call Dfunc("QuoteFileDir(fname<".a:fname."> isfilt=".a:isfilt.")") | |
410 if exists("*shellescape") | |
411 if a:isfilt | |
412 let qnameq= shellescape(a:fname,1) | |
413 else | |
414 let qnameq= shellescape(a:fname) | |
415 endif | |
1621 | 416 else |
417 let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq | |
418 endif | |
419 " call Dret("QuoteFileDir <".qnameq.">") | |
420 return qnameq | |
1121 | 421 endfun |
422 | |
423 " --------------------------------------------------------------------- | |
424 " ChgDir: {{{2 | |
425 fun! s:ChgDir(newdir,errlvl,errmsg) | |
426 " call Dfunc("ChgDir(newdir<".a:newdir."> errlvl=".a:errlvl." errmsg<".a:errmsg.">)") | |
427 | |
428 try | |
1698 | 429 exe "cd ".fnameescape(a:newdir) |
1121 | 430 catch /^Vim\%((\a\+)\)\=:E344/ |
431 redraw! | |
432 if a:errlvl == s:NOTE | |
433 echo "***note*** ".a:errmsg | |
434 elseif a:errlvl == s:WARNING | |
435 echohl WarningMsg | echo "***warning*** ".a:errmsg | echohl NONE | |
436 elseif a:errlvl == s:ERROR | |
437 echohl Error | echo "***error*** ".a:errmsg | echohl NONE | |
438 endif | |
439 " call inputsave()|call input("Press <cr> to continue")|call inputrestore() | |
440 " call Dret("ChgDir 1") | |
441 return 1 | |
442 endtry | |
443 | |
444 " call Dret("ChgDir 0") | |
445 return 0 | |
446 endfun | |
447 | |
448 " --------------------------------------------------------------------- | |
1668 | 449 " s:Rmdir: {{{2 |
530 | 450 fun! s:Rmdir(fname) |
451 " call Dfunc("Rmdir(fname<".a:fname.">)") | |
1121 | 452 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$' |
1668 | 453 call system("rmdir /S/Q ".s:Escape(a:fname,0)) |
1121 | 454 else |
1668 | 455 call system("/bin/rm -rf ".s:Escape(a:fname,0)) |
530 | 456 endif |
457 " call Dret("Rmdir") | |
458 endfun | |
459 | |
460 " ------------------------------------------------------------------------ | |
461 " Modelines And Restoration: {{{1 | |
462 let &cpo= s:keepcpo | |
463 unlet s:keepcpo | |
1214 | 464 " vim:ts=8 fdm=marker |