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