blob: 39060508bff0dcd16cc710e91f67d6f2325b6bbf [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
GuyBrushc854efc2024-09-26 16:14:08 +02006" Version: 37
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
GuyBrushc854efc2024-09-26 16:14:08 +020010" 2024 Sep 08 by Vim Project: several small fixes (#15640)
11" 2024 Sep 23 by Vim Project: runtime dir selection fix (#15722)
12" autoloading search path fix
13" substitution of hardcoded commands with global variables
GuyBrush13a66052024-11-12 20:18:14 +010014" 2024 Nov 12 by Vim Project: fix problems on Windows (#16036)
GuyBrush609599c2024-09-08 19:54:43 +020015" }}}
Bram Moolenaar9964e462007-05-05 17:54:07 +000016"
17" GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
Bram Moolenaar9e368db2007-05-12 13:25:01 +000018"redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar9964e462007-05-05 17:54:07 +000019" ---------------------------------------------------------------------
20" Initialization: {{{1
21" if you're sourcing this file, surely you can't be
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000022" expecting vim to be in its vi-compatible mode!
Bram Moolenaar5c736222010-01-06 20:54:52 +010023if exists("g:loaded_getscript")
24 finish
25endif
GuyBrushc854efc2024-09-26 16:14:08 +020026let g:loaded_getscript= "v37"
Bram Moolenaar9964e462007-05-05 17:54:07 +000027if &cp
28 echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
29 finish
30endif
GuyBrush13a66052024-11-12 20:18:14 +010031if v:version < 901
Bram Moolenaar5c736222010-01-06 20:54:52 +010032 echohl WarningMsg
GuyBrush13a66052024-11-12 20:18:14 +010033 echo "***warning*** this version of GetLatestVimScripts needs vim 9.1"
Bram Moolenaar5c736222010-01-06 20:54:52 +010034 echohl Normal
35 finish
36endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000037let s:keepcpo = &cpo
38set cpo&vim
Bram Moolenaar82038d72007-05-10 17:15:45 +000039"DechoTabOn
Bram Moolenaar9964e462007-05-05 17:54:07 +000040
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000041" ---------------------------
42" Global Variables: {{{1
43" ---------------------------
44" Cygwin Detection ------- {{{2
45if !exists("g:getscript_cygwin")
46 if has("win32") || has("win95") || has("win64") || has("win16")
47 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
48 let g:getscript_cygwin= 1
49 else
50 let g:getscript_cygwin= 0
51 endif
52 else
53 let g:getscript_cygwin= 0
54 endif
55endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000056
57" wget vs curl {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000058if !exists("g:GetLatestVimScripts_wget")
59 if executable("wget")
60 let g:GetLatestVimScripts_wget= "wget"
GuyBrush13a66052024-11-12 20:18:14 +010061 elseif executable("curl.exe")
62 " enforce extension: windows powershell desktop version has a curl alias that hides curl.exe
63 let g:GetLatestVimScripts_wget= "curl.exe"
Bram Moolenaar9964e462007-05-05 17:54:07 +000064 elseif executable("curl")
65 let g:GetLatestVimScripts_wget= "curl"
66 else
67 let g:GetLatestVimScripts_wget = 'echo "GetLatestVimScripts needs wget or curl"'
68 let g:GetLatestVimScripts_options = ""
69 endif
70endif
71
72" options that wget and curl require:
73if !exists("g:GetLatestVimScripts_options")
74 if g:GetLatestVimScripts_wget == "wget"
75 let g:GetLatestVimScripts_options= "-q -O"
GuyBrush13a66052024-11-12 20:18:14 +010076 elseif g:GetLatestVimScripts_wget =~ "curl"
GuyBrush609599c2024-09-08 19:54:43 +020077 let g:GetLatestVimScripts_options= "-s -o"
Bram Moolenaar9964e462007-05-05 17:54:07 +000078 else
79 let g:GetLatestVimScripts_options= ""
80 endif
81endif
82
83" by default, allow autoinstall lines to work
84if !exists("g:GetLatestVimScripts_allowautoinstall")
85 let g:GetLatestVimScripts_allowautoinstall= 1
86endif
87
Bram Moolenaarff034192013-04-24 18:51:19 +020088" set up default scriptaddr address
89if !exists("g:GetLatestVimScripts_scriptaddr")
GuyBrush609599c2024-09-08 19:54:43 +020090 let g:GetLatestVimScripts_scriptaddr = 'https://www.vim.org/scripts/script.php?script_id='
91endif
92
93if !exists("g:GetLatestVimScripts_downloadaddr")
94 let g:GetLatestVimScripts_downloadaddr = 'https://www.vim.org/scripts/download_script.php?src_id='
Bram Moolenaarff034192013-04-24 18:51:19 +020095endif
96
GuyBrushc854efc2024-09-26 16:14:08 +020097" define decompression tools (on windows this allows redirection to wsl or git tools).
98" Note tar is available as builtin since Windows 11.
99if !exists("g:GetLatestVimScripts_bunzip2")
100 let g:GetLatestVimScripts_bunzip2= "bunzip2"
101endif
102
103if !exists("g:GetLatestVimScripts_gunzip")
104 let g:GetLatestVimScripts_gunzip= "gunzip"
105endif
106
107if !exists("g:GetLatestVimScripts_unxz")
108 let g:GetLatestVimScripts_unxz= "unxz"
109endif
110
111if !exists("g:GetLatestVimScripts_unzip")
112 let g:GetLatestVimScripts_unzip= "unzip"
113endif
114
Bram Moolenaar9964e462007-05-05 17:54:07 +0000115"" For debugging:
116"let g:GetLatestVimScripts_wget = "echo"
117"let g:GetLatestVimScripts_options = "options"
118
119" ---------------------------------------------------------------------
120" Check If AutoInstall Capable: {{{1
121let s:autoinstall= ""
122if g:GetLatestVimScripts_allowautoinstall
123
GuyBrushc854efc2024-09-26 16:14:08 +0200124 let s:is_windows = has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")
125 let s:dotvim= s:is_windows ? "vimfiles" : ".vim"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000126
GuyBrushc854efc2024-09-26 16:14:08 +0200127 if !exists("g:GetLatestVimScripts_mv")
GuyBrush13a66052024-11-12 20:18:14 +0100128 if &shell =~? '\<pwsh\>\|\<powershell\>'
129 let g:GetLatestVimScripts_mv= "move -Force"
130 elseif s:is_windows && &shell =~? '\<cmd\>'
GuyBrushc854efc2024-09-26 16:14:08 +0200131 " windows (but not cygwin/bash)
GuyBrush13a66052024-11-12 20:18:14 +0100132 let g:GetLatestVimScripts_mv= "move /Y"
GuyBrushc854efc2024-09-26 16:14:08 +0200133 else
GuyBrush13a66052024-11-12 20:18:14 +0100134 " unix or cygwin bash/zsh
135 " 'mv' overrides existing files without asking
GuyBrushc854efc2024-09-26 16:14:08 +0200136 let g:GetLatestVimScripts_mv= "mv"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000137 endif
138 endif
139
Bram Moolenaar5c736222010-01-06 20:54:52 +0100140 if exists("g:GetLatestVimScripts_autoinstalldir") && isdirectory(g:GetLatestVimScripts_autoinstalldir)
141 let s:autoinstall= g:GetLatestVimScripts_autoinstalldir"
142 elseif exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000143 let s:autoinstall= $HOME."/".s:dotvim
144 endif
145" call Decho("s:autoinstall<".s:autoinstall.">")
146"else "Decho
147" call Decho("g:GetLatestVimScripts_allowautoinstall=".g:GetLatestVimScripts_allowautoinstall.": :AutoInstall: disabled")
148endif
149
150" ---------------------------------------------------------------------
151" Public Interface: {{{1
152com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
153com! -nargs=0 GetScript call getscript#GetLatestVimScripts()
154silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts()
155
156" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000157" GetLatestVimScripts: this function gets the latest versions of {{{1
158" scripts based on the list in
159" (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
160fun! getscript#GetLatestVimScripts()
161" call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">")
162
163" insure that wget is executable
164 if executable(g:GetLatestVimScripts_wget) != 1
165 echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system"
Bram Moolenaar6c391a72021-09-09 21:55:11 +0200166" call Dret("GetLatestVimScripts : wget not executable/available")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000167 return
168 endif
169
170 " Find the .../GetLatest subdirectory under the runtimepath
171 for datadir in split(&rtp,',') + ['']
172 if isdirectory(datadir."/GetLatest")
173" call Decho("found directory<".datadir.">")
174 let datadir= datadir . "/GetLatest"
175 break
176 endif
177 if filereadable(datadir."GetLatestVimScripts.dat")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000178" call Decho("found ".datadir."/GetLatestVimScripts.dat")
179 break
Bram Moolenaar9964e462007-05-05 17:54:07 +0000180 endif
181 endfor
Bram Moolenaar82038d72007-05-10 17:15:45 +0000182
Bram Moolenaar9964e462007-05-05 17:54:07 +0000183 " Sanity checks: readability and writability
184 if datadir == ""
185 echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install'
186" call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory")
187 return
188 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000189 if filewritable(datadir) != 2
190 echoerr "(getLatestVimScripts) Your ".datadir." isn't writable"
191" call Dret("GetLatestVimScripts : non-writable directory<".datadir.">")
192 return
193 endif
194 let datafile= datadir."/GetLatestVimScripts.dat"
195 if !filereadable(datafile)
196 echoerr "Your data file<".datafile."> isn't readable"
197" call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">")
198 return
199 endif
200 if !filewritable(datafile)
201 echoerr "Your data file<".datafile."> isn't writable"
202" call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">")
203 return
204 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100205 " --------------------
206 " Passed sanity checks
207 " --------------------
208
Bram Moolenaar9964e462007-05-05 17:54:07 +0000209" call Decho("datadir <".datadir.">")
210" call Decho("datafile <".datafile.">")
211
Bram Moolenaar5c736222010-01-06 20:54:52 +0100212 " don't let any event handlers interfere (like winmanager's, taglist's, etc)
213 let eikeep = &ei
214 let hlskeep = &hls
215 let acdkeep = &acd
216 set ei=all hls&vim noacd
Bram Moolenaar9964e462007-05-05 17:54:07 +0000217
Bram Moolenaar5c736222010-01-06 20:54:52 +0100218 " Edit the datafile (ie. GetLatestVimScripts.dat):
219 " 1. record current directory (origdir),
220 " 2. change directory to datadir,
221 " 3. split window
222 " 4. edit datafile
Bram Moolenaar9964e462007-05-05 17:54:07 +0000223 let origdir= getcwd()
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000224" call Decho("exe cd ".fnameescape(substitute(datadir,'\','/','ge')))
225 exe "cd ".fnameescape(substitute(datadir,'\','/','ge'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000226 split
Bram Moolenaar5c736222010-01-06 20:54:52 +0100227" call Decho("exe e ".fnameescape(substitute(datafile,'\','/','ge')))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000228 exe "e ".fnameescape(substitute(datafile,'\','/','ge'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000229 res 1000
230 let s:downloads = 0
231 let s:downerrors= 0
232
233 " Check on dependencies mentioned in plugins
234" call Decho(" ")
235" call Decho("searching plugins for GetLatestVimScripts dependencies")
236 let lastline = line("$")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000237" call Decho("lastline#".lastline)
GuyBrushc854efc2024-09-26 16:14:08 +0200238 let firstdir = substitute(&rtp,',.*$','','')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100239 let plugins = split(globpath(firstdir,"plugin/**/*.vim"),'\n')
GuyBrush609599c2024-09-08 19:54:43 +0200240 let plugins += split(globpath(firstdir,"ftplugin/**/*.vim"),'\n')
241 let plugins += split(globpath(firstdir,"AsNeeded/**/*.vim"),'\n')
GuyBrushc854efc2024-09-26 16:14:08 +0200242" extend the search to the packages too (this script predates the feature)
243 let plugins += split(globpath(firstdir,"pack/*/start/*/plugin/**/*.vim"),'\n')
244 let plugins += split(globpath(firstdir,"pack/*/opt/*/plugin/**/*.vim"),'\n')
245 let plugins += split(globpath(firstdir,"pack/*/start/*/ftplugin/**/*.vim"),'\n')
246 let plugins += split(globpath(firstdir,"pack/*/opt/*/ftplugin/**/*.vim"),'\n')
Bram Moolenaar9964e462007-05-05 17:54:07 +0000247 let foundscript = 0
248
Bram Moolenaar5c736222010-01-06 20:54:52 +0100249 " this loop updates the GetLatestVimScripts.dat file
250 " with dependencies explicitly mentioned in the plugins
251 " via GetLatestVimScripts: ... lines
252 " It reads the plugin script at the end of the GetLatestVimScripts.dat
253 " file, examines it, and then removes it.
Bram Moolenaar82038d72007-05-10 17:15:45 +0000254 for plugin in plugins
Bram Moolenaar5c736222010-01-06 20:54:52 +0100255" call Decho(" ")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000256" call Decho("plugin<".plugin.">")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000257
Bram Moolenaar82038d72007-05-10 17:15:45 +0000258 " read plugin in
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000259 " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it
Bram Moolenaar9964e462007-05-05 17:54:07 +0000260 $
261" call Decho(".dependency checking<".plugin."> line$=".line("$"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100262" call Decho("..exe silent r ".fnameescape(plugin))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000263 exe "silent r ".fnameescape(plugin)
264 exe "silent bwipe ".bufnr("#")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000265
Bram Moolenaar9964e462007-05-05 17:54:07 +0000266 while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
Bram Moolenaar5c736222010-01-06 20:54:52 +0100267 let depscript = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
268 let depscriptid = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\(\d\+\)\s\+.*$','\1','')
269 let llp1 = lastline+1
270" call Decho("..depscript<".depscript.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000271
Bram Moolenaar5c736222010-01-06 20:54:52 +0100272 " found a "GetLatestVimScripts: # #" line in the script;
Bram Moolenaar8024f932020-01-14 19:29:13 +0100273 " check if it's already in the datafile by searching backwards from llp1,
Bram Moolenaar5c736222010-01-06 20:54:52 +0100274 " the (prior to reading in the plugin script) last line plus one of the GetLatestVimScripts.dat file,
275 " for the script-id with no wrapping allowed.
276 let curline = line(".")
277 let noai_script = substitute(depscript,'\s*:AutoInstall:\s*','','e')
278 exe llp1
279 let srchline = search('^\s*'.depscriptid.'\s\+\d\+\s\+.*$','bW')
280 if srchline == 0
281 " this second search is taken when, for example, a 0 0 scriptname is to be skipped over
282 let srchline= search('\<'.noai_script.'\>','bW')
Bram Moolenaar82038d72007-05-10 17:15:45 +0000283 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100284" call Decho("..noai_script<".noai_script."> depscriptid#".depscriptid." srchline#".srchline." curline#".line(".")." lastline#".lastline)
285
286 if srchline == 0
287 " found a new script to permanently include in the datafile
288 let keep_rega = @a
289 let @a = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','')
290 echomsg "Appending <".@a."> to ".datafile." for ".depscript
291" call Decho("..Appending <".@a."> to ".datafile." for ".depscript)
292 exe lastline."put a"
293 let @a = keep_rega
294 let lastline = llp1
295 let curline = curline + 1
296 let foundscript = foundscript + 1
297" else " Decho
298" call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")")
299 endif
300
301 let curline = curline + 1
302 exe curline
Bram Moolenaar9964e462007-05-05 17:54:07 +0000303 endwhile
Bram Moolenaar82038d72007-05-10 17:15:45 +0000304
Bram Moolenaar5c736222010-01-06 20:54:52 +0100305 " llp1: last line plus one
Bram Moolenaar9964e462007-05-05 17:54:07 +0000306 let llp1= lastline + 1
307" call Decho(".deleting lines: ".llp1.",$d")
308 exe "silent! ".llp1.",$d"
Bram Moolenaar82038d72007-05-10 17:15:45 +0000309 endfor
310" call Decho("--- end dependency checking loop --- foundscript=".foundscript)
311" call Decho(" ")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000312" call Dredir("BUFFER TEST (GetLatestVimScripts 1)","ls!")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000313
314 if foundscript == 0
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000315 setlocal nomod
Bram Moolenaar9964e462007-05-05 17:54:07 +0000316 endif
317
Bram Moolenaar5c736222010-01-06 20:54:52 +0100318 " --------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000319 " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
Bram Moolenaar5c736222010-01-06 20:54:52 +0100320 " --------------------------------------------------------------------
Bram Moolenaar82038d72007-05-10 17:15:45 +0000321" call Decho("begin: checking out-of-date scripts using datafile<".datafile.">")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000322 setlocal lz
Bram Moolenaar9964e462007-05-05 17:54:07 +0000323 1
Bram Moolenaar82038d72007-05-10 17:15:45 +0000324" /^-----/,$g/^\s*\d/call Decho(getline("."))
325 1
326 /^-----/,$g/^\s*\d/call s:GetOneScript()
327" call Decho("--- end out-of-date checking --- ")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000328
329 " Final report (an echomsg)
330 try
331 silent! ?^-------?
332 catch /^Vim\%((\a\+)\)\=:E114/
333" call Dret("GetLatestVimScripts : nothing done!")
334 return
335 endtry
336 exe "norm! kz\<CR>"
337 redraw!
338 let s:msg = ""
339 if s:downloads == 1
340 let s:msg = "Downloaded one updated script to <".datadir.">"
341 elseif s:downloads == 2
342 let s:msg= "Downloaded two updated scripts to <".datadir.">"
343 elseif s:downloads > 1
344 let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">"
345 else
346 let s:msg= "Everything was already current"
347 endif
348 if s:downerrors > 0
349 let s:msg= s:msg." (".s:downerrors." downloading errors)"
350 endif
351 echomsg s:msg
352 " save the file
353 if &mod
354 silent! w!
355 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200356 q!
Bram Moolenaar9964e462007-05-05 17:54:07 +0000357
358 " restore events and current directory
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000359 exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100360 let &ei = eikeep
361 let &hls = hlskeep
362 let &acd = acdkeep
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000363 setlocal nolz
364" call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000365" call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
366endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +0000367
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000368" ---------------------------------------------------------------------
h-easta4205472024-10-13 19:16:42 +0200369" GetOneScript: (Get Latest Vim script) this function operates {{{1
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000370" on the current line, interpreting two numbers and text as
371" ScriptID, SourceID, and Filename.
Bram Moolenaar5c736222010-01-06 20:54:52 +0100372" It downloads any scripts that have newer versions from vim.sourceforge.net.
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000373fun! s:GetOneScript(...)
374" call Dfunc("GetOneScript()")
375
376 " set options to allow progress to be shown on screen
377 let rega= @a
378 let t_ti= &t_ti
379 let t_te= &t_te
380 let rs = &rs
GuyBrush13a66052024-11-12 20:18:14 +0100381 let ssl = &ssl
382
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000383 set t_ti= t_te= nors
GuyBrush13a66052024-11-12 20:18:14 +0100384 " avoid issues with shellescape() on Windows
385 if s:is_windows && &shell =~? '\<cmd\>'
386 set noshellslash
387 endif
388
389 " restore valures afterwards
390 defer execute("let @a = rega | let &t_ti = t_ti | let &t_te = t_te | let &rs = rs | let &ssl = ssl")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000391
392 " put current line on top-of-screen and interpret it into
Bram Moolenaar6c391a72021-09-09 21:55:11 +0200393 " a script identifier : used to obtain webpage
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000394 " source identifier : used to identify current version
395 " and an associated comment: used to report on what's being considered
396 if a:0 >= 3
397 let scriptid = a:1
398 let srcid = a:2
399 let fname = a:3
400 let cmmnt = ""
401" call Decho("scriptid<".scriptid.">")
402" call Decho("srcid <".srcid.">")
403" call Decho("fname <".fname.">")
404 else
405 let curline = getline(".")
406 if curline =~ '^\s*#'
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000407" call Dret("GetOneScript : skipping a pure comment line")
408 return
409 endif
410 let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
411 try
412 let scriptid = substitute(curline,parsepat,'\1','e')
413 catch /^Vim\%((\a\+)\)\=:E486/
414 let scriptid= 0
415 endtry
416 try
417 let srcid = substitute(curline,parsepat,'\2','e')
418 catch /^Vim\%((\a\+)\)\=:E486/
419 let srcid= 0
420 endtry
421 try
422 let fname= substitute(curline,parsepat,'\3','e')
423 catch /^Vim\%((\a\+)\)\=:E486/
424 let fname= ""
425 endtry
426 try
427 let cmmnt= substitute(curline,parsepat,'\4','e')
428 catch /^Vim\%((\a\+)\)\=:E486/
429 let cmmnt= ""
430 endtry
431" call Decho("curline <".curline.">")
432" call Decho("parsepat<".parsepat.">")
433" call Decho("scriptid<".scriptid.">")
434" call Decho("srcid <".srcid.">")
435" call Decho("fname <".fname.">")
436 endif
437
Bram Moolenaar5c736222010-01-06 20:54:52 +0100438 " plugin author protection from downloading his/her own scripts atop their latest work
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000439 if scriptid == 0 || srcid == 0
440 " When looking for :AutoInstall: lines, skip scripts that have 0 0 scriptname
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000441" call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
442 return
443 endif
444
445 let doautoinstall= 0
446 if fname =~ ":AutoInstall:"
447" call Decho("case AutoInstall: fname<".fname.">")
448 let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
449" call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
450 if s:autoinstall != ""
451 let doautoinstall = g:GetLatestVimScripts_allowautoinstall
452 endif
453 else
454 let aicmmnt= fname
455 endif
456" call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
457
458 exe "norm z\<CR>"
459 redraw!
460" call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
461 echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
462
Bram Moolenaar5c736222010-01-06 20:54:52 +0100463 " grab a copy of the plugin's vim.sourceforge.net webpage
Bram Moolenaarff034192013-04-24 18:51:19 +0200464 let scriptaddr = g:GetLatestVimScripts_scriptaddr.scriptid
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000465 let tmpfile = tempname()
466 let v:errmsg = ""
467
468 " make up to three tries at downloading the description
469 let itry= 1
470 while itry <= 3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100471" call Decho(".try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000472 if has("win32") || has("win16") || has("win95")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100473" call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)."|bw!")
474 new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)|bw!
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000475 else
Bram Moolenaar5c736222010-01-06 20:54:52 +0100476" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr))
477 exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000478 endif
479 if itry == 1
480 exe "silent vsplit ".fnameescape(tmpfile)
481 else
482 silent! e %
483 endif
484 setlocal bh=wipe
485
486 " find the latest source-id in the plugin's webpage
487 silent! 1
488 let findpkg= search('Click on the package to download','W')
489 if findpkg > 0
490 break
491 endif
492 let itry= itry + 1
493 endwhile
494" call Decho(" --- end downloading tries while loop --- itry=".itry)
495
496 " testing: did finding "Click on the package..." fail?
497 if findpkg == 0 || itry >= 4
498 silent q!
499 call delete(tmpfile)
500 " restore options
501 let &t_ti = t_ti
502 let &t_te = t_te
503 let &rs = rs
504 let s:downerrors = s:downerrors + 1
505" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
506 echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
507" call Dret("GetOneScript : srch for /Click on the package/ failed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000508 return
509 endif
510" call Decho('found "Click on the package to download"')
511
512 let findsrcid= search('src_id=','W')
513 if findsrcid == 0
514 silent q!
515 call delete(tmpfile)
516 " restore options
517 let &t_ti = t_ti
518 let &t_te = t_te
519 let &rs = rs
520 let s:downerrors = s:downerrors + 1
521" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
522 echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000523" call Dret("GetOneScript : srch for /src_id/ failed")
524 return
525 endif
526" call Decho('found "src_id=" in description page')
527
528 let srcidpat = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
529 let latestsrcid= substitute(getline("."),srcidpat,'\1','')
530 let sname = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
531" call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
532 silent q!
533 call delete(tmpfile)
534
535 " convert the strings-of-numbers into numbers
536 let srcid = srcid + 0
537 let latestsrcid = latestsrcid + 0
538" call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
539
Bram Moolenaar5c736222010-01-06 20:54:52 +0100540 " has the plugin's most-recent srcid increased, which indicates that it has been updated
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000541 if latestsrcid > srcid
542" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
543
544 let s:downloads= s:downloads + 1
545 if sname == bufname("%")
546 " GetLatestVimScript has to be careful about downloading itself
547 let sname= "NEW_".sname
548 endif
549
Bram Moolenaar5c736222010-01-06 20:54:52 +0100550 " -----------------------------------------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000551 " the plugin has been updated since we last obtained it, so download a new copy
Bram Moolenaar5c736222010-01-06 20:54:52 +0100552 " -----------------------------------------------------------------------------
553" call Decho(".downloading new <".sname.">")
554 echomsg ".downloading new <".sname.">"
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000555 if has("win32") || has("win16") || has("win95")
GuyBrush13a66052024-11-12 20:18:14 +0100556" call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)."|bw!")
557 new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)|bw!
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000558 else
GuyBrush13a66052024-11-12 20:18:14 +0100559" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)
560 exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000561 endif
562
Bram Moolenaar5c736222010-01-06 20:54:52 +0100563 " --------------------------------------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000564 " AutoInstall: only if doautoinstall has been requested by the plugin itself
Bram Moolenaar5c736222010-01-06 20:54:52 +0100565 " --------------------------------------------------------------------------
Bram Moolenaar251e1912011-06-19 05:09:16 +0200566" call Decho("checking if plugin requested autoinstall: doautoinstall=".doautoinstall)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000567 if doautoinstall
Bram Moolenaar5c736222010-01-06 20:54:52 +0100568" call Decho(" ")
569" call Decho("Autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000570 if filereadable(sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100571" call Decho("<".sname."> is readable")
572" call Decho("exe silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall))
573 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200574 let curdir = fnameescape(substitute(getcwd(),'\','/','ge'))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000575 let installdir= curdir."/Installed"
576 if !isdirectory(installdir)
577 call mkdir(installdir)
578 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100579" call Decho("curdir<".curdir."> installdir<".installdir.">")
580" call Decho("exe cd ".fnameescape(s:autoinstall))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000581 exe "cd ".fnameescape(s:autoinstall)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100582
583 " determine target directory for moves
584 let firstdir= substitute(&rtp,',.*$','','')
585 let pname = substitute(sname,'\..*','.vim','')
586" call Decho("determine tgtdir: is <".firstdir.'/AsNeeded/'.pname." readable?")
587 if filereadable(firstdir.'/AsNeeded/'.pname)
588 let tgtdir= "AsNeeded"
589 else
590 let tgtdir= "plugin"
591 endif
592" call Decho("tgtdir<".tgtdir."> pname<".pname.">")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000593
594 " decompress
595 if sname =~ '\.bz2$'
596" call Decho("decompress: attempt to bunzip2 ".sname)
GuyBrushc854efc2024-09-26 16:14:08 +0200597 exe "sil !".g:GetLatestVimScripts_bunzip2." ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000598 let sname= substitute(sname,'\.bz2$','','')
599" call Decho("decompress: new sname<".sname."> after bunzip2")
600 elseif sname =~ '\.gz$'
601" call Decho("decompress: attempt to gunzip ".sname)
GuyBrushc854efc2024-09-26 16:14:08 +0200602 exe "sil !".g:GetLatestVimScripts_gunzip." ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000603 let sname= substitute(sname,'\.gz$','','')
604" call Decho("decompress: new sname<".sname."> after gunzip")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200605 elseif sname =~ '\.xz$'
606" call Decho("decompress: attempt to unxz ".sname)
GuyBrushc854efc2024-09-26 16:14:08 +0200607 exe "sil !".g:GetLatestVimScripts_unxz." ".shellescape(sname)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200608 let sname= substitute(sname,'\.xz$','','')
609" call Decho("decompress: new sname<".sname."> after unxz")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100610 else
611" call Decho("no decompression needed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000612 endif
613
GuyBrush609599c2024-09-08 19:54:43 +0200614 " distribute archive(.zip, .tar, .vba, .vmb, ...) contents
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000615 if sname =~ '\.zip$'
616" call Decho("dearchive: attempt to unzip ".sname)
GuyBrushc854efc2024-09-26 16:14:08 +0200617 exe "silent !".g:GetLatestVimScripts_unzip." -o ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000618 elseif sname =~ '\.tar$'
619" call Decho("dearchive: attempt to untar ".sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100620 exe "silent !tar -xvf ".shellescape(sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100621 elseif sname =~ '\.tgz$'
622" call Decho("dearchive: attempt to untar+gunzip ".sname)
623 exe "silent !tar -zxvf ".shellescape(sname)
624 elseif sname =~ '\.taz$'
625" call Decho("dearchive: attempt to untar+uncompress ".sname)
626 exe "silent !tar -Zxvf ".shellescape(sname)
627 elseif sname =~ '\.tbz$'
628" call Decho("dearchive: attempt to untar+bunzip2 ".sname)
629 exe "silent !tar -jxvf ".shellescape(sname)
630 elseif sname =~ '\.txz$'
631" call Decho("dearchive: attempt to untar+xz ".sname)
632 exe "silent !tar -Jxvf ".shellescape(sname)
GuyBrush609599c2024-09-08 19:54:43 +0200633 elseif sname =~ '\.vba$\|\.vmb$'
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000634" call Decho("dearchive: attempt to handle a vimball: ".sname)
635 silent 1split
Bram Moolenaar5c736222010-01-06 20:54:52 +0100636 if exists("g:vimball_home")
637 let oldvimballhome= g:vimball_home
638 endif
639 let g:vimball_home= s:autoinstall
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000640 exe "silent e ".fnameescape(sname)
641 silent so %
642 silent q
Bram Moolenaar5c736222010-01-06 20:54:52 +0100643 if exists("oldvimballhome")
644 let g:vimball_home= oldvimballhome
645 else
646 unlet g:vimball_home
647 endif
648 else
649" call Decho("no dearchiving needed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000650 endif
651
Bram Moolenaar5c736222010-01-06 20:54:52 +0100652 " ---------------------------------------------
653 " move plugin to plugin/ or AsNeeded/ directory
654 " ---------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000655 if sname =~ '.vim$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100656" call Decho("dearchive: attempt to simply move ".sname." to ".tgtdir)
657 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".tgtdir
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000658 else
659" call Decho("dearchive: move <".sname."> to installdir<".installdir.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100660 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".installdir
661 endif
662 if tgtdir != "plugin"
GuyBrush13a66052024-11-12 20:18:14 +0100663" call Decho("exe silent !".g:GetLatestVimScripts_mv." ".shellescape("plugin/".pname)." ".tgtdir)
664 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape("plugin/".pname)." ".tgtdir
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000665 endif
666
667 " helptags step
668 let docdir= substitute(&rtp,',.*','','e')."/doc"
669" call Decho("helptags: docdir<".docdir.">")
670 exe "helptags ".fnameescape(docdir)
671 exe "cd ".fnameescape(curdir)
672 endif
673 if fname !~ ':AutoInstall:'
674 let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
675 else
676 let modline=scriptid." ".latestsrcid." ".fname.cmmnt
677 endif
678 else
679 let modline=scriptid." ".latestsrcid." ".fname.cmmnt
680 endif
681
682 " update the data in the <GetLatestVimScripts.dat> file
683 call setline(line("."),modline)
684" call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
685" else " Decho
686" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
687 endif
688
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000689" call Dredir("BUFFER TEST (GetOneScript)","ls!")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000690" call Dret("GetOneScript")
691endfun
692
693" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000694" Restore Options: {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000695let &cpo= s:keepcpo
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000696unlet s:keepcpo
Bram Moolenaar9964e462007-05-05 17:54:07 +0000697
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000698" ---------------------------------------------------------------------
699" Modelines: {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000700" vim: ts=8 sts=2 fdm=marker nowrap