~ubuntu-branches/ubuntu/vivid/vim/vivid

« back to all changes in this revision

Viewing changes to runtime/autoload/getscript.vim

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2008-11-05 11:37:43 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081105113743-9i4urcsm3n44mhqe
Tags: 2:7.2.025-2ubuntu1
* Merge from debian unstable, remaining changes:
  - runtime/syntax/debcontrol.vim:
    + Add "metapackages" to the list of valid sections.
  - runtime/syntax/debchangelog.vim:
    + Add "jaunty" to the list of valid suites.
  - Drop vim-lesstif package and lesstif2-dev build-dependency.
  - Enable Python interpreter on basic builds.
  - Create a .pot file for translations.
  - Disable autoindent, line-wrapping, and backup files by default.
  - runtime/syntax/debsources.vim:
    + Add "jaunty" to debsourcesDistrKeyword
  - runtime/syntax/grub.vim:
    + Add Ubuntu-specific 'quiet' keyword.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
" ---------------------------------------------------------------------
2
2
" getscript.vim
3
3
"  Author:      Charles E. Campbell, Jr.
4
 
"  Date:        May 11, 2007
5
 
"  Version:     27
 
4
"  Date:        Jul 10, 2008
 
5
"  Version:     31
6
6
"  Installing:  :help glvs-install
7
7
"  Usage:       :help glvs
8
8
"
11
11
" ---------------------------------------------------------------------
12
12
" Initialization:       {{{1
13
13
" if you're sourcing this file, surely you can't be
14
 
" expecting vim to be in its vi-compatible mode
 
14
" expecting vim to be in its vi-compatible mode!
15
15
if &cp
16
16
 echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
17
17
 finish
23
23
if exists("g:loaded_getscript")
24
24
 finish
25
25
endif
26
 
let g:loaded_getscript= "v27"
27
 
 
28
 
" ---------------------------------------------------------------------
29
 
"  Global Variables: {{{1
30
 
" allow user to change the command for obtaining scripts (does fetch work?)
 
26
let g:loaded_getscript= "v31"
 
27
 
 
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
 
62
 
 
63
" wget vs curl {{{2
31
64
if !exists("g:GetLatestVimScripts_wget")
32
65
 if executable("wget")
33
66
  let g:GetLatestVimScripts_wget= "wget"
94
127
silent! com -nargs=0 GLVS                call getscript#GetLatestVimScripts()
95
128
 
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()")
103
 
 
104
 
 " set options to allow progress to be shown on screen
105
 
  let t_ti= &t_ti
106
 
  let t_te= &t_te
107
 
  let rs  = &rs
108
 
  set t_ti= t_te= nors
109
 
 
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
114
 
  if a:0 >= 3
115
 
   let scriptid = a:1
116
 
   let srcid    = a:2
117
 
   let fname    = a:3
118
 
   let cmmnt    = ""
119
 
"   call Decho("scriptid<".scriptid.">")
120
 
"   call Decho("srcid   <".srcid.">")
121
 
"   call Decho("fname   <".fname.">")
122
 
  else
123
 
   let curline  = getline(".")
124
 
   if curline =~ '^\s*#'
125
 
"    call Dret("GetOneScript : skipping a pure comment line")
126
 
    return
127
 
   endif
128
 
   let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
129
 
   try
130
 
    let scriptid = substitute(curline,parsepat,'\1','e')
131
 
   catch /^Vim\%((\a\+)\)\=:E486/
132
 
    let scriptid= 0
133
 
   endtry
134
 
   try
135
 
    let srcid    = substitute(curline,parsepat,'\2','e')
136
 
   catch /^Vim\%((\a\+)\)\=:E486/
137
 
    let srcid= 0
138
 
   endtry
139
 
   try
140
 
    let fname= substitute(curline,parsepat,'\3','e')
141
 
   catch /^Vim\%((\a\+)\)\=:E486/
142
 
    let fname= ""
143
 
   endtry
144
 
   try
145
 
    let cmmnt= substitute(curline,parsepat,'\4','e')
146
 
   catch /^Vim\%((\a\+)\)\=:E486/
147
 
    let cmmnt= ""
148
 
   endtry
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.">")
154
 
  endif
155
 
 
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")
160
 
   return
161
 
  endif
