annotate runtime/autoload/tar.vim @ 697:f08390485cd3 v7.0210

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