1118
|
1 " vimball.vim : construct a file containing both paths and files
|
|
2 " Author: Charles E. Campbell, Jr.
|
1698
|
3 " Date: Jul 30, 2008
|
|
4 " Version: 29
|
792
|
5 " GetLatestVimScripts: 1502 1 :AutoInstall: vimball.vim
|
1618
|
6 " Copyright: (c) 2004-2008 by Charles E. Campbell, Jr.
|
792
|
7 " The VIM LICENSE applies to Vimball.vim, and Vimball.txt
|
|
8 " (see |copyright|) except use "Vimball" instead of "Vim".
|
|
9 " No warranty, express or implied.
|
|
10 " *** *** Use At-Your-Own-Risk! *** ***
|
|
11
|
|
12 " ---------------------------------------------------------------------
|
|
13 " Load Once: {{{1
|
1118
|
14 if &cp || exists("g:loaded_vimball") || v:version < 700
|
792
|
15 finish
|
|
16 endif
|
|
17 let s:keepcpo = &cpo
|
1698
|
18 let g:loaded_vimball = "v29"
|
792
|
19 set cpo&vim
|
1618
|
20 "DechoTabOn
|
792
|
21
|
|
22 " =====================================================================
|
1118
|
23 " Constants: {{{1
|
|
24 if !exists("s:USAGE")
|
|
25 let s:USAGE = 0
|
|
26 let s:WARNING = 1
|
|
27 let s:ERROR = 2
|
1618
|
28
|
|
29 " determine if cygwin is in use or not
|
|
30 if !exists("g:netrw_cygwin")
|
|
31 if has("win32") || has("win95") || has("win64") || has("win16")
|
|
32 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
|
|
33 let g:netrw_cygwin= 1
|
|
34 else
|
|
35 let g:netrw_cygwin= 0
|
|
36 endif
|
|
37 else
|
|
38 let g:netrw_cygwin= 0
|
|
39 endif
|
|
40 endif
|
|
41
|
|
42 " set up g:vimball_mkdir if the mkdir() call isn't defined
|
|
43 if !exists("*mkdir")
|
|
44 if exists("g:netrw_local_mkdir")
|
|
45 let g:vimball_mkdir= g:netrw_local_mkdir
|
|
46 elseif executable("mkdir")
|
|
47 let g:vimball_mkdir= "mkdir"
|
|
48 elseif executable("makedir")
|
|
49 let g:vimball_mkdir= "makedir"
|
|
50 endif
|
|
51 if !exists(g:vimball_mkdir)
|
|
52 call vimball#ShowMesg(s:WARNING,"(vimball) g:vimball_mkdir undefined")
|
|
53 endif
|
|
54 endif
|
|
55
|
|
56 " set up shell quoting character
|
|
57 if exists("g:vimball_shq") && !exists("g:netrw_shq")
|
|
58 let g:netrw_shq= g:vimball_shq
|
|
59 endif
|
|
60 if !exists("g:netrw_shq")
|
|
61 if exists("&shq") && &shq != ""
|
|
62 let g:netrw_shq= &shq
|
|
63 elseif has("win32") || has("win95") || has("win64") || has("win16")
|
|
64 if g:netrw_cygwin
|
|
65 let g:netrw_shq= "'"
|
|
66 else
|
|
67 let g:netrw_shq= '"'
|
|
68 endif
|
|
69 else
|
|
70 let g:netrw_shq= "'"
|
|
71 endif
|
|
72 " call Decho("g:netrw_shq<".g:netrw_shq.">")
|
|
73 endif
|
|
74
|
|
75 " set up escape string (used to protect paths)
|
|
76 if !exists("g:vimball_path_escape")
|
|
77 let g:vimball_path_escape= ' ;#%'
|
|
78 endif
|
1118
|
79 endif
|
|
80
|
|
81 " =====================================================================
|
792
|
82 " Functions: {{{1
|
|
83
|
|
84 " ---------------------------------------------------------------------
|
1118
|
85 " vimball#MkVimball: creates a vimball given a list of paths to files {{{2
|
1618
|
86 " Input:
|
|
87 " line1,line2: a range of lines containing paths to files to be included in the vimball
|
|
88 " writelevel : if true, force a write to filename.vba, even if it exists
|
|
89 " (usually accomplished with :MkVimball! ...
|
|
90 " filename : base name of file to be created (ie. filename.vba)
|
|
91 " Output: a filename.vba using vimball format:
|
792
|
92 " path
|
|
93 " filesize
|
|
94 " [file]
|
|
95 " path
|
|
96 " filesize
|
|
97 " [file]
|
1118
|
98 fun! vimball#MkVimball(line1,line2,writelevel,...) range
|
|
99 " call Dfunc("MkVimball(line1=".a:line1." line2=".a:line2." writelevel=".a:writelevel." vimballname<".a:1.">) a:0=".a:0)
|
1618
|
100 if a:1 =~ '\.vim$' || a:1 =~ '\.txt$'
|
1118
|
101 let vbname= substitute(a:1,'\.\a\{3}$','.vba','')
|
|
102 else
|
|
103 let vbname= a:1
|
|
104 endif
|
|
105 if vbname !~ '\.vba$'
|
|
106 let vbname= vbname.'.vba'
|
|
107 endif
|
|
108 " call Decho("vbname<".vbname.">")
|
|
109 if a:1 =~ '[\/]'
|
|
110 call vimball#ShowMesg(s:ERROR,"(MkVimball) vimball name<".a:1."> should not include slashes")
|
|
111 " call Dret("MkVimball : vimball name<".a:1."> should not include slashes")
|
|
112 return
|
|
113 endif
|
792
|
114 if !a:writelevel && filereadable(vbname)
|
1118
|
115 call vimball#ShowMesg(s:ERROR,"(MkVimball) file<".vbname."> exists; use ! to insist")
|
792
|
116 " call Dret("MkVimball : file<".vbname."> already exists; use ! to insist")
|
|
117 return
|
|
118 endif
|
|
119
|
|
120 " user option bypass
|
1618
|
121 call vimball#SaveSettings()
|
792
|
122
|
1118
|
123 if a:0 >= 2
|
|
124 " allow user to specify where to get the files
|
|
125 let home= expand(a:2)
|
|
126 else
|
|
127 " use first existing directory from rtp
|
|
128 let home= s:VimballHome()
|
844
|
129 endif
|
|
130
|
|
131 " save current directory
|
792
|
132 let curdir = getcwd()
|
844
|
133 call s:ChgDir(home)
|
792
|
134
|
|
135 " record current tab, initialize while loop index
|
|
136 let curtabnr = tabpagenr()
|
|
137 let linenr = a:line1
|
|
138 " call Decho("curtabnr=".curtabnr)
|
|
139
|
|
140 while linenr <= a:line2
|
|
141 let svfile = getline(linenr)
|
|
142 " call Decho("svfile<".svfile.">")
|
|
143
|
|
144 if !filereadable(svfile)
|
1118
|
145 call vimball#ShowMesg(s:ERROR,"unable to read file<".svfile.">")
|
844
|
146 call s:ChgDir(curdir)
|
1618
|
147 call vimball#RestoreSettings()
|
792
|
148 " call Dret("MkVimball")
|
|
149 return
|
|
150 endif
|
|
151
|
|
152 " create/switch to mkvimball tab
|
|
153 if !exists("vbtabnr")
|
|
154 tabnew
|
|
155 silent! file Vimball
|
|
156 let vbtabnr= tabpagenr()
|
|
157 else
|
|
158 exe "tabn ".vbtabnr
|
|
159 endif
|
|
160
|
|
161 let lastline= line("$") + 1
|
|
162 if lastline == 2 && getline("$") == ""
|
|
163 call setline(1,'" Vimball Archiver by Charles E. Campbell, Jr., Ph.D.')
|
|
164 call setline(2,'UseVimball')
|
|
165 call setline(3,'finish')
|
1118
|
166 let lastline= line("$") + 1
|
792
|
167 endif
|
1118
|
168 call setline(lastline ,substitute(svfile,'$',' [[[1',''))
|
792
|
169 call setline(lastline+1,0)
|
844
|
170
|
|
171 " write the file from the tab
|
1698
|
172 " call Decho("exe $r ".fnameescape(svfile))
|
|
173 exe "$r ".fnameescape(svfile)
|
844
|
174
|
792
|
175 call setline(lastline+1,line("$") - lastline - 1)
|
|
176 " call Decho("lastline=".lastline." line$=".line("$"))
|
|
177
|
|
178 " restore to normal tab
|
|
179 exe "tabn ".curtabnr
|
|
180 let linenr= linenr + 1
|
|
181 endwhile
|
|
182
|
|
183 " write the vimball
|
|
184 exe "tabn ".vbtabnr
|
844
|
185 call s:ChgDir(curdir)
|
1618
|
186 setlocal ff=unix
|
796
|
187 if a:writelevel
|
1698
|
188 " call Decho("exe w! ".fnameescape(vbname))
|
|
189 exe "w! ".fnameescape(vbname)
|
796
|
190 else
|
1698
|
191 " call Decho("exe w ".fnameescape(vbname))
|
|
192 exe "w ".fnameescape(vbname)
|
792
|
193 endif
|
|
194 " call Decho("Vimball<".vbname."> created")
|
|
195 echo "Vimball<".vbname."> created"
|
|
196
|
|
197 " remove the evidence
|
|
198 setlocal nomod bh=wipe
|
|
199 exe "tabn ".curtabnr
|
|
200 exe "tabc ".vbtabnr
|
|
201
|
|
202 " restore options
|
1618
|
203 call vimball#RestoreSettings()
|
792
|
204
|
|
205 " call Dret("MkVimball")
|
|
206 endfun
|
|
207
|
|
208 " ---------------------------------------------------------------------
|
1118
|
209 " vimball#Vimball: extract and distribute contents from a vimball {{{2
|
1618
|
210 " (invoked the the UseVimball command embedded in
|
|
211 " vimballs' prologue)
|
1118
|
212 fun! vimball#Vimball(really,...)
|
|
213 " call Dfunc("vimball#Vimball(really=".a:really.") a:0=".a:0)
|
792
|
214
|
1698
|
215 if v:version < 701 || (v:version == 701 && !exists('*fnameescape'))
|
|
216 echoerr "your vim is missing the fnameescape() function"
|
1618
|
217 " call Dret("vimball#Vimball : needs 7.1 with patch 299")
|
|
218 return
|
|
219 endif
|
|
220
|
792
|
221 if getline(1) !~ '^" Vimball Archiver by Charles E. Campbell, Jr., Ph.D.$'
|
|
222 echoerr "(Vimball) The current file does not appear to be a Vimball!"
|
1118
|
223 " call Dret("vimball#Vimball")
|
792
|
224 return
|
|
225 endif
|
|
226
|
845
|
227 " set up standard settings
|
1618
|
228 call vimball#SaveSettings()
|
|
229 let curtabnr = tabpagenr()
|
|
230 let vimballfile = expand("%:tr")
|
792
|
231
|
|
232 " set up vimball tab
|
1118
|
233 " call Decho("setting up vimball tab")
|
792
|
234 tabnew
|
|
235 silent! file Vimball
|
|
236 let vbtabnr= tabpagenr()
|
|
237 let didhelp= ""
|
|
238
|
|
239 " go to vim plugin home
|
1118
|
240 if a:0 > 0
|
|
241 let home= expand(a:1)
|
|
242 else
|
|
243 let home= s:VimballHome()
|
844
|
244 endif
|
|
245 " call Decho("home<".home.">")
|
|
246
|
1118
|
247 " save current directory and remove older same-named vimball, if any
|
792
|
248 let curdir = getcwd()
|
1118
|
249 " call Decho("home<".home.">")
|
|
250 " call Decho("curdir<".curdir.">")
|
|
251
|
844
|
252 call s:ChgDir(home)
|
1618
|
253 let s:ok_unablefind= 1
|
|
254 call vimball#RmVimball(vimballfile)
|
|
255 unlet s:ok_unablefind
|
844
|
256
|
792
|
257 let linenr = 4
|
|
258 let filecnt = 0
|
|
259
|
|
260 " give title to listing of (extracted) files from Vimball Archive
|
|
261 if a:really
|
1618
|
262 echohl Title | echomsg "Vimball Archive" | echohl None
|
|
263 else
|
|
264 echohl Title | echomsg "Vimball Archive Listing" | echohl None
|
845
|
265 echohl Statement | echomsg "files would be placed under: ".home | echohl None
|
792
|
266 endif
|
|
267
|
|
268 " apportion vimball contents to various files
|
|
269 " call Decho("exe tabn ".curtabnr)
|
|
270 exe "tabn ".curtabnr
|
|
271 " call Decho("linenr=".linenr." line$=".line("$"))
|
|
272 while 1 < linenr && linenr < line("$")
|
1118
|
273 let fname = substitute(getline(linenr),'\t\[\[\[1$','','')
|
|
274 let fname = substitute(fname,'\\','/','g')
|
1618
|
275 let fsize = getline(linenr+1)+0
|
792
|
276 let filecnt = filecnt + 1
|
1118
|
277 " call Decho("fname<".fname."> fsize=".fsize." filecnt=".filecnt)
|
|
278
|
792
|
279 if a:really
|
|
280 echomsg "extracted <".fname.">: ".fsize." lines"
|
|
281 else
|
|
282 echomsg "would extract <".fname.">: ".fsize." lines"
|
|
283 endif
|
842
|
284 " call Decho("using L#".linenr.": will extract file<".fname.">")
|
|
285 " call Decho("using L#".(linenr+1).": fsize=".fsize)
|
792
|
286
|
1118
|
287 " Allow AsNeeded/ directory to take place of plugin/ directory
|
1618
|
288 " when AsNeeded/filename is filereadable or was present in VimballRecord
|
1118
|
289 if fname =~ '\<plugin/'
|
|
290 let anfname= substitute(fname,'\<plugin/','AsNeeded/','')
|
1618
|
291 if filereadable(anfname) || (exists("s:VBRstring") && s:VBRstring =~ anfname)
|
1118
|
292 " call Decho("using anfname<".anfname."> instead of <".fname.">")
|
|
293 let fname= anfname
|
|
294 endif
|
|
295 endif
|
|
296
|
792
|
297 " make directories if they don't exist yet
|
845
|
298 if a:really
|
1118
|
299 " call Decho("making directories if they don't exist yet (fname<".fname.">)")
|
|
300 let fnamebuf= substitute(fname,'\\','/','g')
|
|
301 let dirpath = substitute(home,'\\','/','g')
|
845
|
302 while fnamebuf =~ '/'
|
1118
|
303 let dirname = dirpath."/".substitute(fnamebuf,'/.*$','','')
|
|
304 let dirpath = dirname
|
|
305 let fnamebuf = substitute(fnamebuf,'^.\{-}/\(.*\)$','\1','')
|
|
306 " call Decho("dirname<".dirname.">")
|
845
|
307 if !isdirectory(dirname)
|
1118
|
308 " call Decho("making <".dirname.">")
|
1618
|
309 if exists("g:vimball_mkdir")
|
|
310 call system(g:vimball_mkdir." ".s:Escape(dirname))
|
|
311 else
|
|
312 call mkdir(dirname)
|
|
313 endif
|
1118
|
314 call s:RecordInVar(home,"rmdir('".dirname."')")
|
845
|
315 endif
|
|
316 endwhile
|
|
317 endif
|
844
|
318 call s:ChgDir(home)
|
792
|
319
|
|
320 " grab specified qty of lines and place into "a" buffer
|
842
|
321 " (skip over path/filename and qty-lines)
|
|
322 let linenr = linenr + 2
|
|
323 let lastline = linenr + fsize - 1
|
|
324 " call Decho("exe ".linenr.",".lastline."yank a")
|
844
|
325 exe "silent ".linenr.",".lastline."yank a"
|
792
|
326
|
|
327 " copy "a" buffer into tab
|
|
328 " call Decho('copy "a buffer into tab#'.vbtabnr)
|
|
329 exe "tabn ".vbtabnr
|
1618
|
330 setlocal ma
|
792
|
331 silent! %d
|
844
|
332 silent put a
|
842
|
333 1
|
844
|
334 silent d
|
792
|
335
|
|
336 " write tab to file
|
796
|
337 if a:really
|
1698
|
338 let fnamepath= home."/".fname
|
1618
|
339 " call Decho("exe w! ".fnameescape(fnamepath))
|
|
340 exe "silent w! ".fnameescape(fnamepath)
|
844
|
341 echo "wrote ".fnamepath
|
1618
|
342 call s:RecordInVar(home,"call delete('".fnameescape(fnamepath)."')")
|
796
|
343 endif
|
792
|
344
|
842
|
345 " return to tab with vimball
|
792
|
346 " call Decho("exe tabn ".curtabnr)
|
|
347 exe "tabn ".curtabnr
|
842
|
348
|
|
349 " set up help if its a doc/*.txt file
|
|
350 " call Decho("didhelp<".didhelp."> fname<".fname.">")
|
1618
|
351 if a:really && didhelp == "" && fname =~ 'doc/[^/]\+\.\(txt\|..x\)$'
|
|
352 let didhelp= substitute(fname,'^\(.*\<doc\)[/\\][^.]*\.\(txt\|..x\)$','\1','')
|
842
|
353 " call Decho("didhelp<".didhelp.">")
|
|
354 endif
|
|
355
|
|
356 " update for next file
|
1618
|
357 " call Decho("update linenr= [linenr=".linenr."] + [fsize=".fsize."] = ".(linenr+fsize))
|
|
358 let linenr= linenr + fsize
|
792
|
359 endwhile
|
|
360
|
|
361 " set up help
|
|
362 " call Decho("about to set up help: didhelp<".didhelp.">")
|
|
363 if didhelp != ""
|
1698
|
364 let htpath= home."/".didhelp
|
844
|
365 " call Decho("exe helptags ".htpath)
|
1698
|
366 exe "helptags ".fnameescape(htpath)
|
844
|
367 echo "did helptags"
|
792
|
368 endif
|
|
369
|
|
370 " make sure a "Press ENTER..." prompt appears to keep the messages showing!
|
796
|
371 while filecnt <= &ch
|
792
|
372 echomsg " "
|
|
373 let filecnt= filecnt + 1
|
|
374 endwhile
|
|
375
|
1118
|
376 " record actions in <.VimballRecord>
|
|
377 call s:RecordInFile(home)
|
|
378
|
792
|
379 " restore events, delete tab and buffer
|
|
380 exe "tabn ".vbtabnr
|
|
381 setlocal nomod bh=wipe
|
|
382 exe "tabn ".curtabnr
|
|
383 exe "tabc ".vbtabnr
|
1618
|
384 call vimball#RestoreSettings()
|
844
|
385 call s:ChgDir(curdir)
|
792
|
386
|
1118
|
387 " call Dret("vimball#Vimball")
|
|
388 endfun
|
|
389
|
|
390 " ---------------------------------------------------------------------
|
|
391 " vimball#RmVimball: remove any files, remove any directories made by any {{{2
|
|
392 " previous vimball extraction based on a file of the current
|
|
393 " name.
|
|
394 " Usage: RmVimball (assume current file is a vimball; remove)
|
|
395 " RmVimball vimballname
|
|
396 fun! vimball#RmVimball(...)
|
|
397 " call Dfunc("vimball#RmVimball() a:0=".a:0)
|
|
398 if exists("g:vimball_norecord")
|
|
399 " call Dret("vimball#RmVimball : (g:vimball_norecord)")
|
|
400 return
|
|
401 endif
|
|
402
|
|
403 if a:0 == 0
|
1618
|
404 let curfile= expand("%:tr")
|
|
405 " call Decho("case a:0=0: curfile<".curfile."> (used expand(%:tr))")
|
1118
|
406 else
|
|
407 if a:1 =~ '[\/]'
|
|
408 call vimball#ShowMesg(s:USAGE,"RmVimball vimballname [path]")
|
|
409 " call Dret("vimball#RmVimball : suspect a:1<".a:1.">")
|
|
410 return
|
|
411 endif
|
|
412 let curfile= a:1
|
1618
|
413 " call Decho("case a:0=".a:0.": curfile<".curfile.">")
|
1118
|
414 endif
|
1618
|
415 if curfile =~ '\.vba$'
|
|
416 let curfile= substitute(curfile,'\.vba','','')
|
1118
|
417 endif
|
|
418 if a:0 >= 2
|
|
419 let home= expand(a:2)
|
|
420 else
|
|
421 let home= s:VimballHome()
|
|
422 endif
|
|
423 let curdir = getcwd()
|
|
424 " call Decho("home <".home.">")
|
|
425 " call Decho("curfile<".curfile.">")
|
|
426 " call Decho("curdir <".curdir.">")
|
|
427
|
|
428 call s:ChgDir(home)
|
|
429 if filereadable(".VimballRecord")
|
|
430 " call Decho(".VimballRecord is readable")
|
|
431 " call Decho("curfile<".curfile.">")
|
|
432 keepalt keepjumps 1split
|
|
433 silent! keepalt keepjumps e .VimballRecord
|
|
434 let keepsrch= @/
|
1618
|
435 " call Decho("search for ^".curfile.".vba:")
|
|
436 " call Decho("search for ^".curfile."[-0-9.]*.vba:")
|
|
437 if search('^'.curfile.": ".'cw')
|
|
438 let foundit= 1
|
|
439 elseif search('^'.curfile.".vba: ",'cw')
|
|
440 let foundit= 1
|
|
441 elseif search('^'.curfile.'[-0-9.]*.vba: ','cw')
|
|
442 let foundit= 1
|
|
443 else
|
|
444 let foundit = 0
|
|
445 endif
|
|
446 if foundit
|
|
447 let exestring = substitute(getline("."),'^'.curfile.'\S\{-}\.vba: ','','')
|
|
448 let s:VBRstring= substitute(exestring,'call delete(','','g')
|
|
449 let s:VBRstring= substitute(s:VBRstring,"[')]",'','g')
|
1118
|
450 " call Decho("exe ".exestring)
|
|
451 silent! keepalt keepjumps exe exestring
|
|
452 silent! keepalt keepjumps d
|
1618
|
453 let exestring= strlen(substitute(exestring,'call delete(.\{-})|\=',"D","g"))
|
|
454 " call Decho("exestring<".exestring.">")
|
|
455 echomsg "removed ".exestring." files"
|
1118
|
456 else
|
1618
|
457 let s:VBRstring= ''
|
|
458 let curfile = substitute(curfile,'\.vba','','')
|
|
459 " call Decho("unable to find <".curfile."> in .VimballRecord")
|
|
460 if !exists("s:ok_unablefind")
|
|
461 call vimball#ShowMesg(s:WARNING,"(RmVimball) unable to find <".curfile."> in .VimballRecord")
|
|
462 endif
|
1118
|
463 endif
|
|
464 silent! keepalt keepjumps g/^\s*$/d
|
|
465 silent! keepalt keepjumps wq!
|
|
466 let @/= keepsrch
|
|
467 endif
|
|
468 call s:ChgDir(curdir)
|
|
469
|
|
470 " call Dret("vimball#RmVimball")
|
792
|
471 endfun
|
|
472
|
843
|
473 " ---------------------------------------------------------------------
|
|
474 " vimball#Decompress: attempts to automatically decompress vimballs {{{2
|
|
475 fun! vimball#Decompress(fname)
|
|
476 " call Dfunc("Decompress(fname<".a:fname.">)")
|
|
477
|
|
478 " decompression:
|
|
479 if expand("%") =~ '.*\.gz' && executable("gunzip")
|
1618
|
480 " handle *.gz with gunzip
|
|
481 silent exe "!gunzip ".s:Escape(a:fname)
|
|
482 if v:shell_error != 0
|
|
483 call vimball#ShowMesg(s:WARNING,"(vimball#Decompress) gunzip may have failed with <".a:fname.">")
|
|
484 endif
|
|
485 let fname= substitute(a:fname,'\.gz$','','')
|
|
486 exe "e ".escape(fname,' \')
|
|
487 call vimball#ShowMesg(s:USAGE,"Source this file to extract it! (:so %)")
|
|
488
|
|
489 elseif expand("%") =~ '.*\.gz' && executable("gzip")
|
|
490 " handle *.gz with gzip -d
|
|
491 silent exe "!gzip -d ".s:Escape(a:fname)
|
|
492 if v:shell_error != 0
|
|
493 call vimball#ShowMesg(s:WARNING,'(vimball#Decompress) "gzip -d" may have failed with <'.a:fname.">")
|
|
494 endif
|
843
|
495 let fname= substitute(a:fname,'\.gz$','','')
|
844
|
496 exe "e ".escape(fname,' \')
|
1118
|
497 call vimball#ShowMesg(s:USAGE,"Source this file to extract it! (:so %)")
|
1618
|
498
|
843
|
499 elseif expand("%") =~ '.*\.bz2' && executable("bunzip2")
|
1618
|
500 " handle *.bz2 with bunzip2
|
|
501 silent exe "!bunzip2 ".s:Escape(a:fname)
|
|
502 if v:shell_error != 0
|
|
503 call vimball#ShowMesg(s:WARNING,"(vimball#Decompress) bunzip2 may have failed with <".a:fname.">")
|
|
504 endif
|
843
|
505 let fname= substitute(a:fname,'\.bz2$','','')
|
844
|
506 exe "e ".escape(fname,' \')
|
1118
|
507 call vimball#ShowMesg(s:USAGE,"Source this file to extract it! (:so %)")
|
1618
|
508
|
|
509 elseif expand("%") =~ '.*\.bz2' && executable("bzip2")
|
|
510 " handle *.bz2 with bzip2 -d
|
|
511 silent exe "!bzip2 -d ".s:Escape(a:fname)
|
|
512 if v:shell_error != 0
|
|
513 call vimball#ShowMesg(s:WARNING,'(vimball#Decompress) "bzip2 -d" may have failed with <'.a:fname.">")
|
|
514 endif
|
|
515 let fname= substitute(a:fname,'\.bz2$','','')
|
|
516 exe "e ".escape(fname,' \')
|
|
517 call vimball#ShowMesg(s:USAGE,"Source this file to extract it! (:so %)")
|
|
518
|
843
|
519 elseif expand("%") =~ '.*\.zip' && executable("unzip")
|
1618
|
520 " handle *.zip with unzip
|
|
521 silent exe "!unzip ".s:Escape(a:fname)
|
|
522 if v:shell_error != 0
|
|
523 call vimball#ShowMesg(s:WARNING,"(vimball#Decompress) unzip may have failed with <".a:fname.">")
|
|
524 endif
|
843
|
525 let fname= substitute(a:fname,'\.zip$','','')
|
844
|
526 exe "e ".escape(fname,' \')
|
1118
|
527 call vimball#ShowMesg(s:USAGE,"Source this file to extract it! (:so %)")
|
843
|
528 endif
|
1618
|
529
|
1118
|
530 set noma bt=nofile fmr=[[[,]]] fdm=marker
|
843
|
531
|
|
532 " call Dret("Decompress")
|
|
533 endfun
|
|
534
|
844
|
535 " ---------------------------------------------------------------------
|
1118
|
536 " vimball#ShowMesg: {{{2
|
|
537 fun! vimball#ShowMesg(level,msg)
|
|
538 " call Dfunc("vimball#ShowMesg(level=".a:level." msg<".a:msg.">)")
|
|
539 let rulerkeep = &ruler
|
|
540 let showcmdkeep = &showcmd
|
|
541 set noruler noshowcmd
|
|
542 redraw!
|
|
543
|
|
544 if &fo =~ '[ta]'
|
|
545 echomsg "***vimball*** " a:msg
|
|
546 else
|
|
547 if a:level == s:WARNING || a:level == s:USAGE
|
|
548 echohl WarningMsg
|
|
549 elseif a:level == s:ERROR
|
|
550 echohl Error
|
|
551 endif
|
|
552 echomsg "***vimball*** " a:msg
|
|
553 echohl None
|
|
554 endif
|
|
555
|
|
556 if a:level != s:USAGE
|
|
557 call inputsave()|let ok= input("Press <cr> to continue")|call inputrestore()
|
|
558 endif
|
|
559
|
|
560 let &ruler = rulerkeep
|
|
561 let &showcmd = showcmdkeep
|
|
562
|
|
563 " call Dret("vimball#ShowMesg")
|
|
564 endfun
|
|
565 " =====================================================================
|
|
566 " s:ChgDir: change directory (in spite of Windoze) {{{2
|
844
|
567 fun! s:ChgDir(newdir)
|
|
568 " call Dfunc("ChgDir(newdir<".a:newdir.">)")
|
|
569 if (has("win32") || has("win95") || has("win64") || has("win16"))
|
1618
|
570 exe 'silent cd '.fnameescape(substitute(a:newdir,'/','\\','g'))
|
844
|
571 else
|
1618
|
572 exe 'silent cd '.fnameescape(a:newdir)
|
844
|
573 endif
|
1618
|
574 " call Dret("ChgDir : curdir<".getcwd().">")
|
844
|
575 endfun
|
|
576
|
|
577 " ---------------------------------------------------------------------
|
1118
|
578 " s:RecordInVar: record a un-vimball command in the .VimballRecord file {{{2
|
|
579 fun! s:RecordInVar(home,cmd)
|
|
580 " call Dfunc("RecordInVar(home<".a:home."> cmd<".a:cmd.">)")
|
|
581 if a:cmd =~ '^rmdir'
|
|
582 " if !exists("s:recorddir")
|
|
583 " let s:recorddir= substitute(a:cmd,'^rmdir',"call s:Rmdir",'')
|
|
584 " else
|
|
585 " let s:recorddir= s:recorddir."|".substitute(a:cmd,'^rmdir',"call s:Rmdir",'')
|
|
586 " endif
|
|
587 elseif !exists("s:recordfile")
|
|
588 let s:recordfile= a:cmd
|
|
589 else
|
|
590 let s:recordfile= s:recordfile."|".a:cmd
|
|
591 endif
|
1618
|
592 " call Dret("RecordInVar : s:recordfile<".(exists("s:recordfile")? s:recordfile : "")."> s:recorddir<".(exists("s:recorddir")? s:recorddir : "").">")
|
1118
|
593 endfun
|
|
594
|
|
595 " ---------------------------------------------------------------------
|
|
596 " s:RecordInFile: {{{2
|
|
597 fun! s:RecordInFile(home)
|
1618
|
598 " call Dfunc("s:RecordInFile()")
|
1118
|
599 if exists("g:vimball_norecord")
|
1618
|
600 " call Dret("s:RecordInFile : g:vimball_norecord")
|
1118
|
601 return
|
|
602 endif
|
|
603
|
|
604 if exists("s:recordfile") || exists("s:recorddir")
|
|
605 let curdir= getcwd()
|
|
606 call s:ChgDir(a:home)
|
|
607 keepalt keepjumps 1split
|
1618
|
608
|
1118
|
609 let cmd= expand("%:tr").": "
|
1618
|
610 " call Decho("cmd<".cmd.">")
|
|
611
|
1118
|
612 silent! keepalt keepjumps e .VimballRecord
|
1618
|
613 setlocal ma
|
1118
|
614 $
|
|
615 if exists("s:recordfile") && exists("s:recorddir")
|
|
616 let cmd= cmd.s:recordfile."|".s:recorddir
|
|
617 elseif exists("s:recorddir")
|
|
618 let cmd= cmd.s:recorddir
|
|
619 elseif exists("s:recordfile")
|
|
620 let cmd= cmd.s:recordfile
|
|
621 else
|
1618
|
622 " call Dret("s:RecordInFile : neither recordfile nor recorddir exist")
|
1118
|
623 return
|
|
624 endif
|
1618
|
625 " call Decho("cmd<".cmd.">")
|
|
626
|
|
627 " put command into buffer, write .VimballRecord `file
|
1118
|
628 keepalt keepjumps put=cmd
|
|
629 silent! keepalt keepjumps g/^\s*$/d
|
|
630 silent! keepalt keepjumps wq!
|
|
631 call s:ChgDir(curdir)
|
1618
|
632
|
|
633 if exists("s:recorddir")
|
|
634 " call Decho("unlet s:recorddir<".s:recorddir.">")
|
|
635 unlet s:recorddir
|
|
636 endif
|
|
637 if exists("s:recordfile")
|
|
638 " call Decho("unlet s:recordfile<".s:recordfile.">")
|
|
639 unlet s:recordfile
|
|
640 endif
|
1118
|
641 else
|
|
642 " call Decho("s:record[file|dir] doesn't exist")
|
|
643 endif
|
|
644
|
1618
|
645 " call Dret("s:RecordInFile")
|
1118
|
646 endfun
|
|
647
|
|
648 " ---------------------------------------------------------------------
|
|
649 " s:VimballHome: determine/get home directory path (usually from rtp) {{{2
|
|
650 fun! s:VimballHome()
|
|
651 " call Dfunc("VimballHome()")
|
|
652 if exists("g:vimball_home")
|
|
653 let home= g:vimball_home
|
|
654 else
|
|
655 " go to vim plugin home
|
|
656 for home in split(&rtp,',') + ['']
|
|
657 if isdirectory(home) && filewritable(home) | break | endif
|
1618
|
658 let basehome= substitute(home,'[/\\]\.vim$','','')
|
|
659 if isdirectory(basehome) && filewritable(basehome)
|
|
660 let home= basehome."/.vim"
|
|
661 break
|
|
662 endif
|
1118
|
663 endfor
|
|
664 if home == ""
|
|
665 " just pick the first directory
|
|
666 let home= substitute(&rtp,',.*$','','')
|
|
667 endif
|
|
668 if (has("win32") || has("win95") || has("win64") || has("win16"))
|
|
669 let home= substitute(home,'/','\\','g')
|
|
670 endif
|
|
671 endif
|
1618
|
672 " insure that the home directory exists
|
|
673 " call Decho("picked home<".home.">")
|
|
674 if !isdirectory(home)
|
|
675 if exists("g:vimball_mkdir")
|
|
676 " call Decho("home<".home."> isn't a directory -- making it now with g:vimball_mkdir<".g:vimball_mkdir.">")
|
|
677 " call Decho("system(".g:vimball_mkdir." ".s:Escape(home).")")
|
|
678 call system(g:vimball_mkdir." ".s:Escape(home))
|
|
679 else
|
|
680 " call Decho("home<".home."> isn't a directory -- making it now with mkdir()")
|
|
681 call mkdir(home)
|
|
682 endif
|
|
683 endif
|
1118
|
684 " call Dret("VimballHome <".home.">")
|
|
685 return home
|
844
|
686 endfun
|
|
687
|
|
688 " ---------------------------------------------------------------------
|
1618
|
689 " vimball#SaveSettings: {{{2
|
|
690 fun! vimball#SaveSettings()
|
845
|
691 " call Dfunc("SaveSettings()")
|
|
692 let s:makeep = getpos("'a")
|
|
693 let s:regakeep= @a
|
857
|
694 if exists("&acd")
|
|
695 let s:acdkeep = &acd
|
|
696 endif
|
845
|
697 let s:eikeep = &ei
|
1698
|
698 let s:fenkeep = &l:fen
|
845
|
699 let s:hidkeep = &hidden
|
|
700 let s:ickeep = &ic
|
1186
|
701 let s:lzkeep = &lz
|
|
702 let s:pmkeep = &pm
|
845
|
703 let s:repkeep = &report
|
|
704 let s:vekeep = &ve
|
1698
|
705 let s:ffkeep = &l:ff
|
857
|
706 if exists("&acd")
|
1618
|
707 setlocal ei=all ve=all noacd nofen noic report=999 nohid bt= ma lz pm= ff=unix
|
857
|
708 else
|
1618
|
709 setlocal ei=all ve=all nofen noic report=999 nohid bt= ma lz pm= ff=unix
|
857
|
710 endif
|
1618
|
711 " vimballs should be in unix format
|
|
712 setlocal ff=unix
|
845
|
713 " call Dret("SaveSettings")
|
|
714 endfun
|
|
715
|
|
716 " ---------------------------------------------------------------------
|
1618
|
717 " vimball#RestoreSettings: {{{2
|
|
718 fun! vimball#RestoreSettings()
|
845
|
719 " call Dfunc("RestoreSettings()")
|
|
720 let @a = s:regakeep
|
857
|
721 if exists("&acd")
|
|
722 let &acd = s:acdkeep
|
|
723 endif
|
1698
|
724 let &l:fen = s:fenkeep
|
845
|
725 let &hidden = s:hidkeep
|
|
726 let &ic = s:ickeep
|
1118
|
727 let &lz = s:lzkeep
|
1186
|
728 let &pm = s:pmkeep
|
845
|
729 let &report = s:repkeep
|
|
730 let &ve = s:vekeep
|
1118
|
731 let &ei = s:eikeep
|
1698
|
732 let &l:ff = s:ffkeep
|
845
|
733 if s:makeep[0] != 0
|
|
734 " restore mark a
|
|
735 " call Decho("restore mark-a: makeep=".string(makeep))
|
|
736 call setpos("'a",s:makeep)
|
|
737 endif
|
857
|
738 if exists("&acd")
|
1618
|
739 unlet s:acdkeep
|
857
|
740 endif
|
1618
|
741 unlet s:regakeep s:eikeep s:fenkeep s:hidkeep s:ickeep s:repkeep s:vekeep s:makeep s:lzkeep s:pmkeep s:ffkeep
|
845
|
742 " call Dret("RestoreSettings")
|
|
743 endfun
|
|
744
|
|
745 " ---------------------------------------------------------------------
|
1618
|
746 " s:Escape: {{{2
|
|
747 fun s:Escape(name)
|
|
748 " shellescape() was added by patch 7.0.111
|
|
749 if exists("*shellescape")
|
|
750 return shellescape(a:name)
|
|
751 endif
|
|
752 return g:netrw_shq . a:name . g:netrw_shq
|
|
753 endfun
|
|
754
|
|
755 " ---------------------------------------------------------------------
|
|
756 " Restore:
|
|
757 let &cpo= s:keepcpo
|
|
758 unlet s:keepcpo
|
|
759
|
|
760 " ---------------------------------------------------------------------
|
792
|
761 " Modelines: {{{1
|
|
762 " vim: fdm=marker
|