162
 
 
163
 
  let doautoinstall= 0
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
170
 
   endif
171
 
  else
172
 
   let aicmmnt= fname
173
 
  endif
174
 
"  call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
175
 
 
176
 
  exe "norm z\<CR>"
177
 
  redraw!
178
 
"  call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
179
 
  echomsg 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
180
 
 
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()
184
 
  let v:errmsg   = ""
185
 
 
186
 
  " make up to three tries at downloading the description
187
 
  let itry= 1
188
 
  while itry <= 3
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.'"'
193
 
        else
194
 
"     call Decho("silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".tmpfile." '".scriptaddr."'")
195
 
     exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".tmpfile." '".scriptaddr."'"
196
 
        endif
197
 
        if itry == 1
198
 
    exe "silent vsplit ".tmpfile
199
 
        else
200
 
         silent! e %
201
 
        endif
202
 
  
203
 
   " find the latest source-id in the plugin's webpage
204
 
   silent! 1
205
 
   let findpkg= search('Click on the package to download','W')
206
 
   if findpkg > 0
207
 
    break
208
 
   endif
209
 
   let itry= itry + 1
210
 
  endwhile
211
 
"  call Decho(" --- end downloading tries while loop --- itry=".itry)
212
 
 
213
 
  " testing: did finding "Click on the package..." fail?
214
 
  if findpkg == 0 || itry >= 4
215
 
    silent q!
216
 
    call delete(tmpfile)
217
 
   " restore options
218
 
    let &t_ti        = t_ti
219
 
    let &t_te        = t_te
220
 
    let &rs          = rs
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")
225
 
    return
226
 
  endif
227
 
"  call Decho('found "Click on the package to download"')
228
 
 
229
 
  let findsrcid= search('src_id=','W')
230
 
  if findsrcid == 0
231
 
    silent q!
232
 
    call delete(tmpfile)
233
 
   " restore options
234
 
        let &t_ti        = t_ti
235
 
        let &t_te        = t_te
236
 
        let &rs          = rs
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")
241
 
        return
242
 
  endif
243
 
"  call Decho('found "src_id=" in description page')
244
 
 
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.">")
249
 
  silent q!
250
 
  call delete(tmpfile)
251
 
 
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.">")
256
 
 
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.">")
261
 
 
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
266
 
   endif
267
 
 
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.'"'
274
 
   else
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."'"
277
 
   endif
278
 
 
279
 
   " AutoInstall: only if doautoinstall is so indicating
280
 
   if doautoinstall
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
288
 
      
289
 
       " decompress
290
 
       if sname =~ '\.bz2$'
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")
300
 
       endif
301
 
      
302
 
       " distribute archive(.zip, .tar, .vba) contents
303
 
       if sname =~ '\.zip$'
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)
311
 
         silent 1split
312
 
         exe "silent e ".sname
313
 
         silent so %
314
 
         silent q
315
 
       endif
316
 
      
317
 
       if sname =~ '.vim$'
318
 
"         call Decho("dearchive: attempt to simply move ".sname." to plugin")
319
 
         exe "silent !".g:GetLatestVimScripts_mv." ".sname." plugin"
320
 
       endif
321
 
      
322
 
       " helptags step
323
 
       let docdir= substitute(&rtp,',.*','','e')."/doc"
324
 
"       call Decho("helptags: docdir<".docdir.">")
325
 
       exe "helptags ".docdir
326
 
       exe "cd ".curdir
327
 
     endif
328
 
     if fname !~ ':AutoInstall:'
329
 
      let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
330
 
     else
331
 
      let modline=scriptid." ".latestsrcid." ".fname.cmmnt
332
 
     endif
333
 
   else
334
 
     let modline=scriptid." ".latestsrcid." ".fname.cmmnt
335
 
   endif
336
 
 
337
 
   " update the data in the <GetLatestVimScripts.dat> file
338
 
   call setline(line("."),modline)
339
 
"   call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
340
 
"  else " Decho
341
 
"   call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
342
 
  endif
343
 
 
344
 
 " restore options
345
 
  let &t_ti= t_ti
346
 
  let &t_te= t_te
347
 
  let &rs  = rs
348
 
 
349
 
"  call Dret("GetOneScript")
350
 
endfun
351
 
 
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
363
140
   return
