From 3da9a9e4ac0a32c3d9844bf782d33f532dd97afb Mon Sep 17 00:00:00 2001 From: alterdepp Date: Tue, 2 Aug 2011 08:19:51 +0000 Subject: [PATCH] GetLatestVimScripts git-svn-id: https://vimsuite.svn.sourceforge.net/svnroot/vimsuite/trunk@204 eb2d0018-73a3-4aeb-bfe9-1def61c9ec69 --- vimfiles/GetLatest/GetLatestVimScripts.dat | 10 +- vimfiles/autoload/getscript.vim | 699 ++++++++------- vimfiles/autoload/gundo.py | 574 +++++++++++++ vimfiles/autoload/gundo.vim | 407 +++++++++ vimfiles/autoload/netrw.vim | 146 ++-- vimfiles/doc/gundo.txt | 17 +- vimfiles/doc/pi_getscript.txt | 87 +- vimfiles/doc/pi_netrw.txt | 77 +- vimfiles/doc/tags | 4 + vimfiles/ftplugin/xml.vim | 4 +- vimfiles/plugin/DirDiff.vim | 42 +- vimfiles/plugin/getscriptPlugin.vim | 2 +- vimfiles/plugin/gundo.py | 573 +++++++++++++ vimfiles/plugin/gundo.vim | 939 +-------------------- vimfiles/plugin/netrwPlugin.vim | 2 +- vimfiles/syntax/netrw.vim | 2 +- 16 files changed, 2223 insertions(+), 1362 deletions(-) create mode 100644 vimfiles/autoload/gundo.py create mode 100644 vimfiles/autoload/gundo.vim create mode 100755 vimfiles/plugin/gundo.py diff --git a/vimfiles/GetLatest/GetLatestVimScripts.dat b/vimfiles/GetLatest/GetLatestVimScripts.dat index 804e2ba..78b5102 100644 --- a/vimfiles/GetLatest/GetLatestVimScripts.dat +++ b/vimfiles/GetLatest/GetLatestVimScripts.dat @@ -7,14 +7,14 @@ ScriptID SourceID Filename 670 8073 visincr.vim (Visual Increment) 862 2635 cscope_quickfix.vim 51 171 cscope_macros.vim -102 13435 DirDiff.vim +102 16171 DirDiff.vim 1189 8687 matrix.vim 1173 15731 tcomment 948 2878 Scons Compiler plugin 1709 6421 Scons Syntax file 1772 7248 DAMOS.zip DAMOS tools (von Stefan) 987 14064 DoxygenToolkit.vim -1397 14039 xml.vim +1397 16076 xml.vim 1290 5190 LogiPat.vim 1462 5612 dtd2xml 1046 4249 Lusty Explorer @@ -30,7 +30,7 @@ ScriptID SourceID Filename 1173 15731 tComment.vim 2701 13194 editsrec 3280 14334 Tabbi -642 8136 :AutoInstall: getscript.vim -1075 15352 :AutoInstall: netrw.vim +642 15781 :AutoInstall: getscript.vim +1075 15782 :AutoInstall: netrw.vim 1502 15362 :AutoInstall: vimball.vim -3304 15211 Gundo +3304 16172 Gundo diff --git a/vimfiles/autoload/getscript.vim b/vimfiles/autoload/getscript.vim index 44d5668..9e2a196 100644 --- a/vimfiles/autoload/getscript.vim +++ b/vimfiles/autoload/getscript.vim @@ -1,8 +1,8 @@ " --------------------------------------------------------------------- " getscript.vim " Author: Charles E. Campbell, Jr. -" Date: Jan 08, 2008 -" Version: 29 +" Date: May 31, 2011 +" Version: 33 " Installing: :help glvs-install " Usage: :help glvs " @@ -12,19 +12,24 @@ " Initialization: {{{1 " if you're sourcing this file, surely you can't be " expecting vim to be in its vi-compatible mode! +if exists("g:loaded_getscript") + finish +endif +let g:loaded_getscript= "v33" if &cp echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)" finish endif +if v:version < 702 + echohl WarningMsg + echo "***warning*** this version of getscript needs vim 7.2" + echohl Normal + finish +endif let s:keepcpo = &cpo set cpo&vim "DechoTabOn -if exists("g:loaded_getscript") - finish -endif -let g:loaded_getscript= "v29" - " --------------------------- " Global Variables: {{{1 " --------------------------- @@ -40,25 +45,6 @@ if !exists("g:getscript_cygwin") let g:getscript_cygwin= 0 endif endif -" shell quoting character {{{2 -if exists("g:netrw_shq") && !exists("g:getscript_shq") - let g:getscript_shq= g:netrw_shq -elseif !exists("g:getscript_shq") - if exists("&shq") && &shq != "" - let g:getscript_shq= &shq - elseif exists("&sxq") && &sxq != "" - let g:getscript_shq= &sxq - elseif has("win32") || has("win95") || has("win64") || has("win16") - if g:getscript_cygwin - let g:getscript_shq= "'" - else - let g:getscript_shq= '"' - endif - else - let g:getscript_shq= "'" - endif -" call Decho("g:getscript_shq<".g:getscript_shq.">") -endif " wget vs curl {{{2 if !exists("g:GetLatestVimScripts_wget") @@ -112,7 +98,9 @@ if g:GetLatestVimScripts_allowautoinstall endif endif - if exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim) + if exists("g:GetLatestVimScripts_autoinstalldir") && isdirectory(g:GetLatestVimScripts_autoinstalldir) + let s:autoinstall= g:GetLatestVimScripts_autoinstalldir" + elseif exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim) let s:autoinstall= $HOME."/".s:dotvim endif " call Decho("s:autoinstall<".s:autoinstall.">") @@ -126,11 +114,223 @@ com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts() com! -nargs=0 GetScript call getscript#GetLatestVimScripts() silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts() +" --------------------------------------------------------------------- +" GetLatestVimScripts: this function gets the latest versions of {{{1 +" scripts based on the list in +" (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat +fun! getscript#GetLatestVimScripts() +" call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">") + +" insure that wget is executable + if executable(g:GetLatestVimScripts_wget) != 1 + echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system" +" call Dret("GetLatestVimScripts : wget not executable/availble") + return + endif + + " insure that fnameescape() is available + if !exists("*fnameescape") + echoerr "GetLatestVimScripts needs fnameescape() (provided by 7.1.299 or later)" + return + endif + + " Find the .../GetLatest subdirectory under the runtimepath + for datadir in split(&rtp,',') + [''] + if isdirectory(datadir."/GetLatest") +" call Decho("found directory<".datadir.">") + let datadir= datadir . "/GetLatest" + break + endif + if filereadable(datadir."GetLatestVimScripts.dat") +" call Decho("found ".datadir."/GetLatestVimScripts.dat") + break + endif + endfor + + " Sanity checks: readability and writability + if datadir == "" + echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install' +" call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory") + return + endif + if filewritable(datadir) != 2 + echoerr "(getLatestVimScripts) Your ".datadir." isn't writable" +" call Dret("GetLatestVimScripts : non-writable directory<".datadir.">") + return + endif + let datafile= datadir."/GetLatestVimScripts.dat" + if !filereadable(datafile) + echoerr "Your data file<".datafile."> isn't readable" +" call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">") + return + endif + if !filewritable(datafile) + echoerr "Your data file<".datafile."> isn't writable" +" call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">") + return + endif + " -------------------- + " Passed sanity checks + " -------------------- + +" call Decho("datadir <".datadir.">") +" call Decho("datafile <".datafile.">") + + " don't let any event handlers interfere (like winmanager's, taglist's, etc) + let eikeep = &ei + let hlskeep = &hls + let acdkeep = &acd + set ei=all hls&vim noacd + + " Edit the datafile (ie. GetLatestVimScripts.dat): + " 1. record current directory (origdir), + " 2. change directory to datadir, + " 3. split window + " 4. edit datafile + let origdir= getcwd() +" call Decho("exe cd ".fnameescape(substitute(datadir,'\','/','ge'))) + exe "cd ".fnameescape(substitute(datadir,'\','/','ge')) + split +" call Decho("exe e ".fnameescape(substitute(datafile,'\','/','ge'))) + exe "e ".fnameescape(substitute(datafile,'\','/','ge')) + res 1000 + let s:downloads = 0 + let s:downerrors= 0 + + " Check on dependencies mentioned in plugins +" call Decho(" ") +" call Decho("searching plugins for GetLatestVimScripts dependencies") + let lastline = line("$") +" call Decho("lastline#".lastline) + let firstdir = substitute(&rtp,',.*$','','') + let plugins = split(globpath(firstdir,"plugin/*.vim"),'\n') + let plugins = plugins + split(globpath(firstdir,"AsNeeded/*.vim"),'\n') + let foundscript = 0 + + " this loop updates the GetLatestVimScripts.dat file + " with dependencies explicitly mentioned in the plugins + " via GetLatestVimScripts: ... lines + " It reads the plugin script at the end of the GetLatestVimScripts.dat + " file, examines it, and then removes it. + for plugin in plugins +" call Decho(" ") +" call Decho("plugin<".plugin.">") + + " read plugin in + " evidently a :r creates a new buffer (the "#" buffer) that is subsequently unused -- bwiping it + $ +" call Decho(".dependency checking<".plugin."> line$=".line("$")) +" call Decho("..exe silent r ".fnameescape(plugin)) + exe "silent r ".fnameescape(plugin) + exe "silent bwipe ".bufnr("#") + + while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0 + let depscript = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e') + let depscriptid = substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\(\d\+\)\s\+.*$','\1','') + let llp1 = lastline+1 +" call Decho("..depscript<".depscript.">") + + " found a "GetLatestVimScripts: # #" line in the script; + " check if its already in the datafile by searching backwards from llp1, + " the (prior to reading in the plugin script) last line plus one of the GetLatestVimScripts.dat file, + " for the script-id with no wrapping allowed. + let curline = line(".") + let noai_script = substitute(depscript,'\s*:AutoInstall:\s*','','e') + exe llp1 + let srchline = search('^\s*'.depscriptid.'\s\+\d\+\s\+.*$','bW') + if srchline == 0 + " this second search is taken when, for example, a 0 0 scriptname is to be skipped over + let srchline= search('\<'.noai_script.'\>','bW') + endif +" call Decho("..noai_script<".noai_script."> depscriptid#".depscriptid." srchline#".srchline." curline#".line(".")." lastline#".lastline) + + if srchline == 0 + " found a new script to permanently include in the datafile + let keep_rega = @a + let @a = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','') + echomsg "Appending <".@a."> to ".datafile." for ".depscript +" call Decho("..Appending <".@a."> to ".datafile." for ".depscript) + exe lastline."put a" + let @a = keep_rega + let lastline = llp1 + let curline = curline + 1 + let foundscript = foundscript + 1 +" else " Decho +" call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")") + endif + + let curline = curline + 1 + exe curline + endwhile + + " llp1: last line plus one + let llp1= lastline + 1 +" call Decho(".deleting lines: ".llp1.",$d") + exe "silent! ".llp1.",$d" + endfor +" call Decho("--- end dependency checking loop --- foundscript=".foundscript) +" call Decho(" ") +" call Dredir("BUFFER TEST (GetLatestVimScripts 1)","ls!") + + if foundscript == 0 + setlocal nomod + endif + + " -------------------------------------------------------------------- + " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat + " -------------------------------------------------------------------- +" call Decho("begin: checking out-of-date scripts using datafile<".datafile.">") + setlocal lz + 1 +" /^-----/,$g/^\s*\d/call Decho(getline(".")) + 1 + /^-----/,$g/^\s*\d/call s:GetOneScript() +" call Decho("--- end out-of-date checking --- ") + + " Final report (an echomsg) + try + silent! ?^-------? + catch /^Vim\%((\a\+)\)\=:E114/ +" call Dret("GetLatestVimScripts : nothing done!") + return + endtry + exe "norm! kz\" + redraw! + let s:msg = "" + if s:downloads == 1 + let s:msg = "Downloaded one updated script to <".datadir.">" + elseif s:downloads == 2 + let s:msg= "Downloaded two updated scripts to <".datadir.">" + elseif s:downloads > 1 + let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">" + else + let s:msg= "Everything was already current" + endif + if s:downerrors > 0 + let s:msg= s:msg." (".s:downerrors." downloading errors)" + endif + echomsg s:msg + " save the file + if &mod + silent! w! + endif + q + + " restore events and current directory + exe "cd ".fnameescape(substitute(origdir,'\','/','ge')) + let &ei = eikeep + let &hls = hlskeep + let &acd = acdkeep + setlocal nolz +" call Dredir("BUFFER TEST (GetLatestVimScripts 2)","ls!") +" call Dret("GetLatestVimScripts : did ".s:downloads." downloads") +endfun + " --------------------------------------------------------------------- " GetOneScript: (Get Latest Vim Script) this function operates {{{1 " on the current line, interpreting two numbers and text as " ScriptID, SourceID, and Filename. -" It downloads any scripts that have newer versions from vim.sf.net. +" It downloads any scripts that have newer versions from vim.sourceforge.net. fun! s:GetOneScript(...) " call Dfunc("GetOneScript()") @@ -188,6 +388,7 @@ fun! s:GetOneScript(...) " call Decho("fname <".fname.">") endif + " plugin author protection from downloading his/her own scripts atop their latest work if scriptid == 0 || srcid == 0 " When looking for :AutoInstall: lines, skip scripts that have 0 0 scriptname let @a= rega @@ -211,29 +412,30 @@ fun! s:GetOneScript(...) exe "norm z\" redraw! " call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid) - echomsg 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid + echo 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid - " grab a copy of the plugin's vim.sf.net webpage - let scriptaddr = 'http://vim.sf.net/script.php?script_id='.scriptid + " grab a copy of the plugin's vim.sourceforge.net webpage + let scriptaddr = 'http://vim.sourceforge.net/script.php?script_id='.scriptid let tmpfile = tempname() let v:errmsg = "" " make up to three tries at downloading the description let itry= 1 while itry <= 3 -" call Decho("try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr) - if has("win32") || has("win16") || has("win95") -" call Decho("new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.tmpfile.g:getscript_shq.' '.g:getscript_shq.scriptaddr.g:getscript_shq."|q!") - new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.tmpfile.g:getscript_shq.' '.g:getscript_shq.scriptaddr.g:getscript_shq|q! - else -" call Decho("exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.tmpfile.g:getscript_shq." ".g:getscript_shq.scriptaddr.g:getscript_shq) - exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.tmpfile.g:getscript_shq." ".g:getscript_shq.scriptaddr.g:getscript_shq - endif - if itry == 1 - exe "silent vsplit ".tmpfile - else - silent! e % - endif +" call Decho(".try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr) + if has("win32") || has("win16") || has("win95") +" call Decho(".new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)."|bw!") + new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile).' '.shellescape(scriptaddr)|bw! + else +" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr)) + exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(tmpfile)." ".shellescape(scriptaddr) + endif + if itry == 1 + exe "silent vsplit ".fnameescape(tmpfile) + else + silent! e % + endif + setlocal bh=wipe " find the latest source-id in the plugin's webpage silent! 1 @@ -247,35 +449,35 @@ fun! s:GetOneScript(...) " testing: did finding "Click on the package..." fail? if findpkg == 0 || itry >= 4 - silent q! - call delete(tmpfile) - " restore options - let &t_ti = t_ti - let &t_te = t_te - let &rs = rs - let s:downerrors = s:downerrors + 1 -" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">") - echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">" -" call Dret("GetOneScript : srch for /Click on the package/ failed") - let @a= rega - return + silent q! + call delete(tmpfile) + " restore options + let &t_ti = t_ti + let &t_te = t_te + let &rs = rs + let s:downerrors = s:downerrors + 1 +" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">") + echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">" +" call Dret("GetOneScript : srch for /Click on the package/ failed") + let @a= rega + return endif " call Decho('found "Click on the package to download"') let findsrcid= search('src_id=','W') if findsrcid == 0 - silent q! - call delete(tmpfile) - " restore options - let &t_ti = t_ti - let &t_te = t_te - let &rs = rs - let s:downerrors = s:downerrors + 1 -" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">") - echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">" - let @a= rega -" call Dret("GetOneScript : srch for /src_id/ failed") - return + silent q! + call delete(tmpfile) + " restore options + let &t_ti = t_ti + let &t_te = t_te + let &rs = rs + let s:downerrors = s:downerrors + 1 +" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">") + echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">" + let @a= rega +" call Dret("GetOneScript : srch for /src_id/ failed") + return endif " call Decho('found "src_id=" in description page') @@ -291,8 +493,7 @@ fun! s:GetOneScript(...) let latestsrcid = latestsrcid + 0 " call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">") - " has the plugin's most-recent srcid increased, which indicates - " that it has been updated + " has the plugin's most-recent srcid increased, which indicates that it has been updated if latestsrcid > srcid " call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">") @@ -302,80 +503,124 @@ fun! s:GetOneScript(...) let sname= "NEW_".sname endif + " ----------------------------------------------------------------------------- " the plugin has been updated since we last obtained it, so download a new copy -" call Decho("...downloading new <".sname.">") - echomsg "...downloading new <".sname.">" + " ----------------------------------------------------------------------------- +" call Decho(".downloading new <".sname.">") + echomsg ".downloading new <".sname.">" if has("win32") || has("win16") || has("win95") -" call Decho("new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid.g:getscript_shq."|q") - new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid.g:getscript_shq|q +" 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") + 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 else -" call Decho("silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid.g:getscript_shq) - exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid.g:getscript_shq +" call Decho(".exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id=')) + exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".shellescape(sname)." ".shellescape('http://vim.sourceforge.net/scripts/download_script.php?src_id=').latestsrcid endif + " -------------------------------------------------------------------------- " AutoInstall: only if doautoinstall has been requested by the plugin itself + " -------------------------------------------------------------------------- +" call Decho("checking if plugin requested autoinstall: doautoinstall=".doautoinstall) if doautoinstall -" call Decho("attempting to do autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname)) - if filereadable(sname) -" call Decho("silent !".g:GetLatestVimScripts_mv." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.s:autoinstall.g:getscript_shq) - exe "silent !".g:GetLatestVimScripts_mv." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.s:autoinstall.g:getscript_shq - let curdir = escape(substitute(getcwd(),'\','/','ge'),"|[]*'\" #") - let installdir= curdir."/Installed" - if !isdirectory(installdir) - call mkdir(installdir) - endif -" call Decho("exe cd ".s:autoinstall) - exe "cd ".escape(s:autoinstall,' ') - - " decompress - if sname =~ '\.bz2$' -" call Decho("decompress: attempt to bunzip2 ".sname) - exe "silent !bunzip2 ".g:getscript_shq.sname.g:getscript_shq - let sname= substitute(sname,'\.bz2$','','') -" call Decho("decompress: new sname<".sname."> after bunzip2") - elseif sname =~ '\.gz$' -" call Decho("decompress: attempt to gunzip ".sname) - exe "silent !gunzip ".g:getscript_shq.sname.g:getscript_shq - let sname= substitute(sname,'\.gz$','','') -" call Decho("decompress: new sname<".sname."> after gunzip") - endif - - " distribute archive(.zip, .tar, .vba) contents - if sname =~ '\.zip$' -" call Decho("dearchive: attempt to unzip ".sname) - exe "silent !unzip -o ".g:getscript_shq.sname.g:getscript_shq - elseif sname =~ '\.tar$' -" call Decho("dearchive: attempt to untar ".sname) - exe "silent !tar -xvf ".g:getscript_shq.sname.g:getscript_shq - elseif sname =~ '\.vba$' -" call Decho("dearchive: attempt to handle a vimball: ".sname) - silent 1split - exe "silent e ".escape(sname,' ') - silent so % - silent q - endif - - if sname =~ '.vim$' -" call Decho("dearchive: attempt to simply move ".sname." to plugin") - exe "silent !".g:GetLatestVimScripts_mv." ".g:getscript_shq.sname.g:getscript_shq." plugin" - else -" call Decho("dearchive: move <".sname."> to installdir<".installdir.">") - exe "silent !".g:GetLatestVimScripts_mv." ".g:getscript_shq.sname.g:getscript_shq." ".installdir - endif - - " helptags step - let docdir= substitute(&rtp,',.*','','e')."/doc" -" call Decho("helptags: docdir<".docdir.">") - exe "helptags ".docdir - exe "cd ".curdir +" call Decho(" ") +" call Decho("Autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname)) + if filereadable(sname) +" call Decho("<".sname."> is readable") +" call Decho("exe silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall)) + exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".shellescape(s:autoinstall) + let curdir = fnameescape(substitute(getcwd(),'\','/','ge')) + let installdir= curdir."/Installed" + if !isdirectory(installdir) + call mkdir(installdir) endif - if fname !~ ':AutoInstall:' - let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt +" call Decho("curdir<".curdir."> installdir<".installdir.">") +" call Decho("exe cd ".fnameescape(s:autoinstall)) + exe "cd ".fnameescape(s:autoinstall) + + " determine target directory for moves + let firstdir= substitute(&rtp,',.*$','','') + let pname = substitute(sname,'\..*','.vim','') +" call Decho("determine tgtdir: is <".firstdir.'/AsNeeded/'.pname." readable?") + if filereadable(firstdir.'/AsNeeded/'.pname) + let tgtdir= "AsNeeded" else - let modline=scriptid." ".latestsrcid." ".fname.cmmnt + let tgtdir= "plugin" endif - else +" call Decho("tgtdir<".tgtdir."> pname<".pname.">") + + " decompress + if sname =~ '\.bz2$' +" call Decho("decompress: attempt to bunzip2 ".sname) + exe "silent !bunzip2 ".shellescape(sname) + let sname= substitute(sname,'\.bz2$','','') +" call Decho("decompress: new sname<".sname."> after bunzip2") + elseif sname =~ '\.gz$' +" call Decho("decompress: attempt to gunzip ".sname) + exe "silent !gunzip ".shellescape(sname) + let sname= substitute(sname,'\.gz$','','') +" call Decho("decompress: new sname<".sname."> after gunzip") + elseif sname =~ '\.xz$' +" call Decho("decompress: attempt to unxz ".sname) + exe "silent !unxz ".shellescape(sname) + let sname= substitute(sname,'\.xz$','','') +" call Decho("decompress: new sname<".sname."> after unxz") + else +" call Decho("no decompression needed") + endif + + " distribute archive(.zip, .tar, .vba) contents + if sname =~ '\.zip$' +" call Decho("dearchive: attempt to unzip ".sname) + exe "silent !unzip -o ".shellescape(sname) + elseif sname =~ '\.tar$' +" call Decho("dearchive: attempt to untar ".sname) + exe "silent !tar -xvf ".shellescape(sname) + elseif sname =~ '\.vba$' +" call Decho("dearchive: attempt to handle a vimball: ".sname) + silent 1split + if exists("g:vimball_home") + let oldvimballhome= g:vimball_home + endif + let g:vimball_home= s:autoinstall + exe "silent e ".fnameescape(sname) + silent so % + silent q + if exists("oldvimballhome") + let g:vimball_home= oldvimballhome + else + unlet g:vimball_home + endif + else +" call Decho("no dearchiving needed") + endif + + " --------------------------------------------- + " move plugin to plugin/ or AsNeeded/ directory + " --------------------------------------------- + if sname =~ '.vim$' +" call Decho("dearchive: attempt to simply move ".sname." to ".tgtdir) + exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".tgtdir + else +" call Decho("dearchive: move <".sname."> to installdir<".installdir.">") + exe "silent !".g:GetLatestVimScripts_mv." ".shellescape(sname)." ".installdir + endif + if tgtdir != "plugin" +" call Decho("exe silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir) + exe "silent !".g:GetLatestVimScripts_mv." plugin/".shellescape(pname)." ".tgtdir + endif + + " helptags step + let docdir= substitute(&rtp,',.*','','e')."/doc" +" call Decho("helptags: docdir<".docdir.">") + exe "helptags ".fnameescape(docdir) + exe "cd ".fnameescape(curdir) + endif + if fname !~ ':AutoInstall:' + let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt + else let modline=scriptid." ".latestsrcid." ".fname.cmmnt + endif + else + let modline=scriptid." ".latestsrcid." ".fname.cmmnt endif " update the data in the file @@ -390,197 +635,11 @@ fun! s:GetOneScript(...) let &t_te = t_te let &rs = rs let @a = rega +" call Dredir("BUFFER TEST (GetOneScript)","ls!") " call Dret("GetOneScript") endfun -" --------------------------------------------------------------------- -" GetLatestVimScripts: this function gets the latest versions of {{{1 -" scripts based on the list in -" (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat -fun! getscript#GetLatestVimScripts() -" call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">") - -" insure that wget is executable - if executable(g:GetLatestVimScripts_wget) != 1 - echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system" -" call Dret("GetLatestVimScripts : wget not executable/availble") - return - endif - - " Find the .../GetLatest subdirectory under the runtimepath - for datadir in split(&rtp,',') + [''] - if isdirectory(datadir."/GetLatest") -" call Decho("found directory<".datadir.">") - let datadir= datadir . "/GetLatest" - break - endif - if filereadable(datadir."GetLatestVimScripts.dat") -" call Decho("found ".datadir."/GetLatestVimScripts.dat") - break - endif - endfor - - " Sanity checks: readability and writability - if datadir == "" - echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install' -" call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory") - return - endif - - if filewritable(datadir) != 2 - echoerr "(getLatestVimScripts) Your ".datadir." isn't writable" -" call Dret("GetLatestVimScripts : non-writable directory<".datadir.">") - return - endif - let datafile= datadir."/GetLatestVimScripts.dat" - if !filereadable(datafile) - echoerr "Your data file<".datafile."> isn't readable" -" call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">") - return - endif - if !filewritable(datafile) - echoerr "Your data file<".datafile."> isn't writable" -" call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">") - return - endif -" call Decho("datadir <".datadir.">") -" call Decho("datafile <".datafile.">") - - " don't let any events interfere (like winmanager's, taglist's, etc) - let eikeep= &ei - set ei=all - - " record current directory, change to datadir, open split window with - " datafile - let origdir= getcwd() - exe "cd ".escape(substitute(datadir,'\','/','ge'),"|[]*'\" #") - split - exe "e ".escape(substitute(datafile,'\','/','ge'),"|[]*'\" #") - res 1000 - let s:downloads = 0 - let s:downerrors= 0 - - " Check on dependencies mentioned in plugins -" call Decho(" ") -" call Decho("searching plugins for GetLatestVimScripts dependencies") - let lastline = line("$") -" call Decho("lastline#".lastline) - let plugins = split(globpath(&rtp,"plugin/*.vim"),'\n') - let foundscript = 0 - let firstdir= "" - - for plugin in plugins - - " don't process plugins in system directories - if firstdir == "" - let firstdir= substitute(plugin,'[/\\][^/\\]\+$','','') -" call Decho("setting firstdir<".firstdir.">") - else - let curdir= substitute(plugin,'[/\\][^/\\]\+$','','') -" call Decho("curdir<".curdir.">") - if curdir != firstdir -" call Decho("skipping subsequent plugins: curdir<".curdir."> != firstdir<".firstdir.">") - break - endif - endif - - " read plugin in - $ -" call Decho(" ") -" call Decho(".dependency checking<".plugin."> line$=".line("$")) - exe "silent r ".escape(plugin,"[]#*$%'\" ?`!&();<>\\") - - while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0 - let newscript= substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e') - let llp1 = lastline+1 -" call Decho("..newscript<".newscript.">") - - " don't process ""GetLatestVimScripts lines -- those that have been doubly-commented out - if newscript !~ '^"' - " found a "GetLatestVimScripts: # #" line in the script; check if its already in the datafile - let curline = line(".") - let noai_script = substitute(newscript,'\s*:AutoInstall:\s*','','e') - exe llp1 - let srchline = search('\<'.noai_script.'\>','bW') -" call Decho("..noai_script<".noai_script."> srch=".srchline."curline#".line(".")." lastline#".lastline) - - if srchline == 0 - " found a new script to permanently include in the datafile - let keep_rega = @a - let @a = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','') - exe lastline."put a" - echomsg "Appending <".@a."> to ".datafile." for ".newscript -" call Decho("..APPEND (".noai_script.")<".@a."> to GetLatestVimScripts.dat") - let @a = keep_rega - let lastline = llp1 - let curline = curline + 1 - let foundscript = foundscript + 1 -" else " Decho -" call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")") - endif - - let curline = curline + 1 - exe curline - endif - endwhile - - let llp1= lastline + 1 -" call Decho(".deleting lines: ".llp1.",$d") - exe "silent! ".llp1.",$d" - endfor -" call Decho("--- end dependency checking loop --- foundscript=".foundscript) -" call Decho(" ") - - if foundscript == 0 - setlocal nomod - endif - - " Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat -" call Decho("begin: checking out-of-date scripts using datafile<".datafile.">") - setlocal lz - 1 -" /^-----/,$g/^\s*\d/call Decho(getline(".")) - 1 - /^-----/,$g/^\s*\d/call s:GetOneScript() -" call Decho("--- end out-of-date checking --- ") - - " Final report (an echomsg) - try - silent! ?^-------? - catch /^Vim\%((\a\+)\)\=:E114/ -" call Dret("GetLatestVimScripts : nothing done!") - return - endtry - exe "norm! kz\" - redraw! - let s:msg = "" - if s:downloads == 1 - let s:msg = "Downloaded one updated script to <".datadir.">" - elseif s:downloads == 2 - let s:msg= "Downloaded two updated scripts to <".datadir.">" - elseif s:downloads > 1 - let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">" - else - let s:msg= "Everything was already current" - endif - if s:downerrors > 0 - let s:msg= s:msg." (".s:downerrors." downloading errors)" - endif - echomsg s:msg - " save the file - if &mod - silent! w! - endif - q - - " restore events and current directory - exe "cd ".escape(substitute(origdir,'\','/','ge'),"|[]*'\" #") - let &ei= eikeep - setlocal nolz -" call Dret("GetLatestVimScripts : did ".s:downloads." downloads") -endfun - " --------------------------------------------------------------------- " Restore Options: {{{1 let &cpo= s:keepcpo diff --git a/vimfiles/autoload/gundo.py b/vimfiles/autoload/gundo.py new file mode 100644 index 0000000..aedc05e --- /dev/null +++ b/vimfiles/autoload/gundo.py @@ -0,0 +1,574 @@ +# ============================================================================ +# File: gundo.py +# Description: vim global plugin to visualize your undo tree +# Maintainer: Steve Losh +# License: GPLv2+ -- look it up. +# Notes: Much of this code was thiefed from Mercurial, and the rest was +# heavily inspired by scratch.vim and histwin.vim. +# +# ============================================================================ + +import difflib +import itertools +import sys +import time +import vim + + +# Mercurial's graphlog code -------------------------------------------------------- +def asciiedges(seen, rev, parents): + """adds edge info to changelog DAG walk suitable for ascii()""" + if rev not in seen: + seen.append(rev) + nodeidx = seen.index(rev) + + knownparents = [] + newparents = [] + for parent in parents: + if parent in seen: + knownparents.append(parent) + else: + newparents.append(parent) + + ncols = len(seen) + seen[nodeidx:nodeidx + 1] = newparents + edges = [(nodeidx, seen.index(p)) for p in knownparents] + + if len(newparents) > 0: + edges.append((nodeidx, nodeidx)) + if len(newparents) > 1: + edges.append((nodeidx, nodeidx + 1)) + + nmorecols = len(seen) - ncols + return nodeidx, edges, ncols, nmorecols + +def get_nodeline_edges_tail( + node_index, p_node_index, n_columns, n_columns_diff, p_diff, fix_tail): + if fix_tail and n_columns_diff == p_diff and n_columns_diff != 0: + # Still going in the same non-vertical direction. + if n_columns_diff == -1: + start = max(node_index + 1, p_node_index) + tail = ["|", " "] * (start - node_index - 1) + tail.extend(["/", " "] * (n_columns - start)) + return tail + else: + return ["\\", " "] * (n_columns - node_index - 1) + else: + return ["|", " "] * (n_columns - node_index - 1) + +def draw_edges(edges, nodeline, interline): + for (start, end) in edges: + if start == end + 1: + interline[2 * end + 1] = "/" + elif start == end - 1: + interline[2 * start + 1] = "\\" + elif start == end: + interline[2 * start] = "|" + else: + nodeline[2 * end] = "+" + if start > end: + (start, end) = (end, start) + for i in range(2 * start + 1, 2 * end): + if nodeline[i] != "+": + nodeline[i] = "-" + +def fix_long_right_edges(edges): + for (i, (start, end)) in enumerate(edges): + if end > start: + edges[i] = (start, end + 1) + +def ascii(buf, state, type, char, text, coldata): + """prints an ASCII graph of the DAG + + takes the following arguments (one call per node in the graph): + + - Somewhere to keep the needed state in (init to asciistate()) + - Column of the current node in the set of ongoing edges. + - Type indicator of node data == ASCIIDATA. + - Payload: (char, lines): + - Character to use as node's symbol. + - List of lines to display as the node's text. + - Edges; a list of (col, next_col) indicating the edges between + the current node and its parents. + - Number of columns (ongoing edges) in the current revision. + - The difference between the number of columns (ongoing edges) + in the next revision and the number of columns (ongoing edges) + in the current revision. That is: -1 means one column removed; + 0 means no columns added or removed; 1 means one column added. + """ + + idx, edges, ncols, coldiff = coldata + assert -2 < coldiff < 2 + if coldiff == -1: + # Transform + # + # | | | | | | + # o | | into o---+ + # |X / |/ / + # | | | | + fix_long_right_edges(edges) + + # add_padding_line says whether to rewrite + # + # | | | | | | | | + # | o---+ into | o---+ + # | / / | | | # <--- padding line + # o | | | / / + # o | | + add_padding_line = (len(text) > 2 and coldiff == -1 and + [x for (x, y) in edges if x + 1 < y]) + + # fix_nodeline_tail says whether to rewrite + # + # | | o | | | | o | | + # | | |/ / | | |/ / + # | o | | into | o / / # <--- fixed nodeline tail + # | |/ / | |/ / + # o | | o | | + fix_nodeline_tail = len(text) <= 2 and not add_padding_line + + # nodeline is the line containing the node character (typically o) + nodeline = ["|", " "] * idx + nodeline.extend([char, " "]) + + nodeline.extend( + get_nodeline_edges_tail(idx, state[1], ncols, coldiff, + state[0], fix_nodeline_tail)) + + # shift_interline is the line containing the non-vertical + # edges between this entry and the next + shift_interline = ["|", " "] * idx + if coldiff == -1: + n_spaces = 1 + edge_ch = "/" + elif coldiff == 0: + n_spaces = 2 + edge_ch = "|" + else: + n_spaces = 3 + edge_ch = "\\" + shift_interline.extend(n_spaces * [" "]) + shift_interline.extend([edge_ch, " "] * (ncols - idx - 1)) + + # draw edges from the current node to its parents + draw_edges(edges, nodeline, shift_interline) + + # lines is the list of all graph lines to print + lines = [nodeline] + if add_padding_line: + lines.append(get_padding_line(idx, ncols, edges)) + lines.append(shift_interline) + + # make sure that there are as many graph lines as there are + # log strings + while len(text) < len(lines): + text.append("") + if len(lines) < len(text): + extra_interline = ["|", " "] * (ncols + coldiff) + while len(lines) < len(text): + lines.append(extra_interline) + + # print lines + indentation_level = max(ncols, ncols + coldiff) + for (line, logstr) in zip(lines, text): + ln = "%-*s %s" % (2 * indentation_level, "".join(line), logstr) + buf.write(ln.rstrip() + '\n') + + # ... and start over + state[0] = coldiff + state[1] = idx + +def generate(dag, edgefn, current): + seen, state = [], [0, 0] + buf = Buffer() + for node, parents in list(dag): + if node.time: + age_label = age(int(node.time)) + else: + age_label = 'Original' + line = '[%s] %s' % (node.n, age_label) + if node.n == current: + char = '@' + else: + char = 'o' + ascii(buf, state, 'C', char, [line], edgefn(seen, node, parents)) + return buf.b + + +# Mercurial age function ----------------------------------------------------------- +agescales = [("year", 3600 * 24 * 365), + ("month", 3600 * 24 * 30), + ("week", 3600 * 24 * 7), + ("day", 3600 * 24), + ("hour", 3600), + ("minute", 60), + ("second", 1)] + +def age(ts): + '''turn a timestamp into an age string.''' + + def plural(t, c): + if c == 1: + return t + return t + "s" + def fmt(t, c): + return "%d %s" % (c, plural(t, c)) + + now = time.time() + then = ts + if then > now: + return 'in the future' + + delta = max(1, int(now - then)) + if delta > agescales[0][1] * 2: + return time.strftime('%Y-%m-%d', time.gmtime(float(ts))) + + for t, s in agescales: + n = delta // s + if n >= 2 or s == 1: + return '%s ago' % fmt(t, n) + + +# Python Vim utility functions ----------------------------------------------------- +normal = lambda s: vim.command('normal %s' % s) + +MISSING_BUFFER = "Cannot find Gundo's target buffer (%s)" +MISSING_WINDOW = "Cannot find window (%s) for Gundo's target buffer (%s)" + +def _check_sanity(): + '''Check to make sure we're not crazy. + + Does the following things: + + * Make sure the target buffer still exists. + ''' + b = int(vim.eval('g:gundo_target_n')) + + if not vim.eval('bufloaded(%d)' % b): + vim.command('echo "%s"' % (MISSING_BUFFER % b)) + return False + + w = int(vim.eval('bufwinnr(%d)' % b)) + if w == -1: + vim.command('echo "%s"' % (MISSING_WINDOW % (w, b))) + return False + + return True + +def _goto_window_for_buffer(b): + w = int(vim.eval('bufwinnr(%d)' % int(b))) + vim.command('%dwincmd w' % w) + +def _goto_window_for_buffer_name(bn): + b = vim.eval('bufnr("%s")' % bn) + return _goto_window_for_buffer(b) + +def _undo_to(n): + n = int(n) + if n == 0: + vim.command('silent earlier %s' % (int(vim.eval('&undolevels')) + 1)) + else: + vim.command('silent undo %d' % n) + + +INLINE_HELP = '''\ +" Gundo for %s (%d) +" j/k - move between undo states +" p - preview diff of selected and current states +" - revert to selected state + +''' + + +# Python undo tree data structures and functions ----------------------------------- +class Buffer(object): + def __init__(self): + self.b = '' + + def write(self, s): + self.b += s + +class Node(object): + def __init__(self, n, parent, time, curhead): + self.n = int(n) + self.parent = parent + self.children = [] + self.curhead = curhead + self.time = time + +def _make_nodes(alts, nodes, parent=None): + p = parent + + for alt in alts: + curhead = 'curhead' in alt + node = Node(n=alt['seq'], parent=p, time=alt['time'], curhead=curhead) + nodes.append(node) + if alt.get('alt'): + _make_nodes(alt['alt'], nodes, p) + p = node + +def make_nodes(): + ut = vim.eval('undotree()') + entries = ut['entries'] + + root = Node(0, None, False, 0) + nodes = [] + _make_nodes(entries, nodes, root) + nodes.append(root) + nmap = dict((node.n, node) for node in nodes) + return nodes, nmap + +def changenr(nodes): + _curhead_l = list(itertools.dropwhile(lambda n: not n.curhead, nodes)) + if _curhead_l: + current = _curhead_l[0].parent.n + else: + current = int(vim.eval('changenr()')) + return current + + +# Gundo rendering ------------------------------------------------------------------ + +# Rendering utility functions +def _fmt_time(t): + return time.strftime('%Y-%m-%d %I:%M:%S %p', time.localtime(float(t))) + +def _output_preview_text(lines): + _goto_window_for_buffer_name('__Gundo_Preview__') + vim.command('setlocal modifiable') + vim.current.buffer[:] = lines + vim.command('setlocal nomodifiable') + +def _generate_preview_diff(current, node_before, node_after): + _goto_window_for_buffer(vim.eval('g:gundo_target_n')) + + if not node_after.n: # we're at the original file + before_lines = [] + + _undo_to(0) + after_lines = vim.current.buffer[:] + + before_name = 'n/a' + before_time = '' + after_name = 'Original' + after_time = '' + elif not node_before.n: # we're at a pseudo-root state + _undo_to(0) + before_lines = vim.current.buffer[:] + + _undo_to(node_after.n) + after_lines = vim.current.buffer[:] + + before_name = 'Original' + before_time = '' + after_name = node_after.n + after_time = _fmt_time(node_after.time) + else: + _undo_to(node_before.n) + before_lines = vim.current.buffer[:] + + _undo_to(node_after.n) + after_lines = vim.current.buffer[:] + + before_name = node_before.n + before_time = _fmt_time(node_before.time) + after_name = node_after.n + after_time = _fmt_time(node_after.time) + + _undo_to(current) + + return list(difflib.unified_diff(before_lines, after_lines, + before_name, after_name, + before_time, after_time)) + +def _generate_change_preview_diff(current, node_before, node_after): + _goto_window_for_buffer(vim.eval('g:gundo_target_n')) + + _undo_to(node_before.n) + before_lines = vim.current.buffer[:] + + _undo_to(node_after.n) + after_lines = vim.current.buffer[:] + + before_name = node_before.n or 'Original' + before_time = node_before.time and _fmt_time(node_before.time) or '' + after_name = node_after.n or 'Original' + after_time = node_after.time and _fmt_time(node_after.time) or '' + + _undo_to(current) + + return list(difflib.unified_diff(before_lines, after_lines, + before_name, after_name, + before_time, after_time)) + +def GundoRenderGraph(): + if not _check_sanity(): + return + + nodes, nmap = make_nodes() + + for node in nodes: + node.children = [n for n in nodes if n.parent == node] + + def walk_nodes(nodes): + for node in nodes: + if node.parent: + yield (node, [node.parent]) + else: + yield (node, []) + + dag = sorted(nodes, key=lambda n: int(n.n), reverse=True) + current = changenr(nodes) + + result = generate(walk_nodes(dag), asciiedges, current).rstrip().splitlines() + result = [' ' + l for l in result] + + target = (vim.eval('g:gundo_target_f'), int(vim.eval('g:gundo_target_n'))) + + if int(vim.eval('g:gundo_help')): + header = (INLINE_HELP % target).splitlines() + else: + header = [] + + vim.command('call s:GundoOpenGraph()') + vim.command('setlocal modifiable') + vim.current.buffer[:] = (header + result) + vim.command('setlocal nomodifiable') + + i = 1 + for line in result: + try: + line.split('[')[0].index('@') + i += 1 + break + except ValueError: + pass + i += 1 + vim.command('%d' % (i+len(header)-1)) + +def GundoRenderPreview(): + if not _check_sanity(): + return + + target_state = vim.eval('s:GundoGetTargetState()') + + # Check that there's an undo state. There may not be if we're talking about + # a buffer with no changes yet. + if target_state == None: + _goto_window_for_buffer_name('__Gundo__') + return + else: + target_state = int(target_state) + + _goto_window_for_buffer(vim.eval('g:gundo_target_n')) + + nodes, nmap = make_nodes() + current = changenr(nodes) + + node_after = nmap[target_state] + node_before = node_after.parent + + vim.command('call s:GundoOpenPreview()') + _output_preview_text(_generate_preview_diff(current, node_before, node_after)) + + _goto_window_for_buffer_name('__Gundo__') + +def GundoRenderChangePreview(): + if not _check_sanity(): + return + + target_state = vim.eval('s:GundoGetTargetState()') + + # Check that there's an undo state. There may not be if we're talking about + # a buffer with no changes yet. + if target_state == None: + _goto_window_for_buffer_name('__Gundo__') + return + else: + target_state = int(target_state) + + _goto_window_for_buffer(vim.eval('g:gundo_target_n')) + + nodes, nmap = make_nodes() + current = changenr(nodes) + + node_after = nmap[target_state] + node_before = nmap[current] + + vim.command('call s:GundoOpenPreview()') + _output_preview_text(_generate_change_preview_diff(current, node_before, node_after)) + + _goto_window_for_buffer_name('__Gundo__') + + +# Gundo undo/redo +def GundoRevert(): + if not _check_sanity(): + return + + target_n = int(vim.eval('s:GundoGetTargetState()')) + back = vim.eval('g:gundo_target_n') + + _goto_window_for_buffer(back) + _undo_to(target_n) + + vim.command('GundoRenderGraph') + _goto_window_for_buffer(back) + + if int(vim.eval('g:gundo_close_on_revert')): + vim.command('GundoToggle') + +def GundoPlayTo(): + if not _check_sanity(): + return + + target_n = int(vim.eval('s:GundoGetTargetState()')) + back = int(vim.eval('g:gundo_target_n')) + + vim.command('echo "%s"' % back) + + _goto_window_for_buffer(back) + normal('zR') + + nodes, nmap = make_nodes() + + start = nmap[changenr(nodes)] + end = nmap[target_n] + + def _walk_branch(origin, dest): + rev = origin.n < dest.n + + nodes = [] + if origin.n > dest.n: + current, final = origin, dest + else: + current, final = dest, origin + + while current.n >= final.n: + if current.n == final.n: + break + nodes.append(current) + current = current.parent + else: + return None + nodes.append(current) + + return reversed(nodes) if rev else nodes + + branch = _walk_branch(start, end) + + if not branch: + vim.command('unsilent echo "No path to that node from here!"') + return + + for node in branch: + _undo_to(node.n) + vim.command('GundoRenderGraph') + normal('zz') + _goto_window_for_buffer(back) + vim.command('redraw') + vim.command('sleep 60m') + +def initPythonModule(): + if sys.version_info[:2] < (2, 4): + vim.command('let s:has_supported_python = 0') diff --git a/vimfiles/autoload/gundo.vim b/vimfiles/autoload/gundo.vim new file mode 100644 index 0000000..1b5de02 --- /dev/null +++ b/vimfiles/autoload/gundo.vim @@ -0,0 +1,407 @@ +" ============================================================================ +" File: gundo.vim +" Description: vim global plugin to visualize your undo tree +" Maintainer: Steve Losh +" License: GPLv2+ -- look it up. +" Notes: Much of this code was thiefed from Mercurial, and the rest was +" heavily inspired by scratch.vim and histwin.vim. +" +" ============================================================================ + + +"{{{ Init + +if v:version < '703'"{{{ + function! s:GundoDidNotLoad() + echohl WarningMsg|echomsg "Gundo unavailable: requires Vim 7.3+"|echohl None + endfunction + command! -nargs=0 GundoToggle call s:GundoDidNotLoad() + finish +endif"}}} + +if has('python')"{{{ + let s:has_supported_python = 1 +else + let s:has_supported_python = 0 +endif + +if !s:has_supported_python + function! s:GundoDidNotLoad() + echohl WarningMsg|echomsg "Gundo requires Vim to be compiled with Python 2.4+"|echohl None + endfunction + command! -nargs=0 GundoToggle call s:GundoDidNotLoad() + finish +endif"}}} + +let s:plugin_path = escape(expand(':p:h'), '\') + +if !exists('g:gundo_width')"{{{ + let g:gundo_width = 45 +endif"}}} +if !exists('g:gundo_preview_height')"{{{ + let g:gundo_preview_height = 15 +endif"}}} +if !exists('g:gundo_preview_bottom')"{{{ + let g:gundo_preview_bottom = 0 +endif"}}} +if !exists('g:gundo_right')"{{{ + let g:gundo_right = 0 +endif"}}} +if !exists('g:gundo_help')"{{{ + let g:gundo_help = 1 +endif"}}} +if !exists("g:gundo_map_move_older")"{{{ + let g:gundo_map_move_older = 'j' +endif"}}} +if !exists("g:gundo_map_move_newer")"{{{ + let g:gundo_map_move_newer = 'k' +endif"}}} +if !exists("g:gundo_close_on_revert")"{{{ + let g:gundo_close_on_revert = 0 +endif"}}} + +"}}} + +"{{{ Gundo utility functions + +function! s:GundoGetTargetState()"{{{ + let target_line = matchstr(getline("."), '\v\[[0-9]+\]') + return matchstr(target_line, '\v[0-9]+') +endfunction"}}} + +function! s:GundoGoToWindowForBufferName(name)"{{{ + if bufwinnr(bufnr(a:name)) != -1 + exe bufwinnr(bufnr(a:name)) . "wincmd w" + return 1 + else + return 0 + endif +endfunction"}}} + +function! s:GundoIsVisible()"{{{ + if bufwinnr(bufnr("__Gundo__")) != -1 || bufwinnr(bufnr("__Gundo_Preview__")) != -1 + return 1 + else + return 0 + endif +endfunction"}}} + +function! s:GundoInlineHelpLength()"{{{ + if g:gundo_help + return 6 + else + return 0 + endif +endfunction"}}} + +"}}} + +"{{{ Gundo buffer settings + +function! s:GundoMapGraph()"{{{ + exec 'nnoremap