getscript.vim 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. " ---------------------------------------------------------------------
  2. " getscript.vim
  3. " Author: Charles E. Campbell
  4. " Date: Jan 21, 2014
  5. " Version: 36
  6. " Installing: :help glvs-install
  7. " Usage: :help glvs
  8. "
  9. " GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
  10. "redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
  11. " ---------------------------------------------------------------------
  12. " Initialization: {{{1
  13. " if you're sourcing this file, surely you can't be
  14. " expecting vim to be in its vi-compatible mode!
  15. if exists("g:loaded_getscript")
  16. finish
  17. endif
  18. let g:loaded_getscript= "v36"
  19. if &cp
  20. echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
  21. finish
  22. endif
  23. if v:version < 702
  24. echohl WarningMsg
  25. echo "***warning*** this version of GetLatestVimScripts needs vim 7.2"
  26. echohl Normal
  27. finish
  28. endif
  29. let s:keepcpo = &cpo
  30. set cpo&vim
  31. "DechoTabOn
  32. " ---------------------------
  33. " Global Variables: {{{1
  34. " ---------------------------
  35. " Cygwin Detection ------- {{{2
  36. if !exists("g:getscript_cygwin")
  37. if has("win32") || has("win95") || has("win64") || has("win16")
  38. if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
  39. let g:getscript_cygwin= 1
  40. else
  41. let g:getscript_cygwin= 0
  42. endif
  43. else
  44. let g:getscript_cygwin= 0
  45. endif
  46. endif
  47. " wget vs curl {{{2
  48. if !exists("g:GetLatestVimScripts_wget")
  49. if executable("wget")
  50. let g:GetLatestVimScripts_wget= "wget"
  51. elseif executable("curl")
  52. let g:GetLatestVimScripts_wget= "curl"
  53. else
  54. let g:GetLatestVimScripts_wget = 'echo "GetLatestVimScripts needs wget or curl"'
  55. let g:GetLatestVimScripts_options = ""
  56. endif
  57. endif
  58. " options that wget and curl require:
  59. if !exists("g:GetLatestVimScripts_options")
  60. if g:GetLatestVimScripts_wget == "wget"
  61. let g:GetLatestVimScripts_options= "-q -O"
  62. elseif g:GetLatestVimScripts_wget == "curl"
  63. let g:GetLatestVimScripts_options= "-s -O"
  64. else
  65. let g:GetLatestVimScripts_options= ""
  66. endif
  67. endif
  68. " by default, allow autoinstall lines to work
  69. if !exists("g:GetLatestVimScripts_allowautoinstall")
  70. let g:GetLatestVimScripts_allowautoinstall= 1
  71. endif
  72. " set up default scriptaddr address
  73. if !exists("g:GetLatestVimScripts_scriptaddr")
  74. let g:GetLatestVimScripts_scriptaddr = 'http://vim.sourceforge.net/script.php?script_id='
  75. endif
  76. "" For debugging:
  77. "let g:GetLatestVimScripts_wget = "echo"
  78. "let g:GetLatestVimScripts_options = "options"
  79. " ---------------------------------------------------------------------
  80. " Check If AutoInstall Capable: {{{1
  81. let s:autoinstall= ""
  82. if g:GetLatestVimScripts_allowautoinstall
  83. if (has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")) && &shell != "bash"
  84. " windows (but not cygwin/bash)
  85. let s:dotvim= "vimfiles"
  86. if !exists("g:GetLatestVimScripts_mv")
  87. let g:GetLatestVimScripts_mv= "ren"
  88. endif
  89. else
  90. " unix
  91. let s:dotvim= ".vim"
  92. if !exists("g:GetLatestVimScripts_mv")
  93. let g:GetLatestVimScripts_mv= "mv"
  94. endif
  95. endif
  96. if exists("g:GetLatestVimScripts_autoinstalldir") && isdirectory(g:GetLatestVimScripts_autoinstalldir)
  97. let s:autoinstall= g:GetLatestVimScripts_autoinstalldir"
  98. elseif exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim)
  99. let s:autoinstall= $HOME."/".s:dotvim
  100. endif
  101. " call Decho("s:autoinstall<".s:autoinstall.">")
  102. "else "Decho
  103. " call Decho("g:GetLatestVimScripts_allowautoinstall=".g:GetLatestVimScripts_allowautoinstall.": :AutoInstall: disabled")
  104. endif
  105. " ---------------------------------------------------------------------
  106. " Public Interface: {{{1
  107. com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
  108. com! -nargs=0 GetScript call getscript#GetLatestVimScripts()
  109. silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts()
  110. " ---------------------------------------------------------------------
  111. " GetLatestVimScripts: this function gets the latest versions of {{{1
  112. " scripts based on the list in
  113. " (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
  114. fun! getscript#GetLatestVimScripts()
  115. " call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">")
  116. " insure that wget is executable
  117. if executable(g:GetLatestVimScripts_wget) != 1
  118. echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system"
  119. " call Dret("GetLatestVimScripts : wget not executable/available")
  120. return
  121. endif
  122. " insure that fnameescape() is available
  123. if !exists("*fnameescape")
  124. echoerr "GetLatestVimScripts needs fnameescape() (provided by 7.1.299 or later)"
  125. return
  126. endif
  127. " Find the .../GetLatest subdirectory under the runtimepath
  128. for datadir in split(&rtp,',') + ['']
  129. if isdirectory(datadir."/GetLatest")
  130. " call Decho("found directory<".datadir.">")
  131. let datadir= datadir . "/GetLatest"
  132. break
  133. endif
  134. if filereadable(datadir."GetLatestVimScripts.dat")
  135. " call Decho("found ".datadir."/GetLatestVimScripts.dat")
  136. break
  137. endif
  138. endfor
  139. " Sanity checks: readability and writability
  140. if datadir == ""
  141. echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install'
  142. " call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory")
  143. return
  144. endif
  145. if filewritable(datadir) != 2
  146. echoerr "(getLatestVimScripts) Your ".datadir." isn't writable"
  147. " call Dret("GetLatestVimScripts : non-writable directory<".datadir.">")
  148. return
  149. endif
  150. let datafile= datadir."/GetLatestVimScripts.dat"
  151. if !filereadable(datafile)
  152. echoerr "Your data file<".datafile."> isn't readable"
  153. " call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">")
  154. return
  155. endif
  156. if !filewritable(datafile)
  157. echoerr "Your data file<".datafile."> isn't writable"
  158. " call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">")
  159. return
  160. endif
  161. " --------------------
  162. " Passed sanity checks
  163. " --------------------
  164. " call Decho("datadir <".datadir.">")
  165. " call Decho("datafile <".datafile.">")
  166. " don't let any event handlers interfere (like winmanager's, taglist's, etc)
  167. let eikeep = &ei
  168. let hlskeep = &hls
  169. let acdkeep = &acd
  170. set ei=all hls&vim noacd
  171. " Edit the datafile (ie. GetLatestVimScripts.dat):
  172. " 1. record current directory (origdir),
  173. " 2. change directory to datadir,
  174. " 3. split window
  175. " 4. edit datafile
  176. let origdir= getcwd()
  177. " call Decho("exe cd ".fnameescape(substitute(datadir,'\','/','ge')))
  178. exe "cd ".fnameescape(substitute(datadir,'\','/','ge'))
  179. split
  180. " call Decho("exe e ".fnameescape(substitute(datafile,'\','/','ge')))
  181. exe "e ".fnameescape(substitute(datafile,'\','/','ge'))
  182. res 1000
  183. let s:downloads = 0
  184. let s:downerrors= 0
  185. " Check on dependencies mentioned in plugins
  186. " call Decho(" ")
  187. " call Decho("searching plugins for GetLatestVimScripts dependencies")
  188. let lastline = line("$")
  189. " call Decho("lastline#".lastline)
  190. let firstdir = substitute(&rtp,',.*$','','')
  191. let plugins = split(globpath(firstdir,"plugin/**/*.vim"),'\n')
  192. let plugins = plugins + split(globpath(firstdir,"AsNeeded/**/*.vim"),'\n')
  193. let foundscript = 0
  194. " this loop updates the GetLatestVimScripts.dat file
  195. " with dependencies explicitly mentioned in the plugins
  196. " via GetLatestVimScripts: ... lines
  197. " It reads the plugin script at the end of the GetLatestVimScripts.dat
  198. " file, examines it, and then removes it.
  199. for plugin in plugins
  200. " call Decho(" ")
  201. " call Decho("plugin<".plugin.">")
  202. " read plugin in
  203. " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it
  204. $
  205. " call Decho(".dependency checking<".plugin."> line$=".line("$"))
  206. " call Decho("..exe silent r ".fnameescape(plugin))
  207. exe "silent r ".fnameescape(plugin)
  208. exe "silent bwipe ".bufnr("#")
  209. while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
  210. let depscript = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
  211. let depscriptid = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\(\d\+\)\s\+.*$','\1','')
  212. let llp1 = lastline+1
  213. " call Decho("..depscript<".depscript.">")
  214. " found a "GetLatestVimScripts: # #" line in the script;
  215. " check if it's already in the datafile by searching backwards from llp1,
  216. " the (prior to reading in the plugin script) last line plus one of the GetLatestVimScripts.dat file,
  217. " for the script-id with no wrapping allowed.
  218. let curline = line(".")
  219. let noai_script = substitute(depscript,'\s*:AutoInstall:\s*','','e')
  220. exe llp1
  221. let srchline = search('^\s*'.depscriptid.'\s\+\d\+\s\+.*$','bW')
  222. if srchline == 0
  223. " this second search is taken when, for example, a 0 0 scriptname is to be skipped over
  224. let srchline= search('\<'.noai_script.'\>','bW')
  225. endif
  226. " call Decho("..noai_script<".noai_script."> depscriptid#".depscriptid." srchline#".srchline." curline#".line(".")." lastline#".lastline)
  227. if srchline == 0
  228. " found a new script to permanently include in the datafile
  229. let keep_rega = @a
  230. let @a = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','')
  231. echomsg "Appending <".@a."> to ".datafile." for ".depscript
  232. " call Decho("..Appending <".@a."> to ".datafile." for ".depscript)
  233. exe lastline."put a"
  234. let @a = keep_rega
  235. let lastline = llp1
  236. let curline = curline + 1
  237. let foundscript = foundscript + 1
  238. " else " Decho
  239. " call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")")
  240. endif
  241. let curline = curline + 1
  242. exe curline
  243. endwhile
  244. " llp1: last line plus one
  245. let llp1= lastline + 1
  246. " call Decho(".deleting lines: ".llp1.",$d")
  247. exe "silent! ".llp1.",$d"
  248. endfor
  249. " call Decho("--- end dependency checking loop --- foundscript=".foundscript)
  250. " call Decho(" ")
  251. " call Dredir("BUFFER TEST (GetLatestVimScripts 1)","ls!")
  252. if foundscript == 0
  253. setlocal nomod
  254. endif
  255. " --------------------------------------------------------------------
  256. " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
  257. " --------------------------------------------------------------------
  258. " call Decho("begin: checking out-of-date scripts using datafile<".datafile.">")
  259. setlocal lz
  260. 1
  261. " /^-----/,$g/^\s*\d/call Decho(getline("."))
  262. 1
  263. /^-----/,$g/^\s*\d/call s:GetOneScript()
  264. " call Decho("--- end out-of-date checking --- ")
  265. " Final report (an echomsg)
  266. try
  267. silent! ?^-------?
  268. catch /^Vim\%((\a\+)\)\=:E114/
  269. " call Dret("GetLatestVimScripts : nothing done!")
  270. return
  271. endtry
  272. exe "norm! kz\<CR>"
  273. redraw!
  274. let s:msg = ""
  275. if s:downloads == 1
  276. let s:msg = "Downloaded one updated script to <".datadir.">"
  277. elseif s:downloads == 2
  278. let s:msg= "Downloaded two updated scripts to <".datadir.">"
  279. elseif s:downloads > 1
  280. let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">"
  281. else
  282. let s:msg= "Everything was already current"
  283. endif
  284. if s:downerrors > 0
  285. let s:msg= s:msg." (".s:downerrors." downloading errors)"
  286. endif
  287. echomsg s:msg
  288. " save the file
  289. if &mod
  290. silent! w!
  291. endif
  292. q!
  293. " restore events and current directory
  294. exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
  295. let &ei = eikeep
  296. let &hls = hlskeep
  297. let &acd = acdkeep
  298. setlocal nolz
  299. " call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!")
  300. " call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
  301. endfun
  302. " ---------------------------------------------------------------------
  303. " GetOneScript: (Get Latest Vim Script) this function operates {{{1
  304. " on the current line, interpreting two numbers and text as
  305. " ScriptID, SourceID, and Filename.
  306. " It downloads any scripts that have newer versions from vim.sourceforge.net.
  307. fun! s:GetOneScript(...)
  308. " call Dfunc("GetOneScript()")
  309. " set options to allow progress to be shown on screen
  310. let rega= @a
  311. let t_ti= &t_ti
  312. let t_te= &t_te
  313. let rs = &rs
  314. set t_ti= t_te= nors
  315. " put current line on top-of-screen and interpret it into
  316. " a script identifier : used to obtain webpage
  317. " source identifier : used to identify current version
  318. " and an associated comment: used to report on what's being considered
  319. if a:0 >= 3
  320. let scriptid = a:1
  321. let srcid = a:2
  322. let fname = a:3
  323. let cmmnt = ""
  324. " call Decho("scriptid<".scriptid.">")
  325. " call Decho("srcid <".srcid.">")
  326. " call Decho("fname <".fname.">")
  327. else
  328. let curline = getline(".")
  329. if curline =~ '^\s*#'
  330. let @a= rega
  331. " call Dret("GetOneScript : skipping a pure comment line")
  332. return
  333. endif
  334. let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
  335. try
  336. let scriptid = substitute(curline,parsepat,'\1','e')
  337. catch /^Vim\%((\a\+)\)\=:E486/
  338. let scriptid= 0
  339. endtry
  340. try
  341. let srcid = substitute(curline,parsepat,'\2','e')
  342. catch /^Vim\%((\a\+)\)\=:E486/
  343. let srcid= 0
  344. endtry
  345. try
  346. let fname= substitute(curline,parsepat,'\3','e')
  347. catch /^Vim\%((\a\+)\)\=:E486/
  348. let fname= ""
  349. endtry
  350. try
  351. let cmmnt= substitute(curline,parsepat,'\4','e')
  352. catch /^Vim\%((\a\+)\)\=:E486/
  353. let cmmnt= ""
  354. endtry
  355. " call Decho("curline <".curline.">")
  356. " call Decho("parsepat<".parsepat.">")
  357. " call Decho("scriptid<".scriptid.">")
  358. " call Decho("srcid <".srcid.">")
  359. " call Decho("fname <".fname.">")
  360. endif
  361. " plugin author protection from downloading his/her own scripts atop their latest work
  362. if scriptid == 0 || srcid == 0
  363. " When looking for :AutoInstall: lines, skip scripts that have 0 0 scriptname
  364. let @a= rega
  365. " call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
  366. return
  367. endif
  368. let doautoinstall= 0
  369. if fname =~ ":AutoInstall:"
  370. " call Decho("case AutoInstall: fname<".fname.">")
  371. let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
  372. " call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
  373. if s:autoinstall != ""
  374. let doautoinstall = g:GetLatestVimScripts_allowautoinstall
  375. endif
  376. else
  377. let aicmmnt= fname
  378. endif
  379. " call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
  380. exe "norm z\<CR>"
  381. redraw!
  382. " call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
  383. echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
  384. " grab a copy of the plugin's vim.sourceforge.net webpage
  385. let scriptaddr = g:GetLatestVimScripts_scriptaddr.scriptid
  386. let tmpfile = tempname()
  387. let v:errmsg = ""
  388. " make up to three tries at downloading the description
  389. let itry= 1
  390. while itry <= 3
  391. " call Decho(".try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
  392. if has("win32") || has("win16") || has("win95")
  393. " call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)."|bw!")
  394. new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)|bw!
  395. else
  396. " call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr))
  397. exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr)
  398. endif
  399. if itry == 1
  400. exe "silent vsplit ".fnameescape(tmpfile)
  401. else
  402. silent! e %
  403. endif
  404. setlocal bh=wipe
  405. " find the latest source-id in the plugin's webpage
  406. silent! 1
  407. let findpkg= search('Click on the package to download','W')
  408. if findpkg > 0
  409. break
  410. endif
  411. let itry= itry + 1
  412. endwhile
  413. " call Decho(" --- end downloading tries while loop --- itry=".itry)
  414. " testing: did finding "Click on the package..." fail?
  415. if findpkg == 0 || itry >= 4
  416. silent q!
  417. call delete(tmpfile)
  418. " restore options
  419. let &t_ti = t_ti
  420. let &t_te = t_te
  421. let &rs = rs
  422. let s:downerrors = s:downerrors + 1
  423. " call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
  424. echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
  425. " call Dret("GetOneScript : srch for /Click on the package/ failed")
  426. let @a= rega
  427. return
  428. endif
  429. " call Decho('found "Click on the package to download"')
  430. let findsrcid= search('src_id=','W')
  431. if findsrcid == 0
  432. silent q!
  433. call delete(tmpfile)
  434. " restore options
  435. let &t_ti = t_ti
  436. let &t_te = t_te
  437. let &rs = rs
  438. let s:downerrors = s:downerrors + 1
  439. " call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
  440. echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
  441. let @a= rega
  442. " call Dret("GetOneScript : srch for /src_id/ failed")
  443. return
  444. endif
  445. " call Decho('found "src_id=" in description page')
  446. let srcidpat = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
  447. let latestsrcid= substitute(getline("."),srcidpat,'\1','')
  448. let sname = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
  449. " call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
  450. silent q!
  451. call delete(tmpfile)
  452. " convert the strings-of-numbers into numbers
  453. let srcid = srcid + 0
  454. let latestsrcid = latestsrcid + 0
  455. " call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
  456. " has the plugin's most-recent srcid increased, which indicates that it has been updated
  457. if latestsrcid > srcid
  458. " call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
  459. let s:downloads= s:downloads + 1
  460. if sname == bufname("%")
  461. " GetLatestVimScript has to be careful about downloading itself
  462. let sname= "NEW_".sname
  463. endif
  464. " -----------------------------------------------------------------------------
  465. " the plugin has been updated since we last obtained it, so download a new copy
  466. " -----------------------------------------------------------------------------
  467. " call Decho(".downloading new <".sname.">")
  468. echomsg ".downloading new <".sname.">"
  469. if has("win32") || has("win16") || has("win95")
  470. " call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id='.latestsrcid)."|q")
  471. new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id='.latestsrcid)|q
  472. else
  473. " call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id='))
  474. exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id=').latestsrcid
  475. endif
  476. " --------------------------------------------------------------------------
  477. " AutoInstall: only if doautoinstall has been requested by the plugin itself
  478. " --------------------------------------------------------------------------
  479. " call Decho("checking if plugin requested autoinstall: doautoinstall=".doautoinstall)
  480. if doautoinstall
  481. " call Decho(" ")
  482. " call Decho("Autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname))
  483. if filereadable(sname)
  484. " call Decho("<".sname."> is readable")
  485. " call Decho("exe silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall))
  486. exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall)
  487. let curdir = fnameescape(substitute(getcwd(),'\','/','ge'))
  488. let installdir= curdir."/Installed"
  489. if !isdirectory(installdir)
  490. call mkdir(installdir)
  491. endif
  492. " call Decho("curdir<".curdir."> installdir<".installdir.">")
  493. " call Decho("exe cd ".fnameescape(s:autoinstall))
  494. exe "cd ".fnameescape(s:autoinstall)
  495. " determine target directory for moves
  496. let firstdir= substitute(&rtp,',.*$','','')
  497. let pname = substitute(sname,'\..*','.vim','')
  498. " call Decho("determine tgtdir: is <".firstdir.'/AsNeeded/'.pname." readable?")
  499. if filereadable(firstdir.'/AsNeeded/'.pname)
  500. let tgtdir= "AsNeeded"
  501. else
  502. let tgtdir= "plugin"
  503. endif
  504. " call Decho("tgtdir<".tgtdir."> pname<".pname.">")
  505. " decompress
  506. if sname =~ '\.bz2$'
  507. " call Decho("decompress: attempt to bunzip2 ".sname)
  508. exe "sil !bunzip2 ".shellescape(sname)
  509. let sname= substitute(sname,'\.bz2$','','')
  510. " call Decho("decompress: new sname<".sname."> after bunzip2")
  511. elseif sname =~ '\.gz$'
  512. " call Decho("decompress: attempt to gunzip ".sname)
  513. exe "sil !gunzip ".shellescape(sname)
  514. let sname= substitute(sname,'\.gz$','','')
  515. " call Decho("decompress: new sname<".sname."> after gunzip")
  516. elseif sname =~ '\.xz$'
  517. " call Decho("decompress: attempt to unxz ".sname)
  518. exe "sil !unxz ".shellescape(sname)
  519. let sname= substitute(sname,'\.xz$','','')
  520. " call Decho("decompress: new sname<".sname."> after unxz")
  521. else
  522. " call Decho("no decompression needed")
  523. endif
  524. " distribute archive(.zip, .tar, .vba, ...) contents
  525. if sname =~ '\.zip$'
  526. " call Decho("dearchive: attempt to unzip ".sname)
  527. exe "silent !unzip -o ".shellescape(sname)
  528. elseif sname =~ '\.tar$'
  529. " call Decho("dearchive: attempt to untar ".sname)
  530. exe "silent !tar -xvf ".shellescape(sname)
  531. elseif sname =~ '\.tgz$'
  532. " call Decho("dearchive: attempt to untar+gunzip ".sname)
  533. exe "silent !tar -zxvf ".shellescape(sname)
  534. elseif sname =~ '\.taz$'
  535. " call Decho("dearchive: attempt to untar+uncompress ".sname)
  536. exe "silent !tar -Zxvf ".shellescape(sname)
  537. elseif sname =~ '\.tbz$'
  538. " call Decho("dearchive: attempt to untar+bunzip2 ".sname)
  539. exe "silent !tar -jxvf ".shellescape(sname)
  540. elseif sname =~ '\.txz$'
  541. " call Decho("dearchive: attempt to untar+xz ".sname)
  542. exe "silent !tar -Jxvf ".shellescape(sname)
  543. elseif sname =~ '\.vba$'
  544. " call Decho("dearchive: attempt to handle a vimball: ".sname)
  545. silent 1split
  546. if exists("g:vimball_home")
  547. let oldvimballhome= g:vimball_home
  548. endif
  549. let g:vimball_home= s:autoinstall
  550. exe "silent e ".fnameescape(sname)
  551. silent so %
  552. silent q
  553. if exists("oldvimballhome")
  554. let g:vimball_home= oldvimballhome
  555. else
  556. unlet g:vimball_home
  557. endif
  558. else
  559. " call Decho("no dearchiving needed")
  560. endif
  561. " ---------------------------------------------
  562. " move plugin to plugin/ or AsNeeded/ directory
  563. " ---------------------------------------------
  564. if sname =~ '.vim$'
  565. " call Decho("dearchive: attempt to simply move ".sname." to ".tgtdir)
  566. exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".tgtdir
  567. else
  568. " call Decho("dearchive: move <".sname."> to installdir<".installdir.">")
  569. exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".installdir
  570. endif
  571. if tgtdir != "plugin"
  572. " call Decho("exe silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir)
  573. exe "silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir
  574. endif
  575. " helptags step
  576. let docdir= substitute(&rtp,',.*','','e')."/doc"
  577. " call Decho("helptags: docdir<".docdir.">")
  578. exe "helptags ".fnameescape(docdir)
  579. exe "cd ".fnameescape(curdir)
  580. endif
  581. if fname !~ ':AutoInstall:'
  582. let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
  583. else
  584. let modline=scriptid." ".latestsrcid." ".fname.cmmnt
  585. endif
  586. else
  587. let modline=scriptid." ".latestsrcid." ".fname.cmmnt
  588. endif
  589. " update the data in the <GetLatestVimScripts.dat> file
  590. call setline(line("."),modline)
  591. " call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
  592. " else " Decho
  593. " call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
  594. endif
  595. " restore options
  596. let &t_ti = t_ti
  597. let &t_te = t_te
  598. let &rs = rs
  599. let @a = rega
  600. " call Dredir("BUFFER TEST (GetOneScript)","ls!")
  601. " call Dret("GetOneScript")
  602. endfun
  603. " ---------------------------------------------------------------------
  604. " Restore Options: {{{1
  605. let &cpo= s:keepcpo
  606. unlet s:keepcpo
  607. " ---------------------------------------------------------------------
  608. " Modelines: {{{1
  609. " vim: ts=8 sts=2 fdm=marker nowrap