364
141
  endif
365
142
 
 
143
  " insure that fnameescape() is available
 
144
  if !exists("*fnameescape")
 
145
   echoerr "GetLatestVimScripts needs fnameescape() (provided by 7.1.299 or later)"
 
146
   return
 
147
  endif
 
148
 
366
149
  " Find the .../GetLatest subdirectory under the runtimepath
367
150
  for datadir in split(&rtp,',') + ['']
368
151
   if isdirectory(datadir."/GetLatest")
404
187
 
405
188
  " don't let any events interfere (like winmanager's, taglist's, etc)
406
189
  let eikeep= &ei
407
 
  set ei=all
 
190
  let hlskeep= &hls
 
191
  set ei=all hls&vim
408
192
 
409
193
  " record current directory, change to datadir, open split window with
410
194
  " datafile
411
195
  let origdir= getcwd()
412
 
  exe "cd ".escape(substitute(datadir,'\','/','ge'),"|[]*'\" #")
 
196
"  call Decho("exe cd ".fnameescape(substitute(datadir,'\','/','ge')))
 
197
  exe "cd ".fnameescape(substitute(datadir,'\','/','ge'))
413
198
  split
414
 
  exe "e ".escape(substitute(datafile,'\','/','ge'),"|[]*'\" #")
 
199
"  call Decho("exe e ".fnameescape(substitute(datafile,'\','/','ge')))
 
200
  exe "e ".fnameescape(substitute(datafile,'\','/','ge'))
415
201
  res 1000
416
202
  let s:downloads = 0
417
203
  let s:downerrors= 0
421
207
"  call Decho("searching plugins for GetLatestVimScripts dependencies")
422
208
  let lastline    = line("$")
423
209
"  call Decho("lastline#".lastline)
424
 
  let plugins     = split(globpath(&rtp,"plugin/*.vim"))
 
210
  let plugins     = split(globpath(&rtp,"plugin/*.vim"),'\n')
425
211
  let foundscript = 0
426
212
  let firstdir= ""
427
213
 
428
214
  for plugin in plugins
 
215
"   call Decho("plugin<".plugin.">")
429
216
 
430
217
   " don't process plugins in system directories
431
218
   if firstdir == ""
432
219
    let firstdir= substitute(plugin,'[/\\][^/\\]\+$','','')
433
 
"    call Decho("firstdir<".firstdir.">")
 
220
"    call Decho("setting firstdir<".firstdir.">")
434
221
   else
435
222
    let curdir= substitute(plugin,'[/\\][^/\\]\+$','','')
436
223
"    call Decho("curdir<".curdir.">")
437
224
    if curdir != firstdir
 
225
"     call Decho("skipping subsequent plugins: curdir<".curdir."> != firstdir<".firstdir.">")
438
226
     break
439
227
    endif
440
228
   endif
441
229
 
442
230
   " read plugin in
 
231
   " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it
443
232
   $
444
233
"   call Decho(" ")
445
234
"   call Decho(".dependency checking<".plugin."> line$=".line("$"))
446
 
   exe "silent r ".plugin
 
235
"   call Decho("exe silent r ".fnameescape(plugin))
 
236
   exe "silent r ".fnameescape(plugin)
 
237
   exe "silent bwipe ".bufnr("#")
447
238
 
448
239
   while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
449
240
    let newscript= substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
450
241
    let llp1     = lastline+1
451
242
"    call Decho("..newscript<".newscript.">")
452
243
 
453
 
    " don't process ""GetLatestVimScripts lines
 
244
    " don't process ""GetLatestVimScripts lines -- those that have been doubly-commented out
454
245
    if newscript !~ '^"'
455
246
     " found a "GetLatestVimScripts: # #" line in the script; check if its already in the datafile
456
247
     let curline     = line(".")
485
276
  endfor
486
277
"  call Decho("--- end dependency checking loop ---  foundscript=".foundscript)
487
278
"  call Decho(" ")
 
279
"  call Dredir("BUFFER TEST (GetLatestVimScripts 1)","ls!")
488
280
 
489
281
  if foundscript == 0
490
 
   set nomod
 
282
   setlocal nomod
491
283
  endif
492
284
 
493
285
  " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
494
286
"  call Decho("begin: checking out-of-date scripts using datafile<".datafile.">")
495
 
  set lz
 
287
  setlocal lz
496
288
  1
497
289
"  /^-----/,$g/^\s*\d/call Decho(getline("."))
498
290
  1
529
321
  q
530
322
 
531
323
  " restore events and current directory
532
 
  exe "cd ".escape(substitute(origdir,'\','/','ge'),"|[]*'\" #")
 
324
  exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
533
325
  let &ei= eikeep
534
 
  set nolz
 
326
  let &hls= hlskeep
 
327
  setlocal nolz
 
328
"  call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!")
535
329
"  call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
536
330
endfun
537
 
" ---------------------------------------------------------------------
538
 
 
 
331
 
 
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()")
 
339
 
 
340
 " set options to allow progress to be shown on screen
 
341
  let rega= @a
 
342
  let t_ti= &t_ti
 
343
  let t_te= &t_te
 
344
  let rs  = &rs
 
345
  set t_ti= t_te= nors
 
346
 
 
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
 
351
  if a:0 >= 3
 
352
   let scriptid = a:1
 
353
   let srcid    = a:2
 
354
   let fname    = a:3
 
355
   let cmmnt    = ""
 
356
"   call Decho("scriptid<".scriptid.">")
 
357
"   call Decho("srcid   <".srcid.">")
 
358
"   call Decho("fname   <".fname.">")
 
359
  else
 
360
   let curline  = getline(".")
 
361
   if curline =~ '^\s*#'
 
362
    let @a= rega
 
363
"    call Dret("GetOneScript : skipping a pure comment line")
 
364
    return
 
365
   endif
 
366
   let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
 
367
   try
 
368
    let scriptid = substitute(curline,parsepat,'\1','e')
 
369
   catch /^Vim\%((\a\+)\)\=:E486/
 
370
    let scriptid= 0
 
371
   endtry
 
372
   try
 
373
    let srcid    = substitute(curline,parsepat,'\2','e')
 
374
   catch /^Vim\%((\a\+)\)\=:E486/
 
375
    let srcid= 0
 
376
   endtry
 
377
   try
 
378
    let fname= substitute(curline,parsepat,'\3','e')
 
379
   catch /^Vim\%((\a\+)\)\=:E486/
 
380
    let fname= ""
 
381
   endtry
 
382
   try
 
383
    let cmmnt= substitute(curline,parsepat,'\4','e')
 
384
   catch /^Vim\%((\a\+)\)\=:E486/
 
385
    let cmmnt= ""
 
386
   endtry
 
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.">")
 
392
  endif
 
393
 
 
394
  if scriptid == 0 || srcid == 0
 
395
   " When looking for :AutoInstall: lines, skip scripts that have   0 0 scriptname
 
396
   let @a= rega
 
397
"   call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
 
398
   return
 
399
  endif
 
400
 
 
401
  let doautoinstall= 0
 
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
 
408
   endif
 
409
  else
 
410
   let aicmmnt= fname
 
411
  endif
 
412
"  call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
 
413
 
 
414
  exe "norm z\<CR>"
 
415
  redraw!
 
416
"  call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
 
417
  echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
 
418
 
 
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()
 
422
  let v:errmsg   = ""
 
423
 
 
424
  " make up to three tries at downloading the description
 
425
  let itry= 1
 
426
  while itry <= 3
 
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!
 
431
   else
 
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)
 
434
   endif
 
435
   if itry == 1
 
436
    exe "silent vsplit ".fnameescape(tmpfile)
 
437
   else
 
438
    silent! e %
 
439
   endif
 
440
   setlocal bh=wipe
 
441
  
 
442
   " find the latest source-id in the plugin's webpage
 
443
   silent! 1
 
444
   let findpkg= search('Click on the package to download','W')
 
445
   if findpkg > 0
 
446
    break
 
447
   endif
 
448
   let itry= itry + 1
 
449
  endwhile
 
450
"  call Decho(" --- end downloading tries while loop --- itry=".itry)
 
451
 
 
452
  " testing: did finding "Click on the package..." fail?
 
453
  if findpkg == 0 || itry >= 4
 
454
   silent q!
 
455
   call delete(tmpfile)
 
456
  " restore options
 
457
   let &t_ti        = t_ti
 
458
   let &t_te        = t_te
 
459
   let &rs          = rs
 
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")
 
464
   let @a= rega
 
465
   return
 
466
  endif
 
467
"  call Decho('found "Click on the package to download"')
 
468
 
 
469
  let findsrcid= search('src_id=','W')
 
470
  if findsrcid == 0
 
471
   silent q!
 
472
   call delete(tmpfile)
 
473
  " restore options
 
474
   let &t_ti        = t_ti
 
475
   let &t_te        = t_te
 
476
   let &rs          = rs
 
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.">"
 
480
   let @a= rega
 
481
"  call Dret("GetOneScript : srch for /src_id/ failed")
 
482
   return
 
483
  endif
 
484
"  call Decho('found "src_id=" in description page')
 
485
 
 
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.">")
 
490
  silent q!
 
491
  call delete(tmpfile)
 
492
 
 
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.">")
 
497
 
 
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.">")
 
502
 
 
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
 
507
   endif
 
508
 
 
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
 
515
   else
 
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
 
518
   endif
 
519
 
 
520
   " AutoInstall: only if doautoinstall has been requested by the plugin itself
 
521
   if doautoinstall
 
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)
 
