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