annotate runtime/autoload/zip.vim @ 841:c2cae213194d v7.0e07

updated for version 7.0e07
author vimboss
date Sun, 23 Apr 2006 22:40:29 +0000
parents 1cdd2661f34c
children b933657f7c9d
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
826
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
3 " Date: Apr 10, 2006
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
4 " Version: 8
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
826
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
25 let g:loaded_zip = "v8"
798
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
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
78 " call Decho("exe silent r! unzip -l '".a:zipfile."'")
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
79 exe "silent r! unzip -l '".a:zipfile."'"
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
80 " call Decho("line 6: ".getline(6))
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
81 let namecol= stridx(getline(6),'Name') + 1
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
82 " call Decho("namecol=".namecol)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
83 4,$g/^\s*----/d
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
84 4,$g/^\s*\a/d
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
85 $d
826
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
86 if namecol > 0
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
87 exe 'silent 4,$s/^.*\%'.namecol.'c//'
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
88 endif
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
89
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
90 setlocal noma nomod ro
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
91 noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr>
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
92
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
93 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
94 " call Dret("zip#Browse")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
95 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
96
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
97 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
98 " ZipBrowseSelect: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
99 fun! s:ZipBrowseSelect()
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
100 " call Dfunc("ZipBrowseSelect() zipfile<".w:zipfile."> curfile<".expand("%").">")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
101 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
102 set report=10
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
103 let fname= getline(".")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
104
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
105 " sanity check
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
106 if fname =~ '^"'
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
107 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
108 " call Dret("ZipBrowseSelect")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
109 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
110 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
111 if fname =~ '/$'
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
112 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
113 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
114 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
115 " call Dret("ZipBrowseSelect")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
116 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
117 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
118
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
119 " call Decho("fname<".fname.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
120
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
121 " get zipfile to the new-window
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
122 let zipfile= substitute(w:zipfile,'.zip$','','e')
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
123 let curfile= expand("%")
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
124 " call Decho("zipfile<".zipfile.">")
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
125 " call Decho("curfile<".curfile.">")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
126
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
127 new
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
128 wincmd _
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
129 let s:zipfile_{winnr()}= curfile
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
130 " call Decho("exe e zipfile:".escape(zipfile,s:zipfile_escape).':'.escape(fname,s:zipfile_escape))
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
131 exe "e zipfile:".escape(zipfile,s:zipfile_escape).':'.escape(fname,s:zipfile_escape)
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
132 filetype detect
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
133
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
134 let &report= repkeep
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
135 " call Dret("ZipBrowseSelect : s:zipfile_".winnr()."<".s:zipfile_{winnr()}.">")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
136 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
137
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
138 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
139 " zip#Read: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
140 fun! zip#Read(fname,mode)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
141 " call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
142 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
143 set report=10
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
144
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
145 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\):[^\\].*$','\1','')
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
146 let fname = substitute(a:fname,'zipfile:.\{-}:\([^\\].*\)$','\1','')
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
147 " call Decho("zipfile<".zipfile."> fname<".fname.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
148
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
149 " call Decho("exe r! unzip -p '".zipfile."' '".fname."'")
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
150 exe "silent r! unzip -p '".zipfile."' '".fname."'"
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
151
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
152 " cleanup
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
153 0d
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
154 set nomod
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
155
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
156 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
157 " call Dret("zip#Read")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
158 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
159
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
160 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
161 " zip#Write: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
162 fun! zip#Write(fname)
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
163 " call Dfunc("zip#Write(fname<".a:fname.">) zipfile_".winnr()."<".s:zipfile_{winnr()}.">")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
164 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
165 set report=10
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
166
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
167 " sanity checks
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
168 if !executable("zip")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
169 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
170 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
171 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
172 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
173 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
174 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
175 if !exists("*mkdir")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
176 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
177 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
178 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
179 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
180 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
181 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
182
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
183 let curdir= getcwd()
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
184 let tmpdir= tempname()
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
185 " call Decho("orig tempname<".tmpdir.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
186 if tmpdir =~ '\.'
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
187 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
188 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
189 " call Decho("tmpdir<".tmpdir.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
190 call mkdir(tmpdir,"p")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
191
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
192 " attempt to change to the indicated directory
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
193 try
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
194 exe "cd ".escape(tmpdir,' \')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
195 catch /^Vim\%((\a\+)\)\=:E344/
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
196 echohl Error | echo "***error*** (zip#Write) cannot cd to temporary directory" | Echohl None
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
197 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
198 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
199 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
200 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
201 endtry
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
202 " call Decho("current directory now: ".getcwd())
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
203
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
204 " place temporary files under .../_ZIPVIM_/
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
205 if isdirectory("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
206 call s:Rmdir("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
207 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
208 call mkdir("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
209 cd _ZIPVIM_
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
210 " call Decho("current directory now: ".getcwd())
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
211
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
212 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\):.*$','\1','')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
213 let fname = substitute(a:fname,'zipfile:.\{-}:\(.*\)$','\1','')
623
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
214
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
215 if fname =~ '/'
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
216 let dirpath = substitute(fname,'/[^/]\+$','','e')
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
217 if executable("cygpath")
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
218 let dirpath = substitute(system("cygpath ".dirpath),'\n','','e')
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
219 endif
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
220 " call Decho("mkdir(dirpath<".dirpath.">,p)")
623
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
221 call mkdir(dirpath,"p")
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
222 endif
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
223 if zipfile !~ '/'
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
224 let zipfile= curdir.'/'.zipfile
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
225 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
226 " call Decho("zipfile<".zipfile."> fname<".fname.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
227
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
228 exe "w! ".escape(fname,s:zipfile_escape)
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
229 if executable("cygpath")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
230 let zipfile = substitute(system("cygpath ".zipfile),'\n','','e')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
231 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
232
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
233 " call Decho("zip -u '".zipfile.".zip' '".fname."'")
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
234 call system("zip -u '".zipfile.".zip' '".fname."'")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
235 if v:shell_error != 0
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
236 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
237 call inputsave()|call input("Press <cr> to continue")|call inputrestore()
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
238
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
239 elseif s:zipfile_{winnr()} =~ '^\a\+://'
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
240 " support writing zipfiles across a network
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
241 let netzipfile= s:zipfile_{winnr()}
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
242 " call Decho("handle writing <".zipfile.".zip> across network as <".netzipfile.">")
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
243 1split|enew
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
244 let binkeep= &binary
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
245 let eikeep = &ei
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
246 set binary ei=all
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
247 exe "e! ".zipfile.".zip"
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
248 call netrw#NetWrite(netzipfile)
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
249 let &ei = eikeep
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
250 let &binary = binkeep
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
251 q!
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
252 unlet s:zipfile_{winnr()}
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
253 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
254
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
255 " cleanup and restore current directory
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
256 cd ..
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
257 call s:Rmdir("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
258 exe "cd ".escape(curdir,' \')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
259 setlocal nomod
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
260
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
261 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
262 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
263 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
264
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
265 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
266 " Rmdir: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
267 fun! s:Rmdir(fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
268 " call Dfunc("Rmdir(fname<".a:fname.">)")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
269 if has("unix")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
270 call system("/bin/rm -rf ".a:fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
271 elseif has("win32") || has("win95") || has("win64") || has("win16")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
272 if &shell =~? "sh$"
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
273 call system("/bin/rm -rf ".a:fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
274 else
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
275 call system("del /S ".a:fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
276 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
277 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
278 " call Dret("Rmdir")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
279 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
280
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
281 " ------------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
282 " Modelines And Restoration: {{{1
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
283 let &cpo= s:keepcpo
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
284 unlet s:keepcpo
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
285 " vim:ts=8 fdm=marker