blob: e599d1ed95d5a448c5309fe6f089b7f7a79ca561 [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)
Jim Zhou56957ed2025-02-28 18:06:14 +010015" 2025 Feb 28 by Vim Project: add support for bzip3 (#16755)
GuyBrush609599c2024-09-08 19:54:43 +020016" }}}
Bram Moolenaar9964e462007-05-05 17:54:07 +000017"
18" GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
Bram Moolenaar9e368db2007-05-12 13:25:01 +000019"redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar9964e462007-05-05 17:54:07 +000020" ---------------------------------------------------------------------
21" Initialization: {{{1
22" if you're sourcing this file, surely you can't be
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000023" expecting vim to be in its vi-compatible mode!
Bram Moolenaar5c736222010-01-06 20:54:52 +010024if exists("g:loaded_getscript")
25 finish
26endif
GuyBrushc854efc2024-09-26 16:14:08 +020027let g:loaded_getscript= "v37"
Bram Moolenaar9964e462007-05-05 17:54:07 +000028if &cp
29 echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
30 finish
31endif
GuyBrush13a66052024-11-12 20:18:14 +010032if v:version < 901
Bram Moolenaar5c736222010-01-06 20:54:52 +010033 echohl WarningMsg
GuyBrush13a66052024-11-12 20:18:14 +010034 echo "***warning*** this version of GetLatestVimScripts needs vim 9.1"
Bram Moolenaar5c736222010-01-06 20:54:52 +010035 echohl Normal
36 finish
37endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000038let s:keepcpo = &cpo
39set cpo&vim
Bram Moolenaar82038d72007-05-10 17:15:45 +000040"DechoTabOn
Bram Moolenaar9964e462007-05-05 17:54:07 +000041
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000042" ---------------------------
43" Global Variables: {{{1
44" ---------------------------
45" Cygwin Detection ------- {{{2
46if !exists("g:getscript_cygwin")
47 if has("win32") || has("win95") || has("win64") || has("win16")
48 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
49 let g:getscript_cygwin= 1
50 else
51 let g:getscript_cygwin= 0
52 endif
53 else
54 let g:getscript_cygwin= 0
55 endif
56endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000057
58" wget vs curl {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000059if !exists("g:GetLatestVimScripts_wget")
60 if executable("wget")
61 let g:GetLatestVimScripts_wget= "wget"
GuyBrush13a66052024-11-12 20:18:14 +010062 elseif executable("curl.exe")
63 " enforce extension: windows powershell desktop version has a curl alias that hides curl.exe
64 let g:GetLatestVimScripts_wget= "curl.exe"
Bram Moolenaar9964e462007-05-05 17:54:07 +000065 elseif executable("curl")
66 let g:GetLatestVimScripts_wget= "curl"
67 else
68 let g:GetLatestVimScripts_wget = 'echo "GetLatestVimScripts needs wget or curl"'
69 let g:GetLatestVimScripts_options = ""
70 endif
71endif
72
73" options that wget and curl require:
74if !exists("g:GetLatestVimScripts_options")
75 if g:GetLatestVimScripts_wget == "wget"
76 let g:GetLatestVimScripts_options= "-q -O"
GuyBrush13a66052024-11-12 20:18:14 +010077 elseif g:GetLatestVimScripts_wget =~ "curl"
GuyBrush609599c2024-09-08 19:54:43 +020078 let g:GetLatestVimScripts_options= "-s -o"
Bram Moolenaar9964e462007-05-05 17:54:07 +000079 else
80 let g:GetLatestVimScripts_options= ""
81 endif
82endif
83
84" by default, allow autoinstall lines to work
85if !exists("g:GetLatestVimScripts_allowautoinstall")
86 let g:GetLatestVimScripts_allowautoinstall= 1
87endif
88
Bram Moolenaarff034192013-04-24 18:51:19 +020089" set up default scriptaddr address
90if !exists("g:GetLatestVimScripts_scriptaddr")
GuyBrush609599c2024-09-08 19:54:43 +020091 let g:GetLatestVimScripts_scriptaddr = 'https://www.vim.org/scripts/script.php?script_id='
92endif
93
94if !exists("g:GetLatestVimScripts_downloadaddr")
95 let g:GetLatestVimScripts_downloadaddr = 'https://www.vim.org/scripts/download_script.php?src_id='
Bram Moolenaarff034192013-04-24 18:51:19 +020096endif
97
GuyBrushc854efc2024-09-26 16:14:08 +020098" define decompression tools (on windows this allows redirection to wsl or git tools).
99" Note tar is available as builtin since Windows 11.
100if !exists("g:GetLatestVimScripts_bunzip2")
101 let g:GetLatestVimScripts_bunzip2= "bunzip2"
102endif
103
Jim Zhou56957ed2025-02-28 18:06:14 +0100104if !exists("g:GetLatestVimScripts_bunzip3")
105 let g:GetLatestVimScripts_bunzip3= "bunzip3"
106endif
107
GuyBrushc854efc2024-09-26 16:14:08 +0200108if !exists("g:GetLatestVimScripts_gunzip")
109 let g:GetLatestVimScripts_gunzip= "gunzip"
110endif
111
112if !exists("g:GetLatestVimScripts_unxz")
113 let g:GetLatestVimScripts_unxz= "unxz"
114endif
115
116if !exists("g:GetLatestVimScripts_unzip")
117 let g:GetLatestVimScripts_unzip= "unzip"
118endif
119
Bram Moolenaar9964e462007-05-05 17:54:07 +0000120"" For debugging:
121"let g:GetLatestVimScripts_wget = "echo"
122"let g:GetLatestVimScripts_options = "options"
123
124" ---------------------------------------------------------------------
125" Check If AutoInstall Capable: {{{1
126let s:autoinstall= ""
127if g:GetLatestVimScripts_allowautoinstall
128
GuyBrushc854efc2024-09-26 16:14:08 +0200129 let s:is_windows = has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")
130 let s:dotvim= s:is_windows ? "vimfiles" : ".vim"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000131
GuyBrushc854efc2024-09-26 16:14:08 +0200132 if !exists("g:GetLatestVimScripts_mv")
GuyBrush13a66052024-11-12 20:18:14 +0100133 if &shell =~? '\<pwsh\>\|\<powershell\>'
134 let g:GetLatestVimScripts_mv= "move -Force"
135 elseif s:is_windows && &shell =~? '\<cmd\>'
GuyBrushc854efc2024-09-26 16:14:08 +0200136 " windows (but not cygwin/bash)
GuyBrush13a66052024-11-12 20:18:14 +0100137 let g:GetLatestVimScripts_mv= "move /Y"
GuyBrushc854efc2024-09-26 16:14:08 +0200138 else
GuyBrush13a66052024-11-12 20:18:14 +0100139 " unix or cygwin bash/zsh
140 " 'mv' overrides existing files without asking
GuyBrushc854efc2024-09-26 16:14:08 +0200141 let g:GetLatestVimScripts_mv= "mv"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000142 endif
143 endif
144
Bram Moolenaar5c736222010-01-06 20:54:52 +0100145 if exists("g:GetLatestVimScripts_autoinstalldir") && isdirectory(g:GetLatestVimScripts_autoinstalldir)
146 let s:autoinstall= g:GetLatestVimScripts_autoinstalldir"
147 elseif exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000148 let s:autoinstall= $HOME."/".s:dotvim
149 endif
150" call Decho("s:autoinstall<".s:autoinstall.">")
151"else "Decho
152" call Decho("g:GetLatestVimScripts_allowautoinstall=".g:GetLatestVimScripts_allowautoinstall.": :AutoInstall: disabled")
153endif
154
155" ---------------------------------------------------------------------
156" Public Interface: {{{1
157com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
158com! -nargs=0 GetScript call getscript#GetLatestVimScripts()
159silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts()
160
161" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000162" GetLatestVimScripts: this function gets the latest versions of {{{1
163" scripts based on the list in
164" (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
165fun! getscript#GetLatestVimScripts()
166" call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">")
167
168" insure that wget is executable
169 if executable(g:GetLatestVimScripts_wget) != 1
170 echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system"
Bram Moolenaar6c391a72021-09-09 21:55:11 +0200171" call Dret("GetLatestVimScripts : wget not executable/available")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000172 return
173 endif
174
175 " Find the .../GetLatest subdirectory under the runtimepath
176 for datadir in split(&rtp,',') + ['']
177 if isdirectory(datadir."/GetLatest")
178" call Decho("found directory<".datadir.">")
179 let datadir= datadir . "/GetLatest"
180 break
181 endif
182 if filereadable(datadir."GetLatestVimScripts.dat")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000183" call Decho("found ".datadir."/GetLatestVimScripts.dat")
184 break
Bram Moolenaar9964e462007-05-05 17:54:07 +0000185 endif
186 endfor
Bram Moolenaar82038d72007-05-10 17:15:45 +0000187
Bram Moolenaar9964e462007-05-05 17:54:07 +0000188 " Sanity checks: readability and writability
189 if datadir == ""
190 echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install'
191" call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory")
192 return
193 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000194 if filewritable(datadir) != 2
195 echoerr "(getLatestVimScripts) Your ".datadir." isn't writable"
196" call Dret("GetLatestVimScripts : non-writable directory<".datadir.">")
197 return
198 endif
199 let datafile= datadir."/GetLatestVimScripts.dat"
200 if !filereadable(datafile)
201 echoerr "Your data file<".datafile."> isn't readable"
202" call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">")
203 return
204 endif
205 if !filewritable(datafile)
206 echoerr "Your data file<".datafile."> isn't writable"
207" call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">")
208 return
209 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100210 " --------------------
211 " Passed sanity checks
212 " --------------------
213
Bram Moolenaar9964e462007-05-05 17:54:07 +0000214" call Decho("datadir <".datadir.">")
215" call Decho("datafile <".datafile.">")
216
Bram Moolenaar5c736222010-01-06 20:54:52 +0100217 " don't let any event handlers interfere (like winmanager's, taglist's, etc)
218 let eikeep = &ei
219 let hlskeep = &hls
220 let acdkeep = &acd
221 set ei=all hls&vim noacd
Bram Moolenaar9964e462007-05-05 17:54:07 +0000222
Bram Moolenaar5c736222010-01-06 20:54:52 +0100223 " Edit the datafile (ie. GetLatestVimScripts.dat):
224 " 1. record current directory (origdir),
225 " 2. change directory to datadir,
226 " 3. split window
227 " 4. edit datafile
Bram Moolenaar9964e462007-05-05 17:54:07 +0000228 let origdir= getcwd()
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000229" call Decho("exe cd ".fnameescape(substitute(datadir,'\','/','ge')))
230 exe "cd ".fnameescape(substitute(datadir,'\','/','ge'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000231 split
Bram Moolenaar5c736222010-01-06 20:54:52 +0100232" call Decho("exe e ".fnameescape(substitute(datafile,'\','/','ge')))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000233 exe "e ".fnameescape(substitute(datafile,'\','/','ge'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000234 res 1000
235 let s:downloads = 0
236 let s:downerrors= 0
237
238 " Check on dependencies mentioned in plugins
239" call Decho(" ")
240" call Decho("searching plugins for GetLatestVimScripts dependencies")
241 let lastline = line("$")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000242" call Decho("lastline#".lastline)
GuyBrushc854efc2024-09-26 16:14:08 +0200243 let firstdir = substitute(&rtp,',.*$','','')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100244 let plugins = split(globpath(firstdir,"plugin/**/*.vim"),'\n')
GuyBrush609599c2024-09-08 19:54:43 +0200245 let plugins += split(globpath(firstdir,"ftplugin/**/*.vim"),'\n')
246 let plugins += split(globpath(firstdir,"AsNeeded/**/*.vim"),'\n')
GuyBrushc854efc2024-09-26 16:14:08 +0200247" extend the search to the packages too (this script predates the feature)
248 let plugins += split(globpath(firstdir,"pack/*/start/*/plugin/**/*.vim"),'\n')
249 let plugins += split(globpath(firstdir,"pack/*/opt/*/plugin/**/*.vim"),'\n')
250 let plugins += split(globpath(firstdir,"pack/*/start/*/ftplugin/**/*.vim"),'\n')
251 let plugins += split(globpath(firstdir,"pack/*/opt/*/ftplugin/**/*.vim"),'\n')
Bram Moolenaar9964e462007-05-05 17:54:07 +0000252 let foundscript = 0
253
Bram Moolenaar5c736222010-01-06 20:54:52 +0100254 " this loop updates the GetLatestVimScripts.dat file
255 " with dependencies explicitly mentioned in the plugins
256 " via GetLatestVimScripts: ... lines
257 " It reads the plugin script at the end of the GetLatestVimScripts.dat
258 " file, examines it, and then removes it.
Bram Moolenaar82038d72007-05-10 17:15:45 +0000259 for plugin in plugins
Bram Moolenaar5c736222010-01-06 20:54:52 +0100260" call Decho(" ")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000261" call Decho("plugin<".plugin.">")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000262
Bram Moolenaar82038d72007-05-10 17:15:45 +0000263 " read plugin in
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000264 " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it
Bram Moolenaar9964e462007-05-05 17:54:07 +0000265 $
266" call Decho(".dependency checking<".plugin."> line$=".line("$"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100267" call Decho("..exe silent r ".fnameescape(plugin))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000268 exe "silent r ".fnameescape(plugin)
269 exe "silent bwipe ".bufnr("#")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000270
Bram Moolenaar9964e462007-05-05 17:54:07 +0000271 while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
Bram Moolenaar5c736222010-01-06 20:54:52 +0100272 let depscript = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
273 let depscriptid = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\(\d\+\)\s\+.*$','\1','')
274 let llp1 = lastline+1
275" call Decho("..depscript<".depscript.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000276
Bram Moolenaar5c736222010-01-06 20:54:52 +0100277 " found a "GetLatestVimScripts: # #" line in the script;
Bram Moolenaar8024f932020-01-14 19:29:13 +0100278 " check if it's already in the datafile by searching backwards from llp1,
Bram Moolenaar5c736222010-01-06 20:54:52 +0100279 " the (prior to reading in the plugin script) last line plus one of the GetLatestVimScripts.dat file,
280 " for the script-id with no wrapping allowed.
281 let curline = line(".")
282 let noai_script = substitute(depscript,'\s*:AutoInstall:\s*','','e')
283 exe llp1
284 let srchline = search('^\s*'.depscriptid.'\s\+\d\+\s\+.*$','bW')
285 if srchline == 0
286 " this second search is taken when, for example, a 0 0 scriptname is to be skipped over
287 let srchline= search('\<'.noai_script.'\>','bW')
Bram Moolenaar82038d72007-05-10 17:15:45 +0000288 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100289" call Decho("..noai_script<".noai_script."> depscriptid#".depscriptid." srchline#".srchline." curline#".line(".")." lastline#".lastline)
290
291 if srchline == 0
292 " found a new script to permanently include in the datafile
293 let keep_rega = @a
294 let @a = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','')
295 echomsg "Appending <".@a."> to ".datafile." for ".depscript
296" call Decho("..Appending <".@a."> to ".datafile." for ".depscript)
297 exe lastline."put a"
298 let @a = keep_rega
299 let lastline = llp1
300 let curline = curline + 1
301 let foundscript = foundscript + 1
302" else " Decho
303" call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")")
304 endif
305
306 let curline = curline + 1
307 exe curline
Bram Moolenaar9964e462007-05-05 17:54:07 +0000308 endwhile
Bram Moolenaar82038d72007-05-10 17:15:45 +0000309
Bram Moolenaar5c736222010-01-06 20:54:52 +0100310 " llp1: last line plus one
Bram Moolenaar9964e462007-05-05 17:54:07 +0000311 let llp1= lastline + 1
312" call Decho(".deleting lines: ".llp1.",$d")
313 exe "silent! ".llp1.",$d"
Bram Moolenaar82038d72007-05-10 17:15:45 +0000314 endfor
315" call Decho("--- end dependency checking loop --- foundscript=".foundscript)
316" call Decho(" ")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000317" call Dredir("BUFFER TEST (GetLatestVimScripts 1)","ls!")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000318
319 if foundscript == 0
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000320 setlocal nomod
Bram Moolenaar9964e462007-05-05 17:54:07 +0000321 endif
322
Bram Moolenaar5c736222010-01-06 20:54:52 +0100323 " --------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000324 " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
Bram Moolenaar5c736222010-01-06 20:54:52 +0100325 " --------------------------------------------------------------------
Bram Moolenaar82038d72007-05-10 17:15:45 +0000326" call Decho("begin: checking out-of-date scripts using datafile<".datafile.">")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000327 setlocal lz
Bram Moolenaar9964e462007-05-05 17:54:07 +0000328 1
Bram Moolenaar82038d72007-05-10 17:15:45 +0000329" /^-----/,$g/^\s*\d/call Decho(getline("."))
330 1
331 /^-----/,$g/^\s*\d/call s:GetOneScript()
332" call Decho("--- end out-of-date checking --- ")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000333
334 " Final report (an echomsg)
335 try
336 silent! ?^-------?
337 catch /^Vim\%((\a\+)\)\=:E114/
338" call Dret("GetLatestVimScripts : nothing done!")
339 return
340 endtry
341 exe "norm! kz\<CR>"
342 redraw!
343 let s:msg = ""
344 if s:downloads == 1
345 let s:msg = "Downloaded one updated script to <".datadir.">"
346 elseif s:downloads == 2
347 let s:msg= "Downloaded two updated scripts to <".datadir.">"
348 elseif s:downloads > 1
349 let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">"
350 else
351 let s:msg= "Everything was already current"
352 endif
353 if s:downerrors > 0
354 let s:msg= s:msg." (".s:downerrors." downloading errors)"
355 endif
356 echomsg s:msg
357 " save the file
358 if &mod
359 silent! w!
360 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200361 q!
Bram Moolenaar9964e462007-05-05 17:54:07 +0000362
363 " restore events and current directory
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000364 exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100365 let &ei = eikeep
366 let &hls = hlskeep
367 let &acd = acdkeep
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000368 setlocal nolz
369" call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000370" call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
371endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +0000372
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000373" ---------------------------------------------------------------------
h-easta4205472024-10-13 19:16:42 +0200374" GetOneScript: (Get Latest Vim script) this function operates {{{1
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000375" on the current line, interpreting two numbers and text as
376" ScriptID, SourceID, and Filename.
Bram Moolenaar5c736222010-01-06 20:54:52 +0100377" It downloads any scripts that have newer versions from vim.sourceforge.net.
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000378fun! s:GetOneScript(...)
379" call Dfunc("GetOneScript()")
380
381 " set options to allow progress to be shown on screen
382 let rega= @a
383 let t_ti= &t_ti
384 let t_te= &t_te
385 let rs = &rs
GuyBrush13a66052024-11-12 20:18:14 +0100386 let ssl = &ssl
387
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000388 set t_ti= t_te= nors
GuyBrush13a66052024-11-12 20:18:14 +0100389 " avoid issues with shellescape() on Windows
390 if s:is_windows && &shell =~? '\<cmd\>'
391 set noshellslash
392 endif
393
394 " restore valures afterwards
395 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 +0000396
397 " put current line on top-of-screen and interpret it into
Bram Moolenaar6c391a72021-09-09 21:55:11 +0200398 " a script identifier : used to obtain webpage
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000399 " source identifier : used to identify current version
400 " and an associated comment: used to report on what's being considered
401 if a:0 >= 3
402 let scriptid = a:1
403 let srcid = a:2
404 let fname = a:3
405 let cmmnt = ""
406" call Decho("scriptid<".scriptid.">")
407" call Decho("srcid <".srcid.">")
408" call Decho("fname <".fname.">")
409 else
410 let curline = getline(".")
411 if curline =~ '^\s*#'
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000412" call Dret("GetOneScript : skipping a pure comment line")
413 return
414 endif
415 let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
416 try
417 let scriptid = substitute(curline,parsepat,'\1','e')
418 catch /^Vim\%((\a\+)\)\=:E486/
419 let scriptid= 0
420 endtry
421 try
422 let srcid = substitute(curline,parsepat,'\2','e')
423 catch /^Vim\%((\a\+)\)\=:E486/
424 let srcid= 0
425 endtry
426 try
427 let fname= substitute(curline,parsepat,'\3','e')
428 catch /^Vim\%((\a\+)\)\=:E486/
429 let fname= ""
430 endtry
431 try
432 let cmmnt= substitute(curline,parsepat,'\4','e')
433 catch /^Vim\%((\a\+)\)\=:E486/
434 let cmmnt= ""
435 endtry
436" call Decho("curline <".curline.">")
437" call Decho("parsepat<".parsepat.">")
438" call Decho("scriptid<".scriptid.">")
439" call Decho("srcid <".srcid.">")
440" call Decho("fname <".fname.">")
441 endif
442
Bram Moolenaar5c736222010-01-06 20:54:52 +0100443 " plugin author protection from downloading his/her own scripts atop their latest work
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000444 if scriptid == 0 || srcid == 0
445 " When looking for :AutoInstall: lines, skip scripts that have 0 0 scriptname
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000446" call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
447 return
448 endif
449
450 let doautoinstall= 0
451 if fname =~ ":AutoInstall:"
452" call Decho("case AutoInstall: fname<".fname.">")
453 let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
454" call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
455 if s:autoinstall != ""
456 let doautoinstall = g:GetLatestVimScripts_allowautoinstall
457 endif
458 else
459 let aicmmnt= fname
460 endif
461" call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
462
463 exe "norm z\<CR>"
464 redraw!
465" call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
466 echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
467
Bram Moolenaar5c736222010-01-06 20:54:52 +0100468 " grab a copy of the plugin's vim.sourceforge.net webpage
Bram Moolenaarff034192013-04-24 18:51:19 +0200469 let scriptaddr = g:GetLatestVimScripts_scriptaddr.scriptid
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000470 let tmpfile = tempname()
471 let v:errmsg = ""
472
473 " make up to three tries at downloading the description
474 let itry= 1
475 while itry <= 3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100476" call Decho(".try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000477 if has("win32") || has("win16") || has("win95")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100478" call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)."|bw!")
479 new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)|bw!
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000480 else
Bram Moolenaar5c736222010-01-06 20:54:52 +0100481" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr))
482 exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000483 endif
484 if itry == 1
485 exe "silent vsplit ".fnameescape(tmpfile)
486 else
487 silent! e %
488 endif
489 setlocal bh=wipe
490
491 " find the latest source-id in the plugin's webpage
492 silent! 1
493 let findpkg= search('Click on the package to download','W')
494 if findpkg > 0
495 break
496 endif
497 let itry= itry + 1
498 endwhile
499" call Decho(" --- end downloading tries while loop --- itry=".itry)
500
501 " testing: did finding "Click on the package..." fail?
502 if findpkg == 0 || itry >= 4
503 silent q!
504 call delete(tmpfile)
505 " restore options
506 let &t_ti = t_ti
507 let &t_te = t_te
508 let &rs = rs
509 let s:downerrors = s:downerrors + 1
510" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
511 echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
512" call Dret("GetOneScript : srch for /Click on the package/ failed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000513 return
514 endif
515" call Decho('found "Click on the package to download"')
516
517 let findsrcid= search('src_id=','W')
518 if findsrcid == 0
519 silent q!
520 call delete(tmpfile)
521 " restore options
522 let &t_ti = t_ti
523 let &t_te = t_te
524 let &rs = rs
525 let s:downerrors = s:downerrors + 1
526" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
527 echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000528" call Dret("GetOneScript : srch for /src_id/ failed")
529 return
530 endif
531" call Decho('found "src_id=" in description page')
532
533 let srcidpat = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
534 let latestsrcid= substitute(getline("."),srcidpat,'\1','')
535 let sname = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
536" call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
537 silent q!
538 call delete(tmpfile)
539
540 " convert the strings-of-numbers into numbers
541 let srcid = srcid + 0
542 let latestsrcid = latestsrcid + 0
543" call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
544
Bram Moolenaar5c736222010-01-06 20:54:52 +0100545 " has the plugin's most-recent srcid increased, which indicates that it has been updated
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000546 if latestsrcid > srcid
547" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
548
549 let s:downloads= s:downloads + 1
550 if sname == bufname("%")
551 " GetLatestVimScript has to be careful about downloading itself
552 let sname= "NEW_".sname
553 endif
554
Bram Moolenaar5c736222010-01-06 20:54:52 +0100555 " -----------------------------------------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000556 " the plugin has been updated since we last obtained it, so download a new copy
Bram Moolenaar5c736222010-01-06 20:54:52 +0100557 " -----------------------------------------------------------------------------
558" call Decho(".downloading new <".sname.">")
559 echomsg ".downloading new <".sname.">"
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000560 if has("win32") || has("win16") || has("win95")
GuyBrush13a66052024-11-12 20:18:14 +0100561" call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)."|bw!")
562 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 +0000563 else
GuyBrush13a66052024-11-12 20:18:14 +0100564" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)
565 exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000566 endif
567
Bram Moolenaar5c736222010-01-06 20:54:52 +0100568 " --------------------------------------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000569 " AutoInstall: only if doautoinstall has been requested by the plugin itself
Bram Moolenaar5c736222010-01-06 20:54:52 +0100570 " --------------------------------------------------------------------------
Bram Moolenaar251e1912011-06-19 05:09:16 +0200571" call Decho("checking if plugin requested autoinstall: doautoinstall=".doautoinstall)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000572 if doautoinstall
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000573 if filereadable(sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100574 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200575 let curdir = fnameescape(substitute(getcwd(),'\','/','ge'))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000576 let installdir= curdir."/Installed"
577 if !isdirectory(installdir)
578 call mkdir(installdir)
579 endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000580 exe "cd ".fnameescape(s:autoinstall)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100581
582 " determine target directory for moves
583 let firstdir= substitute(&rtp,',.*$','','')
584 let pname = substitute(sname,'\..*','.vim','')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100585 if filereadable(firstdir.'/AsNeeded/'.pname)
586 let tgtdir= "AsNeeded"
587 else
588 let tgtdir= "plugin"
589 endif
Jim Zhou56957ed2025-02-28 18:06:14 +0100590
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000591 " decompress
592 if sname =~ '\.bz2$'
GuyBrushc854efc2024-09-26 16:14:08 +0200593 exe "sil !".g:GetLatestVimScripts_bunzip2." ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000594 let sname= substitute(sname,'\.bz2$','','')
Jim Zhou56957ed2025-02-28 18:06:14 +0100595 elseif sname =~ '\.bz3$'
596 exe "sil !".g:GetLatestVimScripts_bunzip3." ".shellescape(sname)
597 let sname= substitute(sname,'\.bz3$','','')
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000598 elseif sname =~ '\.gz$'
GuyBrushc854efc2024-09-26 16:14:08 +0200599 exe "sil !".g:GetLatestVimScripts_gunzip." ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000600 let sname= substitute(sname,'\.gz$','','')
Bram Moolenaar251e1912011-06-19 05:09:16 +0200601 elseif sname =~ '\.xz$'
GuyBrushc854efc2024-09-26 16:14:08 +0200602 exe "sil !".g:GetLatestVimScripts_unxz." ".shellescape(sname)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200603 let sname= substitute(sname,'\.xz$','','')
Bram Moolenaar5c736222010-01-06 20:54:52 +0100604 else
605" call Decho("no decompression needed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000606 endif
Jim Zhou56957ed2025-02-28 18:06:14 +0100607
GuyBrush609599c2024-09-08 19:54:43 +0200608 " distribute archive(.zip, .tar, .vba, .vmb, ...) contents
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000609 if sname =~ '\.zip$'
GuyBrushc854efc2024-09-26 16:14:08 +0200610 exe "silent !".g:GetLatestVimScripts_unzip." -o ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000611 elseif sname =~ '\.tar$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100612 exe "silent !tar -xvf ".shellescape(sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100613 elseif sname =~ '\.tgz$'
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100614 exe "silent !tar -zxvf ".shellescape(sname)
615 elseif sname =~ '\.taz$'
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100616 exe "silent !tar -Zxvf ".shellescape(sname)
617 elseif sname =~ '\.tbz$'
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100618 exe "silent !tar -jxvf ".shellescape(sname)
619 elseif sname =~ '\.txz$'
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100620 exe "silent !tar -Jxvf ".shellescape(sname)
GuyBrush609599c2024-09-08 19:54:43 +0200621 elseif sname =~ '\.vba$\|\.vmb$'
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000622 silent 1split
Bram Moolenaar5c736222010-01-06 20:54:52 +0100623 if exists("g:vimball_home")
624 let oldvimballhome= g:vimball_home
625 endif
626 let g:vimball_home= s:autoinstall
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000627 exe "silent e ".fnameescape(sname)
628 silent so %
629 silent q
Bram Moolenaar5c736222010-01-06 20:54:52 +0100630 if exists("oldvimballhome")
631 let g:vimball_home= oldvimballhome
632 else
633 unlet g:vimball_home
634 endif
635 else
636" call Decho("no dearchiving needed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000637 endif
Jim Zhou56957ed2025-02-28 18:06:14 +0100638
Bram Moolenaar5c736222010-01-06 20:54:52 +0100639 " ---------------------------------------------
640 " move plugin to plugin/ or AsNeeded/ directory
641 " ---------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000642 if sname =~ '.vim$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100643 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".tgtdir
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000644 else
Bram Moolenaar5c736222010-01-06 20:54:52 +0100645 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".installdir
646 endif
647 if tgtdir != "plugin"
GuyBrush13a66052024-11-12 20:18:14 +0100648 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape("plugin/".pname)." ".tgtdir
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000649 endif
Jim Zhou56957ed2025-02-28 18:06:14 +0100650
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000651 " helptags step
652 let docdir= substitute(&rtp,',.*','','e')."/doc"
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000653 exe "helptags ".fnameescape(docdir)
654 exe "cd ".fnameescape(curdir)
655 endif
656 if fname !~ ':AutoInstall:'
657 let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
658 else
659 let modline=scriptid." ".latestsrcid." ".fname.cmmnt
660 endif
661 else
662 let modline=scriptid." ".latestsrcid." ".fname.cmmnt
663 endif
664
665 " update the data in the <GetLatestVimScripts.dat> file
666 call setline(line("."),modline)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000667 endif
668
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000669endfun
670
671" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000672" Restore Options: {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000673let &cpo= s:keepcpo
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000674unlet s:keepcpo
Bram Moolenaar9964e462007-05-05 17:54:07 +0000675
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000676" ---------------------------------------------------------------------
677" Modelines: {{{1
Bram Moolenaar9964e462007-05-05 17:54:07 +0000678" vim: ts=8 sts=2 fdm=marker nowrap