blob: dced99cc465e93021a310bbc1d3fec19016a5692 [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
GuyBrush609599c2024-09-08 19:54:43 +020014" }}}
Bram Moolenaar9964e462007-05-05 17:54:07 +000015"
16" GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
Bram Moolenaar9e368db2007-05-12 13:25:01 +000017"redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
Bram Moolenaar9964e462007-05-05 17:54:07 +000018" ---------------------------------------------------------------------
19" Initialization: {{{1
20" if you're sourcing this file, surely you can't be
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000021" expecting vim to be in its vi-compatible mode!
Bram Moolenaar5c736222010-01-06 20:54:52 +010022if exists("g:loaded_getscript")
23 finish
24endif
GuyBrushc854efc2024-09-26 16:14:08 +020025let g:loaded_getscript= "v37"
Bram Moolenaar9964e462007-05-05 17:54:07 +000026if &cp
27 echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
28 finish
29endif
Bram Moolenaar5c736222010-01-06 20:54:52 +010030if v:version < 702
31 echohl WarningMsg
Bram Moolenaar29634562020-01-09 21:46:04 +010032 echo "***warning*** this version of GetLatestVimScripts needs vim 7.2"
Bram Moolenaar5c736222010-01-06 20:54:52 +010033 echohl Normal
34 finish
35endif
Bram Moolenaar9964e462007-05-05 17:54:07 +000036let s:keepcpo = &cpo
37set cpo&vim
Bram Moolenaar82038d72007-05-10 17:15:45 +000038"DechoTabOn
Bram Moolenaar9964e462007-05-05 17:54:07 +000039
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000040" ---------------------------
41" Global Variables: {{{1
42" ---------------------------
43" Cygwin Detection ------- {{{2
44if !exists("g:getscript_cygwin")
45 if has("win32") || has("win95") || has("win64") || has("win16")
46 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
47 let g:getscript_cygwin= 1
48 else
49 let g:getscript_cygwin= 0
50 endif
51 else
52 let g:getscript_cygwin= 0
53 endif
54endif
Bram Moolenaar3577c6f2008-06-24 21:16:56 +000055
56" wget vs curl {{{2
Bram Moolenaar9964e462007-05-05 17:54:07 +000057if !exists("g:GetLatestVimScripts_wget")
58 if executable("wget")
59 let g:GetLatestVimScripts_wget= "wget"
60 elseif executable("curl")
61 let g:GetLatestVimScripts_wget= "curl"
62 else
63 let g:GetLatestVimScripts_wget = 'echo "GetLatestVimScripts needs wget or curl"'
64 let g:GetLatestVimScripts_options = ""
65 endif
66endif
67
68" options that wget and curl require:
69if !exists("g:GetLatestVimScripts_options")
70 if g:GetLatestVimScripts_wget == "wget"
71 let g:GetLatestVimScripts_options= "-q -O"
72 elseif g:GetLatestVimScripts_wget == "curl"
GuyBrush609599c2024-09-08 19:54:43 +020073 let g:GetLatestVimScripts_options= "-s -o"
Bram Moolenaar9964e462007-05-05 17:54:07 +000074 else
75 let g:GetLatestVimScripts_options= ""
76 endif
77endif
78
79" by default, allow autoinstall lines to work
80if !exists("g:GetLatestVimScripts_allowautoinstall")
81 let g:GetLatestVimScripts_allowautoinstall= 1
82endif
83
Bram Moolenaarff034192013-04-24 18:51:19 +020084" set up default scriptaddr address
85if !exists("g:GetLatestVimScripts_scriptaddr")
GuyBrush609599c2024-09-08 19:54:43 +020086 let g:GetLatestVimScripts_scriptaddr = 'https://www.vim.org/scripts/script.php?script_id='
87endif
88
89if !exists("g:GetLatestVimScripts_downloadaddr")
90 let g:GetLatestVimScripts_downloadaddr = 'https://www.vim.org/scripts/download_script.php?src_id='
Bram Moolenaarff034192013-04-24 18:51:19 +020091endif
92
GuyBrushc854efc2024-09-26 16:14:08 +020093" define decompression tools (on windows this allows redirection to wsl or git tools).
94" Note tar is available as builtin since Windows 11.
95if !exists("g:GetLatestVimScripts_bunzip2")
96 let g:GetLatestVimScripts_bunzip2= "bunzip2"
97endif
98
99if !exists("g:GetLatestVimScripts_gunzip")
100 let g:GetLatestVimScripts_gunzip= "gunzip"
101endif
102
103if !exists("g:GetLatestVimScripts_unxz")
104 let g:GetLatestVimScripts_unxz= "unxz"
105endif
106
107if !exists("g:GetLatestVimScripts_unzip")
108 let g:GetLatestVimScripts_unzip= "unzip"
109endif
110
Bram Moolenaar9964e462007-05-05 17:54:07 +0000111"" For debugging:
112"let g:GetLatestVimScripts_wget = "echo"
113"let g:GetLatestVimScripts_options = "options"
114
115" ---------------------------------------------------------------------
116" Check If AutoInstall Capable: {{{1
117let s:autoinstall= ""
118if g:GetLatestVimScripts_allowautoinstall
119
GuyBrushc854efc2024-09-26 16:14:08 +0200120 let s:is_windows = has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")
121 let s:dotvim= s:is_windows ? "vimfiles" : ".vim"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000122
GuyBrushc854efc2024-09-26 16:14:08 +0200123 if !exists("g:GetLatestVimScripts_mv")
124 if s:is_windows && &shell !~ '\cbash\|pwsh\|powershell'
125 " windows (but not cygwin/bash)
126 let g:GetLatestVimScripts_mv= "move"
127 else
128 " unix
129 let g:GetLatestVimScripts_mv= "mv"
Bram Moolenaar9964e462007-05-05 17:54:07 +0000130 endif
131 endif
132
Bram Moolenaar5c736222010-01-06 20:54:52 +0100133 if exists("g:GetLatestVimScripts_autoinstalldir") && isdirectory(g:GetLatestVimScripts_autoinstalldir)
134 let s:autoinstall= g:GetLatestVimScripts_autoinstalldir"
135 elseif exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim)
Bram Moolenaar9964e462007-05-05 17:54:07 +0000136 let s:autoinstall= $HOME."/".s:dotvim
137 endif
138" call Decho("s:autoinstall<".s:autoinstall.">")
139"else "Decho
140" call Decho("g:GetLatestVimScripts_allowautoinstall=".g:GetLatestVimScripts_allowautoinstall.": :AutoInstall: disabled")
141endif
142
143" ---------------------------------------------------------------------
144" Public Interface: {{{1
145com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
146com! -nargs=0 GetScript call getscript#GetLatestVimScripts()
147silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts()
148
149" ---------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000150" GetLatestVimScripts: this function gets the latest versions of {{{1
151" scripts based on the list in
152" (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
153fun! getscript#GetLatestVimScripts()
154" call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">")
155
156" insure that wget is executable
157 if executable(g:GetLatestVimScripts_wget) != 1
158 echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system"
Bram Moolenaar6c391a72021-09-09 21:55:11 +0200159" call Dret("GetLatestVimScripts : wget not executable/available")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000160 return
161 endif
162
Bram Moolenaarc236c162008-07-13 17:41:49 +0000163 " insure that fnameescape() is available
164 if !exists("*fnameescape")
165 echoerr "GetLatestVimScripts needs fnameescape() (provided by 7.1.299 or later)"
166 return
167 endif
168
Bram Moolenaar9964e462007-05-05 17:54:07 +0000169 " Find the .../GetLatest subdirectory under the runtimepath
170 for datadir in split(&rtp,',') + ['']
171 if isdirectory(datadir."/GetLatest")
172" call Decho("found directory<".datadir.">")
173 let datadir= datadir . "/GetLatest"
174 break
175 endif
176 if filereadable(datadir."GetLatestVimScripts.dat")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000177" call Decho("found ".datadir."/GetLatestVimScripts.dat")
178 break
Bram Moolenaar9964e462007-05-05 17:54:07 +0000179 endif
180 endfor
Bram Moolenaar82038d72007-05-10 17:15:45 +0000181
Bram Moolenaar9964e462007-05-05 17:54:07 +0000182 " Sanity checks: readability and writability
183 if datadir == ""
184 echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install'
185" call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory")
186 return
187 endif
Bram Moolenaar9964e462007-05-05 17:54:07 +0000188 if filewritable(datadir) != 2
189 echoerr "(getLatestVimScripts) Your ".datadir." isn't writable"
190" call Dret("GetLatestVimScripts : non-writable directory<".datadir.">")
191 return
192 endif
193 let datafile= datadir."/GetLatestVimScripts.dat"
194 if !filereadable(datafile)
195 echoerr "Your data file<".datafile."> isn't readable"
196" call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">")
197 return
198 endif
199 if !filewritable(datafile)
200 echoerr "Your data file<".datafile."> isn't writable"
201" call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">")
202 return
203 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100204 " --------------------
205 " Passed sanity checks
206 " --------------------
207
Bram Moolenaar9964e462007-05-05 17:54:07 +0000208" call Decho("datadir <".datadir.">")
209" call Decho("datafile <".datafile.">")
210
Bram Moolenaar5c736222010-01-06 20:54:52 +0100211 " don't let any event handlers interfere (like winmanager's, taglist's, etc)
212 let eikeep = &ei
213 let hlskeep = &hls
214 let acdkeep = &acd
215 set ei=all hls&vim noacd
Bram Moolenaar9964e462007-05-05 17:54:07 +0000216
Bram Moolenaar5c736222010-01-06 20:54:52 +0100217 " Edit the datafile (ie. GetLatestVimScripts.dat):
218 " 1. record current directory (origdir),
219 " 2. change directory to datadir,
220 " 3. split window
221 " 4. edit datafile
Bram Moolenaar9964e462007-05-05 17:54:07 +0000222 let origdir= getcwd()
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000223" call Decho("exe cd ".fnameescape(substitute(datadir,'\','/','ge')))
224 exe "cd ".fnameescape(substitute(datadir,'\','/','ge'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000225 split
Bram Moolenaar5c736222010-01-06 20:54:52 +0100226" call Decho("exe e ".fnameescape(substitute(datafile,'\','/','ge')))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000227 exe "e ".fnameescape(substitute(datafile,'\','/','ge'))
Bram Moolenaar9964e462007-05-05 17:54:07 +0000228 res 1000
229 let s:downloads = 0
230 let s:downerrors= 0
231
232 " Check on dependencies mentioned in plugins
233" call Decho(" ")
234" call Decho("searching plugins for GetLatestVimScripts dependencies")
235 let lastline = line("$")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000236" call Decho("lastline#".lastline)
GuyBrushc854efc2024-09-26 16:14:08 +0200237 let firstdir = substitute(&rtp,',.*$','','')
Bram Moolenaar8d043172014-01-23 14:24:41 +0100238 let plugins = split(globpath(firstdir,"plugin/**/*.vim"),'\n')
GuyBrush609599c2024-09-08 19:54:43 +0200239 let plugins += split(globpath(firstdir,"ftplugin/**/*.vim"),'\n')
240 let plugins += split(globpath(firstdir,"AsNeeded/**/*.vim"),'\n')
GuyBrushc854efc2024-09-26 16:14:08 +0200241" extend the search to the packages too (this script predates the feature)
242 let plugins += split(globpath(firstdir,"pack/*/start/*/plugin/**/*.vim"),'\n')
243 let plugins += split(globpath(firstdir,"pack/*/opt/*/plugin/**/*.vim"),'\n')
244 let plugins += split(globpath(firstdir,"pack/*/start/*/ftplugin/**/*.vim"),'\n')
245 let plugins += split(globpath(firstdir,"pack/*/opt/*/ftplugin/**/*.vim"),'\n')
Bram Moolenaar9964e462007-05-05 17:54:07 +0000246 let foundscript = 0
247
Bram Moolenaar5c736222010-01-06 20:54:52 +0100248 " this loop updates the GetLatestVimScripts.dat file
249 " with dependencies explicitly mentioned in the plugins
250 " via GetLatestVimScripts: ... lines
251 " It reads the plugin script at the end of the GetLatestVimScripts.dat
252 " file, examines it, and then removes it.
Bram Moolenaar82038d72007-05-10 17:15:45 +0000253 for plugin in plugins
Bram Moolenaar5c736222010-01-06 20:54:52 +0100254" call Decho(" ")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000255" call Decho("plugin<".plugin.">")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000256
Bram Moolenaar82038d72007-05-10 17:15:45 +0000257 " read plugin in
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000258 " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it
Bram Moolenaar9964e462007-05-05 17:54:07 +0000259 $
260" call Decho(".dependency checking<".plugin."> line$=".line("$"))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100261" call Decho("..exe silent r ".fnameescape(plugin))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000262 exe "silent r ".fnameescape(plugin)
263 exe "silent bwipe ".bufnr("#")
Bram Moolenaar82038d72007-05-10 17:15:45 +0000264
Bram Moolenaar9964e462007-05-05 17:54:07 +0000265 while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
Bram Moolenaar5c736222010-01-06 20:54:52 +0100266 let depscript = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
267 let depscriptid = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\(\d\+\)\s\+.*$','\1','')
268 let llp1 = lastline+1
269" call Decho("..depscript<".depscript.">")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000270
Bram Moolenaar5c736222010-01-06 20:54:52 +0100271 " found a "GetLatestVimScripts: # #" line in the script;
Bram Moolenaar8024f932020-01-14 19:29:13 +0100272 " check if it's already in the datafile by searching backwards from llp1,
Bram Moolenaar5c736222010-01-06 20:54:52 +0100273 " the (prior to reading in the plugin script) last line plus one of the GetLatestVimScripts.dat file,
274 " for the script-id with no wrapping allowed.
275 let curline = line(".")
276 let noai_script = substitute(depscript,'\s*:AutoInstall:\s*','','e')
277 exe llp1
278 let srchline = search('^\s*'.depscriptid.'\s\+\d\+\s\+.*$','bW')
279 if srchline == 0
280 " this second search is taken when, for example, a 0 0 scriptname is to be skipped over
281 let srchline= search('\<'.noai_script.'\>','bW')
Bram Moolenaar82038d72007-05-10 17:15:45 +0000282 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100283" call Decho("..noai_script<".noai_script."> depscriptid#".depscriptid." srchline#".srchline." curline#".line(".")." lastline#".lastline)
284
285 if srchline == 0
286 " found a new script to permanently include in the datafile
287 let keep_rega = @a
288 let @a = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','')
289 echomsg "Appending <".@a."> to ".datafile." for ".depscript
290" call Decho("..Appending <".@a."> to ".datafile." for ".depscript)
291 exe lastline."put a"
292 let @a = keep_rega
293 let lastline = llp1
294 let curline = curline + 1
295 let foundscript = foundscript + 1
296" else " Decho
297" call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")")
298 endif
299
300 let curline = curline + 1
301 exe curline
Bram Moolenaar9964e462007-05-05 17:54:07 +0000302 endwhile
Bram Moolenaar82038d72007-05-10 17:15:45 +0000303
Bram Moolenaar5c736222010-01-06 20:54:52 +0100304 " llp1: last line plus one
Bram Moolenaar9964e462007-05-05 17:54:07 +0000305 let llp1= lastline + 1
306" call Decho(".deleting lines: ".llp1.",$d")
307 exe "silent! ".llp1.",$d"
Bram Moolenaar82038d72007-05-10 17:15:45 +0000308 endfor
309" call Decho("--- end dependency checking loop --- foundscript=".foundscript)
310" call Decho(" ")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000311" call Dredir("BUFFER TEST (GetLatestVimScripts 1)","ls!")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000312
313 if foundscript == 0
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000314 setlocal nomod
Bram Moolenaar9964e462007-05-05 17:54:07 +0000315 endif
316
Bram Moolenaar5c736222010-01-06 20:54:52 +0100317 " --------------------------------------------------------------------
Bram Moolenaar9964e462007-05-05 17:54:07 +0000318 " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
Bram Moolenaar5c736222010-01-06 20:54:52 +0100319 " --------------------------------------------------------------------
Bram Moolenaar82038d72007-05-10 17:15:45 +0000320" call Decho("begin: checking out-of-date scripts using datafile<".datafile.">")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000321 setlocal lz
Bram Moolenaar9964e462007-05-05 17:54:07 +0000322 1
Bram Moolenaar82038d72007-05-10 17:15:45 +0000323" /^-----/,$g/^\s*\d/call Decho(getline("."))
324 1
325 /^-----/,$g/^\s*\d/call s:GetOneScript()
326" call Decho("--- end out-of-date checking --- ")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000327
328 " Final report (an echomsg)
329 try
330 silent! ?^-------?
331 catch /^Vim\%((\a\+)\)\=:E114/
332" call Dret("GetLatestVimScripts : nothing done!")
333 return
334 endtry
335 exe "norm! kz\<CR>"
336 redraw!
337 let s:msg = ""
338 if s:downloads == 1
339 let s:msg = "Downloaded one updated script to <".datadir.">"
340 elseif s:downloads == 2
341 let s:msg= "Downloaded two updated scripts to <".datadir.">"
342 elseif s:downloads > 1
343 let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">"
344 else
345 let s:msg= "Everything was already current"
346 endif
347 if s:downerrors > 0
348 let s:msg= s:msg." (".s:downerrors." downloading errors)"
349 endif
350 echomsg s:msg
351 " save the file
352 if &mod
353 silent! w!
354 endif
Bram Moolenaarff034192013-04-24 18:51:19 +0200355 q!
Bram Moolenaar9964e462007-05-05 17:54:07 +0000356
357 " restore events and current directory
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000358 exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
Bram Moolenaar5c736222010-01-06 20:54:52 +0100359 let &ei = eikeep
360 let &hls = hlskeep
361 let &acd = acdkeep
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000362 setlocal nolz
363" call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!")
Bram Moolenaar9964e462007-05-05 17:54:07 +0000364" call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
365endfun
Bram Moolenaar9964e462007-05-05 17:54:07 +0000366
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000367" ---------------------------------------------------------------------
h-easta4205472024-10-13 19:16:42 +0200368" GetOneScript: (Get Latest Vim script) this function operates {{{1
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000369" on the current line, interpreting two numbers and text as
370" ScriptID, SourceID, and Filename.
Bram Moolenaar5c736222010-01-06 20:54:52 +0100371" It downloads any scripts that have newer versions from vim.sourceforge.net.
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000372fun! s:GetOneScript(...)
373" call Dfunc("GetOneScript()")
374
375 " set options to allow progress to be shown on screen
376 let rega= @a
377 let t_ti= &t_ti
378 let t_te= &t_te
379 let rs = &rs
380 set t_ti= t_te= nors
381
382 " put current line on top-of-screen and interpret it into
Bram Moolenaar6c391a72021-09-09 21:55:11 +0200383 " a script identifier : used to obtain webpage
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000384 " source identifier : used to identify current version
385 " and an associated comment: used to report on what's being considered
386 if a:0 >= 3
387 let scriptid = a:1
388 let srcid = a:2
389 let fname = a:3
390 let cmmnt = ""
391" call Decho("scriptid<".scriptid.">")
392" call Decho("srcid <".srcid.">")
393" call Decho("fname <".fname.">")
394 else
395 let curline = getline(".")
396 if curline =~ '^\s*#'
397 let @a= rega
398" call Dret("GetOneScript : skipping a pure comment line")
399 return
400 endif
401 let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
402 try
403 let scriptid = substitute(curline,parsepat,'\1','e')
404 catch /^Vim\%((\a\+)\)\=:E486/
405 let scriptid= 0
406 endtry
407 try
408 let srcid = substitute(curline,parsepat,'\2','e')
409 catch /^Vim\%((\a\+)\)\=:E486/
410 let srcid= 0
411 endtry
412 try
413 let fname= substitute(curline,parsepat,'\3','e')
414 catch /^Vim\%((\a\+)\)\=:E486/
415 let fname= ""
416 endtry
417 try
418 let cmmnt= substitute(curline,parsepat,'\4','e')
419 catch /^Vim\%((\a\+)\)\=:E486/
420 let cmmnt= ""
421 endtry
422" call Decho("curline <".curline.">")
423" call Decho("parsepat<".parsepat.">")
424" call Decho("scriptid<".scriptid.">")
425" call Decho("srcid <".srcid.">")
426" call Decho("fname <".fname.">")
427 endif
428
Bram Moolenaar5c736222010-01-06 20:54:52 +0100429 " plugin author protection from downloading his/her own scripts atop their latest work
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000430 if scriptid == 0 || srcid == 0
431 " When looking for :AutoInstall: lines, skip scripts that have 0 0 scriptname
432 let @a= rega
433" call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
434 return
435 endif
436
437 let doautoinstall= 0
438 if fname =~ ":AutoInstall:"
439" call Decho("case AutoInstall: fname<".fname.">")
440 let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
441" call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
442 if s:autoinstall != ""
443 let doautoinstall = g:GetLatestVimScripts_allowautoinstall
444 endif
445 else
446 let aicmmnt= fname
447 endif
448" call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
449
450 exe "norm z\<CR>"
451 redraw!
452" call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
453 echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
454
Bram Moolenaar5c736222010-01-06 20:54:52 +0100455 " grab a copy of the plugin's vim.sourceforge.net webpage
Bram Moolenaarff034192013-04-24 18:51:19 +0200456 let scriptaddr = g:GetLatestVimScripts_scriptaddr.scriptid
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000457 let tmpfile = tempname()
458 let v:errmsg = ""
459
460 " make up to three tries at downloading the description
461 let itry= 1
462 while itry <= 3
Bram Moolenaar5c736222010-01-06 20:54:52 +0100463" call Decho(".try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000464 if has("win32") || has("win16") || has("win95")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100465" call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)."|bw!")
466 new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)|bw!
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000467 else
Bram Moolenaar5c736222010-01-06 20:54:52 +0100468" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr))
469 exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000470 endif
471 if itry == 1
472 exe "silent vsplit ".fnameescape(tmpfile)
473 else
474 silent! e %
475 endif
476 setlocal bh=wipe
477
478 " find the latest source-id in the plugin's webpage
479 silent! 1
480 let findpkg= search('Click on the package to download','W')
481 if findpkg > 0
482 break
483 endif
484 let itry= itry + 1
485 endwhile
486" call Decho(" --- end downloading tries while loop --- itry=".itry)
487
488 " testing: did finding "Click on the package..." fail?
489 if findpkg == 0 || itry >= 4
490 silent q!
491 call delete(tmpfile)
492 " restore options
493 let &t_ti = t_ti
494 let &t_te = t_te
495 let &rs = rs
496 let s:downerrors = s:downerrors + 1
497" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
498 echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
499" call Dret("GetOneScript : srch for /Click on the package/ failed")
500 let @a= rega
501 return
502 endif
503" call Decho('found "Click on the package to download"')
504
505 let findsrcid= search('src_id=','W')
506 if findsrcid == 0
507 silent q!
508 call delete(tmpfile)
509 " restore options
510 let &t_ti = t_ti
511 let &t_te = t_te
512 let &rs = rs
513 let s:downerrors = s:downerrors + 1
514" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
515 echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
516 let @a= rega
517" call Dret("GetOneScript : srch for /src_id/ failed")
518 return
519 endif
520" call Decho('found "src_id=" in description page')
521
522 let srcidpat = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
523 let latestsrcid= substitute(getline("."),srcidpat,'\1','')
524 let sname = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
525" call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
526 silent q!
527 call delete(tmpfile)
528
529 " convert the strings-of-numbers into numbers
530 let srcid = srcid + 0
531 let latestsrcid = latestsrcid + 0
532" call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
533
Bram Moolenaar5c736222010-01-06 20:54:52 +0100534 " has the plugin's most-recent srcid increased, which indicates that it has been updated
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000535 if latestsrcid > srcid
536" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
537
538 let s:downloads= s:downloads + 1
539 if sname == bufname("%")
540 " GetLatestVimScript has to be careful about downloading itself
541 let sname= "NEW_".sname
542 endif
543
Bram Moolenaar5c736222010-01-06 20:54:52 +0100544 " -----------------------------------------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000545 " the plugin has been updated since we last obtained it, so download a new copy
Bram Moolenaar5c736222010-01-06 20:54:52 +0100546 " -----------------------------------------------------------------------------
547" call Decho(".downloading new <".sname.">")
548 echomsg ".downloading new <".sname.">"
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000549 if has("win32") || has("win16") || has("win95")
GuyBrush609599c2024-09-08 19:54:43 +0200550" call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr.latestsrcid)."|q")
551 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 +0000552 else
GuyBrush609599c2024-09-08 19:54:43 +0200553" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr).latestsrcid
554 exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape(g:GetLatestVimScripts_downloadaddr).latestsrcid
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000555 endif
556
Bram Moolenaar5c736222010-01-06 20:54:52 +0100557 " --------------------------------------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000558 " AutoInstall: only if doautoinstall has been requested by the plugin itself
Bram Moolenaar5c736222010-01-06 20:54:52 +0100559 " --------------------------------------------------------------------------
Bram Moolenaar251e1912011-06-19 05:09:16 +0200560" call Decho("checking if plugin requested autoinstall: doautoinstall=".doautoinstall)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000561 if doautoinstall
Bram Moolenaar5c736222010-01-06 20:54:52 +0100562" call Decho(" ")
563" call Decho("Autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000564 if filereadable(sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100565" call Decho("<".sname."> is readable")
566" call Decho("exe silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall))
567 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200568 let curdir = fnameescape(substitute(getcwd(),'\','/','ge'))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000569 let installdir= curdir."/Installed"
570 if !isdirectory(installdir)
571 call mkdir(installdir)
572 endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100573" call Decho("curdir<".curdir."> installdir<".installdir.">")
574" call Decho("exe cd ".fnameescape(s:autoinstall))
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000575 exe "cd ".fnameescape(s:autoinstall)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100576
577 " determine target directory for moves
578 let firstdir= substitute(&rtp,',.*$','','')
579 let pname = substitute(sname,'\..*','.vim','')
580" call Decho("determine tgtdir: is <".firstdir.'/AsNeeded/'.pname." readable?")
581 if filereadable(firstdir.'/AsNeeded/'.pname)
582 let tgtdir= "AsNeeded"
583 else
584 let tgtdir= "plugin"
585 endif
586" call Decho("tgtdir<".tgtdir."> pname<".pname.">")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000587
588 " decompress
589 if sname =~ '\.bz2$'
590" call Decho("decompress: attempt to bunzip2 ".sname)
GuyBrushc854efc2024-09-26 16:14:08 +0200591 exe "sil !".g:GetLatestVimScripts_bunzip2." ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000592 let sname= substitute(sname,'\.bz2$','','')
593" call Decho("decompress: new sname<".sname."> after bunzip2")
594 elseif sname =~ '\.gz$'
595" call Decho("decompress: attempt to gunzip ".sname)
GuyBrushc854efc2024-09-26 16:14:08 +0200596 exe "sil !".g:GetLatestVimScripts_gunzip." ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000597 let sname= substitute(sname,'\.gz$','','')
598" call Decho("decompress: new sname<".sname."> after gunzip")
Bram Moolenaar251e1912011-06-19 05:09:16 +0200599 elseif sname =~ '\.xz$'
600" call Decho("decompress: attempt to unxz ".sname)
GuyBrushc854efc2024-09-26 16:14:08 +0200601 exe "sil !".g:GetLatestVimScripts_unxz." ".shellescape(sname)
Bram Moolenaar251e1912011-06-19 05:09:16 +0200602 let sname= substitute(sname,'\.xz$','','')
603" call Decho("decompress: new sname<".sname."> after unxz")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100604 else
605" call Decho("no decompression needed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000606 endif
607
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$'
610" call Decho("dearchive: attempt to unzip ".sname)
GuyBrushc854efc2024-09-26 16:14:08 +0200611 exe "silent !".g:GetLatestVimScripts_unzip." -o ".shellescape(sname)
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000612 elseif sname =~ '\.tar$'
613" call Decho("dearchive: attempt to untar ".sname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100614 exe "silent !tar -xvf ".shellescape(sname)
Bram Moolenaar6be7f872012-01-20 21:08:56 +0100615 elseif sname =~ '\.tgz$'
616" call Decho("dearchive: attempt to untar+gunzip ".sname)
617 exe "silent !tar -zxvf ".shellescape(sname)
618 elseif sname =~ '\.taz$'
619" call Decho("dearchive: attempt to untar+uncompress ".sname)
620 exe "silent !tar -Zxvf ".shellescape(sname)
621 elseif sname =~ '\.tbz$'
622" call Decho("dearchive: attempt to untar+bunzip2 ".sname)
623 exe "silent !tar -jxvf ".shellescape(sname)
624 elseif sname =~ '\.txz$'
625" call Decho("dearchive: attempt to untar+xz ".sname)
626 exe "silent !tar -Jxvf ".shellescape(sname)
GuyBrush609599c2024-09-08 19:54:43 +0200627 elseif sname =~ '\.vba$\|\.vmb$'
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000628" call Decho("dearchive: attempt to handle a vimball: ".sname)
629 silent 1split
Bram Moolenaar5c736222010-01-06 20:54:52 +0100630 if exists("g:vimball_home")
631 let oldvimballhome= g:vimball_home
632 endif
633 let g:vimball_home= s:autoinstall
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000634 exe "silent e ".fnameescape(sname)
635 silent so %
636 silent q
Bram Moolenaar5c736222010-01-06 20:54:52 +0100637 if exists("oldvimballhome")
638 let g:vimball_home= oldvimballhome
639 else
640 unlet g:vimball_home
641 endif
642 else
643" call Decho("no dearchiving needed")
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000644 endif
645
Bram Moolenaar5c736222010-01-06 20:54:52 +0100646 " ---------------------------------------------
647 " move plugin to plugin/ or AsNeeded/ directory
648 " ---------------------------------------------
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000649 if sname =~ '.vim$'
Bram Moolenaar5c736222010-01-06 20:54:52 +0100650" call Decho("dearchive: attempt to simply move ".sname." to ".tgtdir)
651 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".tgtdir
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000652 else
653" call Decho("dearchive: move <".sname."> to installdir<".installdir.">")
Bram Moolenaar5c736222010-01-06 20:54:52 +0100654 exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".installdir
655 endif
656 if tgtdir != "plugin"
657" call Decho("exe silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir)
658 exe "silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir
Bram Moolenaar3577c6f2008-06-24 21:16:56 +0000659 endif
660
661 " helptags step
662 let docdir= substitute(&rtp,',.*','','e')."/doc"
663" call Decho("helptags: docdir<".docdir.">")
664 exe "helptags ".fnameescape(docdir)
665 exe "cd ".fnameescape(curdir)
666 endif
667 if fname !~ ':AutoInstall:'
668 let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
669 else
670 let modline=scriptid." ".latestsrcid." ".fname.cmmnt
671 endif
672 else
673 let modline=scriptid." ".latestsrcid." ".fname.cmmnt
674 endif
675
676 " update the data in the <GetLatestVimScripts.dat> file
677 call setline(line("."),modline)
678" call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
679" else " Decho
680" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
681 endif
682
683 " restore options
684 let &t_ti = t_ti
685 let &t_te = t_te
686 let &rs = rs
687 let @a = rega
688" call Dredir("BUFFER TEST (GetOneScript)","ls!")
689
690" 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