blob: d61e6992d4bf1435fd31acada2655e0456cbac64 [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
GuyBrush609599c2024-09-08 19:54:43 +02009" Last Change: {{{1
10" 2024 Sep 08 by Vim Project: several small fixes
11" }}}
Bram Moolenaar9964e462007-05-05 17:54:07 +000012"
13" GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
Bram Moolenaar9e368db2007-05-12 13:25:01 +000014"redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar9964e462007-05-05 17:54:07 +000015" ---------------------------------------------------------------------
16" Initialization: {{{1
17" if you're sourcing this file, surely you can't be
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000018" expecting vim to be in its vi-compatible mode!
Bram Moolenaar5c736222010-01-06 20:54:52 +010019if exists("g:loaded_getscript")
20 finish
21endif
Bram Moolenaar8d043172014-01-23 14:24:41 +010022let g:loaded_getscript= "v36"
Bram Moolenaar9964e462007-05-05 17:54:07 +000023if &cp
24 echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
25 finish
26endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010027if v:version < 702
28 echohl WarningMsg
Bram Moolenaar29634562020-01-09 21:46:04 +010029 echo "***warning*** this version of GetLatestVimScripts needs vim 7.2"
Bram Moolenaar5c736222010-01-06 20:54:52 +010030 echohl Normal
31 finish
32endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000033let s:keepcpo = &cpo
34set cpo&vim
Bram Moolenaar82038d72007-05-10 17:15:45 +000035"DechoTabOn
Bram Moolenaar9964e462007-05-05 17:54:07 +000036
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000037" ---------------------------
38" Global Variables: {{{1
39" ---------------------------
40" Cygwin Detection ------- {{{2
41if !exists("g:getscript_cygwin")
42 if has("win32") || has("win95") || has("win64") || has("win16")
43 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
44 let g:getscript_cygwin= 1
45 else
46 let g:getscript_cygwin= 0
47 endif
48 else
49 let g:getscript_cygwin= 0
50 endif
51endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000052
53" wget vs curl {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000054if !exists("g:GetLatestVimScripts_wget")
55 if executable("wget")
56 let g:GetLatestVimScripts_wget= "wget"
57 elseif executable("curl")
58 let g:GetLatestVimScripts_wget= "curl"
59 else
60 let g:GetLatestVimScripts_wget = 'echo "GetLatestVimScripts needs wget or curl"'
61 let g:GetLatestVimScripts_options = ""
62 endif
63endif
64
65" options that wget and curl require:
66if !exists("g:GetLatestVimScripts_options")
67 if g:GetLatestVimScripts_wget == "wget"
68 let g:GetLatestVimScripts_options= "-q -O"
69 elseif g:GetLatestVimScripts_wget == "curl"
GuyBrush609599c2024-09-08 19:54:43 +020070 let g:GetLatestVimScripts_options= "-s -o"
Bram Moolenaar9964e462007-05-05 17:54:07 +000071 else
72 let g:GetLatestVimScripts_options= ""
73 endif
74endif
75
76" by default, allow autoinstall lines to work
77if !exists("g:GetLatestVimScripts_allowautoinstall")
78 let g:GetLatestVimScripts_allowautoinstall= 1
79endif
80
Bram Moolenaarff034192013-04-24 18:51:19 +020081" set up default scriptaddr address
82if !exists("g:GetLatestVimScripts_scriptaddr")
GuyBrush609599c2024-09-08 19:54:43 +020083 let g:GetLatestVimScripts_scriptaddr = 'https://www.vim.org/scripts/script.php?script_id='
84endif
85
86if !exists("g:GetLatestVimScripts_downloadaddr")
87 let g:GetLatestVimScripts_downloadaddr = 'https://www.vim.org/scripts/download_script.php?src_id='
Bram Moolenaarff034192013-04-24 18:51:19 +020088endif
89
Bram Moolenaar9964e462007-05-05 17:54:07 +000090"" For debugging:
91"let g:GetLatestVimScripts_wget = "echo"
92"let g:GetLatestVimScripts_options = "options"
93
94" ---------------------------------------------------------------------
95" Check If AutoInstall Capable: {{{1
96let s:autoinstall= ""
97if g:GetLatestVimScripts_allowautoinstall
98
GuyBrush609599c2024-09-08 19:54:43 +020099 if (has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")) && &shell !~ '\cbash\|pwsh\|powershell'
Bram Moolenaar9964e462007-05-05 17:54:07 +0000100 " windows (but not cygwin/bash)
101 let s:dotvim= "vimfiles"
102 if !exists("g:GetLatestVimScripts_mv")
GuyBrush609599c2024-09-08 19:54:43 +0200103 let g:GetLatestVimScripts_mv= "move"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000104 endif
105
106 else
107 " unix
108 let s:dotvim= ".vim"
109 if !exists("g:GetLatestVimScripts_mv")
110 let g:GetLatestVimScripts_mv= "mv"
111 endif
112 endif
113
Bram Moolenaar5c736222010-01-06 20:54:52 +0100114 if exists("g:GetLatestVimScripts_autoinstalldir") && isdirectory(g:GetLatestVimScripts_autoinstalldir)
115 let s:autoinstall= g:GetLatestVimScripts_autoinstalldir"
116 elseif exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000117 let s:autoinstall= $HOME."/".s:dotvim
118 endif
119" call Decho("s:autoinstall<".s:autoinstall.">")
120"else "Decho
121" call Decho("g:GetLatestVimScripts_allowautoinstall=".g:GetLatestVimScripts_allowautoinstall.": :AutoInstall: disabled")
122endif
123
124" ---------------------------------------------------------------------
125" Public Interface: {{{1
126com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
127com! -nargs=0 GetScript call getscript#GetLatestVimScripts()
128silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts()
129
130" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000131" GetLatestVimScripts: this function gets the latest versions of {{{1
132" scripts based on the list in
133" (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
134fun! getscript#GetLatestVimScripts()
135" call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">")
136
137" insure that wget is executable
138 if executable(g:GetLatestVimScripts_wget) != 1
139 echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system"
Bram Moolenaar6c391a72021-09-09 21:55:11 +0200140" call Dret("GetLatestVimScripts : wget not executable/available")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000141 return
142 endif
143
Bram Moolenaarc236c162008-07-13 17:41:49 +0000144 " insure that fnameescape() is available
145 if !exists("*fnameescape")
146 echoerr "GetLatestVimScripts needs fnameescape() (provided by 7.1.299 or later)"
147 return
148 endif
149
Bram Moolenaar9964e462007-05-05 17:54:07 +0000150 " Find the .../GetLatest subdirectory under the runtimepath
151 for datadir in split(&rtp,',') + ['']
152 if isdirectory(datadir."/GetLatest")
153" call Decho("found directory<".datadir.">")
154 let datadir= datadir . "/GetLatest"
155 break
156 endif
157 if filereadable(datadir."GetLatestVimScripts.dat")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000158" call Decho("found ".datadir."/GetLatestVimScripts.dat")
159 break
Bram Moolenaar9964e462007-05-05 17:54:07 +0000160 endif
161 endfor
Bram Moolenaar82038d72007-05-10 17:15:45 +0000162
Bram Moolenaar9964e462007-05-05 17:54:07 +0000163 " Sanity checks: readability and writability
164 if datadir == ""
165 echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install'
166" call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory")
167 return
168 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000169 if filewritable(datadir) != 2
170 echoerr "(getLatestVimScripts) Your ".datadir." isn't writable"
171" call Dret("GetLatestVimScripts : non-writable directory<".datadir.">")
172 return
173 endif
174 let datafile= datadir."/GetLatestVimScripts.dat"
175 if !filereadable(datafile)
176 echoerr "Your data file<".datafile."> isn't readable"
177" call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">")
178 return
179 endif
180 if !filewritable(datafile)
181 echoerr "Your data file<".datafile."> isn't writable"
182" call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">")
183 return
184 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100185 " --------------------
186 " Passed sanity checks
187 " --------------------
188
Bram Moolenaar9964e462007-05-05 17:54:07 +0000189" call Decho("datadir <".datadir.">")
190" call Decho("datafile <".datafile.">")
191
Bram Moolenaar5c736222010-01-06 20:54:52 +0100192 " don't let any event handlers interfere (like winmanager's, taglist's, etc)
193 let eikeep = &ei
194 let hlskeep = &hls
195 let acdkeep = &acd
196 set ei=all hls&vim noacd
Bram Moolenaar9964e462007-05-05 17:54:07 +0000197
Bram Moolenaar5c736222010-01-06 20:54:52 +0100198 " Edit the datafile (ie. GetLatestVimScripts.dat):
199 " 1. record current directory (origdir),
200 " 2. change directory to datadir,
201 " 3. split window
202 " 4. edit datafile
Bram Moolenaar9964e462007-05-05 17:54:07 +0000203 let origdir= getcwd()
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000204" call Decho("exe cd ".fnameescape(substitute(datadir,'\','/','ge')))
205 exe "cd ".fnameescape(substitute(datadir,'\','/','ge'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000206 split
Bram Moolenaar5c736222010-01-06 20:54:52 +0100207" call Decho("exe e ".fnameescape(substitute(datafile,'\','/','ge')))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000208 exe "e ".fnameescape(substitute(datafile,'\','/','ge'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000209 res 1000
210 let s:downloads = 0
211 let s:downerrors= 0
212
213 " Check on dependencies mentioned in plugins
214" call Decho(" ")
215" call Decho("searching plugins for GetLatestVimScripts dependencies")
216 let lastline = line("$")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000217" call Decho("lastline#".lastline)
GuyBrush609599c2024-09-08 19:54:43 +0200218 let firstdir = substitute(&rtp,',.{-}$','','')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100219 let plugins = split(globpath(firstdir,"plugin/**/*.vim"),'\n')
GuyBrush609599c2024-09-08 19:54:43 +0200220 let plugins += split(globpath(firstdir,"ftplugin/**/*.vim"),'\n')
221 let plugins += split(globpath(firstdir,"AsNeeded/**/*.vim"),'\n')
Bram Moolenaar9964e462007-05-05 17:54:07 +0000222 let foundscript = 0
223
Bram Moolenaar5c736222010-01-06 20:54:52 +0100224 " this loop updates the GetLatestVimScripts.dat file
225 " with dependencies explicitly mentioned in the plugins
226 " via GetLatestVimScripts: ... lines
227 " It reads the plugin script at the end of the GetLatestVimScripts.dat
228 " file, examines it, and then removes it.
Bram Moolenaar82038d72007-05-10 17:15:45 +0000229 for plugin in plugins
Bram Moolenaar5c736222010-01-06 20:54:52 +0100230" call Decho(" ")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000231" call Decho("plugin<".plugin.">")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000232
Bram Moolenaar82038d72007-05-10 17:15:45 +0000233 " read plugin in
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000234 " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it
Bram Moolenaar9964e462007-05-05 17:54:07 +0000235 $
236" call Decho(".dependency checking<".plugin."> line$=".line("$"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100237" call Decho("..exe silent r ".fnameescape(plugin))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000238 exe "silent r ".fnameescape(plugin)
239 exe "silent bwipe ".bufnr("#")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000240
Bram Moolenaar9964e462007-05-05 17:54:07 +0000241 while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
Bram Moolenaar5c736222010-01-06 20:54:52 +0100242 let depscript = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
243 let depscriptid = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\(\d\+\)\s\+.*$','\1','')
244 let llp1 = lastline+1
245" call Decho("..depscript<".depscript.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000246
Bram Moolenaar5c736222010-01-06 20:54:52 +0100247 " found a "GetLatestVimScripts: # #" line in the script;
Bram Moolenaar8024f932020-01-14 19:29:13 +0100248 " check if it's already in the datafile by searching backwards from llp1,
Bram Moolenaar5c736222010-01-06 20:54:52 +0100249 " the (prior to reading in the plugin script) last line plus one of the GetLatestVimScripts.dat file,
250 " for the script-id with no wrapping allowed.
251 let curline = line(".")
252 let noai_script = substitute(depscript,'\s*:AutoInstall:\s*','','e')
253 exe llp1
254 let srchline = search('^\s*'.depscriptid.'\s\+\d\+\s\+.*$','bW')
255 if srchline == 0
256 " this second search is taken when, for example, a 0 0 scriptname is to be skipped over
257 let srchline= search('\<'.noai_script.'\>','bW')
Bram Moolenaar82038d72007-05-10 17:15:45 +0000258 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100259" call Decho("..noai_script<".noai_script."> depscriptid#".depscriptid." srchline#".srchline." curline#".line(".")." lastline#".lastline)
260
261 if srchline == 0
262 " found a new script to permanently include in the datafile
263 let keep_rega = @a
264 let @a = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','')
265 echomsg "Appending <".@a."> to ".datafile." for ".depscript
266" call Decho("..Appending <".@a."> to ".datafile." for ".depscript)
267 exe lastline."put a"
268 let @a = keep_rega
269 let lastline = llp1
270 let curline = curline + 1
271 let foundscript = foundscript + 1
272" else " Decho
273" call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")")
274 endif
275
276 let curline = curline + 1
277 exe curline
Bram Moolenaar9964e462007-05-05 17:54:07 +0000278 endwhile
Bram Moolenaar82038d72007-05-10 17:15:45 +0000279
Bram Moolenaar5c736222010-01-06 20:54:52 +0100280 " llp1: last line plus one
Bram Moolenaar9964e462007-05-05 17:54:07 +0000281 let llp1= lastline + 1
282" call Decho(".deleting lines: ".llp1.",$d")
283 exe "silent! ".llp1.",$d"
Bram Moolenaar82038d72007-05-10 17:15:45 +0000284 endfor
285" call Decho("--- end dependency checking loop --- foundscript=".foundscript)
286" call Decho(" ")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000287" call Dredir("BUFFER TEST (GetLatestVimScripts 1)","ls!")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000288
289 if foundscript == 0
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000290 setlocal nomod
Bram Moolenaar9964e462007-05-05 17:54:07 +0000291 endif
292
Bram Moolenaar5c736222010-01-06 20:54:52 +0100293 " --------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000294 " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
Bram Moolenaar5c736222010-01-06 20:54:52 +0100295 " --------------------------------------------------------------------
Bram Moolenaar82038d72007-05-10 17:15:45 +0000296" call Decho("begin: checking out-of-date scripts using datafile<".datafile.">")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000297 setlocal lz
Bram Moolenaar9964e462007-05-05 17:54:07 +0000298 1
Bram Moolenaar82038d72007-05-10 17:15:45 +0000299" /^-----/,$g/^\s*\d/call Decho(getline("."))
300 1
301 /^-----/,$g/^\s*\d/call s:GetOneScript()
302" call Decho("--- end out-of-date checking --- ")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000303
304 " Final report (an echomsg)
305 try
306 silent! ?^-------?
307 catch /^Vim\%((\a\+)\)\=:E114/
308" call Dret("GetLatestVimScripts : nothing done!")
309 return
310 endtry
311 exe "norm! kz\<CR>"
312 redraw!
313 let s:msg = ""
314 if s:downloads == 1
315 let s:msg = "Downloaded one updated script to <".datadir.">"
316 elseif s:downloads == 2
317 let s:msg= "Downloaded two updated scripts to <".datadir.">"
318 elseif s:downloads > 1
319 let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">"
320 else
321 let s:msg= "Everything was already current"
322 endif
323 if s:downerrors > 0
324 let s:msg= s:msg." (".s:downerrors." downloading errors)"
325 endif
326 echomsg s:msg
327 " save the file
328 if &mod
329 silent! w!
330 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200331 q!
Bram Moolenaar9964e462007-05-05 17:54:07 +0000332
333 " restore events and current directory
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000334 exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100335 let &ei = eikeep
336 let &hls = hlskeep
337 let &acd = acdkeep
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000338 setlocal nolz
339" call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000340" call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
341endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +0000342
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000343" ---------------------------------------------------------------------
344" GetOneScript: (Get Latest Vim Script) this function operates {{{1
345" on the current line, interpreting two numbers and text as
346" ScriptID, SourceID, and Filename.
Bram Moolenaar5c736222010-01-06 20:54:52 +0100347" It downloads any scripts that have newer versions from vim.sourceforge.net.
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000348fun! s:GetOneScript(...)
349" call Dfunc("GetOneScript()")
350
351 " set options to allow progress to be shown on screen
352 let rega= @a
353 let t_ti= &t_ti
354 let t_te= &t_te
355 let rs = &rs
356 set t_ti= t_te= nors
357
358 " put current line on top-of-screen and interpret it into
Bram Moolenaar6c391a72021-09-09 21:55:11 +0200359 " a script identifier : used to obtain webpage
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000360 " source identifier : used to identify current version
361 " and an associated comment: used to report on what's being considered
362 if a:0 >= 3
363 let scriptid = a:1
364 let srcid = a:2
365 let fname = a:3
366 let cmmnt = ""
367" call Decho("scriptid<".scriptid.">")
368" call Decho("srcid <".srcid.">")
369" call Decho("fname <".fname.">")
370 else
371 let curline = getline(".")
372 if curline =~ '^\s*#'
373 let @a= rega
374" call Dret("GetOneScript : skipping a pure comment line")
375 return
376 endif
377 let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
378 try
379 let scriptid = substitute(curline,parsepat,'\1','e')
380 catch /^Vim\%((\a\+)\)\=:E486/
381 let scriptid= 0
382 endtry
383 try
384 let srcid = substitute(curline,parsepat,'\2','e')
385 catch /^Vim\%((\a\+)\)\=:E486/
386 let srcid= 0
387 endtry
388 try
389 let fname= substitute(curline,parsepat,'\3','e')
390 catch /^Vim\%((\a\+)\)\=:E486/
391 let fname= ""
392 endtry
393 try
394 let cmmnt= substitute(curline,parsepat,'\4','e')
395 catch /^Vim\%((\a\+)\)\=:E486/
396 let cmmnt= ""
397 endtry
398" call Decho("curline <".curline.">")
399" call Decho("parsepat<".parsepat.">")
400" call Decho("scriptid<".scriptid.">")
401" call Decho("srcid <".srcid.">")
402" call Decho("fname <".fname.">")
403 endif
404
Bram Moolenaar5c736222010-01-06 20:54:52 +0100405 " plugin author protection from downloading his/her own scripts atop their latest work
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000406 if scriptid == 0 || srcid == 0
407 " When looking for :AutoInstall: lines, skip scripts that have 0 0 scriptname
408 let @a= rega
409" call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
410 return
411 endif
412
413 let doautoinstall= 0
414 if fname =~ ":AutoInstall:"
415" call Decho("case AutoInstall: fname<".fname.">")
416 let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
417" call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
418 if s:autoinstall != ""
419 let doautoinstall = g:GetLatestVimScripts_allowautoinstall
420 endif
421 else
422 let aicmmnt= fname
423 endif
424" call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
425
426 exe "norm z\<CR>"
427 redraw!
428" call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
429 echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
430
Bram Moolenaar5c736222010-01-06 20:54:52 +0100431 " grab a copy of the plugin's vim.sourceforge.net webpage
Bram Moolenaarff034192013-04-24 18:51:19 +0200432 let scriptaddr = g:GetLatestVimScripts_scriptaddr.scriptid
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000433 let tmpfile = tempname()
434 let v:errmsg = ""
435
436 " make up to three tries at downloading the description
437 let itry= 1
438 while itry <= 3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100439" call Decho(".try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000440 if has("win32") || has("win16") || has("win95")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100441" call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)."|bw!")
442 new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)|bw!
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000443 else
Bram Moolenaar5c736222010-01-06 20:54:52 +0100444" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr))
445 exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000446 endif
447 if itry == 1
448 exe "silent vsplit ".fnameescape(tmpfile)
449 else
450 silent! e %
451 endif
452 setlocal bh=wipe
453
454 " find the latest source-id in the plugin's webpage
455 silent! 1
456 let findpkg= search('Click on the package to download','W')
457 if findpkg > 0
458 break
459 endif
460 let itry= itry + 1
461 endwhile
462" call Decho(" --- end downloading tries while loop --- itry=".itry)
463
464 " testing: did finding "Click on the package..." fail?
465 if findpkg == 0 || itry >= 4
466 silent q!
467 call delete(tmpfile)
468 " restore options
469 let &t_ti = t_ti
470 let &t_te = t_te
471 let &rs = rs
472 let s:downerrors = s:downerrors + 1
473" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
474 echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
475" call Dret("GetOneScript : srch for /Click on the package/ failed")
476 let @a= rega
477 return
478 endif
479" call Decho('found "Click on the package to download"')
480
481 let findsrcid= search('src_id=','W')
482 if findsrcid == 0
483 silent q!
484 call delete(tmpfile)
485 " restore options
486 let &t_ti = t_ti
487 let &t_te = t_te
488 let &rs = rs
489 let s:downerrors = s:downerrors + 1
490" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
491 echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
492 let @a= rega
493" call Dret("GetOneScript : srch for /src_id/ failed")
494 return
495 endif
496" call Decho('found "src_id=" in description page')
497
498 let srcidpat = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
499 let latestsrcid= substitute(getline("."),srcidpat,'\1','')
500 let sname = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
501" call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
502 silent q!
503 call delete(tmpfile)
504
505 " convert the strings-of-numbers into numbers
506 let srcid = srcid + 0
507 let latestsrcid = latestsrcid + 0
508" call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
509
Bram Moolenaar5c736222010-01-06 20:54:52 +0100510 " has the plugin's most-recent srcid increased, which indicates that it has been updated
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000511 if latestsrcid > srcid
512" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
513
514 let s:downloads= s:downloads + 1
515 if sname == bufname("%")
516 " GetLatestVimScript has to be careful about downloading itself
517 let sname= "NEW_".sname
518 endif
519
Bram Moolenaar5c736222010-01-06 20:54:52 +0100520 " -----------------------------------------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000521 " the plugin has been updated since we last obtained it, so download a new copy
Bram Moolenaar5c736222010-01-06 20:54:52 +0100522 " -----------------------------------------------------------------------------
523" call Decho(".downloading new <".sname.">")
524 echomsg ".downloading new <".sname.">"
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000525 if has("win32") || has("win16") || has("win95")
GuyBrush609599c2024-09-08 19:54:43 +0200526" call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)."|q")
527 new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)|q
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000528 else
GuyBrush609599c2024-09-08 19:54:43 +0200529" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr).latestsrcid
530 exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr).latestsrcid
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000531 endif
532
Bram Moolenaar5c736222010-01-06 20:54:52 +0100533 " --------------------------------------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000534 " AutoInstall: only if doautoinstall has been requested by the plugin itself
Bram Moolenaar5c736222010-01-06 20:54:52 +0100535 " --------------------------------------------------------------------------
Bram Moolenaar251e1912011-06-19 05:09:16 +0200536" call Decho("checking if plugin requested autoinstall: doautoinstall=".doautoinstall)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000537 if doautoinstall
Bram Moolenaar5c736222010-01-06 20:54:52 +0100538" call Decho(" ")
539" call Decho("Autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000540 if filereadable(sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100541" call Decho("<".sname."> is readable")
542" call Decho("exe silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall))
543 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200544 let curdir = fnameescape(substitute(getcwd(),'\','/','ge'))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000545 let installdir= curdir."/Installed"
546 if !isdirectory(installdir)
547 call mkdir(installdir)
548 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100549" call Decho("curdir<".curdir."> installdir<".installdir.">")
550" call Decho("exe cd ".fnameescape(s:autoinstall))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000551 exe "cd ".fnameescape(s:autoinstall)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100552
553 " determine target directory for moves
554 let firstdir= substitute(&rtp,',.*$','','')
555 let pname = substitute(sname,'\..*','.vim','')
556" call Decho("determine tgtdir: is <".firstdir.'/AsNeeded/'.pname." readable?")
557 if filereadable(firstdir.'/AsNeeded/'.pname)
558 let tgtdir= "AsNeeded"
559 else
560 let tgtdir= "plugin"
561 endif
562" call Decho("tgtdir<".tgtdir."> pname<".pname.">")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000563
564 " decompress
565 if sname =~ '\.bz2$'
566" call Decho("decompress: attempt to bunzip2 ".sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100567 exe "sil !bunzip2 ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000568 let sname= substitute(sname,'\.bz2$','','')
569" call Decho("decompress: new sname<".sname."> after bunzip2")
570 elseif sname =~ '\.gz$'
571" call Decho("decompress: attempt to gunzip ".sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100572 exe "sil !gunzip ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000573 let sname= substitute(sname,'\.gz$','','')
574" call Decho("decompress: new sname<".sname."> after gunzip")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200575 elseif sname =~ '\.xz$'
576" call Decho("decompress: attempt to unxz ".sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100577 exe "sil !unxz ".shellescape(sname)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200578 let sname= substitute(sname,'\.xz$','','')
579" call Decho("decompress: new sname<".sname."> after unxz")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100580 else
581" call Decho("no decompression needed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000582 endif
583
GuyBrush609599c2024-09-08 19:54:43 +0200584 " distribute archive(.zip, .tar, .vba, .vmb, ...) contents
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000585 if sname =~ '\.zip$'
586" call Decho("dearchive: attempt to unzip ".sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100587 exe "silent !unzip -o ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000588 elseif sname =~ '\.tar$'
589" call Decho("dearchive: attempt to untar ".sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100590 exe "silent !tar -xvf ".shellescape(sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100591 elseif sname =~ '\.tgz$'
592" call Decho("dearchive: attempt to untar+gunzip ".sname)
593 exe "silent !tar -zxvf ".shellescape(sname)
594 elseif sname =~ '\.taz$'
595" call Decho("dearchive: attempt to untar+uncompress ".sname)
596 exe "silent !tar -Zxvf ".shellescape(sname)
597 elseif sname =~ '\.tbz$'
598" call Decho("dearchive: attempt to untar+bunzip2 ".sname)
599 exe "silent !tar -jxvf ".shellescape(sname)
600 elseif sname =~ '\.txz$'
601" call Decho("dearchive: attempt to untar+xz ".sname)
602 exe "silent !tar -Jxvf ".shellescape(sname)
GuyBrush609599c2024-09-08 19:54:43 +0200603 elseif sname =~ '\.vba$\|\.vmb$'
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000604" call Decho("dearchive: attempt to handle a vimball: ".sname)
605 silent 1split
Bram Moolenaar5c736222010-01-06 20:54:52 +0100606 if exists("g:vimball_home")
607 let oldvimballhome= g:vimball_home
608 endif
609 let g:vimball_home= s:autoinstall
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000610 exe "silent e ".fnameescape(sname)
611 silent so %
612 silent q
Bram Moolenaar5c736222010-01-06 20:54:52 +0100613 if exists("oldvimballhome")
614 let g:vimball_home= oldvimballhome
615 else
616 unlet g:vimball_home
617 endif
618 else
619" call Decho("no dearchiving needed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000620 endif
621
Bram Moolenaar5c736222010-01-06 20:54:52 +0100622 " ---------------------------------------------
623 " move plugin to plugin/ or AsNeeded/ directory
624 " ---------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000625 if sname =~ '.vim$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100626" call Decho("dearchive: attempt to simply move ".sname." to ".tgtdir)
627 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".tgtdir
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000628 else
629" call Decho("dearchive: move <".sname."> to installdir<".installdir.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100630 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".installdir
631 endif
632 if tgtdir != "plugin"
633" call Decho("exe silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir)
634 exe "silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000635 endif
636
637 " helptags step
638 let docdir= substitute(&rtp,',.*','','e')."/doc"
639" call Decho("helptags: docdir<".docdir.">")
640 exe "helptags ".fnameescape(docdir)
641 exe "cd ".fnameescape(curdir)
642 endif
643 if fname !~ ':AutoInstall:'
644 let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
645 else
646 let modline=scriptid." ".latestsrcid." ".fname.cmmnt
647 endif
648 else
649 let modline=scriptid." ".latestsrcid." ".fname.cmmnt
650 endif
651
652 " update the data in the <GetLatestVimScripts.dat> file
653 call setline(line("."),modline)
654" call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
655" else " Decho
656" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
657 endif
658
659 " restore options
660 let &t_ti = t_ti
661 let &t_te = t_te
662 let &rs = rs
663 let @a = rega
664" call Dredir("BUFFER TEST (GetOneScript)","ls!")
665
666" call Dret("GetOneScript")
667endfun
668
669" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000670" Restore Options: {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000671let &cpo= s:keepcpo
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000672unlet s:keepcpo
Bram Moolenaar9964e462007-05-05 17:54:07 +0000673
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000674" ---------------------------------------------------------------------
675" Modelines: {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000676" vim: ts=8 sts=2 fdm=marker nowrap