blob: 1fd4e63025a3cce5674359b97f2890d8a98d1c00 [file] [log] [blame]
Bram Moolenaar9964e462007-05-05 17:54:07 +00001" ---------------------------------------------------------------------
2" getscript.vim
Christian Brabandtf9ca1392024-02-19 20:37:11 +01003" Maintainer: This runtime file is looking for a new maintainer.
4" Original Author: Charles E. Campbell
Bram Moolenaar8d043172014-01-23 14:24:41 +01005" Date: Jan 21, 2014
6" Version: 36
Bram Moolenaar9964e462007-05-05 17:54:07 +00007" Installing: :help glvs-install
8" Usage: :help glvs
9"
10" GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
Bram Moolenaar9e368db2007-05-12 13:25:01 +000011"redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar9964e462007-05-05 17:54:07 +000012" ---------------------------------------------------------------------
13" Initialization: {{{1
14" if you're sourcing this file, surely you can't be
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000015" expecting vim to be in its vi-compatible mode!
Bram Moolenaar5c736222010-01-06 20:54:52 +010016if exists("g:loaded_getscript")
17 finish
18endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010019let g:loaded_getscript= "v36"
Bram Moolenaar9964e462007-05-05 17:54:07 +000020if &cp
21 echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
22 finish
23endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010024if v:version < 702
25 echohl WarningMsg
Bram Moolenaar29634562020-01-09 21:46:04 +010026 echo "***warning*** this version of GetLatestVimScripts needs vim 7.2"
Bram Moolenaar5c736222010-01-06 20:54:52 +010027 echohl Normal
28 finish
29endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000030let s:keepcpo = &cpo
31set cpo&vim
Bram Moolenaar82038d72007-05-10 17:15:45 +000032"DechoTabOn
Bram Moolenaar9964e462007-05-05 17:54:07 +000033
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000034" ---------------------------
35" Global Variables: {{{1
36" ---------------------------
37" Cygwin Detection ------- {{{2
38if !exists("g:getscript_cygwin")
39 if has("win32") || has("win95") || has("win64") || has("win16")
40 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
41 let g:getscript_cygwin= 1
42 else
43 let g:getscript_cygwin= 0
44 endif
45 else
46 let g:getscript_cygwin= 0
47 endif
48endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000049
50" wget vs curl {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000051if !exists("g:GetLatestVimScripts_wget")
52 if executable("wget")
53 let g:GetLatestVimScripts_wget= "wget"
54 elseif executable("curl")
55 let g:GetLatestVimScripts_wget= "curl"
56 else
57 let g:GetLatestVimScripts_wget = 'echo "GetLatestVimScripts needs wget or curl"'
58 let g:GetLatestVimScripts_options = ""
59 endif
60endif
61
62" options that wget and curl require:
63if !exists("g:GetLatestVimScripts_options")
64 if g:GetLatestVimScripts_wget == "wget"
65 let g:GetLatestVimScripts_options= "-q -O"
66 elseif g:GetLatestVimScripts_wget == "curl"
67 let g:GetLatestVimScripts_options= "-s -O"
68 else
69 let g:GetLatestVimScripts_options= ""
70 endif
71endif
72
73" by default, allow autoinstall lines to work
74if !exists("g:GetLatestVimScripts_allowautoinstall")
75 let g:GetLatestVimScripts_allowautoinstall= 1
76endif
77
Bram Moolenaarff034192013-04-24 18:51:19 +020078" set up default scriptaddr address
79if !exists("g:GetLatestVimScripts_scriptaddr")
80 let g:GetLatestVimScripts_scriptaddr = 'http://vim.sourceforge.net/script.php?script_id='
81endif
82
Bram Moolenaar9964e462007-05-05 17:54:07 +000083"" For debugging:
84"let g:GetLatestVimScripts_wget = "echo"
85"let g:GetLatestVimScripts_options = "options"
86
87" ---------------------------------------------------------------------
88" Check If AutoInstall Capable: {{{1
89let s:autoinstall= ""
90if g:GetLatestVimScripts_allowautoinstall
91
92 if (has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")) && &shell != "bash"
93 " windows (but not cygwin/bash)
94 let s:dotvim= "vimfiles"
95 if !exists("g:GetLatestVimScripts_mv")
96 let g:GetLatestVimScripts_mv= "ren"
97 endif
98
99 else
100 " unix
101 let s:dotvim= ".vim"
102 if !exists("g:GetLatestVimScripts_mv")
103 let g:GetLatestVimScripts_mv= "mv"
104 endif
105 endif
106
Bram Moolenaar5c736222010-01-06 20:54:52 +0100107 if exists("g:GetLatestVimScripts_autoinstalldir") && isdirectory(g:GetLatestVimScripts_autoinstalldir)
108 let s:autoinstall= g:GetLatestVimScripts_autoinstalldir"
109 elseif exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000110 let s:autoinstall= $HOME."/".s:dotvim
111 endif
112" call Decho("s:autoinstall<".s:autoinstall.">")
113"else "Decho
114" call Decho("g:GetLatestVimScripts_allowautoinstall=".g:GetLatestVimScripts_allowautoinstall.": :AutoInstall: disabled")
115endif
116
117" ---------------------------------------------------------------------
118" Public Interface: {{{1
119com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
120com! -nargs=0 GetScript call getscript#GetLatestVimScripts()
121silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts()
122
123" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000124" GetLatestVimScripts: this function gets the latest versions of {{{1
125" scripts based on the list in
126" (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
127fun! getscript#GetLatestVimScripts()
128" call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">")
129
130" insure that wget is executable
131 if executable(g:GetLatestVimScripts_wget) != 1
132 echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system"
Bram Moolenaar6c391a72021-09-09 21:55:11 +0200133" call Dret("GetLatestVimScripts : wget not executable/available")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000134 return
135 endif
136
Bram Moolenaarc236c162008-07-13 17:41:49 +0000137 " insure that fnameescape() is available
138 if !exists("*fnameescape")
139 echoerr "GetLatestVimScripts needs fnameescape() (provided by 7.1.299 or later)"
140 return
141 endif
142
Bram Moolenaar9964e462007-05-05 17:54:07 +0000143 " Find the .../GetLatest subdirectory under the runtimepath
144 for datadir in split(&rtp,',') + ['']
145 if isdirectory(datadir."/GetLatest")
146" call Decho("found directory<".datadir.">")
147 let datadir= datadir . "/GetLatest"
148 break
149 endif
150 if filereadable(datadir."GetLatestVimScripts.dat")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000151" call Decho("found ".datadir."/GetLatestVimScripts.dat")
152 break
Bram Moolenaar9964e462007-05-05 17:54:07 +0000153 endif
154 endfor
Bram Moolenaar82038d72007-05-10 17:15:45 +0000155
Bram Moolenaar9964e462007-05-05 17:54:07 +0000156 " Sanity checks: readability and writability
157 if datadir == ""
158 echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install'
159" call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory")
160 return
161 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000162 if filewritable(datadir) != 2
163 echoerr "(getLatestVimScripts) Your ".datadir." isn't writable"
164" call Dret("GetLatestVimScripts : non-writable directory<".datadir.">")
165 return
166 endif
167 let datafile= datadir."/GetLatestVimScripts.dat"
168 if !filereadable(datafile)
169 echoerr "Your data file<".datafile."> isn't readable"
170" call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">")
171 return
172 endif
173 if !filewritable(datafile)
174 echoerr "Your data file<".datafile."> isn't writable"
175" call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">")
176 return
177 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100178 " --------------------
179 " Passed sanity checks
180 " --------------------
181
Bram Moolenaar9964e462007-05-05 17:54:07 +0000182" call Decho("datadir <".datadir.">")
183" call Decho("datafile <".datafile.">")
184
Bram Moolenaar5c736222010-01-06 20:54:52 +0100185 " don't let any event handlers interfere (like winmanager's, taglist's, etc)
186 let eikeep = &ei
187 let hlskeep = &hls
188 let acdkeep = &acd
189 set ei=all hls&vim noacd
Bram Moolenaar9964e462007-05-05 17:54:07 +0000190
Bram Moolenaar5c736222010-01-06 20:54:52 +0100191 " Edit the datafile (ie. GetLatestVimScripts.dat):
192 " 1. record current directory (origdir),
193 " 2. change directory to datadir,
194 " 3. split window
195 " 4. edit datafile
Bram Moolenaar9964e462007-05-05 17:54:07 +0000196 let origdir= getcwd()
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000197" call Decho("exe cd ".fnameescape(substitute(datadir,'\','/','ge')))
198 exe "cd ".fnameescape(substitute(datadir,'\','/','ge'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000199 split
Bram Moolenaar5c736222010-01-06 20:54:52 +0100200" call Decho("exe e ".fnameescape(substitute(datafile,'\','/','ge')))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000201 exe "e ".fnameescape(substitute(datafile,'\','/','ge'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000202 res 1000
203 let s:downloads = 0
204 let s:downerrors= 0
205
206 " Check on dependencies mentioned in plugins
207" call Decho(" ")
208" call Decho("searching plugins for GetLatestVimScripts dependencies")
209 let lastline = line("$")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000210" call Decho("lastline#".lastline)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100211 let firstdir = substitute(&rtp,',.*$','','')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100212 let plugins = split(globpath(firstdir,"plugin/**/*.vim"),'\n')
213 let plugins = plugins + split(globpath(firstdir,"AsNeeded/**/*.vim"),'\n')
Bram Moolenaar9964e462007-05-05 17:54:07 +0000214 let foundscript = 0
215
Bram Moolenaar5c736222010-01-06 20:54:52 +0100216 " this loop updates the GetLatestVimScripts.dat file
217 " with dependencies explicitly mentioned in the plugins
218 " via GetLatestVimScripts: ... lines
219 " It reads the plugin script at the end of the GetLatestVimScripts.dat
220 " file, examines it, and then removes it.
Bram Moolenaar82038d72007-05-10 17:15:45 +0000221 for plugin in plugins
Bram Moolenaar5c736222010-01-06 20:54:52 +0100222" call Decho(" ")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000223" call Decho("plugin<".plugin.">")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000224
Bram Moolenaar82038d72007-05-10 17:15:45 +0000225 " read plugin in
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000226 " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it
Bram Moolenaar9964e462007-05-05 17:54:07 +0000227 $
228" call Decho(".dependency checking<".plugin."> line$=".line("$"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100229" call Decho("..exe silent r ".fnameescape(plugin))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000230 exe "silent r ".fnameescape(plugin)
231 exe "silent bwipe ".bufnr("#")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000232
Bram Moolenaar9964e462007-05-05 17:54:07 +0000233 while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
Bram Moolenaar5c736222010-01-06 20:54:52 +0100234 let depscript = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
235 let depscriptid = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\(\d\+\)\s\+.*$','\1','')
236 let llp1 = lastline+1
237" call Decho("..depscript<".depscript.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000238
Bram Moolenaar5c736222010-01-06 20:54:52 +0100239 " found a "GetLatestVimScripts: # #" line in the script;
Bram Moolenaar8024f932020-01-14 19:29:13 +0100240 " check if it's already in the datafile by searching backwards from llp1,
Bram Moolenaar5c736222010-01-06 20:54:52 +0100241 " the (prior to reading in the plugin script) last line plus one of the GetLatestVimScripts.dat file,
242 " for the script-id with no wrapping allowed.
243 let curline = line(".")
244 let noai_script = substitute(depscript,'\s*:AutoInstall:\s*','','e')
245 exe llp1
246 let srchline = search('^\s*'.depscriptid.'\s\+\d\+\s\+.*$','bW')
247 if srchline == 0
248 " this second search is taken when, for example, a 0 0 scriptname is to be skipped over
249 let srchline= search('\<'.noai_script.'\>','bW')
Bram Moolenaar82038d72007-05-10 17:15:45 +0000250 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100251" call Decho("..noai_script<".noai_script."> depscriptid#".depscriptid." srchline#".srchline." curline#".line(".")." lastline#".lastline)
252
253 if srchline == 0
254 " found a new script to permanently include in the datafile
255 let keep_rega = @a
256 let @a = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','')
257 echomsg "Appending <".@a."> to ".datafile." for ".depscript
258" call Decho("..Appending <".@a."> to ".datafile." for ".depscript)
259 exe lastline."put a"
260 let @a = keep_rega
261 let lastline = llp1
262 let curline = curline + 1
263 let foundscript = foundscript + 1
264" else " Decho
265" call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")")
266 endif
267
268 let curline = curline + 1
269 exe curline
Bram Moolenaar9964e462007-05-05 17:54:07 +0000270 endwhile
Bram Moolenaar82038d72007-05-10 17:15:45 +0000271
Bram Moolenaar5c736222010-01-06 20:54:52 +0100272 " llp1: last line plus one
Bram Moolenaar9964e462007-05-05 17:54:07 +0000273 let llp1= lastline + 1
274" call Decho(".deleting lines: ".llp1.",$d")
275 exe "silent! ".llp1.",$d"
Bram Moolenaar82038d72007-05-10 17:15:45 +0000276 endfor
277" call Decho("--- end dependency checking loop --- foundscript=".foundscript)
278" call Decho(" ")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000279" call Dredir("BUFFER TEST (GetLatestVimScripts 1)","ls!")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000280
281 if foundscript == 0
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000282 setlocal nomod
Bram Moolenaar9964e462007-05-05 17:54:07 +0000283 endif
284
Bram Moolenaar5c736222010-01-06 20:54:52 +0100285 " --------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000286 " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
Bram Moolenaar5c736222010-01-06 20:54:52 +0100287 " --------------------------------------------------------------------
Bram Moolenaar82038d72007-05-10 17:15:45 +0000288" call Decho("begin: checking out-of-date scripts using datafile<".datafile.">")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000289 setlocal lz
Bram Moolenaar9964e462007-05-05 17:54:07 +0000290 1
Bram Moolenaar82038d72007-05-10 17:15:45 +0000291" /^-----/,$g/^\s*\d/call Decho(getline("."))
292 1
293 /^-----/,$g/^\s*\d/call s:GetOneScript()
294" call Decho("--- end out-of-date checking --- ")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000295
296 " Final report (an echomsg)
297 try
298 silent! ?^-------?
299 catch /^Vim\%((\a\+)\)\=:E114/
300" call Dret("GetLatestVimScripts : nothing done!")
301 return
302 endtry
303 exe "norm! kz\<CR>"
304 redraw!
305 let s:msg = ""
306 if s:downloads == 1
307 let s:msg = "Downloaded one updated script to <".datadir.">"
308 elseif s:downloads == 2
309 let s:msg= "Downloaded two updated scripts to <".datadir.">"
310 elseif s:downloads > 1
311 let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">"
312 else
313 let s:msg= "Everything was already current"
314 endif
315 if s:downerrors > 0
316 let s:msg= s:msg." (".s:downerrors." downloading errors)"
317 endif
318 echomsg s:msg
319 " save the file
320 if &mod
321 silent! w!
322 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200323 q!
Bram Moolenaar9964e462007-05-05 17:54:07 +0000324
325 " restore events and current directory
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000326 exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100327 let &ei = eikeep
328 let &hls = hlskeep
329 let &acd = acdkeep
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000330 setlocal nolz
331" call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000332" call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
333endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +0000334
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000335" ---------------------------------------------------------------------
336" GetOneScript: (Get Latest Vim Script) this function operates {{{1
337" on the current line, interpreting two numbers and text as
338" ScriptID, SourceID, and Filename.
Bram Moolenaar5c736222010-01-06 20:54:52 +0100339" It downloads any scripts that have newer versions from vim.sourceforge.net.
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000340fun! s:GetOneScript(...)
341" call Dfunc("GetOneScript()")
342
343 " set options to allow progress to be shown on screen
344 let rega= @a
345 let t_ti= &t_ti
346 let t_te= &t_te
347 let rs = &rs
348 set t_ti= t_te= nors
349
350 " put current line on top-of-screen and interpret it into
Bram Moolenaar6c391a72021-09-09 21:55:11 +0200351 " a script identifier : used to obtain webpage
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000352 " source identifier : used to identify current version
353 " and an associated comment: used to report on what's being considered
354 if a:0 >= 3
355 let scriptid = a:1
356 let srcid = a:2
357 let fname = a:3
358 let cmmnt = ""
359" call Decho("scriptid<".scriptid.">")
360" call Decho("srcid <".srcid.">")
361" call Decho("fname <".fname.">")
362 else
363 let curline = getline(".")
364 if curline =~ '^\s*#'
365 let @a= rega
366" call Dret("GetOneScript : skipping a pure comment line")
367 return
368 endif
369 let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
370 try
371 let scriptid = substitute(curline,parsepat,'\1','e')
372 catch /^Vim\%((\a\+)\)\=:E486/
373 let scriptid= 0
374 endtry
375 try
376 let srcid = substitute(curline,parsepat,'\2','e')
377 catch /^Vim\%((\a\+)\)\=:E486/
378 let srcid= 0
379 endtry
380 try
381 let fname= substitute(curline,parsepat,'\3','e')
382 catch /^Vim\%((\a\+)\)\=:E486/
383 let fname= ""
384 endtry
385 try
386 let cmmnt= substitute(curline,parsepat,'\4','e')
387 catch /^Vim\%((\a\+)\)\=:E486/
388 let cmmnt= ""
389 endtry
390" call Decho("curline <".curline.">")
391" call Decho("parsepat<".parsepat.">")
392" call Decho("scriptid<".scriptid.">")
393" call Decho("srcid <".srcid.">")
394" call Decho("fname <".fname.">")
395 endif
396
Bram Moolenaar5c736222010-01-06 20:54:52 +0100397 " plugin author protection from downloading his/her own scripts atop their latest work
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000398 if scriptid == 0 || srcid == 0
399 " When looking for :AutoInstall: lines, skip scripts that have 0 0 scriptname
400 let @a= rega
401" call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
402 return
403 endif
404
405 let doautoinstall= 0
406 if fname =~ ":AutoInstall:"
407" call Decho("case AutoInstall: fname<".fname.">")
408 let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
409" call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
410 if s:autoinstall != ""
411 let doautoinstall = g:GetLatestVimScripts_allowautoinstall
412 endif
413 else
414 let aicmmnt= fname
415 endif
416" call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
417
418 exe "norm z\<CR>"
419 redraw!
420" call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
421 echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
422
Bram Moolenaar5c736222010-01-06 20:54:52 +0100423 " grab a copy of the plugin's vim.sourceforge.net webpage
Bram Moolenaarff034192013-04-24 18:51:19 +0200424 let scriptaddr = g:GetLatestVimScripts_scriptaddr.scriptid
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000425 let tmpfile = tempname()
426 let v:errmsg = ""
427
428 " make up to three tries at downloading the description
429 let itry= 1
430 while itry <= 3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100431" call Decho(".try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000432 if has("win32") || has("win16") || has("win95")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100433" call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)."|bw!")
434 new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)|bw!
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000435 else
Bram Moolenaar5c736222010-01-06 20:54:52 +0100436" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr))
437 exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000438 endif
439 if itry == 1
440 exe "silent vsplit ".fnameescape(tmpfile)
441 else
442 silent! e %
443 endif
444 setlocal bh=wipe
445
446 " find the latest source-id in the plugin's webpage
447 silent! 1
448 let findpkg= search('Click on the package to download','W')
449 if findpkg > 0
450 break
451 endif
452 let itry= itry + 1
453 endwhile
454" call Decho(" --- end downloading tries while loop --- itry=".itry)
455
456 " testing: did finding "Click on the package..." fail?
457 if findpkg == 0 || itry >= 4
458 silent q!
459 call delete(tmpfile)
460 " restore options
461 let &t_ti = t_ti
462 let &t_te = t_te
463 let &rs = rs
464 let s:downerrors = s:downerrors + 1
465" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
466 echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
467" call Dret("GetOneScript : srch for /Click on the package/ failed")
468 let @a= rega
469 return
470 endif
471" call Decho('found "Click on the package to download"')
472
473 let findsrcid= search('src_id=','W')
474 if findsrcid == 0
475 silent q!
476 call delete(tmpfile)
477 " restore options
478 let &t_ti = t_ti
479 let &t_te = t_te
480 let &rs = rs
481 let s:downerrors = s:downerrors + 1
482" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
483 echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
484 let @a= rega
485" call Dret("GetOneScript : srch for /src_id/ failed")
486 return
487 endif
488" call Decho('found "src_id=" in description page')
489
490 let srcidpat = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
491 let latestsrcid= substitute(getline("."),srcidpat,'\1','')
492 let sname = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
493" call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
494 silent q!
495 call delete(tmpfile)
496
497 " convert the strings-of-numbers into numbers
498 let srcid = srcid + 0
499 let latestsrcid = latestsrcid + 0
500" call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
501
Bram Moolenaar5c736222010-01-06 20:54:52 +0100502 " has the plugin's most-recent srcid increased, which indicates that it has been updated
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000503 if latestsrcid > srcid
504" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
505
506 let s:downloads= s:downloads + 1
507 if sname == bufname("%")
508 " GetLatestVimScript has to be careful about downloading itself
509 let sname= "NEW_".sname
510 endif
511
Bram Moolenaar5c736222010-01-06 20:54:52 +0100512 " -----------------------------------------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000513 " the plugin has been updated since we last obtained it, so download a new copy
Bram Moolenaar5c736222010-01-06 20:54:52 +0100514 " -----------------------------------------------------------------------------
515" call Decho(".downloading new <".sname.">")
516 echomsg ".downloading new <".sname.">"
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000517 if has("win32") || has("win16") || has("win95")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100518" 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")
519 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
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000520 else
Bram Moolenaar5c736222010-01-06 20:54:52 +0100521" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id='))
522 exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id=').latestsrcid
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000523 endif
524
Bram Moolenaar5c736222010-01-06 20:54:52 +0100525 " --------------------------------------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000526 " AutoInstall: only if doautoinstall has been requested by the plugin itself
Bram Moolenaar5c736222010-01-06 20:54:52 +0100527 " --------------------------------------------------------------------------
Bram Moolenaar251e1912011-06-19 05:09:16 +0200528" call Decho("checking if plugin requested autoinstall: doautoinstall=".doautoinstall)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000529 if doautoinstall
Bram Moolenaar5c736222010-01-06 20:54:52 +0100530" call Decho(" ")
531" call Decho("Autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000532 if filereadable(sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100533" call Decho("<".sname."> is readable")
534" call Decho("exe silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall))
535 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200536 let curdir = fnameescape(substitute(getcwd(),'\','/','ge'))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000537 let installdir= curdir."/Installed"
538 if !isdirectory(installdir)
539 call mkdir(installdir)
540 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100541" call Decho("curdir<".curdir."> installdir<".installdir.">")
542" call Decho("exe cd ".fnameescape(s:autoinstall))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000543 exe "cd ".fnameescape(s:autoinstall)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100544
545 " determine target directory for moves
546 let firstdir= substitute(&rtp,',.*$','','')
547 let pname = substitute(sname,'\..*','.vim','')
548" call Decho("determine tgtdir: is <".firstdir.'/AsNeeded/'.pname." readable?")
549 if filereadable(firstdir.'/AsNeeded/'.pname)
550 let tgtdir= "AsNeeded"
551 else
552 let tgtdir= "plugin"
553 endif
554" call Decho("tgtdir<".tgtdir."> pname<".pname.">")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000555
556 " decompress
557 if sname =~ '\.bz2$'
558" call Decho("decompress: attempt to bunzip2 ".sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100559 exe "sil !bunzip2 ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000560 let sname= substitute(sname,'\.bz2$','','')
561" call Decho("decompress: new sname<".sname."> after bunzip2")
562 elseif sname =~ '\.gz$'
563" call Decho("decompress: attempt to gunzip ".sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100564 exe "sil !gunzip ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000565 let sname= substitute(sname,'\.gz$','','')
566" call Decho("decompress: new sname<".sname."> after gunzip")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200567 elseif sname =~ '\.xz$'
568" call Decho("decompress: attempt to unxz ".sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100569 exe "sil !unxz ".shellescape(sname)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200570 let sname= substitute(sname,'\.xz$','','')
571" call Decho("decompress: new sname<".sname."> after unxz")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100572 else
573" call Decho("no decompression needed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000574 endif
575
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100576 " distribute archive(.zip, .tar, .vba, ...) contents
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000577 if sname =~ '\.zip$'
578" call Decho("dearchive: attempt to unzip ".sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100579 exe "silent !unzip -o ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000580 elseif sname =~ '\.tar$'
581" call Decho("dearchive: attempt to untar ".sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100582 exe "silent !tar -xvf ".shellescape(sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100583 elseif sname =~ '\.tgz$'
584" call Decho("dearchive: attempt to untar+gunzip ".sname)
585 exe "silent !tar -zxvf ".shellescape(sname)
586 elseif sname =~ '\.taz$'
587" call Decho("dearchive: attempt to untar+uncompress ".sname)
588 exe "silent !tar -Zxvf ".shellescape(sname)
589 elseif sname =~ '\.tbz$'
590" call Decho("dearchive: attempt to untar+bunzip2 ".sname)
591 exe "silent !tar -jxvf ".shellescape(sname)
592 elseif sname =~ '\.txz$'
593" call Decho("dearchive: attempt to untar+xz ".sname)
594 exe "silent !tar -Jxvf ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000595 elseif sname =~ '\.vba$'
596" call Decho("dearchive: attempt to handle a vimball: ".sname)
597 silent 1split
Bram Moolenaar5c736222010-01-06 20:54:52 +0100598 if exists("g:vimball_home")
599 let oldvimballhome= g:vimball_home
600 endif
601 let g:vimball_home= s:autoinstall
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000602 exe "silent e ".fnameescape(sname)
603 silent so %
604 silent q
Bram Moolenaar5c736222010-01-06 20:54:52 +0100605 if exists("oldvimballhome")
606 let g:vimball_home= oldvimballhome
607 else
608 unlet g:vimball_home
609 endif
610 else
611" call Decho("no dearchiving needed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000612 endif
613
Bram Moolenaar5c736222010-01-06 20:54:52 +0100614 " ---------------------------------------------
615 " move plugin to plugin/ or AsNeeded/ directory
616 " ---------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000617 if sname =~ '.vim$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100618" call Decho("dearchive: attempt to simply move ".sname." to ".tgtdir)
619 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".tgtdir
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000620 else
621" call Decho("dearchive: move <".sname."> to installdir<".installdir.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100622 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".installdir
623 endif
624 if tgtdir != "plugin"
625" call Decho("exe silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir)
626 exe "silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000627 endif
628
629 " helptags step
630 let docdir= substitute(&rtp,',.*','','e')."/doc"
631" call Decho("helptags: docdir<".docdir.">")
632 exe "helptags ".fnameescape(docdir)
633 exe "cd ".fnameescape(curdir)
634 endif
635 if fname !~ ':AutoInstall:'
636 let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
637 else
638 let modline=scriptid." ".latestsrcid." ".fname.cmmnt
639 endif
640 else
641 let modline=scriptid." ".latestsrcid." ".fname.cmmnt
642 endif
643
644 " update the data in the <GetLatestVimScripts.dat> file
645 call setline(line("."),modline)
646" call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
647" else " Decho
648" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
649 endif
650
651 " restore options
652 let &t_ti = t_ti
653 let &t_te = t_te
654 let &rs = rs
655 let @a = rega
656" call Dredir("BUFFER TEST (GetOneScript)","ls!")
657
658" call Dret("GetOneScript")
659endfun
660
661" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000662" Restore Options: {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000663let &cpo= s:keepcpo
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000664unlet s:keepcpo
Bram Moolenaar9964e462007-05-05 17:54:07 +0000665
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000666" ---------------------------------------------------------------------
667" Modelines: {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000668" vim: ts=8 sts=2 fdm=marker nowrap