94
127
silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts()
96
129
" ---------------------------------------------------------------------
97
" GetOneScript: (Get Latest Vim Script) this function operates {{{1
98
" on the current line, interpreting two numbers and text as
99
" ScriptID, SourceID, and Filename.
100
" It downloads any scripts that have newer versions from vim.sf.net.
101
fun! s:GetOneScript(...)
102
" call Dfunc("GetOneScript()")
104
" set options to allow progress to be shown on screen
110
" put current line on top-of-screen and interpret it into
111
" a script identifer : used to obtain webpage
112
" source identifier : used to identify current version
113
" and an associated comment: used to report on what's being considered
119
" call Decho("scriptid<".scriptid.">")
120
" call Decho("srcid <".srcid.">")
121
" call Decho("fname <".fname.">")
123
let curline = getline(".")
124
if curline =~ '^\s*#'
125
" call Dret("GetOneScript : skipping a pure comment line")
128
let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
130
let scriptid = substitute(curline,parsepat,'\1','e')
131
catch /^Vim\%((\a\+)\)\=:E486/
135
let srcid = substitute(curline,parsepat,'\2','e')
136
catch /^Vim\%((\a\+)\)\=:E486/
140
let fname= substitute(curline,parsepat,'\3','e')
141
catch /^Vim\%((\a\+)\)\=:E486/
145
let cmmnt= substitute(curline,parsepat,'\4','e')
146
catch /^Vim\%((\a\+)\)\=:E486/
149
" call Decho("curline <".curline.">")
150
" call Decho("parsepat<".parsepat.">")
151
" call Decho("scriptid<".scriptid.">")
152
" call Decho("srcid <".srcid.">")
153
" call Decho("fname <".fname.">")
156
if scriptid == 0 || srcid == 0
157
" When looking for :AutoInstall: lines, skip scripts that
158
" have 0 0 scriptname
159
" call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
164
if fname =~ ":AutoInstall:"
165
" call Decho("fname<".fname."> has :AutoInstall:...")
166
let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
167
" call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
168
if s:autoinstall != ""
169
let doautoinstall = g:GetLatestVimScripts_allowautoinstall
174
" call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
178
" call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
179
echomsg 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
181
" grab a copy of the plugin's vim.sf.net webpage
182
let scriptaddr = 'http://vim.sf.net/script.php?script_id='.scriptid
183
let tmpfile = tempname()
186
" make up to three tries at downloading the description
189
" call Decho("try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
190
if has("win32") || has("win16") || has("win95")
191
" call Decho("silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".tmpfile.' "'.scriptaddr.'"')
192
exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".tmpfile.' "'.scriptaddr.'"'
194
" call Decho("silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".tmpfile." '".scriptaddr."'")
195
exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".tmpfile." '".scriptaddr."'"
198
exe "silent vsplit ".tmpfile
203
" find the latest source-id in the plugin's webpage
205
let findpkg= search('Click on the package to download','W')
211
" call Decho(" --- end downloading tries while loop --- itry=".itry)
213
" testing: did finding "Click on the package..." fail?
214
if findpkg == 0 || itry >= 4
221
let s:downerrors = s:downerrors + 1
222
" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
223
echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
224
" call Dret("GetOneScript : srch for /Click on the package/ failed")
227
" call Decho('found "Click on the package to download"')
229
let findsrcid= search('src_id=','W')
237
let s:downerrors = s:downerrors + 1
238
" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
239
echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
240
" call Dret("GetOneScript : srch for /src_id/ failed")
243
" call Decho('found "src_id=" in description page')
245
let srcidpat = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
246
let latestsrcid= substitute(getline("."),srcidpat,'\1','')
247
let sname = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
248
" call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
252
" convert the strings-of-numbers into numbers
253
let srcid = srcid + 0
254
let latestsrcid = latestsrcid + 0
255
" call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
257
" has the plugin's most-recent srcid increased, which indicates
258
" that it has been updated
259
if latestsrcid > srcid
260
" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
262
let s:downloads= s:downloads + 1
263
if sname == bufname("%")
264
" GetLatestVimScript has to be careful about downloading itself
265
let sname= "NEW_".sname
268
" the plugin has been updated since we last obtained it, so download a new copy
269
" call Decho("...downloading new <".sname.">")
270
echomsg "...downloading new <".sname.">"
271
if has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")
272
" call Decho("windows: silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".sname.' "'.'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid.'"')
273
exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".sname.' "'.'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid.'"'
275
" call Decho("unix: silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".sname." '".'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid."'")
276
exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".sname." '".'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid."'"
279
" AutoInstall: only if doautoinstall is so indicating
281
" call Decho("attempting to do autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname))
282
if filereadable(sname)
283
" call Decho("move <".sname."> to ".s:autoinstall)
284
exe "silent !".g:GetLatestVimScripts_mv." ".sname." ".s:autoinstall
285
let curdir= escape(substitute(getcwd(),'\','/','ge'),"|[]*'\" #")
286
" call Decho("exe cd ".s:autoinstall)
287
exe "cd ".s:autoinstall
291
" call Decho("decompress: attempt to bunzip2 ".sname)
292
exe "silent !bunzip2 ".sname
293
let sname= substitute(sname,'\.bz2$','','')
294
" call Decho("decompress: new sname<".sname."> after bunzip2")
295
elseif sname =~ '\.gz$'
296
" call Decho("decompress: attempt to gunzip ".sname)
297
exe "silent !gunzip ".sname
298
let sname= substitute(sname,'\.gz$','','')
299
" call Decho("decompress: new sname<".sname."> after gunzip")
302
" distribute archive(.zip, .tar, .vba) contents
304
" call Decho("dearchive: attempt to unzip ".sname)
305
exe "silent !unzip -o ".sname
306
elseif sname =~ '\.tar$'
307
" call Decho("dearchive: attempt to untar ".sname)
308
exe "silent !tar -xvf ".sname
309
elseif sname =~ '\.vba$'
310
" call Decho("dearchive: attempt to handle a vimball: ".sname)
312
exe "silent e ".sname
318
" call Decho("dearchive: attempt to simply move ".sname." to plugin")
319
exe "silent !".g:GetLatestVimScripts_mv." ".sname." plugin"
323
let docdir= substitute(&rtp,',.*','','e')."/doc"
324
" call Decho("helptags: docdir<".docdir.">")
325
exe "helptags ".docdir
328
if fname !~ ':AutoInstall:'
329
let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
331
let modline=scriptid." ".latestsrcid." ".fname.cmmnt
334
let modline=scriptid." ".latestsrcid." ".fname.cmmnt
337
" update the data in the <GetLatestVimScripts.dat> file
338
call setline(line("."),modline)
339
" call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
341
" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
349
" call Dret("GetOneScript")
352
" ---------------------------------------------------------------------
353
130
" GetLatestVimScripts: this function gets the latest versions of {{{1
354
131
" scripts based on the list in
355
132
" (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
531
323
" restore events and current directory
532
exe "cd ".escape(substitute(origdir,'\','/','ge'),"|[]*'\" #")
324
exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
328
" call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!")
535
329
" call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
537
" ---------------------------------------------------------------------
332
" ---------------------------------------------------------------------
333
" GetOneScript: (Get Latest Vim Script) this function operates {{{1
334
" on the current line, interpreting two numbers and text as
335
" ScriptID, SourceID, and Filename.
336
" It downloads any scripts that have newer versions from vim.sf.net.
337
fun! s:GetOneScript(...)
338
" call Dfunc("GetOneScript()")
340
" set options to allow progress to be shown on screen
347
" put current line on top-of-screen and interpret it into
348
" a script identifer : used to obtain webpage
349
" source identifier : used to identify current version
350
" and an associated comment: used to report on what's being considered
356
" call Decho("scriptid<".scriptid.">")
357
" call Decho("srcid <".srcid.">")
358
" call Decho("fname <".fname.">")
360
let curline = getline(".")
361
if curline =~ '^\s*#'
363
" call Dret("GetOneScript : skipping a pure comment line")
366
let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
368
let scriptid = substitute(curline,parsepat,'\1','e')
369
catch /^Vim\%((\a\+)\)\=:E486/
373
let srcid = substitute(curline,parsepat,'\2','e')
374
catch /^Vim\%((\a\+)\)\=:E486/
378
let fname= substitute(curline,parsepat,'\3','e')
379
catch /^Vim\%((\a\+)\)\=:E486/
383
let cmmnt= substitute(curline,parsepat,'\4','e')
384
catch /^Vim\%((\a\+)\)\=:E486/
387
" call Decho("curline <".curline.">")
388
" call Decho("parsepat<".parsepat.">")
389
" call Decho("scriptid<".scriptid.">")
390
" call Decho("srcid <".srcid.">")
391
" call Decho("fname <".fname.">")
394
if scriptid == 0 || srcid == 0
395
" When looking for :AutoInstall: lines, skip scripts that have 0 0 scriptname
397
" call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
402
if fname =~ ":AutoInstall:"
403
" call Decho("case AutoInstall: fname<".fname.">")
404
let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
405
" call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
406
if s:autoinstall != ""
407
let doautoinstall = g:GetLatestVimScripts_allowautoinstall
412
" call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
416
" call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
417
echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
419
" grab a copy of the plugin's vim.sf.net webpage
420
let scriptaddr = 'http://vim.sf.net/script.php?script_id='.scriptid
421
let tmpfile = tempname()
424
" make up to three tries at downloading the description
427
" call Decho("try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
428
if has("win32") || has("win16") || has("win95")
429
" call Decho("new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".s:Escape(tmpfile).' '.s:Escape(scriptaddr)."|bw!")
430
new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".s:Escape(tmpfile).' '.s:Escape(scriptaddr)|bw!
432
" call Decho("exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".s:Escape(tmpfile)." ".s:Escape(scriptaddr))
433
exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".s:Escape(tmpfile)." ".s:Escape(scriptaddr)
436
exe "silent vsplit ".fnameescape(tmpfile)
442
" find the latest source-id in the plugin's webpage
444
let findpkg= search('Click on the package to download','W')
450
" call Decho(" --- end downloading tries while loop --- itry=".itry)
452
" testing: did finding "Click on the package..." fail?
453
if findpkg == 0 || itry >= 4
460
let s:downerrors = s:downerrors + 1
461
" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
462
echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
463
" call Dret("GetOneScript : srch for /Click on the package/ failed")
467
" call Decho('found "Click on the package to download"')
469
let findsrcid= search('src_id=','W')
477
let s:downerrors = s:downerrors + 1
478
" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
479
echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
481
" call Dret("GetOneScript : srch for /src_id/ failed")
484
" call Decho('found "src_id=" in description page')
486
let srcidpat = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
487
let latestsrcid= substitute(getline("."),srcidpat,'\1','')
488
let sname = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
489
" call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
493
" convert the strings-of-numbers into numbers
494
let srcid = srcid + 0
495
let latestsrcid = latestsrcid + 0
496
" call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
498
" has the plugin's most-recent srcid increased, which indicates
499
" that it has been updated
500
if latestsrcid > srcid
501
" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
503
let s:downloads= s:downloads + 1
504
if sname == bufname("%")
505
" GetLatestVimScript has to be careful about downloading itself
506
let sname= "NEW_".sname
509
" the plugin has been updated since we last obtained it, so download a new copy
510
" call Decho("...downloading new <".sname.">")
511
echomsg "...downloading new <".sname.">"
512
if has("win32") || has("win16") || has("win95")
513
" call Decho("new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".s:Escape(sname)." ".s:Escape('http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid)."|q")
514
new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".s:Escape(sname)." ".s:Escape('http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid)|q
516
" call Decho("exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".s:Escape(sname)." ".s:Escape('http://vim.sf.net/scripts/download_script.php?src_id='))
517
exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".s:Escape(sname)." ".s:Escape('http://vim.sf.net/scripts/download_script.php?src_id=').latestsrcid
520
" AutoInstall: only if doautoinstall has been requested by the plugin itself
522
" call Decho("attempting to do autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname))
523
if filereadable(sname)
524
" call Decho("exe silent !".g:GetLatestVimScripts_mv." ".s:Escape(sname)." ".s:Escape(s:autoinstall))
525
exe "silent !".g:GetLatestVimScripts_mv." ".s:Escape(sname)." ".s:Escape(s:autoinstall)
526
let curdir = escape(substitute(getcwd(),'\','/','ge'),"|[]*'\" #")
527
let installdir= curdir."/Installed"
528
if !isdirectory(installdir)
529
call mkdir(installdir)
531
" call Decho("exe cd ".fnameescape(s:autoinstall))
532
exe "cd ".fnameescape(s:autoinstall)
536
" call Decho("decompress: attempt to bunzip2 ".sname)
537
exe "silent !bunzip2 ".s:Escape(sname)
538
let sname= substitute(sname,'\.bz2$','','')
539
" call Decho("decompress: new sname<".sname."> after bunzip2")
540
elseif sname =~ '\.gz$'
541
" call Decho("decompress: attempt to gunzip ".sname)
542
exe "silent !gunzip ".s:Escape(sname)
543
let sname= substitute(sname,'\.gz$','','')
544
" call Decho("decompress: new sname<".sname."> after gunzip")
547
" distribute archive(.zip, .tar, .vba) contents
549
" call Decho("dearchive: attempt to unzip ".sname)
550
exe "silent !unzip -o ".s:Escape(sname)
551
elseif sname =~ '\.tar$'
552
" call Decho("dearchive: attempt to untar ".sname)
553
exe "silent !tar -xvf ".s:Escape(sname)
554
elseif sname =~ '\.vba$'
555
" call Decho("dearchive: attempt to handle a vimball: ".sname)
557
exe "silent e ".fnameescape(sname)
563
" call Decho("dearchive: attempt to simply move ".sname." to plugin")
564
exe "silent !".g:GetLatestVimScripts_mv." ".s:Escape(sname)." plugin"
566
" call Decho("dearchive: move <".sname."> to installdir<".installdir.">")
567
exe "silent !".g:GetLatestVimScripts_mv." ".s:Escape(sname)." ".installdir
571
let docdir= substitute(&rtp,',.*','','e')."/doc"
572
" call Decho("helptags: docdir<".docdir.">")
573
exe "helptags ".fnameescape(docdir)
574
exe "cd ".fnameescape(curdir)
576
if fname !~ ':AutoInstall:'
577
let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
579
let modline=scriptid." ".latestsrcid." ".fname.cmmnt
582
let modline=scriptid." ".latestsrcid." ".fname.cmmnt
585
" update the data in the <GetLatestVimScripts.dat> file
586
call setline(line("."),modline)
587
" call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
589
" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
597
" call Dredir("BUFFER TEST (GetOneScript)","ls!")
599
" call Dret("GetOneScript")
602
" ---------------------------------------------------------------------
603
" s:Escape: makes a string safe&suitable for the shell {{{2
605
" call Dfunc("s:Escape(name<".a:name.">)")
606
if exists("*shellescape")
607
" shellescape() was added by patch 7.0.111
608
let name= shellescape(a:name)
610
let name= g:getscript_shq . a:name . g:getscript_shq
612
" call Dret("s:Escape ".name)
616
" ---------------------------------------------------------------------
539
617
" Restore Options: {{{1
540
618
let &cpo= s:keepcpo
621
" ---------------------------------------------------------------------
542
623
" vim: ts=8 sts=2 fdm=marker nowrap