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