19964e468SBram Moolenaar" ---------------------------------------------------------------------
29964e468SBram Moolenaar" getscript.vim
39964e468SBram Moolenaar"  Author:	Charles E. Campbell, Jr.
4*6be7f873SBram Moolenaar"  Date:	Jan 17, 2012
5*6be7f873SBram Moolenaar"  Version:	34
69964e468SBram Moolenaar"  Installing:	:help glvs-install
79964e468SBram Moolenaar"  Usage:	:help glvs
89964e468SBram Moolenaar"
99964e468SBram Moolenaar" GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
109e368dbaSBram Moolenaar"redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
119964e468SBram Moolenaar" ---------------------------------------------------------------------
129964e468SBram Moolenaar" Initialization:	{{{1
139964e468SBram Moolenaar" if you're sourcing this file, surely you can't be
143577c6faSBram Moolenaar" expecting vim to be in its vi-compatible mode!
155c73622aSBram Moolenaarif exists("g:loaded_getscript")
165c73622aSBram Moolenaar finish
175c73622aSBram Moolenaarendif
18*6be7f873SBram Moolenaarlet g:loaded_getscript= "v34"
199964e468SBram Moolenaarif &cp
209964e468SBram Moolenaar echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
219964e468SBram Moolenaar finish
229964e468SBram Moolenaarendif
235c73622aSBram Moolenaarif v:version < 702
245c73622aSBram Moolenaar echohl WarningMsg
255c73622aSBram Moolenaar echo "***warning*** this version of getscript needs vim 7.2"
265c73622aSBram Moolenaar echohl Normal
275c73622aSBram Moolenaar finish
285c73622aSBram Moolenaarendif
299964e468SBram Moolenaarlet s:keepcpo = &cpo
309964e468SBram Moolenaarset cpo&vim
3182038d73SBram Moolenaar"DechoTabOn
329964e468SBram Moolenaar
333577c6faSBram Moolenaar" ---------------------------
349964e468SBram Moolenaar" Global Variables: {{{1
353577c6faSBram Moolenaar" ---------------------------
363577c6faSBram Moolenaar" Cygwin Detection ------- {{{2
373577c6faSBram Moolenaarif !exists("g:getscript_cygwin")
383577c6faSBram Moolenaar if has("win32") || has("win95") || has("win64") || has("win16")
393577c6faSBram Moolenaar  if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
403577c6faSBram Moolenaar   let g:getscript_cygwin= 1
413577c6faSBram Moolenaar  else
423577c6faSBram Moolenaar   let g:getscript_cygwin= 0
433577c6faSBram Moolenaar  endif
443577c6faSBram Moolenaar else
453577c6faSBram Moolenaar  let g:getscript_cygwin= 0
463577c6faSBram Moolenaar endif
473577c6faSBram Moolenaarendif
483577c6faSBram Moolenaar
493577c6faSBram Moolenaar" wget vs curl {{{2
509964e468SBram Moolenaarif !exists("g:GetLatestVimScripts_wget")
519964e468SBram Moolenaar if executable("wget")
529964e468SBram Moolenaar  let g:GetLatestVimScripts_wget= "wget"
539964e468SBram Moolenaar elseif executable("curl")
549964e468SBram Moolenaar  let g:GetLatestVimScripts_wget= "curl"
559964e468SBram Moolenaar else
569964e468SBram Moolenaar  let g:GetLatestVimScripts_wget    = 'echo "GetLatestVimScripts needs wget or curl"'
579964e468SBram Moolenaar  let g:GetLatestVimScripts_options = ""
589964e468SBram Moolenaar endif
599964e468SBram Moolenaarendif
609964e468SBram Moolenaar
619964e468SBram Moolenaar" options that wget and curl require:
629964e468SBram Moolenaarif !exists("g:GetLatestVimScripts_options")
639964e468SBram Moolenaar if g:GetLatestVimScripts_wget == "wget"
649964e468SBram Moolenaar  let g:GetLatestVimScripts_options= "-q -O"
659964e468SBram Moolenaar elseif g:GetLatestVimScripts_wget == "curl"
669964e468SBram Moolenaar  let g:GetLatestVimScripts_options= "-s -O"
679964e468SBram Moolenaar else
689964e468SBram Moolenaar  let g:GetLatestVimScripts_options= ""
699964e468SBram Moolenaar endif
709964e468SBram Moolenaarendif
719964e468SBram Moolenaar
729964e468SBram Moolenaar" by default, allow autoinstall lines to work
739964e468SBram Moolenaarif !exists("g:GetLatestVimScripts_allowautoinstall")
749964e468SBram Moolenaar let g:GetLatestVimScripts_allowautoinstall= 1
759964e468SBram Moolenaarendif
769964e468SBram Moolenaar
779964e468SBram Moolenaar"" For debugging:
789964e468SBram Moolenaar"let g:GetLatestVimScripts_wget    = "echo"
799964e468SBram Moolenaar"let g:GetLatestVimScripts_options = "options"
809964e468SBram Moolenaar
819964e468SBram Moolenaar" ---------------------------------------------------------------------
829964e468SBram Moolenaar" Check If AutoInstall Capable: {{{1
839964e468SBram Moolenaarlet s:autoinstall= ""
849964e468SBram Moolenaarif g:GetLatestVimScripts_allowautoinstall
859964e468SBram Moolenaar
869964e468SBram Moolenaar if (has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")) && &shell != "bash"
879964e468SBram Moolenaar  " windows (but not cygwin/bash)
889964e468SBram Moolenaar  let s:dotvim= "vimfiles"
899964e468SBram Moolenaar  if !exists("g:GetLatestVimScripts_mv")
909964e468SBram Moolenaar   let g:GetLatestVimScripts_mv= "ren"
919964e468SBram Moolenaar  endif
929964e468SBram Moolenaar
939964e468SBram Moolenaar else
949964e468SBram Moolenaar  " unix
959964e468SBram Moolenaar  let s:dotvim= ".vim"
969964e468SBram Moolenaar  if !exists("g:GetLatestVimScripts_mv")
979964e468SBram Moolenaar   let g:GetLatestVimScripts_mv= "mv"
989964e468SBram Moolenaar  endif
999964e468SBram Moolenaar endif
1009964e468SBram Moolenaar
1015c73622aSBram Moolenaar if exists("g:GetLatestVimScripts_autoinstalldir") && isdirectory(g:GetLatestVimScripts_autoinstalldir)
1025c73622aSBram Moolenaar  let s:autoinstall= g:GetLatestVimScripts_autoinstalldir"
1035c73622aSBram Moolenaar elseif exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim)
1049964e468SBram Moolenaar  let s:autoinstall= $HOME."/".s:dotvim
1059964e468SBram Moolenaar endif
1069964e468SBram Moolenaar" call Decho("s:autoinstall<".s:autoinstall.">")
1079964e468SBram Moolenaar"else "Decho
1089964e468SBram Moolenaar" call Decho("g:GetLatestVimScripts_allowautoinstall=".g:GetLatestVimScripts_allowautoinstall.": :AutoInstall: disabled")
1099964e468SBram Moolenaarendif
1109964e468SBram Moolenaar
1119964e468SBram Moolenaar" ---------------------------------------------------------------------
1129964e468SBram Moolenaar"  Public Interface: {{{1
1139964e468SBram Moolenaarcom!        -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
1149964e468SBram Moolenaarcom!        -nargs=0 GetScript           call getscript#GetLatestVimScripts()
1159964e468SBram Moolenaarsilent! com -nargs=0 GLVS                call getscript#GetLatestVimScripts()
1169964e468SBram Moolenaar
1179964e468SBram Moolenaar" ---------------------------------------------------------------------
1189964e468SBram Moolenaar" GetLatestVimScripts: this function gets the latest versions of {{{1
1199964e468SBram Moolenaar"                      scripts based on the list in
1209964e468SBram Moolenaar"   (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
1219964e468SBram Moolenaarfun! getscript#GetLatestVimScripts()
1229964e468SBram Moolenaar"  call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">")
1239964e468SBram Moolenaar
1249964e468SBram Moolenaar" insure that wget is executable
1259964e468SBram Moolenaar  if executable(g:GetLatestVimScripts_wget) != 1
1269964e468SBram Moolenaar   echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system"
1279964e468SBram Moolenaar"   call Dret("GetLatestVimScripts : wget not executable/availble")
1289964e468SBram Moolenaar   return
1299964e468SBram Moolenaar  endif
1309964e468SBram Moolenaar
131c236c16dSBram Moolenaar  " insure that fnameescape() is available
132c236c16dSBram Moolenaar  if !exists("*fnameescape")
133c236c16dSBram Moolenaar   echoerr "GetLatestVimScripts needs fnameescape() (provided by 7.1.299 or later)"
134c236c16dSBram Moolenaar   return
135c236c16dSBram Moolenaar  endif
136c236c16dSBram Moolenaar
1379964e468SBram Moolenaar  " Find the .../GetLatest subdirectory under the runtimepath
1389964e468SBram Moolenaar  for datadir in split(&rtp,',') + ['']
1399964e468SBram Moolenaar   if isdirectory(datadir."/GetLatest")
1409964e468SBram Moolenaar"    call Decho("found directory<".datadir.">")
1419964e468SBram Moolenaar    let datadir= datadir . "/GetLatest"
1429964e468SBram Moolenaar    break
1439964e468SBram Moolenaar   endif
1449964e468SBram Moolenaar   if filereadable(datadir."GetLatestVimScripts.dat")
1459964e468SBram Moolenaar"    call Decho("found ".datadir."/GetLatestVimScripts.dat")
1469964e468SBram Moolenaar    break
1479964e468SBram Moolenaar   endif
1489964e468SBram Moolenaar  endfor
14982038d73SBram Moolenaar
1509964e468SBram Moolenaar  " Sanity checks: readability and writability
1519964e468SBram Moolenaar  if datadir == ""
1529964e468SBram Moolenaar   echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install'
1539964e468SBram Moolenaar"   call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory")
1549964e468SBram Moolenaar   return
1559964e468SBram Moolenaar  endif
1569964e468SBram Moolenaar  if filewritable(datadir) != 2
1579964e468SBram Moolenaar   echoerr "(getLatestVimScripts) Your ".datadir." isn't writable"
1589964e468SBram Moolenaar"   call Dret("GetLatestVimScripts : non-writable directory<".datadir.">")
1599964e468SBram Moolenaar   return
1609964e468SBram Moolenaar  endif
1619964e468SBram Moolenaar  let datafile= datadir."/GetLatestVimScripts.dat"
1629964e468SBram Moolenaar  if !filereadable(datafile)
1639964e468SBram Moolenaar   echoerr "Your data file<".datafile."> isn't readable"
1649964e468SBram Moolenaar"   call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">")
1659964e468SBram Moolenaar   return
1669964e468SBram Moolenaar  endif
1679964e468SBram Moolenaar  if !filewritable(datafile)
1689964e468SBram Moolenaar   echoerr "Your data file<".datafile."> isn't writable"
1699964e468SBram Moolenaar"   call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">")
1709964e468SBram Moolenaar   return
1719964e468SBram Moolenaar  endif
1725c73622aSBram Moolenaar  " --------------------
1735c73622aSBram Moolenaar  " Passed sanity checks
1745c73622aSBram Moolenaar  " --------------------
1755c73622aSBram Moolenaar
1769964e468SBram Moolenaar"  call Decho("datadir  <".datadir.">")
1779964e468SBram Moolenaar"  call Decho("datafile <".datafile.">")
1789964e468SBram Moolenaar
1795c73622aSBram Moolenaar  " don't let any event handlers interfere (like winmanager's, taglist's, etc)
1809964e468SBram Moolenaar  let eikeep  = &ei
181c236c16dSBram Moolenaar  let hlskeep = &hls
1825c73622aSBram Moolenaar  let acdkeep = &acd
1835c73622aSBram Moolenaar  set ei=all hls&vim noacd
1849964e468SBram Moolenaar
1855c73622aSBram Moolenaar  " Edit the datafile (ie. GetLatestVimScripts.dat):
1865c73622aSBram Moolenaar  " 1. record current directory (origdir),
1875c73622aSBram Moolenaar  " 2. change directory to datadir,
1885c73622aSBram Moolenaar  " 3. split window
1895c73622aSBram Moolenaar  " 4. edit datafile
1909964e468SBram Moolenaar  let origdir= getcwd()
1913577c6faSBram Moolenaar"  call Decho("exe cd ".fnameescape(substitute(datadir,'\','/','ge')))
1923577c6faSBram Moolenaar  exe "cd ".fnameescape(substitute(datadir,'\','/','ge'))
1939964e468SBram Moolenaar  split
1943577c6faSBram Moolenaar"  call Decho("exe  e ".fnameescape(substitute(datafile,'\','/','ge')))
1953577c6faSBram Moolenaar  exe "e ".fnameescape(substitute(datafile,'\','/','ge'))
1969964e468SBram Moolenaar  res 1000
1979964e468SBram Moolenaar  let s:downloads = 0
1989964e468SBram Moolenaar  let s:downerrors= 0
1999964e468SBram Moolenaar
2009964e468SBram Moolenaar  " Check on dependencies mentioned in plugins
2019964e468SBram Moolenaar"  call Decho(" ")
2029964e468SBram Moolenaar"  call Decho("searching plugins for GetLatestVimScripts dependencies")
2039964e468SBram Moolenaar  let lastline    = line("$")
20482038d73SBram Moolenaar"  call Decho("lastline#".lastline)
2055c73622aSBram Moolenaar  let firstdir    = substitute(&rtp,',.*$','','')
2065c73622aSBram Moolenaar  let plugins     = split(globpath(firstdir,"plugin/*.vim"),'\n')
2075c73622aSBram Moolenaar  let plugins     = plugins + split(globpath(firstdir,"AsNeeded/*.vim"),'\n')
2089964e468SBram Moolenaar  let foundscript = 0
2099964e468SBram Moolenaar
2105c73622aSBram Moolenaar  " this loop updates the GetLatestVimScripts.dat file
2115c73622aSBram Moolenaar  " with dependencies explicitly mentioned in the plugins
2125c73622aSBram Moolenaar  " via   GetLatestVimScripts: ... lines
2135c73622aSBram Moolenaar  " It reads the plugin script at the end of the GetLatestVimScripts.dat
2145c73622aSBram Moolenaar  " file, examines it, and then removes it.
21582038d73SBram Moolenaar  for plugin in plugins
2165c73622aSBram Moolenaar"   call Decho(" ")
2173577c6faSBram Moolenaar"   call Decho("plugin<".plugin.">")
21882038d73SBram Moolenaar
21982038d73SBram Moolenaar   " read plugin in
2203577c6faSBram Moolenaar   " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it
2219964e468SBram Moolenaar   $
2229964e468SBram Moolenaar"   call Decho(".dependency checking<".plugin."> line$=".line("$"))
2235c73622aSBram Moolenaar"   call Decho("..exe silent r ".fnameescape(plugin))
2243577c6faSBram Moolenaar   exe "silent r ".fnameescape(plugin)
2253577c6faSBram Moolenaar   exe "silent bwipe ".bufnr("#")
22682038d73SBram Moolenaar
2279964e468SBram Moolenaar   while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
2285c73622aSBram Moolenaar    let depscript   = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
2295c73622aSBram Moolenaar    let depscriptid = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\(\d\+\)\s\+.*$','\1','')
2309964e468SBram Moolenaar    let llp1        = lastline+1
2315c73622aSBram Moolenaar"    call Decho("..depscript<".depscript.">")
2329964e468SBram Moolenaar
2335c73622aSBram Moolenaar    " found a "GetLatestVimScripts: # #" line in the script;
2345c73622aSBram Moolenaar    " check if its already in the datafile by searching backwards from llp1,
2355c73622aSBram Moolenaar    " the (prior to reading in the plugin script) last line plus one of the GetLatestVimScripts.dat file,
2365c73622aSBram Moolenaar    " for the script-id with no wrapping allowed.
2379964e468SBram Moolenaar    let curline     = line(".")
2385c73622aSBram Moolenaar    let noai_script = substitute(depscript,'\s*:AutoInstall:\s*','','e')
2399964e468SBram Moolenaar    exe llp1
2405c73622aSBram Moolenaar    let srchline    = search('^\s*'.depscriptid.'\s\+\d\+\s\+.*$','bW')
2415c73622aSBram Moolenaar    if srchline == 0
2425c73622aSBram Moolenaar     " this second search is taken when, for example, a   0 0 scriptname  is to be skipped over
2439964e468SBram Moolenaar     let srchline= search('\<'.noai_script.'\>','bW')
2445c73622aSBram Moolenaar    endif
2455c73622aSBram Moolenaar"    call Decho("..noai_script<".noai_script."> depscriptid#".depscriptid." srchline#".srchline." curline#".line(".")." lastline#".lastline)
2469964e468SBram Moolenaar
2479964e468SBram Moolenaar    if srchline == 0
2489964e468SBram Moolenaar     " found a new script to permanently include in the datafile
2499964e468SBram Moolenaar     let keep_rega   = @a
2509964e468SBram Moolenaar     let @a          = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','')
2515c73622aSBram Moolenaar     echomsg "Appending <".@a."> to ".datafile." for ".depscript
2525c73622aSBram Moolenaar"     call Decho("..Appending <".@a."> to ".datafile." for ".depscript)
2539964e468SBram Moolenaar     exe lastline."put a"
2549964e468SBram Moolenaar     let @a          = keep_rega
2559964e468SBram Moolenaar     let lastline    = llp1
2569964e468SBram Moolenaar     let curline     = curline     + 1
2579964e468SBram Moolenaar     let foundscript = foundscript + 1
2589964e468SBram Moolenaar"    else	" Decho
2599964e468SBram Moolenaar"     call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")")
2609964e468SBram Moolenaar    endif
2619964e468SBram Moolenaar
2629964e468SBram Moolenaar    let curline = curline + 1
2639964e468SBram Moolenaar    exe curline
2649964e468SBram Moolenaar   endwhile
26582038d73SBram Moolenaar
2665c73622aSBram Moolenaar   " llp1: last line plus one
2679964e468SBram Moolenaar   let llp1= lastline + 1
2689964e468SBram Moolenaar"   call Decho(".deleting lines: ".llp1.",$d")
2699964e468SBram Moolenaar   exe "silent! ".llp1.",$d"
27082038d73SBram Moolenaar  endfor
27182038d73SBram Moolenaar"  call Decho("--- end dependency checking loop ---  foundscript=".foundscript)
27282038d73SBram Moolenaar"  call Decho(" ")
2733577c6faSBram Moolenaar"  call Dredir("BUFFER TEST (GetLatestVimScripts 1)","ls!")
2749964e468SBram Moolenaar
2759964e468SBram Moolenaar  if foundscript == 0
2763577c6faSBram Moolenaar   setlocal nomod
2779964e468SBram Moolenaar  endif
2789964e468SBram Moolenaar
2795c73622aSBram Moolenaar  " --------------------------------------------------------------------
2809964e468SBram Moolenaar  " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
2815c73622aSBram Moolenaar  " --------------------------------------------------------------------
28282038d73SBram Moolenaar"  call Decho("begin: checking out-of-date scripts using datafile<".datafile.">")
2833577c6faSBram Moolenaar  setlocal lz
2849964e468SBram Moolenaar  1
28582038d73SBram Moolenaar"  /^-----/,$g/^\s*\d/call Decho(getline("."))
28682038d73SBram Moolenaar  1
28782038d73SBram Moolenaar  /^-----/,$g/^\s*\d/call s:GetOneScript()
28882038d73SBram Moolenaar"  call Decho("--- end out-of-date checking --- ")
2899964e468SBram Moolenaar
2909964e468SBram Moolenaar  " Final report (an echomsg)
2919964e468SBram Moolenaar  try
2929964e468SBram Moolenaar   silent! ?^-------?
2939964e468SBram Moolenaar  catch /^Vim\%((\a\+)\)\=:E114/
2949964e468SBram Moolenaar"   call Dret("GetLatestVimScripts : nothing done!")
2959964e468SBram Moolenaar   return
2969964e468SBram Moolenaar  endtry
2979964e468SBram Moolenaar  exe "norm! kz\<CR>"
2989964e468SBram Moolenaar  redraw!
2999964e468SBram Moolenaar  let s:msg = ""
3009964e468SBram Moolenaar  if s:downloads == 1
3019964e468SBram Moolenaar  let s:msg = "Downloaded one updated script to <".datadir.">"
3029964e468SBram Moolenaar  elseif s:downloads == 2
3039964e468SBram Moolenaar   let s:msg= "Downloaded two updated scripts to <".datadir.">"
3049964e468SBram Moolenaar  elseif s:downloads > 1
3059964e468SBram Moolenaar   let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">"
3069964e468SBram Moolenaar  else
3079964e468SBram Moolenaar   let s:msg= "Everything was already current"
3089964e468SBram Moolenaar  endif
3099964e468SBram Moolenaar  if s:downerrors > 0
3109964e468SBram Moolenaar   let s:msg= s:msg." (".s:downerrors." downloading errors)"
3119964e468SBram Moolenaar  endif
3129964e468SBram Moolenaar  echomsg s:msg
3139964e468SBram Moolenaar  " save the file
3149964e468SBram Moolenaar  if &mod
3159964e468SBram Moolenaar   silent! w!
3169964e468SBram Moolenaar  endif
3179964e468SBram Moolenaar  q
3189964e468SBram Moolenaar
3199964e468SBram Moolenaar  " restore events and current directory
3203577c6faSBram Moolenaar  exe "cd ".fnameescape(substitute(origdir,'\','/','ge'))
3219964e468SBram Moolenaar  let &ei  = eikeep
322c236c16dSBram Moolenaar  let &hls = hlskeep
3235c73622aSBram Moolenaar  let &acd = acdkeep
3243577c6faSBram Moolenaar  setlocal nolz
3253577c6faSBram Moolenaar"  call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!")
3269964e468SBram Moolenaar"  call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
3279964e468SBram Moolenaarendfun
3289964e468SBram Moolenaar
3293577c6faSBram Moolenaar" ---------------------------------------------------------------------
3303577c6faSBram Moolenaar"  GetOneScript: (Get Latest Vim Script) this function operates {{{1
3313577c6faSBram Moolenaar"    on the current line, interpreting two numbers and text as
3323577c6faSBram Moolenaar"    ScriptID, SourceID, and Filename.
3335c73622aSBram Moolenaar"    It downloads any scripts that have newer versions from vim.sourceforge.net.
3343577c6faSBram Moolenaarfun! s:GetOneScript(...)
3353577c6faSBram Moolenaar"   call Dfunc("GetOneScript()")
3363577c6faSBram Moolenaar
3373577c6faSBram Moolenaar " set options to allow progress to be shown on screen
3383577c6faSBram Moolenaar  let rega= @a
3393577c6faSBram Moolenaar  let t_ti= &t_ti
3403577c6faSBram Moolenaar  let t_te= &t_te
3413577c6faSBram Moolenaar  let rs  = &rs
3423577c6faSBram Moolenaar  set t_ti= t_te= nors
3433577c6faSBram Moolenaar
3443577c6faSBram Moolenaar " put current line on top-of-screen and interpret it into
3453577c6faSBram Moolenaar " a      script identifer  : used to obtain webpage
3463577c6faSBram Moolenaar "        source identifier : used to identify current version
3473577c6faSBram Moolenaar " and an associated comment: used to report on what's being considered
3483577c6faSBram Moolenaar  if a:0 >= 3
3493577c6faSBram Moolenaar   let scriptid = a:1
3503577c6faSBram Moolenaar   let srcid    = a:2
3513577c6faSBram Moolenaar   let fname    = a:3
3523577c6faSBram Moolenaar   let cmmnt    = ""
3533577c6faSBram Moolenaar"   call Decho("scriptid<".scriptid.">")
3543577c6faSBram Moolenaar"   call Decho("srcid   <".srcid.">")
3553577c6faSBram Moolenaar"   call Decho("fname   <".fname.">")
3563577c6faSBram Moolenaar  else
3573577c6faSBram Moolenaar   let curline  = getline(".")
3583577c6faSBram Moolenaar   if curline =~ '^\s*#'
3593577c6faSBram Moolenaar    let @a= rega
3603577c6faSBram Moolenaar"    call Dret("GetOneScript : skipping a pure comment line")
3613577c6faSBram Moolenaar    return
3623577c6faSBram Moolenaar   endif
3633577c6faSBram Moolenaar   let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
3643577c6faSBram Moolenaar   try
3653577c6faSBram Moolenaar    let scriptid = substitute(curline,parsepat,'\1','e')
3663577c6faSBram Moolenaar   catch /^Vim\%((\a\+)\)\=:E486/
3673577c6faSBram Moolenaar    let scriptid= 0
3683577c6faSBram Moolenaar   endtry
3693577c6faSBram Moolenaar   try
3703577c6faSBram Moolenaar    let srcid    = substitute(curline,parsepat,'\2','e')
3713577c6faSBram Moolenaar   catch /^Vim\%((\a\+)\)\=:E486/
3723577c6faSBram Moolenaar    let srcid= 0
3733577c6faSBram Moolenaar   endtry
3743577c6faSBram Moolenaar   try
3753577c6faSBram Moolenaar    let fname= substitute(curline,parsepat,'\3','e')
3763577c6faSBram Moolenaar   catch /^Vim\%((\a\+)\)\=:E486/
3773577c6faSBram Moolenaar    let fname= ""
3783577c6faSBram Moolenaar   endtry
3793577c6faSBram Moolenaar   try
3803577c6faSBram Moolenaar    let cmmnt= substitute(curline,parsepat,'\4','e')
3813577c6faSBram Moolenaar   catch /^Vim\%((\a\+)\)\=:E486/
3823577c6faSBram Moolenaar    let cmmnt= ""
3833577c6faSBram Moolenaar   endtry
3843577c6faSBram Moolenaar"   call Decho("curline <".curline.">")
3853577c6faSBram Moolenaar"   call Decho("parsepat<".parsepat.">")
3863577c6faSBram Moolenaar"   call Decho("scriptid<".scriptid.">")
3873577c6faSBram Moolenaar"   call Decho("srcid   <".srcid.">")
3883577c6faSBram Moolenaar"   call Decho("fname   <".fname.">")
3893577c6faSBram Moolenaar  endif
3903577c6faSBram Moolenaar
3915c73622aSBram Moolenaar  " plugin author protection from downloading his/her own scripts atop their latest work
3923577c6faSBram Moolenaar  if scriptid == 0 || srcid == 0
3933577c6faSBram Moolenaar   " When looking for :AutoInstall: lines, skip scripts that have   0 0 scriptname
3943577c6faSBram Moolenaar   let @a= rega
3953577c6faSBram Moolenaar"   call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
3963577c6faSBram Moolenaar   return
3973577c6faSBram Moolenaar  endif
3983577c6faSBram Moolenaar
3993577c6faSBram Moolenaar  let doautoinstall= 0
4003577c6faSBram Moolenaar  if fname =~ ":AutoInstall:"
4013577c6faSBram Moolenaar"   call Decho("case AutoInstall: fname<".fname.">")
4023577c6faSBram Moolenaar   let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
4033577c6faSBram Moolenaar"   call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
4043577c6faSBram Moolenaar   if s:autoinstall != ""
4053577c6faSBram Moolenaar    let doautoinstall = g:GetLatestVimScripts_allowautoinstall
4063577c6faSBram Moolenaar   endif
4073577c6faSBram Moolenaar  else
4083577c6faSBram Moolenaar   let aicmmnt= fname
4093577c6faSBram Moolenaar  endif
4103577c6faSBram Moolenaar"  call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
4113577c6faSBram Moolenaar
4123577c6faSBram Moolenaar  exe "norm z\<CR>"
4133577c6faSBram Moolenaar  redraw!
4143577c6faSBram Moolenaar"  call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
4153577c6faSBram Moolenaar  echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
4163577c6faSBram Moolenaar
4175c73622aSBram Moolenaar  " grab a copy of the plugin's vim.sourceforge.net webpage
4185c73622aSBram Moolenaar  let scriptaddr = 'http://vim.sourceforge.net/script.php?script_id='.scriptid
4193577c6faSBram Moolenaar  let tmpfile    = tempname()
4203577c6faSBram Moolenaar  let v:errmsg   = ""
4213577c6faSBram Moolenaar
4223577c6faSBram Moolenaar  " make up to three tries at downloading the description
4233577c6faSBram Moolenaar  let itry= 1
4243577c6faSBram Moolenaar  while itry <= 3
4255c73622aSBram Moolenaar"   call Decho(".try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
4263577c6faSBram Moolenaar   if has("win32") || has("win16") || has("win95")
4275c73622aSBram Moolenaar"    call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)."|bw!")
4285c73622aSBram Moolenaar    new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)|bw!
4293577c6faSBram Moolenaar   else
4305c73622aSBram Moolenaar"    call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr))
4315c73622aSBram Moolenaar    exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr)
4323577c6faSBram Moolenaar   endif
4333577c6faSBram Moolenaar   if itry == 1
4343577c6faSBram Moolenaar    exe "silent vsplit ".fnameescape(tmpfile)
4353577c6faSBram Moolenaar   else
4363577c6faSBram Moolenaar    silent! e %
4373577c6faSBram Moolenaar   endif
4383577c6faSBram Moolenaar   setlocal bh=wipe
4393577c6faSBram Moolenaar
4403577c6faSBram Moolenaar   " find the latest source-id in the plugin's webpage
4413577c6faSBram Moolenaar   silent! 1
4423577c6faSBram Moolenaar   let findpkg= search('Click on the package to download','W')
4433577c6faSBram Moolenaar   if findpkg > 0
4443577c6faSBram Moolenaar    break
4453577c6faSBram Moolenaar   endif
4463577c6faSBram Moolenaar   let itry= itry + 1
4473577c6faSBram Moolenaar  endwhile
4483577c6faSBram Moolenaar"  call Decho(" --- end downloading tries while loop --- itry=".itry)
4493577c6faSBram Moolenaar
4503577c6faSBram Moolenaar  " testing: did finding "Click on the package..." fail?
4513577c6faSBram Moolenaar  if findpkg == 0 || itry >= 4
4523577c6faSBram Moolenaar   silent q!
4533577c6faSBram Moolenaar   call delete(tmpfile)
4543577c6faSBram Moolenaar  " restore options
4553577c6faSBram Moolenaar   let &t_ti        = t_ti
4563577c6faSBram Moolenaar   let &t_te        = t_te
4573577c6faSBram Moolenaar   let &rs          = rs
4583577c6faSBram Moolenaar   let s:downerrors = s:downerrors + 1
4593577c6faSBram Moolenaar"   call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
4603577c6faSBram Moolenaar   echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
4613577c6faSBram Moolenaar"   call Dret("GetOneScript : srch for /Click on the package/ failed")
4623577c6faSBram Moolenaar   let @a= rega
4633577c6faSBram Moolenaar   return
4643577c6faSBram Moolenaar  endif
4653577c6faSBram Moolenaar"  call Decho('found "Click on the package to download"')
4663577c6faSBram Moolenaar
4673577c6faSBram Moolenaar  let findsrcid= search('src_id=','W')
4683577c6faSBram Moolenaar  if findsrcid == 0
4693577c6faSBram Moolenaar   silent q!
4703577c6faSBram Moolenaar   call delete(tmpfile)
4713577c6faSBram Moolenaar  " restore options
4723577c6faSBram Moolenaar   let &t_ti        = t_ti
4733577c6faSBram Moolenaar   let &t_te        = t_te
4743577c6faSBram Moolenaar   let &rs          = rs
4753577c6faSBram Moolenaar   let s:downerrors = s:downerrors + 1
4763577c6faSBram Moolenaar"   call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
4773577c6faSBram Moolenaar   echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
4783577c6faSBram Moolenaar   let @a= rega
4793577c6faSBram Moolenaar"  call Dret("GetOneScript : srch for /src_id/ failed")
4803577c6faSBram Moolenaar   return
4813577c6faSBram Moolenaar  endif
4823577c6faSBram Moolenaar"  call Decho('found "src_id=" in description page')
4833577c6faSBram Moolenaar
4843577c6faSBram Moolenaar  let srcidpat   = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
4853577c6faSBram Moolenaar  let latestsrcid= substitute(getline("."),srcidpat,'\1','')
4863577c6faSBram Moolenaar  let sname      = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
4873577c6faSBram Moolenaar"  call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
4883577c6faSBram Moolenaar  silent q!
4893577c6faSBram Moolenaar  call delete(tmpfile)
4903577c6faSBram Moolenaar
4913577c6faSBram Moolenaar  " convert the strings-of-numbers into numbers
4923577c6faSBram Moolenaar  let srcid       = srcid       + 0
4933577c6faSBram Moolenaar  let latestsrcid = latestsrcid + 0
4943577c6faSBram Moolenaar"  call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
4953577c6faSBram Moolenaar
4965c73622aSBram Moolenaar  " has the plugin's most-recent srcid increased, which indicates that it has been updated
4973577c6faSBram Moolenaar  if latestsrcid > srcid
4983577c6faSBram Moolenaar"   call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
4993577c6faSBram Moolenaar
5003577c6faSBram Moolenaar   let s:downloads= s:downloads + 1
5013577c6faSBram Moolenaar   if sname == bufname("%")
5023577c6faSBram Moolenaar    " GetLatestVimScript has to be careful about downloading itself
5033577c6faSBram Moolenaar    let sname= "NEW_".sname
5043577c6faSBram Moolenaar   endif
5053577c6faSBram Moolenaar
5065c73622aSBram Moolenaar   " -----------------------------------------------------------------------------
5073577c6faSBram Moolenaar   " the plugin has been updated since we last obtained it, so download a new copy
5085c73622aSBram Moolenaar   " -----------------------------------------------------------------------------
5095c73622aSBram Moolenaar"   call Decho(".downloading new <".sname.">")
5105c73622aSBram Moolenaar   echomsg ".downloading new <".sname.">"
5113577c6faSBram Moolenaar   if has("win32") || has("win16") || has("win95")
5125c73622aSBram Moolenaar"    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")
5135c73622aSBram Moolenaar    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
5143577c6faSBram Moolenaar   else
5155c73622aSBram Moolenaar"    call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id='))
5165c73622aSBram Moolenaar    exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id=').latestsrcid
5173577c6faSBram Moolenaar   endif
5183577c6faSBram Moolenaar
5195c73622aSBram Moolenaar   " --------------------------------------------------------------------------
5203577c6faSBram Moolenaar   " AutoInstall: only if doautoinstall has been requested by the plugin itself
5215c73622aSBram Moolenaar   " --------------------------------------------------------------------------
522251e1912SBram Moolenaar"   call Decho("checking if plugin requested autoinstall: doautoinstall=".doautoinstall)
5233577c6faSBram Moolenaar   if doautoinstall
5245c73622aSBram Moolenaar"    call Decho(" ")
5255c73622aSBram Moolenaar"    call Decho("Autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname))
5263577c6faSBram Moolenaar    if filereadable(sname)
5275c73622aSBram Moolenaar"     call Decho("<".sname."> is readable")
5285c73622aSBram Moolenaar"     call Decho("exe silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall))
5295c73622aSBram Moolenaar     exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall)
530251e1912SBram Moolenaar     let curdir    = fnameescape(substitute(getcwd(),'\','/','ge'))
5313577c6faSBram Moolenaar     let installdir= curdir."/Installed"
5323577c6faSBram Moolenaar     if !isdirectory(installdir)
5333577c6faSBram Moolenaar      call mkdir(installdir)
5343577c6faSBram Moolenaar     endif
5355c73622aSBram Moolenaar"     call Decho("curdir<".curdir."> installdir<".installdir.">")
5363577c6faSBram Moolenaar"     call Decho("exe cd ".fnameescape(s:autoinstall))
5373577c6faSBram Moolenaar     exe "cd ".fnameescape(s:autoinstall)
5383577c6faSBram Moolenaar
5395c73622aSBram Moolenaar     " determine target directory for moves
5405c73622aSBram Moolenaar     let firstdir= substitute(&rtp,',.*$','','')
5415c73622aSBram Moolenaar     let pname   = substitute(sname,'\..*','.vim','')
5425c73622aSBram Moolenaar"     call Decho("determine tgtdir: is <".firstdir.'/AsNeeded/'.pname." readable?")
5435c73622aSBram Moolenaar     if filereadable(firstdir.'/AsNeeded/'.pname)
5445c73622aSBram Moolenaar      let tgtdir= "AsNeeded"
5455c73622aSBram Moolenaar     else
5465c73622aSBram Moolenaar      let tgtdir= "plugin"
5475c73622aSBram Moolenaar     endif
5485c73622aSBram Moolenaar"     call Decho("tgtdir<".tgtdir.">  pname<".pname.">")
5495c73622aSBram Moolenaar
5503577c6faSBram Moolenaar     " decompress
5513577c6faSBram Moolenaar     if sname =~ '\.bz2$'
5523577c6faSBram Moolenaar"      call Decho("decompress: attempt to bunzip2 ".sname)
553*6be7f873SBram Moolenaar      exe "sil !bunzip2 ".shellescape(sname)
5543577c6faSBram Moolenaar      let sname= substitute(sname,'\.bz2$','','')
5553577c6faSBram Moolenaar"      call Decho("decompress: new sname<".sname."> after bunzip2")
5563577c6faSBram Moolenaar     elseif sname =~ '\.gz$'
5573577c6faSBram Moolenaar"      call Decho("decompress: attempt to gunzip ".sname)
558*6be7f873SBram Moolenaar      exe "sil !gunzip ".shellescape(sname)
5593577c6faSBram Moolenaar      let sname= substitute(sname,'\.gz$','','')
5603577c6faSBram Moolenaar"      call Decho("decompress: new sname<".sname."> after gunzip")
561251e1912SBram Moolenaar     elseif sname =~ '\.xz$'
562251e1912SBram Moolenaar"      call Decho("decompress: attempt to unxz ".sname)
563*6be7f873SBram Moolenaar      exe "sil !unxz ".shellescape(sname)
564251e1912SBram Moolenaar      let sname= substitute(sname,'\.xz$','','')
565251e1912SBram Moolenaar"      call Decho("decompress: new sname<".sname."> after unxz")
5665c73622aSBram Moolenaar     else
5675c73622aSBram Moolenaar"      call Decho("no decompression needed")
5683577c6faSBram Moolenaar     endif
5693577c6faSBram Moolenaar
570*6be7f873SBram Moolenaar     " distribute archive(.zip, .tar, .vba, ...) contents
5713577c6faSBram Moolenaar     if sname =~ '\.zip$'
5723577c6faSBram Moolenaar"      call Decho("dearchive: attempt to unzip ".sname)
5735c73622aSBram Moolenaar      exe "silent !unzip -o ".shellescape(sname)
5743577c6faSBram Moolenaar     elseif sname =~ '\.tar$'
5753577c6faSBram Moolenaar"      call Decho("dearchive: attempt to untar ".sname)
5765c73622aSBram Moolenaar      exe "silent !tar -xvf ".shellescape(sname)
577*6be7f873SBram Moolenaar     elseif sname =~ '\.tgz$'
578*6be7f873SBram Moolenaar"      call Decho("dearchive: attempt to untar+gunzip ".sname)
579*6be7f873SBram Moolenaar      exe "silent !tar -zxvf ".shellescape(sname)
580*6be7f873SBram Moolenaar     elseif sname =~ '\.taz$'
581*6be7f873SBram Moolenaar"      call Decho("dearchive: attempt to untar+uncompress ".sname)
582*6be7f873SBram Moolenaar      exe "silent !tar -Zxvf ".shellescape(sname)
583*6be7f873SBram Moolenaar     elseif sname =~ '\.tbz$'
584*6be7f873SBram Moolenaar"      call Decho("dearchive: attempt to untar+bunzip2 ".sname)
585*6be7f873SBram Moolenaar      exe "silent !tar -jxvf ".shellescape(sname)
586*6be7f873SBram Moolenaar     elseif sname =~ '\.txz$'
587*6be7f873SBram Moolenaar"      call Decho("dearchive: attempt to untar+xz ".sname)
588*6be7f873SBram Moolenaar      exe "silent !tar -Jxvf ".shellescape(sname)
5893577c6faSBram Moolenaar     elseif sname =~ '\.vba$'
5903577c6faSBram Moolenaar"      call Decho("dearchive: attempt to handle a vimball: ".sname)
5913577c6faSBram Moolenaar      silent 1split
5925c73622aSBram Moolenaar      if exists("g:vimball_home")
5935c73622aSBram Moolenaar       let oldvimballhome= g:vimball_home
5945c73622aSBram Moolenaar      endif
5955c73622aSBram Moolenaar      let g:vimball_home= s:autoinstall
5963577c6faSBram Moolenaar      exe "silent e ".fnameescape(sname)
5973577c6faSBram Moolenaar      silent so %
5983577c6faSBram Moolenaar      silent q
5995c73622aSBram Moolenaar      if exists("oldvimballhome")
6005c73622aSBram Moolenaar       let g:vimball_home= oldvimballhome
6015c73622aSBram Moolenaar      else
6025c73622aSBram Moolenaar       unlet g:vimball_home
6035c73622aSBram Moolenaar      endif
6045c73622aSBram Moolenaar     else
6055c73622aSBram Moolenaar"      call Decho("no dearchiving needed")
6063577c6faSBram Moolenaar     endif
6073577c6faSBram Moolenaar
6085c73622aSBram Moolenaar     " ---------------------------------------------
6095c73622aSBram Moolenaar     " move plugin to plugin/ or AsNeeded/ directory
6105c73622aSBram Moolenaar     " ---------------------------------------------
6113577c6faSBram Moolenaar     if sname =~ '.vim$'
6125c73622aSBram Moolenaar"      call Decho("dearchive: attempt to simply move ".sname." to ".tgtdir)
6135c73622aSBram Moolenaar      exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".tgtdir
6143577c6faSBram Moolenaar     else
6153577c6faSBram Moolenaar"      call Decho("dearchive: move <".sname."> to installdir<".installdir.">")
6165c73622aSBram Moolenaar      exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".installdir
6175c73622aSBram Moolenaar     endif
6185c73622aSBram Moolenaar     if tgtdir != "plugin"
6195c73622aSBram Moolenaar"      call Decho("exe silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir)
6205c73622aSBram Moolenaar      exe "silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir
6213577c6faSBram Moolenaar     endif
6223577c6faSBram Moolenaar
6233577c6faSBram Moolenaar     " helptags step
6243577c6faSBram Moolenaar     let docdir= substitute(&rtp,',.*','','e')."/doc"
6253577c6faSBram Moolenaar"     call Decho("helptags: docdir<".docdir.">")
6263577c6faSBram Moolenaar     exe "helptags ".fnameescape(docdir)
6273577c6faSBram Moolenaar     exe "cd ".fnameescape(curdir)
6283577c6faSBram Moolenaar    endif
6293577c6faSBram Moolenaar    if fname !~ ':AutoInstall:'
6303577c6faSBram Moolenaar     let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
6313577c6faSBram Moolenaar    else
6323577c6faSBram Moolenaar     let modline=scriptid." ".latestsrcid." ".fname.cmmnt
6333577c6faSBram Moolenaar    endif
6343577c6faSBram Moolenaar   else
6353577c6faSBram Moolenaar    let modline=scriptid." ".latestsrcid." ".fname.cmmnt
6363577c6faSBram Moolenaar   endif
6373577c6faSBram Moolenaar
6383577c6faSBram Moolenaar   " update the data in the <GetLatestVimScripts.dat> file
6393577c6faSBram Moolenaar   call setline(line("."),modline)
6403577c6faSBram Moolenaar"   call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
6413577c6faSBram Moolenaar"  else " Decho
6423577c6faSBram Moolenaar"   call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
6433577c6faSBram Moolenaar  endif
6443577c6faSBram Moolenaar
6453577c6faSBram Moolenaar " restore options
6463577c6faSBram Moolenaar  let &t_ti = t_ti
6473577c6faSBram Moolenaar  let &t_te = t_te
6483577c6faSBram Moolenaar  let &rs   = rs
6493577c6faSBram Moolenaar  let @a    = rega
6503577c6faSBram Moolenaar"  call Dredir("BUFFER TEST (GetOneScript)","ls!")
6513577c6faSBram Moolenaar
6523577c6faSBram Moolenaar"  call Dret("GetOneScript")
6533577c6faSBram Moolenaarendfun
6543577c6faSBram Moolenaar
6553577c6faSBram Moolenaar" ---------------------------------------------------------------------
6569964e468SBram Moolenaar" Restore Options: {{{1
6579964e468SBram Moolenaarlet &cpo= s:keepcpo
6583577c6faSBram Moolenaarunlet s:keepcpo
6599964e468SBram Moolenaar
6603577c6faSBram Moolenaar" ---------------------------------------------------------------------
6613577c6faSBram Moolenaar"  Modelines: {{{1
6629964e468SBram Moolenaar" vim: ts=8 sts=2 fdm=marker nowrap
663