annotate runtime/autoload/zip.vim @ 1240:5bed56fce2b5

updated for version 7.1
author vimboss
date Sat, 12 May 2007 13:25:01 +0000
parents a91a2e0c4108
children 82b5078be2dd
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
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
3 " Date: May 08, 2007
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
4 " Version: 14
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
5 " Maintainer: Charles E Campbell, Jr <NdrOchip@ScampbellPfamily.AbizM-NOSPAM>
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
6 " License: Vim License (see vim's :help license)
530
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 " ---------------------------------------------------------------------
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
18 " Load Once: {{{1
530
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
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
21 if &cp || exists("g:loaded_zip") || v:version < 700
530
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
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
25 let g:loaded_zip = "v14"
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
26 let s:zipfile_escape = ' ?&;\'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
27 let s:ERROR = 2
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
28 let s:WARNING = 1
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
29 let s:NOTE = 0
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
30
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
31 " ---------------------------------------------------------------------
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
32 " Global Values: {{{1
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
33 if !exists("g:zip_shq")
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
34 if has("unix")
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
35 let g:zip_shq= "'"
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
36 else
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
37 let g:zip_shq= '"'
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
38 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
39 endif
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
40 if !exists("g:zip_zipcmd")
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
41 let g:zip_zipcmd= "zip"
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
42 endif
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
43 if !exists("g:zip_unzipcmd")
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
44 let g:zip_unzipcmd= "unzip"
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
45 endif
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
46
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
47 " ----------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
48 " Functions: {{{1
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
49 " ----------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
50
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
51 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
52 " zip#Browse: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
53 fun! zip#Browse(zipfile)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
54 " call Dfunc("zip#Browse(zipfile<".a:zipfile.">)")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
55 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
56 set report=10
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
57
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
58 " sanity checks
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
59 if !executable(g:zip_unzipcmd)
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
60 redraw!
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
61 echohl Error | echo "***error*** (zip#Browse) unzip not available on your system"
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
62 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
63 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
64 " call Dret("zip#Browse")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
65 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
66 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
67 if !filereadable(a:zipfile)
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
68 if a:zipfile !~# '^\a\+://'
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
69 " if its an url, don't complain, let url-handlers such as vim do its thing
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
70 redraw!
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
71 echohl Error | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
72 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
73 endif
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
74 let &report= repkeep
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
75 " call Dret("zip#Browse : file<".a:zipfile."> not readable")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
76 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
77 endif
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
78 " call Decho("passed sanity checks")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
79 if &ma != 1
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
80 set ma
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
81 endif
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
82 let b:zipfile= a:zipfile
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
83
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
84 setlocal noswapfile
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
85 setlocal buftype=nofile
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
86 setlocal bufhidden=hide
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
87 setlocal nobuflisted
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
88 setlocal nowrap
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
89 set ft=tar
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
90
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
91 " give header
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
92 exe "$put ='".'\"'." zip.vim version ".g:loaded_zip."'"
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
93 exe "$put ='".'\"'." Browsing zipfile ".a:zipfile."'"
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
94 exe "$put ='".'\"'." Select a file with cursor and press ENTER"."'"
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
95 $put =''
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
96 0d
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
97 $
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
98
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
99 " call Decho("exe silent r! ".g:zip_unzipcmd." -l ".s:QuoteFileDir(a:zipfile))
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
100 exe "silent r! ".g:zip_unzipcmd." -l ".s:QuoteFileDir(a:zipfile)
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
101 if v:shell_error != 0
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
102 redraw!
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
103 echohl WarningMsg | echo "***warning*** (zip#Browse) ".a:zipfile." is not a zip file" | echohl None
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
104 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
105 silent %d
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
106 let eikeep= &ei
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
107 set ei=BufReadCmd,FileReadCmd
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
108 exe "r ".a:zipfile
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
109 let &ei= eikeep
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
110 1d
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
111 " call Dret("zip#Browse")
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
112 return
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
113 endif
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
114 " call Decho("line 6: ".getline(6))
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
115 let namecol= stridx(getline(6),'Name') + 1
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
116 " call Decho("namecol=".namecol)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
117 4,$g/^\s*----/d
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
118 4,$g/^\s*\a/d
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
119 $d
826
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
120 if namecol > 0
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
121 exe 'silent 4,$s/^.*\%'.namecol.'c//'
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 819
diff changeset
122 endif
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
123
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
124 setlocal noma nomod ro
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
125 noremap <silent> <buffer> <cr> :call <SID>ZipBrowseSelect()<cr>
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
126
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
127 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
128 " call Dret("zip#Browse")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
129 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
130
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
131 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
132 " ZipBrowseSelect: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
133 fun! s:ZipBrowseSelect()
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
134 " call Dfunc("ZipBrowseSelect() zipfile<".b:zipfile."> curfile<".expand("%").">")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
135 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
136 set report=10
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
137 let fname= getline(".")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
138
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
139 " sanity check
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
140 if fname =~ '^"'
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
141 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
142 " call Dret("ZipBrowseSelect")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
143 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
144 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
145 if fname =~ '/$'
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
146 redraw!
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
147 echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
148 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
149 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
150 " call Dret("ZipBrowseSelect")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
151 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
152 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
153
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
154 " call Decho("fname<".fname.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
155
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
156 " get zipfile to the new-window
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
157 let zipfile = b:zipfile
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
158 let curfile= expand("%")
798
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
159 " call Decho("zipfile<".zipfile.">")
95dac6af3b3a updated for version 7.0232
vimboss
parents: 623
diff changeset
160 " call Decho("curfile<".curfile.">")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
161
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
162 new
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
163 wincmd _
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
164 let s:zipfile_{winnr()}= curfile
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
165 " call Decho("exe e zipfile:".escape(zipfile,s:zipfile_escape).'::'.escape(fname,s:zipfile_escape))
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
166 exe "e zipfile:".escape(zipfile,s:zipfile_escape).'::'.escape(fname,s:zipfile_escape)
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
167 filetype detect
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
168
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
169 let &report= repkeep
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
170 " call Dret("ZipBrowseSelect : s:zipfile_".winnr()."<".s:zipfile_{winnr()}.">")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
171 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
172
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
173 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
174 " zip#Read: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
175 fun! zip#Read(fname,mode)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
176 " call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
177 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
178 set report=10
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
179
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
180 if has("unix")
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
181 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\)::[^\\].*$','\1','')
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
182 let fname = substitute(a:fname,'zipfile:.\{-}::\([^\\].*\)$','\1','')
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
183 else
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
184 let zipfile = substitute(a:fname,'^.\{-}zipfile:\(.\{-}\)::[^\\].*$','\1','')
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
185 let fname = substitute(a:fname,'^.\{-}zipfile:.\{-}::\([^\\].*\)$','\1','')
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
186 let fname = substitute(fname, '[', '[[]', 'g')
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
187 endif
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
188 " call Decho("zipfile<".zipfile.">")
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
189 " call Decho("fname <".fname.">")
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
190
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
191 " call Decho("exe r! ".g:zip_unzipcmd." -p ".s:QuoteFileDir(zipfile)." ".s:QuoteFileDir(fname))
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
192 exe "silent r! ".g:zip_unzipcmd." -p ".s:QuoteFileDir(zipfile)." ".s:QuoteFileDir(fname)
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
193
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
194 " cleanup
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
195 0d
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
196 set nomod
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
197
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#Read")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
200 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
201
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
202 " ---------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
203 " zip#Write: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
204 fun! zip#Write(fname)
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
205 " call Dfunc("zip#Write(fname<".a:fname.">) zipfile_".winnr()."<".s:zipfile_{winnr()}.">")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
206 let repkeep= &report
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
207 set report=10
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
208
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
209 " sanity checks
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
210 if !executable(g:zip_zipcmd)
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
211 redraw!
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
212 echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the zip pgm" | echohl None
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
213 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
214 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
215 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
216 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
217 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
218 if !exists("*mkdir")
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
219 redraw!
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
220 echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
221 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
222 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
223 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
224 return
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
225 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
226
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
227 let curdir= getcwd()
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
228 let tmpdir= tempname()
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
229 " call Decho("orig tempname<".tmpdir.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
230 if tmpdir =~ '\.'
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
231 let tmpdir= substitute(tmpdir,'\.[^.]*$','','e')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
232 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
233 " call Decho("tmpdir<".tmpdir.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
234 call mkdir(tmpdir,"p")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
235
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
236 " attempt to change to the indicated directory
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
237 if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory")
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
238 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
239 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
240 return
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
241 endif
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
242 " call Decho("current directory now: ".getcwd())
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
243
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
244 " place temporary files under .../_ZIPVIM_/
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
245 if isdirectory("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
246 call s:Rmdir("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
247 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
248 call mkdir("_ZIPVIM_")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
249 cd _ZIPVIM_
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
250 " call Decho("current directory now: ".getcwd())
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
251
857
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
252 if has("unix")
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
253 let zipfile = substitute(a:fname,'zipfile:\(.\{-}\)::[^\\].*$','\1','')
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
254 let fname = substitute(a:fname,'zipfile:.\{-}::\([^\\].*\)$','\1','')
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
255 else
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
256 let zipfile = substitute(a:fname,'^.\{-}zipfile:\(.\{-}\)::[^\\].*$','\1','')
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
257 let fname = substitute(a:fname,'^.\{-}zipfile:.\{-}::\([^\\].*\)$','\1','')
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
258 endif
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
259 " call Decho("zipfile<".zipfile.">")
b933657f7c9d updated for version 7.0g01
vimboss
parents: 826
diff changeset
260 " call Decho("fname <".fname.">")
623
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
261
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
262 if fname =~ '/'
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
263 let dirpath = substitute(fname,'/[^/]\+$','','e')
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
264 if executable("cygpath")
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
265 let dirpath = substitute(system("cygpath ".dirpath),'\n','','e')
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
266 endif
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
267 " call Decho("mkdir(dirpath<".dirpath.">,p)")
623
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
268 call mkdir(dirpath,"p")
bd2fe62c9d77 updated for version 7.0178
vimboss
parents: 568
diff changeset
269 endif
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
270 if zipfile !~ '/'
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
271 let zipfile= curdir.'/'.zipfile
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
272 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
273 " call Decho("zipfile<".zipfile."> fname<".fname.">")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
274
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 804
diff changeset
275 exe "w! ".escape(fname,s:zipfile_escape)
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
276 if executable("cygpath")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
277 let zipfile = substitute(system("cygpath ".zipfile),'\n','','e')
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
278 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
279
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
280 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$'
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
281 let fname = substitute(fname, '[', '[[]', 'g')
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
282 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
283
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
284 " call Decho(g:zip_zipcmd." -u ".s:QuoteFileDir(zipfile)." ".s:QuoteFileDir(fname))
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
285 call system(g:zip_zipcmd." -u ".s:QuoteFileDir(zipfile)." ".s:QuoteFileDir(fname))
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
286 if v:shell_error != 0
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
287 redraw!
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
288 echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
289 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
290
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
291 elseif s:zipfile_{winnr()} =~ '^\a\+://'
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
292 " support writing zipfiles across a network
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
293 let netzipfile= s:zipfile_{winnr()}
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
294 " call Decho("handle writing <".zipfile."> across network as <".netzipfile.">")
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
295 1split|enew
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
296 let binkeep= &binary
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
297 let eikeep = &ei
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
298 set binary ei=all
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
299 exe "e! ".zipfile
557
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
300 call netrw#NetWrite(netzipfile)
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
301 let &ei = eikeep
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
302 let &binary = binkeep
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
303 q!
862863033fdd updated for version 7.0158
vimboss
parents: 530
diff changeset
304 unlet s:zipfile_{winnr()}
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
305 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
306
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
307 " cleanup and restore current directory
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
308 cd ..
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
309 call s:Rmdir("_ZIPVIM_")
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
310 call s:ChgDir(curdir,s:WARNING,"(zip#Write) unable to return to ".curdir."!")
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
311 call s:Rmdir(tmpdir)
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
312 setlocal nomod
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
313
568
db92c5cc4f66 updated for version 7.0161
vimboss
parents: 557
diff changeset
314 let &report= repkeep
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
315 " call Dret("zip#Write")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
316 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
317
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
318 " ---------------------------------------------------------------------
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
319 " QuoteFileDir: {{{2
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
320 fun! s:QuoteFileDir(fname)
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
321 " call Dfunc("QuoteFileDir(fname<".a:fname.">)")
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
322 " call Dret("QuoteFileDir")
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
323 return g:zip_shq.a:fname.g:zip_shq
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
324 endfun
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
325
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
326 " ---------------------------------------------------------------------
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
327 " ChgDir: {{{2
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
328 fun! s:ChgDir(newdir,errlvl,errmsg)
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
329 " call Dfunc("ChgDir(newdir<".a:newdir."> errlvl=".a:errlvl." errmsg<".a:errmsg.">)")
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
330
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
331 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$'
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
332 let newdir= escape(a:newdir,' ')
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
333 else
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
334 let newdir= escape(a:newdir,'\ ')
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
335 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
336
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
337 try
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
338 exe "cd ".newdir
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
339 catch /^Vim\%((\a\+)\)\=:E344/
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
340 redraw!
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
341 if a:errlvl == s:NOTE
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
342 echo "***note*** ".a:errmsg
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
343 elseif a:errlvl == s:WARNING
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
344 echohl WarningMsg | echo "***warning*** ".a:errmsg | echohl NONE
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
345 elseif a:errlvl == s:ERROR
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
346 echohl Error | echo "***error*** ".a:errmsg | echohl NONE
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
347 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
348 " call inputsave()|call input("Press <cr> to continue")|call inputrestore()
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
349 " call Dret("ChgDir 1")
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
350 return 1
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
351 endtry
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
352
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
353 " call Dret("ChgDir 0")
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
354 return 0
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
355 endfun
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
356
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
357 " ---------------------------------------------------------------------
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
358 " Rmdir: {{{2
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
359 fun! s:Rmdir(fname)
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
360 " call Dfunc("Rmdir(fname<".a:fname.">)")
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
361 if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$'
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
362 call system("rmdir /S/Q ".s:QuoteFileDir(a:fname))
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
363 else
e63691e7c504 updated for version 7.1a
vimboss
parents: 857
diff changeset
364 call system("/bin/rm -rf ".s:QuoteFileDir(a:fname))
530
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
365 endif
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
366 " call Dret("Rmdir")
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
367 endfun
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
368
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
369 " ------------------------------------------------------------------------
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
370 " Modelines And Restoration: {{{1
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
371 let &cpo= s:keepcpo
339999b511a0 updated for version 7.0148
vimboss
parents:
diff changeset
372 unlet s:keepcpo
1214
a91a2e0c4108 updated for version 7.1b
vimboss
parents: 1121
diff changeset
373 " vim:ts=8 fdm=marker