530
     endif
 
531
"    call Decho("exe cd ".fnameescape(s:autoinstall))
 
532
     exe "cd ".fnameescape(s:autoinstall)
 
533
     
 
534
     " decompress
 
535
     if sname =~ '\.bz2$'
 
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")
 
545
     endif
 
546
     
 
547
     " distribute archive(.zip, .tar, .vba) contents
 
548
     if sname =~ '\.zip$'
 
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)
 
556
      silent 1split
 
557
      exe "silent e ".fnameescape(sname)
 
558
      silent so %
 
559
      silent q
 
560
     endif
 
561
     
 
562
     if sname =~ '.vim$'
 
563
"      call Decho("dearchive: attempt to simply move ".sname." to plugin")
 
564
      exe "silent !".g:GetLatestVimScripts_mv." ".s:Escape(sname)." plugin"
 
565
     else
 
566
"      call Decho("dearchive: move <".sname."> to installdir<".installdir.">")
 
567
      exe "silent !".g:GetLatestVimScripts_mv." ".s:Escape(sname)." ".installdir
 
568
     endif
 
569
     
 
570
     " helptags step
 
571
     let docdir= substitute(&rtp,',.*','','e')."/doc"
 
572
"     call Decho("helptags: docdir<".docdir.">")
 
573
     exe "helptags ".fnameescape(docdir)
 
