1" ---------------------------------------------------------------------
2" getscript.vim
3"  Author:	Charles E. Campbell, Jr.
4"  Date:	Dec 28, 2009
5"  Version:	32
6"  Installing:	:help glvs-install
7"  Usage:	:help glvs
8"
9" GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
10"redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
11" ---------------------------------------------------------------------
12" Initialization:	{{{1
13" if you're sourcing this file, surely you can't be
14" expecting vim to be in its vi-compatible mode!
15if exists("g:loaded_getscript")
16 finish
17endif
18let g:loaded_getscript= "v32"
19if &cp
20 echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
21 finish
22endif
23if v:version < 702
24 echohl WarningMsg
25 echo "***warning*** this version of getscript needs vim 7.2"
26 echohl Normal
27 finish
28endif
29let s:keepcpo = &cpo
30set cpo&vim
31"DechoTabOn
32
33" ---------------------------
34" Global Variables: {{{1
35" ---------------------------
36" Cygwin Detection ------- {{{2
37if !exists("g:getscript_cygwin")
38 if has("win32") || has("win95") || has("win64") || has("win16")
39  if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
40   let g:getscript_cygwin= 1
41  else
42   let g:getscript_cygwin= 0
43  endif
44 else
45  let g:getscript_cygwin= 0
46 endif
47endif
48
49" wget vs curl {{{2
50if !exists("g:GetLatestVimScripts_wget")
51 if executable("wget")
52  let g:GetLatestVimScripts_wget= "wget"
53 elseif executable("curl")
54  let g:GetLatestVimScripts_wget= "curl"
55 else
56  let g:GetLatestVimScripts_wget    = 'echo "GetLatestVimScripts needs wget or curl"'
57  let g:GetLatestVimScripts_options = ""
58 endif
59endif
60
61" options that wget and curl require:
62if !exists("g:GetLatestVimScripts_options")
63 if g:GetLatestVimScripts_wget == "wget"
64  let g:GetLatestVimScripts_options= "-q -O"
65 elseif g:GetLatestVimScripts_wget == "curl"
66  let g:GetLatestVimScripts_options= "-s -O"
67 else
68  let g:GetLatestVimScripts_options= ""
69 endif
70endif
71
72" by default, allow autoinstall lines to work
73if !exists("g:GetLatestVimScripts_allowautoinstall")
74 let g:GetLatestVimScripts_allowautoinstall= 1
75endif
76
77"" For debugging:
78"let g:GetLatestVimScripts_wget    = "echo"
79"let g:GetLatestVimScripts_options = "options"
80
81" ---------------------------------------------------------------------
82" Check If AutoInstall Capable: {{{1
83let s:autoinstall= ""
84if g:GetLatestVimScripts_allowautoinstall
85
86 if (has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")) && &shell != "bash"
87  " windows (but not cygwin/bash)
88  let s:dotvim= "vimfiles"
89  if !exists("g:GetLatestVimScripts_mv")
90   let g:GetLatestVimScripts_mv= "ren"
91  endif
92
93 else
94  " unix
95  let s:dotvim= ".vim"
96  if !exists("g:GetLatestVimScripts_mv")
97   let g:GetLatestVimScripts_mv= "mv"
98  endif
99 endif
100
101 if exists("g:GetLatestVimScripts_autoinstalldir") && isdirectory(g:GetLatestVimScripts_autoinstalldir)
102  let s:autoinstall= g:GetLatestVimScripts_autoinstalldir"
103 elseif exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim)
104  let s:autoinstall= $HOME."/".s:dotvim
105 endif
106" call Decho("s:autoinstall<".s:autoinstall.">")
107"else "Decho
108" call Decho("g:GetLatestVimScripts_allowautoinstall=".g:GetLatestVimScripts_allowautoinstall.": :AutoInstall: disabled")
109endif
110
111" ---------------------------------------------------------------------
112"  Public Interface: {{{1
113com!        -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
114com!        -nargs=0 GetScript           call getscript#GetLatestVimScripts()
115silent! com -nargs=0 GLVS                call getscript#GetLatestVimScripts()
116
117" ---------------------------------------------------------------------
118" GetLatestVimScripts: this function gets the latest versions of {{{1
119"                      scripts based on the list in
120"   (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
121fun! getscript#GetLatestVimScripts()
122"  call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">")
123
124" insure that wget is executable
125  if executable(g:GetLatestVimScripts_wget) != 1
126   echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system"
127"   call Dret("GetLatestVimScripts : wget not executable/availble")
128   return
129  endif
130
131  " insure that fnameescape() is available
132  if !exists("*fnameescape")
133   echoerr "GetLatestVimScripts needs fnameescape() (provided by 7.1.299 or later)"
134   return
135  endif
136
137  " Find the .../GetLatest subdirectory under the runtimepath
138  for datadir in split(&rtp,',') + ['']
139   if isdirectory(datadir."/GetLatest")
140"    call Decho("found directory<".datadir.">")
141    let datadir= datadir . "/GetLatest"
142    break
143   endif
144   if filereadable(datadir."GetLatestVimScripts.dat")
145"    call Decho("found ".datadir."/GetLatestVimScripts.dat")
146    break
147   endif
148  endfor
149
150  " Sanity checks: readability and writability
151  if datadir == ""
152   echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install'
153"   call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory")
154   return
155  endif
156  if filewritable(datadir) != 2
157   echoerr "(getLatestVimScripts) Your ".datadir." isn't writable"
158"   call Dret("GetLatestVimScripts : non-writable directory<".datadir.">")
159   return
160  endif
161  let datafile= datadir."/GetLatestVimScripts.dat"
162  if !filereadable(datafile)
163   echoerr "Your data file<".datafile."> isn't readable"
164"   call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">")
165   return
166  endif
167  if !filewritable(datafile)
168   echoerr "Your data file<".datafile."> isn't writable"
169"   call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">")
170   return
171  endif
172  " --------------------
173  " Passed sanity checks
174  " --------------------
175
176"  call Decho("datadir  <".datadir.">")
177"  call Decho("datafile <".datafile.">")
178
179  " don't let any event handlers interfere (like winmanager's, taglist's, etc)
180  let eikeep  = &ei
181  let hlskeep = &hls
182  let acdkeep = &acd
183  set ei=all hls&vim noacd
184
185  " Edit the datafile (ie. GetLatestVimScripts.dat):
186  " 1. record current directory (origdir),
187  " 2. change directory to datadir,
188  " 3. split window
189  " 4. edit datafile
190  let origdir= getcwd()
191"  call Decho("exe cd ".fnameescape(substitute(datadir,'\','/','ge')))
192  exe "cd ".fnameescape(substitute(datadir,'\','/','ge'))
193  split
194"  call Decho("exe  e ".fnameescape(substitute(datafile,'\','/','ge')))
195  exe "e ".fnameescape(substitute(datafile,'\','/','ge'))
196  res 1000
197  let s:downloads = 0
198  let s:downerrors= 0
199
200  " Check on dependencies mentioned in plugins
201"  call Decho(" ")
202"  call Decho("searching plugins for GetLatestVimScripts dependencies")
203  let lastline    = line("$")
204"  call Decho("lastline#".lastline)
205  let firstdir    = substitute(&rtp,',.*$','','')
206  let plugins     = split(globpath(firstdir,"plugin/*.vim"),'\n')
207  let plugins     = plugins + split(globpath(firstdir,"AsNeeded/*.vim"),'\n')
208  let foundscript = 0
209
210  " this loop updates the GetLatestVimScripts.dat file
211  " with dependencies explicitly mentioned in the plugins
212  " via   GetLatestVimScripts: ... lines
213  " It reads the plugin script at the end of the GetLatestVimScripts.dat
214  " file, examines it, and then removes it.
215  for plugin in plugins
216"   call Decho(" ")
217"   call Decho("plugin<".plugin.">")
218
219   " read plugin in
220   " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it
221   $
222"   call Decho(".dependency checking<".plugin."> line$=".line("$"))
223"   call Decho("..exe silent r ".fnameescape(plugin))
224   exe "silent r ".fnameescape(plugin)
225   exe "silent bwipe ".bufnr("#")
226
227   while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
228    let depscript   = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
229    let depscriptid = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\(\d\+\)\s\+.*$','\1','')
230    let llp1        = lastline+1
231"    call Decho("..depscript<".depscript.">")
232
233    " found a "GetLatestVimScripts: # #" line in the script;
234    " check if its already in the datafile by searching backwards from llp1,
235    " the (prior to reading in the plugin script) last line plus one of the GetLatestVimScripts.dat file,
236    " for the script-id with no wrapping allowed.
237    let curline     = line(".")
238    let noai_script = substitute(depscript,'\s*:AutoInstall:\s*','','e')
239    exe llp1
240    let srchline    = search('^\s*'.depscriptid.'\s\+\d\+\s\+.*$','bW')
241    if srchline == 0
242     " this second search is taken when, for example, a   0 0 scriptname  is to be skipped over
243     let srchline= search('\<'.noai_script.'\>','bW')
244    endif
245"    call Decho("..noai_script<".noai_script."> depscriptid#".depscriptid." srchline#".srchline." curline#".line(".")." lastline#".lastline)
246
247    if srchline == 0
248     " found a new script to permanently include in the datafile
249     let keep_rega   = @a
250     let @a          = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','')
251     echomsg "Appending <".@a."> to ".datafile." for ".depscript
252"     call Decho("..Appending <".@a."> to ".datafile." for ".depscript)
253     exe lastline."put a"
254     let @a          = keep_rega
255     let lastline    = llp1
256     let curline     = curline     + 1
257     let foundscript = foundscript + 1
258"    else	" Decho
259"     call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")")
260    endif
261
262    let curline = curline + 1
263    exe curline
264   endwhile
265
266   " llp1: last line plus one
267   let llp1= lastline + 1
268"   call Decho(".deleting lines: ".llp1.",$d")
269   exe "silent! ".llp1.",$d"
270  endfor
271"  call Decho("--- end dependency checking loop ---  foundscript=".foundscript)
272"  call Decho(" ")
273"  call Dredir("BUFFER TEST (GetLatestVimScripts 1)","ls!")
274
275  if foundscript == 0
276   setlocal nomod
277  endif
278
279  " --------------------------------------------------------------------
280  " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
281  " --------------------------------------------------------------------
282"  call Decho("begin: checking out-of-date scripts using datafile<".datafile.">")
283  setlocal lz
284  1
285"  /^-----/,$g/^\s*\d/call Decho(getline("."))
286  1
287  /^-----/,$g/^\s*\d/call s:GetOneScript()
288"  call Decho("--- end out-of-date checking --- ")
289
290  " Final report (an echomsg)
291  try
292   silent! ?^-------?
293  catch /^Vim\%((\a\+)\)\=:E114/
294"   call Dret("GetLatestVimScripts : nothing done!")
295   return
296  endtry
297  exe "norm! kz\<CR>"
298  redraw!
299  let s:msg = ""
300  if s:downloads == 1
301  let s:msg = "Downloaded one updated script to <".datadir.">"
302  elseif s:downloads == 2
303   let s:msg= "Downloaded two updated scripts to <".datadir.">"
304  elseif s:downloads > 1
305   let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">"
306  else
307   let s:msg= "Everything was already current"
308  endif
309  if s:downerrors > 0
310   let s:msg= s:msg." (".s:downerrors." downloading errors)"
311  endif
312  echomsg s:msg
313  " save the file
314  if &mod
315   silent! w!
316  endif
317  q
318
319  " restore events and current directory
320  exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
321  let &ei  = eikeep
322  let &hls = hlskeep
323  let &acd = acdkeep
324  setlocal nolz
325"  call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!")
326"  call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
327endfun
328
329" ---------------------------------------------------------------------
330"  GetOneScript: (Get Latest Vim Script) this function operates {{{1
331"    on the current line, interpreting two numbers and text as
332"    ScriptID, SourceID, and Filename.
333"    It downloads any scripts that have newer versions from vim.sourceforge.net.
334fun! s:GetOneScript(...)
335"   call Dfunc("GetOneScript()")
336
337 " set options to allow progress to be shown on screen
338  let rega= @a
339  let t_ti= &t_ti
340  let t_te= &t_te
341  let rs  = &rs
342  set t_ti= t_te= nors
343
344 " put current line on top-of-screen and interpret it into
345 " a      script identifer  : used to obtain webpage
346 "        source identifier : used to identify current version
347 " and an associated comment: used to report on what's being considered
348  if a:0 >= 3
349   let scriptid = a:1
350   let srcid    = a:2
351   let fname    = a:3
352   let cmmnt    = ""
353"   call Decho("scriptid<".scriptid.">")
354"   call Decho("srcid   <".srcid.">")
355"   call Decho("fname   <".fname.">")
356  else
357   let curline  = getline(".")
358   if curline =~ '^\s*#'
359    let @a= rega
360"    call Dret("GetOneScript : skipping a pure comment line")
361    return
362   endif
363   let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
364   try
365    let scriptid = substitute(curline,parsepat,'\1','e')
366   catch /^Vim\%((\a\+)\)\=:E486/
367    let scriptid= 0
368   endtry
369   try
370    let srcid    = substitute(curline,parsepat,'\2','e')
371   catch /^Vim\%((\a\+)\)\=:E486/
372    let srcid= 0
373   endtry
374   try
375    let fname= substitute(curline,parsepat,'\3','e')
376   catch /^Vim\%((\a\+)\)\=:E486/
377    let fname= ""
378   endtry
379   try
380    let cmmnt= substitute(curline,parsepat,'\4','e')
381   catch /^Vim\%((\a\+)\)\=:E486/
382    let cmmnt= ""
383   endtry
384"   call Decho("curline <".curline.">")
385"   call Decho("parsepat<".parsepat.">")
386"   call Decho("scriptid<".scriptid.">")
387"   call Decho("srcid   <".srcid.">")
388"   call Decho("fname   <".fname.">")
389  endif
390
391  " plugin author protection from downloading his/her own scripts atop their latest work
392  if scriptid == 0 || srcid == 0
393   " When looking for :AutoInstall: lines, skip scripts that have   0 0 scriptname
394   let @a= rega
395"   call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
396   return
397  endif
398
399  let doautoinstall= 0
400  if fname =~ ":AutoInstall:"
401"   call Decho("case AutoInstall: fname<".fname.">")
402   let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
403"   call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
404   if s:autoinstall != ""
405    let doautoinstall = g:GetLatestVimScripts_allowautoinstall
406   endif
407  else
408   let aicmmnt= fname
409  endif
410"  call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
411
412  exe "norm z\<CR>"
413  redraw!
414"  call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
415  echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
416
417  " grab a copy of the plugin's vim.sourceforge.net webpage
418  let scriptaddr = 'http://vim.sourceforge.net/script.php?script_id='.scriptid
419  let tmpfile    = tempname()
420  let v:errmsg   = ""
421
422  " make up to three tries at downloading the description
423  let itry= 1
424  while itry <= 3
425"   call Decho(".try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
426   if has("win32") || has("win16") || has("win95")
427"    call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)."|bw!")
428    new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)|bw!
429   else
430"    call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr))
431    exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr)
432   endif
433   if itry == 1
434    exe "silent vsplit ".fnameescape(tmpfile)
435   else
436    silent! e %
437   endif
438   setlocal bh=wipe
439  
440   " find the latest source-id in the plugin's webpage
441   silent! 1
442   let findpkg= search('Click on the package to download','W')
443   if findpkg > 0
444    break
445   endif
446   let itry= itry + 1
447  endwhile
448"  call Decho(" --- end downloading tries while loop --- itry=".itry)
449
450  " testing: did finding "Click on the package..." fail?
451  if findpkg == 0 || itry >= 4
452   silent q!
453   call delete(tmpfile)
454  " restore options
455   let &t_ti        = t_ti
456   let &t_te        = t_te
457   let &rs          = rs
458   let s:downerrors = s:downerrors + 1
459"   call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
460   echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
461"   call Dret("GetOneScript : srch for /Click on the package/ failed")
462   let @a= rega
463   return
464  endif
465"  call Decho('found "Click on the package to download"')
466
467  let findsrcid= search('src_id=','W')
468  if findsrcid == 0
469   silent q!
470   call delete(tmpfile)
471  " restore options
472   let &t_ti        = t_ti
473   let &t_te        = t_te
474   let &rs          = rs
475   let s:downerrors = s:downerrors + 1
476"   call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
477   echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
478   let @a= rega
479"  call Dret("GetOneScript : srch for /src_id/ failed")
480   return
481  endif
482"  call Decho('found "src_id=" in description page')
483
484  let srcidpat   = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
485  let latestsrcid= substitute(getline("."),srcidpat,'\1','')
486  let sname      = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
487"  call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
488  silent q!
489  call delete(tmpfile)
490
491  " convert the strings-of-numbers into numbers
492  let srcid       = srcid       + 0
493  let latestsrcid = latestsrcid + 0
494"  call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
495
496  " has the plugin's most-recent srcid increased, which indicates that it has been updated
497  if latestsrcid > srcid
498"   call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
499
500   let s:downloads= s:downloads + 1
501   if sname == bufname("%")
502    " GetLatestVimScript has to be careful about downloading itself
503    let sname= "NEW_".sname
504   endif
505
506   " -----------------------------------------------------------------------------
507   " the plugin has been updated since we last obtained it, so download a new copy
508   " -----------------------------------------------------------------------------
509"   call Decho(".downloading new <".sname.">")
510   echomsg ".downloading new <".sname.">"
511   if has("win32") || has("win16") || has("win95")
512"    call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id='.latestsrcid)."|q")
513    new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id='.latestsrcid)|q
514   else
515"    call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id='))
516    exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id=').latestsrcid
517   endif
518
519   " --------------------------------------------------------------------------
520   " AutoInstall: only if doautoinstall has been requested by the plugin itself
521   " --------------------------------------------------------------------------
522   if doautoinstall
523"    call Decho(" ")
524"    call Decho("Autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname))
525    if filereadable(sname)
526"     call Decho("<".sname."> is readable")
527"     call Decho("exe silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall))
528     exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall)
529     let curdir    = escape(substitute(getcwd(),'\','/','ge'),"|[]*'\" #")
530     let installdir= curdir."/Installed"
531     if !isdirectory(installdir)
532      call mkdir(installdir)
533     endif
534"     call Decho("curdir<".curdir."> installdir<".installdir.">")
535"     call Decho("exe cd ".fnameescape(s:autoinstall))
536     exe "cd ".fnameescape(s:autoinstall)
537
538     " determine target directory for moves
539     let firstdir= substitute(&rtp,',.*$','','')
540     let pname   = substitute(sname,'\..*','.vim','')
541"     call Decho("determine tgtdir: is <".firstdir.'/AsNeeded/'.pname." readable?")
542     if filereadable(firstdir.'/AsNeeded/'.pname)
543      let tgtdir= "AsNeeded"
544     else
545      let tgtdir= "plugin"
546     endif
547"     call Decho("tgtdir<".tgtdir.">  pname<".pname.">")
548     
549     " decompress
550     if sname =~ '\.bz2$'
551"      call Decho("decompress: attempt to bunzip2 ".sname)
552      exe "silent !bunzip2 ".shellescape(sname)
553      let sname= substitute(sname,'\.bz2$','','')
554"      call Decho("decompress: new sname<".sname."> after bunzip2")
555     elseif sname =~ '\.gz$'
556"      call Decho("decompress: attempt to gunzip ".sname)
557      exe "silent !gunzip ".shellescape(sname)
558      let sname= substitute(sname,'\.gz$','','')
559"      call Decho("decompress: new sname<".sname."> after gunzip")
560     else
561"      call Decho("no decompression needed")
562     endif
563     
564     " distribute archive(.zip, .tar, .vba) contents
565     if sname =~ '\.zip$'
566"      call Decho("dearchive: attempt to unzip ".sname)
567      exe "silent !unzip -o ".shellescape(sname)
568     elseif sname =~ '\.tar$'
569"      call Decho("dearchive: attempt to untar ".sname)
570      exe "silent !tar -xvf ".shellescape(sname)
571     elseif sname =~ '\.vba$'
572"      call Decho("dearchive: attempt to handle a vimball: ".sname)
573      silent 1split
574      if exists("g:vimball_home")
575       let oldvimballhome= g:vimball_home
576      endif
577      let g:vimball_home= s:autoinstall
578      exe "silent e ".fnameescape(sname)
579      silent so %
580      silent q
581      if exists("oldvimballhome")
582       let g:vimball_home= oldvimballhome
583      else
584       unlet g:vimball_home
585      endif
586     else
587"      call Decho("no dearchiving needed")
588     endif
589     
590     " ---------------------------------------------
591     " move plugin to plugin/ or AsNeeded/ directory
592     " ---------------------------------------------
593     if sname =~ '.vim$'
594"      call Decho("dearchive: attempt to simply move ".sname." to ".tgtdir)
595      exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".tgtdir
596     else
597"      call Decho("dearchive: move <".sname."> to installdir<".installdir.">")
598      exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".installdir
599     endif
600     if tgtdir != "plugin"
601"      call Decho("exe silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir)
602      exe "silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir
603     endif
604     
605     " helptags step
606     let docdir= substitute(&rtp,',.*','','e')."/doc"
607"     call Decho("helptags: docdir<".docdir.">")
608     exe "helptags ".fnameescape(docdir)
609     exe "cd ".fnameescape(curdir)
610    endif
611    if fname !~ ':AutoInstall:'
612     let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
613    else
614     let modline=scriptid." ".latestsrcid." ".fname.cmmnt
615    endif
616   else
617    let modline=scriptid." ".latestsrcid." ".fname.cmmnt
618   endif
619
620   " update the data in the <GetLatestVimScripts.dat> file
621   call setline(line("."),modline)
622"   call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
623"  else " Decho
624"   call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
625  endif
626
627 " restore options
628  let &t_ti = t_ti
629  let &t_te = t_te
630  let &rs   = rs
631  let @a    = rega
632"  call Dredir("BUFFER TEST (GetOneScript)","ls!")
633
634"  call Dret("GetOneScript")
635endfun
636
637" ---------------------------------------------------------------------
638" Restore Options: {{{1
639let &cpo= s:keepcpo
640unlet s:keepcpo
641
642" ---------------------------------------------------------------------
643"  Modelines: {{{1
644" vim: ts=8 sts=2 fdm=marker nowrap
645