annotate runtime/autoload/zip.vim @ 798:95dac6af3b3a v7.0232

updated for version 7.0232
author vimboss
date Thu, 23 Mar 2006 22:59:57 +0000
parents bd2fe62c9d77
children 6beb2c667935
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
1 " zip.vim: Handles browsing zipfiles
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
2 " AUTOLOAD PORTION
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
3 " Date: Mar 22, 2006
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
4 " Version: 7
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
5 " Maintainer: Charles E Campbell, Jr <drchipNOSPAM at campbellfamily dot biz>
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
6 " License: Vim License (see vim's :help license)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
7 " Copyright: Copyright (C) 2005 Charles E. Campbell, Jr. {{{1
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
8 " Permission is hereby granted to use and distribute this code,
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
9 " with or without modifications, provided that this copyright
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
10 " notice is copied with it. Like anything else that's free,
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
11 " zipPlugin.vim is provided *as is* and comes with no warranty
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
12 " of any kind, either expressed or implied. By using this
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
13 " plugin, you agree that in no event will the copyright
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
14 " holder be liable for any damages resulting from the use
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
15 " of this software.
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
16
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
17 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
18 " Initialization: {{{1
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
19 let s:keepcpo= &cpo
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
20 set cpo&vim
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
21 if exists("g:loaded_zip")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
22 finish
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
23 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
24
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
25 let g:loaded_zip = "v7"
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
26 let s:zipfile_escape = ' ?&;\'
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
27
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
28 " ----------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
29 " Functions: {{{1
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
30 " ----------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
31
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
32 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
33 " zip#Browse: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
34 fun! zip#Browse(zipfile)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
35 " call Dfunc("zip#Browse(zipfile<".a:zipfile.">)")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
36 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
37 set report=10
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
38
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
39 " sanity checks
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
40 if !executable("unzip")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
41 echohl Error | echo "***error*** (zip#Browse) unzip not available on your system"
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
42 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
43 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
44 " call Dret("zip#Browse")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
45 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
46 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
47 if !filereadable(a:zipfile)
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
48 if a:zipfile !~# '^\a\+://'
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
49 " if its an url, don't complain, let url-handlers such as vim do its thing
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
50 echohl Error | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
51 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
52 endif
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
53 let &report= repkeep
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
54 " call Dret("zip#Browse : file<".a:zipfile."> not readable")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
55 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
56 endif
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
57 " call Decho("passed sanity checks")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
58 if &ma != 1
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
59 set ma
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
60 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
61 let w:zipfile= a:zipfile
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
62
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
63 setlocal noswapfile
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
64 setlocal buftype=nofile
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
65 setlocal bufhidden=hide
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
66 setlocal nobuflisted
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
67 setlocal nowrap
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
68 set ft=tar
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
69
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
70 " give header
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
71 exe "$put ='".'\"'." zip.vim version ".g:loaded_zip."'"
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
72 exe "$put ='".'\"'." Browsing zipfile ".a:zipfile."'"
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
73 exe "$put ='".'\"'." Select a file with cursor and press ENTER"."'"
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
74 $put =''
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
75 0d
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
76 $
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
77
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
78 call Decho("exe silent r! unzip -l '".escape(a:zipfile,s:zipfile_escape)."'")
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
79 exe "silent r! unzip -l '".escape(a:zipfile,s:zipfile_escape)."'"
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
80 $d
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
81 silent 4,$v/^\s\+\d\+\s\{0,5}\d/d
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
82 silent 4,$s/^\%(.*\)\s\+\(\S\)/\1/
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
83
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
84 setlocal noma nomod ro
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
85 noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr>
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
86
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
87 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
88 " call Dret("zip#Browse")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
89 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
90
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
91 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
92 " ZipBrowseSelect: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
93 fun! s:ZipBrowseSelect()
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
94 " call Dfunc("ZipBrowseSelect() zipfile<".w:zipfile."> curfile<".expand("%").">")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
95 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
96 set report=10
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
97 let fname= getline(".")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
98
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
99 " sanity check
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
100 if fname =~ '^"'
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
101 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
102 " call Dret("ZipBrowseSelect")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
103 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
104 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
105 if fname =~ '/$'
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
106 echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
107 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
108 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
109 " call Dret("ZipBrowseSelect")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
110 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
111 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
112
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
113 " call Decho("fname<".fname.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
114
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
115 " get zipfile to the new-window
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
116 let zipfile= substitute(w:zipfile,'.zip$','','e')
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
117 let curfile= escape(expand("%"),s:zipfile_escape)
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
118 " call Decho("zipfile<".zipfile.">")
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
119 " call Decho("curfile<".curfile.">")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
120
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
121 new
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
122 wincmd _
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
123 let s:zipfile_{winnr()}= curfile
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
124 " call Decho("exe e zipfile:".escape(zipfile,s:zipfile_escape).':'.fname)
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
125 exe "e zipfile:".escape(zipfile,s:zipfile_escape).':'.fname
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
126 filetype detect
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
127
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
128 let &report= repkeep
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
129 " call Dret("ZipBrowseSelect : s:zipfile_".winnr()."<".s:zipfile_{winnr()}.">")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
130 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
131
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
132 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
133 " zip#Read: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
134 fun! zip#Read(fname,mode)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
135 " call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
136 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
137 set report=10
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
138
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
139 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\):[^\\].*$','\1','')
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
140 let fname = substitute(a:fname,'zipfile:.\{-}:\([^\\].*\)$','\1','')
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
141 " call Decho("zipfile<".zipfile."> fname<".fname.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
142
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
143 " call Decho("exe r! unzip -p '".escape(zipfile,s:zipfile_escape)."' ".fname)
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
144 exe "r! unzip -p '".escape(zipfile,s:zipfile_escape)."' ".fname
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
145
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
146 " cleanup
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
147 0d
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
148 set nomod
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
149
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
150 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
151 " call Dret("zip#Read")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
152 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
153
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
154 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
155 " zip#Write: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
156 fun! zip#Write(fname)
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
157 " call Dfunc("zip#Write(fname<".a:fname.") zipfile_".winnr()."<".s:zipfile_{winnr()}.">")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
158 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
159 set report=10
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
160
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
161 " sanity checks
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
162 if !executable("zip")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
163 echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the zip pgm" | echohl None
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
164 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
165 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
166 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
167 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
168 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
169 if !exists("*mkdir")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
170 echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
171 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
172 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
173 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
174 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
175 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
176
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
177 let curdir= getcwd()
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
178 let tmpdir= tempname()
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
179 " call Decho("orig tempname<".tmpdir.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
180 if tmpdir =~ '\.'
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
181 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
182 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
183 " call Decho("tmpdir<".tmpdir.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
184 call mkdir(tmpdir,"p")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
185
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
186 " attempt to change to the indicated directory
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
187 try
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
188 exe "cd ".escape(tmpdir,' \')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
189 catch /^Vim\%((\a\+)\)\=:E344/
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
190 echohl Error | echo "***error*** (zip#Write) cannot cd to temporary directory" | Echohl None
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
191 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
192 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
193 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
194 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
195 endtry
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
196 " call Decho("current directory now: ".getcwd())
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
197
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
198 " place temporary files under .../_ZIPVIM_/
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
199 if isdirectory("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
200 call s:Rmdir("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
201 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
202 call mkdir("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
203 cd _ZIPVIM_
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
204 " call Decho("current directory now: ".getcwd())
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
205
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
206 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\):.*$','\1','')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
207 let fname = substitute(a:fname,'zipfile:.\{-}:\(.*\)$','\1','')
623
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
208
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
209 if fname =~ '/'
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
210 let dirpath = substitute(fname,'/[^/]\+$','','e')
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
211 if executable("cygpath")
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
212 let dirpath = substitute(system("cygpath ".dirpath),'\n','','e')
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
213 endif
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
214 call mkdir(dirpath,"p")
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
215 endif
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
216 if zipfile !~ '/'
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
217 let zipfile= curdir.'/'.zipfile
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
218 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
219 " call Decho("zipfile<".zipfile."> fname<".fname.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
220
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
221 exe "w! ".fname
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
222 if executable("cygpath")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
223 let zipfile = substitute(system("cygpath ".zipfile),'\n','','e')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
224 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
225
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
226 " call Decho("zip -u ".zipfile.".zip ".fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
227 call system("zip -u ".zipfile.".zip ".fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
228 if v:shell_error != 0
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
229 echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
230 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
231
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
232 elseif s:zipfile_{winnr()} =~ '^\a\+://'
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
233 " support writing zipfiles across a network
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
234 let netzipfile= s:zipfile_{winnr()}
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
235 " call Decho("handle writing <".zipfile.".zip> across network as <".netzipfile.">")
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
236 1split|enew
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
237 let binkeep= &binary
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
238 let eikeep = &ei
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
239 set binary ei=all
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
240 exe "e! ".zipfile.".zip"
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
241 call netrw#NetWrite(netzipfile)
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
242 let &ei = eikeep
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
243 let &binary = binkeep
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
244 q!
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
245 unlet s:zipfile_{winnr()}
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
246 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
247
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
248 " cleanup and restore current directory
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
249 cd ..
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
250 call s:Rmdir("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
251 exe "cd ".escape(curdir,' \')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
252 setlocal nomod
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
253
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
254 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
255 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
256 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
257
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
258 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
259 " Rmdir: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
260 fun! s:Rmdir(fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
261 " call Dfunc("Rmdir(fname<".a:fname.">)")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
262 if has("unix")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
263 call system("/bin/rm -rf ".a:fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
264 elseif has("win32") || has("win95") || has("win64") || has("win16")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
265 if &shell =~? "sh$"
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
266 call system("/bin/rm -rf ".a:fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
267 else
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
268 call system("del /S ".a:fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
269 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
270 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
271 " call Dret("Rmdir")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
272 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
273
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
274 " ------------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
275 " Modelines And Restoration: {{{1
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
276 let &cpo= s:keepcpo
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
277 unlet s:keepcpo
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
278 " vim:ts=8 fdm=marker