574
     exe "cd ".fnameescape(curdir)
 
575
    endif
 
576
    if fname !~ ':AutoInstall:'
 
577
     let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
 
578
    else
 
579
     let modline=scriptid." ".latestsrcid." ".fname.cmmnt
 
580
    endif
 
581
   else
 
582
    let modline=scriptid." ".latestsrcid." ".fname.cmmnt
 
583
   endif
 
584
 
 
585
   " update the data in the <GetLatestVimScripts.dat> file
 
586
   call setline(line("."),modline)
 
587
"   call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
 
588
"  else " Decho
 
589
"   call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
 
590
  endif
 
591
 
 
592
 " restore options
 
593
  let &t_ti = t_ti
 
594
  let &t_te = t_te
 
595
  let &rs   = rs
 
596
  let @a    = rega
 
597
"  call Dredir("BUFFER TEST (GetOneScript)","ls!")
 
598
 
 
599
"  call Dret("GetOneScript")
 
600
endfun
 
601
 
 
602
" ---------------------------------------------------------------------
 
603
" s:Escape: makes a string safe&suitable for the shell {{{2
 
604
fun! s:Escape(name)
 
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)
 
609
  else
 
610
   let name= g:getscript_shq . a:name . g:getscript_shq
 
611
  endif
 
612
"  call Dret("s:Escape ".name)
 
613
  return name
 
614
endfun
 
615
 
 
616
" ---------------------------------------------------------------------
539
617
" Restore Options: {{{1
540
618
let &cpo= s:keepcpo
 
619
unlet s:keepcpo
541
620
 
 
621
" ---------------------------------------------------------------------
 
622
"  Modelines: {{{1
542
623
" vim: ts=8 sts=2 fdm=marker nowrap