annotate runtime/autoload/zip.vim @ 3229:e958eeffa0a7 v7.3.384

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