annotate runtime/autoload/zip.vim @ 33482:39b2e200c4d7 v9.0.1992

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