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