diff --git a/.gvimrc b/.gvimrc index b4eecc0..b0fcfc8 100644 --- a/.gvimrc +++ b/.gvimrc @@ -1,5 +1,6 @@ -winsize 110 43 +winsize 115 45 set expandtab +set guifont=DejaVu\ Sans\ Mono:h14.00 call AppleTSetPath("~/work/client") map gg :CmdT diff --git a/.vim/autoload/DrawIt.vim b/.vim/autoload/DrawIt.vim new file mode 100644 index 0000000..aa8fb92 --- /dev/null +++ b/.vim/autoload/DrawIt.vim @@ -0,0 +1,1660 @@ +" DrawIt.vim: a simple way to draw things in Vim -- just put this file in +" +" Maintainer: Charles E. Campbell, Jr. (Charles.E.Campbell.1@gsfc.nasa.gov) +" Authors: Charles E. Campbell, Jr. (NdrchipO@ScampbellPfamily.AbizM - NOSPAM) +" Sylvain Viart (molo@multimania.com) +" Version: 9 +" Date: Oct 10, 2007 +" +" Quick Setup: {{{1 +" tar -oxvf DrawIt.tar +" Should put DrawItPlugin.vim in your .vim/plugin directory, +" put DrawIt.vim in your .vim/autoload directory +" put DrawIt.txt in your .vim/doc directory. +" Then, use \di to start DrawIt, +" \ds to stop Drawit, and +" draw by simply moving about using the cursor keys. +" +" You may also use visual-block mode to select endpoints and +" draw lines, arrows, and ellipses. +" +" Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1 +" Permission is hereby granted to use and distribute this code, +" with or without modifications, provided that this copyright +" notice is copied with it. Like anything else that's free, +" DrawIt.vim is provided *as is* and comes with no warranty +" of any kind, either expressed or implied. By using this +" plugin, you agree that in no event will the copyright +" holder be liable for any damages resulting from the use +" of this software. +" +" Required: THIS SCRIPT REQUIRES VIM 7.0 (or later) {{{1 +" GetLatestVimScripts: 40 1 :AutoInstall: DrawIt.vim +" GetLatestVimScripts: 1066 1 cecutil.vim +" +" Woe to her who is rebellious and polluted, the oppressing {{{1 +" city! She didn't obey the voice. She didn't receive correction. +" She didn't trust in Yahweh. She didn't draw near to her God. (Zeph 3:1,2 WEB) + +" --------------------------------------------------------------------- +" Load Once: {{{1 +if &cp || exists("g:loaded_DrawIt") + finish +endif +let s:keepcpo= &cpo +set cpo&vim + +" --------------------------------------------------------------------- +" Script Variables: {{{1 +if !exists("s:saveposn_count") + let s:saveposn_count= 0 +endif +let g:loaded_DrawIt= "v9" +"DechoTabOn + +" ===================================================================== +" DrawIt Functions: (by Charles E. Campbell, Jr.) {{{1 +" ===================================================================== + +" --------------------------------------------------------------------- +" DrawIt#StartDrawIt: this function maps the cursor keys, sets up default {{{2 +" drawing characters, and makes some settings +fun! DrawIt#StartDrawIt() +" call Dfunc("StartDrawIt()") + + " StartDrawIt: report on [DrawIt] mode {{{3 + if exists("b:dodrawit") && b:dodrawit == 1 + " already in DrawIt mode + echo "[DrawIt] (already on, use ".((exists("mapleader") && mapleader != "")? mapleader : '\')."ds to stop)" +" call Dret("StartDrawIt") + return + endif + let b:dodrawit= 1 + + " indicate in DrawIt mode + echo "[DrawIt]" + + " StartDrawIt: turn on mouse {{{3 + if !exists("b:drawit_keep_mouse") + let b:drawit_keep_mouse= &mouse + endif + setlocal mouse=a + + " StartDrawIt: set up DrawIt commands {{{3 + com! -nargs=1 -range SetBrush ,call DrawIt#SetBrush() + com! -count Canvas call s:Spacer(line("."),line(".") + - 1,0) + + " StartDrawIt: set up default drawing characters {{{3 + if !exists("b:di_vert") + let b:di_vert= "|" + endif + if !exists("b:di_horiz") + let b:di_horiz= "-" + endif + if !exists("b:di_plus") + let b:di_plus= "+" + endif + if !exists("b:di_upright") " also downleft + let b:di_upright= "/" + endif + if !exists("b:di_upleft") " also downright + let b:di_upleft= "\\" + endif + if !exists("b:di_cross") + let b:di_cross= "X" + endif + if !exists("b:di_ellipse") + let b:di_ellipse= '*' + endif + + " set up initial DrawIt behavior (as opposed to erase behavior) + let b:di_erase = 0 + + " StartDrawIt: option recording {{{3 + let b:di_aikeep = &ai + let b:di_cinkeep = &cin + let b:di_cpokeep = &cpo + let b:di_etkeep = &et + let b:di_fokeep = &fo + let b:di_gdkeep = &gd + let b:di_gokeep = &go + let b:di_magickeep = &magic + let b:di_remapkeep = &remap + let b:di_repkeep = &report + let b:di_sikeep = &si + let b:di_stakeep = &sta + let b:di_vekeep = &ve + set cpo&vim + set nocin noai nosi nogd sta et ve=all report=10000 + set go-=aA + set fo-=a + set remap magic + + " StartDrawIt: save and unmap user maps {{{3 + let b:lastdir = 1 + if exists("mapleader") + let usermaplead = mapleader + else + let usermaplead = "\\" + endif + call SaveUserMaps("n","","><^v","DrawIt") + call SaveUserMaps("v",usermaplead,"abeflsy","DrawIt") + call SaveUserMaps("n",usermaplead,"h>","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n","","","DrawIt") + call SaveUserMaps("n",usermaplead,":pa","DrawIt") + call SaveUserMaps("n",usermaplead,":pb","DrawIt") + call SaveUserMaps("n",usermaplead,":pc","DrawIt") + call SaveUserMaps("n",usermaplead,":pd","DrawIt") + call SaveUserMaps("n",usermaplead,":pe","DrawIt") + call SaveUserMaps("n",usermaplead,":pf","DrawIt") + call SaveUserMaps("n",usermaplead,":pg","DrawIt") + call SaveUserMaps("n",usermaplead,":ph","DrawIt") + call SaveUserMaps("n",usermaplead,":pi","DrawIt") + call SaveUserMaps("n",usermaplead,":pj","DrawIt") + call SaveUserMaps("n",usermaplead,":pk","DrawIt") + call SaveUserMaps("n",usermaplead,":pl","DrawIt") + call SaveUserMaps("n",usermaplead,":pm","DrawIt") + call SaveUserMaps("n",usermaplead,":pn","DrawIt") + call SaveUserMaps("n",usermaplead,":po","DrawIt") + call SaveUserMaps("n",usermaplead,":pp","DrawIt") + call SaveUserMaps("n",usermaplead,":pq","DrawIt") + call SaveUserMaps("n",usermaplead,":pr","DrawIt") + call SaveUserMaps("n",usermaplead,":ps","DrawIt") + call SaveUserMaps("n",usermaplead,":pt","DrawIt") + call SaveUserMaps("n",usermaplead,":pu","DrawIt") + call SaveUserMaps("n",usermaplead,":pv","DrawIt") + call SaveUserMaps("n",usermaplead,":pw","DrawIt") + call SaveUserMaps("n",usermaplead,":px","DrawIt") + call SaveUserMaps("n",usermaplead,":py","DrawIt") + call SaveUserMaps("n",usermaplead,":pz","DrawIt") + call SaveUserMaps("n",usermaplead,":ra","DrawIt") + call SaveUserMaps("n",usermaplead,":rb","DrawIt") + call SaveUserMaps("n",usermaplead,":rc","DrawIt") + call SaveUserMaps("n",usermaplead,":rd","DrawIt") + call SaveUserMaps("n",usermaplead,":re","DrawIt") + call SaveUserMaps("n",usermaplead,":rf","DrawIt") + call SaveUserMaps("n",usermaplead,":rg","DrawIt") + call SaveUserMaps("n",usermaplead,":rh","DrawIt") + call SaveUserMaps("n",usermaplead,":ri","DrawIt") + call SaveUserMaps("n",usermaplead,":rj","DrawIt") + call SaveUserMaps("n",usermaplead,":rk","DrawIt") + call SaveUserMaps("n",usermaplead,":rl","DrawIt") + call SaveUserMaps("n",usermaplead,":rm","DrawIt") + call SaveUserMaps("n",usermaplead,":rn","DrawIt") + call SaveUserMaps("n",usermaplead,":ro","DrawIt") + call SaveUserMaps("n",usermaplead,":rp","DrawIt") + call SaveUserMaps("n",usermaplead,":rq","DrawIt") + call SaveUserMaps("n",usermaplead,":rr","DrawIt") + call SaveUserMaps("n",usermaplead,":rs","DrawIt") + call SaveUserMaps("n",usermaplead,":rt","DrawIt") + call SaveUserMaps("n",usermaplead,":ru","DrawIt") + call SaveUserMaps("n",usermaplead,":rv","DrawIt") + call SaveUserMaps("n",usermaplead,":rw","DrawIt") + call SaveUserMaps("n",usermaplead,":rx","DrawIt") + call SaveUserMaps("n",usermaplead,":ry","DrawIt") + call SaveUserMaps("n",usermaplead,":rz","DrawIt") + if exists("g:drawit_insertmode") && g:drawit_insertmode + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + call SaveUserMaps("i","","","DrawIt") + endif + call SaveUserMaps("n","",":\","DrawIt") + + " StartDrawIt: DrawIt maps (Charles Campbell) {{{3 + nmap :set lz:silent! call DrawLeft():set nolz + nmap :set lz:silent! call DrawRight():set nolz + nmap :set lz:silent! call DrawUp():set nolz + nmap :set lz:silent! call DrawDown():set nolz + nmap :set lz:silent! call MoveLeft():set nolz + nmap :set lz:silent! call MoveRight():set nolz + nmap :set lz:silent! call MoveUp():set nolz + nmap :set lz:silent! call MoveDown():set nolz + nmap :set lz:silent! call DrawErase():set nolz + nmap > :set lz:silent! call DrawSpace('>',1):set nolz + nmap < :set lz:silent! call DrawSpace('<',2):set nolz + nmap ^ :set lz:silent! call DrawSpace('^',3):set nolz + nmap v :set lz:silent! call DrawSpace('v',4):set nolz + nmap :set lz:silent! call DrawSlantUpLeft():set nolz + nmap :set lz:silent! call DrawSlantDownLeft():set nolz + nmap :set lz:silent! call DrawSlantUpRight():set nolz + nmap :set lz:silent! call DrawSlantDownRight():set nolz + nmap > :set lz:silent! call DrawFatRArrow():set nolz + nmap < :set lz:silent! call DrawFatLArrow():set nolz + nmap ^ :set lz:silent! call DrawFatUArrow():set nolz + nmap v :set lz:silent! call DrawFatDArrow():set nolz + nmap f :call Flood() + + " StartDrawIt: Set up insertmode maps {{{3 + if exists("g:drawit_insertmode") && g:drawit_insertmode + imap a + imap a + imap a + imap a + imap a + imap a + imap a + imap a + imap a + imap a + imap a + imap a + endif + + " StartDrawIt: set up drawing mode mappings (Sylvain Viart) {{{3 + nnoremap :call LeftStart() + vmap a :call CallBox('Arrow') + vmap b :call CallBox('DrawBox') + nmap c :call Canvas() + vmap l :call CallBox('DrawPlainLine') + vmap s :call Spacer(line("'<"), line("'>"),0) + + " StartDrawIt: set up drawing mode mappings (Charles Campbell) {{{3 + " \pa ... \pz : blanks are transparent + " \ra ... \rz : blanks copy over + vmap e :call CallBox('DrawEllipse') + + let allreg= "abcdefghijklmnopqrstuvwxyz" + while strlen(allreg) > 0 + let ireg= strpart(allreg,0,1) + exe "nmap p".ireg.' :set lz:silent! call PutBlock("'.ireg.'",0):set nolz' + exe "nmap r".ireg.' :set lz:silent! call PutBlock("'.ireg.'",1):set nolz' + let allreg= strpart(allreg,1) + endwhile + + " StartDrawIt: mouse maps (Sylvain Viart) {{{3 + " start visual-block with leftmouse + nnoremap :call LeftStart() + vnoremap :call RightStart(1) + vnoremap :call RightStart(0) + vnoremap :call CLeftStart() + + " StartDrawIt: mouse maps (Charles Campbell) {{{3 + " Draw with current brush + nnoremap :call SLeftStart() + nnoremap :call CLeftStart() + + " StartDrawIt: Menu support {{{3 + if has("gui_running") && has("menu") && &go =~ 'm' + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Stop\ \ DrawIt\\ds ds' + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Toggle\ Erase\ Mode ' + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Draw\ Arrow\\a a' + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Draw\ Box\\b b' + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Make\ Blank\ Zone\\c c' + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Draw\ Ellipse\\e e' + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Draw\ Flood\\e f' + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Draw\ Line\\l l' + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Append\ Blanks\\s s' + exe 'silent! unmenu '.g:DrChipTopLvlMenu.'DrawIt.Start\ DrawIt' + endif +" call Dret("StartDrawIt") +endfun + +" --------------------------------------------------------------------- +" DrawIt#StopDrawIt: this function unmaps the cursor keys and restores settings {{{2 +fun! DrawIt#StopDrawIt() +" call Dfunc("StopDrawIt()") + + " StopDrawIt: report on [DrawIt off] mode {{{3 + if !exists("b:dodrawit") + echo "[DrawIt off]" +" call Dret("StopDrawIt") + return + endif + + " StopDrawIt: restore mouse {{{3 + if exists("b:drawit_keep_mouse") + let &mouse= b:drawit_keep_mouse + unlet b:drawit_keep_mouse + endif + unlet b:dodrawit + echo "[DrawIt off]" + + if exists("b:drawit_canvas_used") + " StopDrawIt: clean up trailing white space {{{3 + call s:SavePosn() + silent! %s/\s\+$//e + unlet b:drawit_canvas_used + call s:RestorePosn() + endif + + " StopDrawIt: remove drawit commands {{{3 + delc SetBrush + + " StopDrawIt: insure that erase mode is off {{{3 + " (thanks go to Gary Johnson for this) + if b:di_erase == 1 + call s:DrawErase() + endif + + " StopDrawIt: restore user map(s), if any {{{3 + call RestoreUserMaps("DrawIt") + + " StopDrawIt: restore user's options {{{3 + let &ai = b:di_aikeep + let &cin = b:di_cinkeep + let &cpo = b:di_cpokeep + let &et = b:di_etkeep + let &fo = b:di_fokeep + let &gd = b:di_gdkeep + let &go = b:di_gokeep + let &magic = b:di_magickeep + let &remap = b:di_remapkeep + let &report = b:di_repkeep + let &si = b:di_sikeep + let &sta = b:di_stakeep + let &ve = b:di_vekeep + unlet b:di_aikeep + unlet b:di_cinkeep + unlet b:di_cpokeep + unlet b:di_etkeep + unlet b:di_fokeep + unlet b:di_gdkeep + unlet b:di_gokeep + unlet b:di_magickeep + unlet b:di_remapkeep + unlet b:di_repkeep + unlet b:di_sikeep + unlet b:di_stakeep + unlet b:di_vekeep + + " StopDrawIt: DrChip menu support: {{{3 + if has("gui_running") && has("menu") && &go =~ 'm' + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Start\ DrawIt\\di di' + exe 'unmenu '.g:DrChipTopLvlMenu.'DrawIt.Stop\ \ DrawIt' + exe 'unmenu '.g:DrChipTopLvlMenu.'DrawIt.Toggle\ Erase\ Mode' + exe 'unmenu '.g:DrChipTopLvlMenu.'DrawIt.Draw\ Arrow' + exe 'unmenu '.g:DrChipTopLvlMenu.'DrawIt.Draw\ Box' + exe 'unmenu '.g:DrChipTopLvlMenu.'DrawIt.Draw\ Ellipse' + exe 'unmenu '.g:DrChipTopLvlMenu.'DrawIt.Draw\ Flood' + exe 'unmenu '.g:DrChipTopLvlMenu.'DrawIt.Draw\ Line' + exe 'unmenu '.g:DrChipTopLvlMenu.'DrawIt.Make\ Blank\ Zone' + exe 'unmenu '.g:DrChipTopLvlMenu.'DrawIt.Append\ Blanks' + endif +" call Dret("StopDrawIt") +endfun + +" --------------------------------------------------------------------- +" SetDrawIt: this function allows one to change the drawing characters {{{2 +fun! SetDrawIt(di_vert,di_horiz,di_plus,di_upleft,di_upright,di_cross,di_ellipse) +" call Dfunc("SetDrawIt(vert<".a:di_vert."> horiz<".a:di_horiz."> plus<".a:di_plus."> upleft<".a:di_upleft."> upright<".a:di_upright."> cross<".a:di_cross."> ellipse<".a:di_ellipse.">)") + let b:di_vert = a:di_vert + let b:di_horiz = a:di_horiz + let b:di_plus = a:di_plus + let b:di_upleft = a:di_upleft + let b:di_upright = a:di_upright + let b:di_cross = a:di_cross + let b:di_ellipse = a:di_ellipse +" call Dret("SetDrawIt") +endfun + +" ===================================================================== +" s:DrawLeft: {{{2 +fun! s:DrawLeft() +" call Dfunc("s:DrawLeft()") + let curline = getline(".") + let curcol = virtcol(".") + let b:lastdir = 2 + + if curcol > 0 + let curchar= strpart(curline,curcol-1,1) + + " replace + if curchar == b:di_vert || curchar == b:di_plus + exe "norm! r".b:di_plus + else + exe "norm! r".b:di_horiz + endif + + " move and replace + if curcol >= 2 + call s:MoveLeft() + let curchar= strpart(curline,curcol-2,1) + if curchar == b:di_vert || curchar == b:di_plus + exe "norm! r".b:di_plus + else + exe "norm! r".b:di_horiz + endif + endif + endif +" call Dret("s:DrawLeft") +endfun + +" --------------------------------------------------------------------- +" s:DrawRight: {{{2 +fun! s:DrawRight() +" call Dfunc("s:DrawRight()") + let curline = getline(".") + let curcol = virtcol(".") + let b:lastdir = 1 + + " replace + if curcol == virtcol("$") + exe "norm! a".b:di_horiz."\" + else + let curchar= strpart(curline,curcol-1,1) + if curchar == b:di_vert || curchar == b:di_plus + exe "norm! r".b:di_plus + else + exe "norm! r".b:di_horiz + endif + endif + + " move and replace + call s:MoveRight() + if curcol == virtcol("$") + exe "norm! i".b:di_horiz."\" + else + let curchar= strpart(curline,curcol,1) + if curchar == b:di_vert || curchar == b:di_plus + exe "norm! r".b:di_plus + else + exe "norm! r".b:di_horiz + endif + endif +" call Dret("s:DrawRight") +endfun + +" --------------------------------------------------------------------- +" s:DrawUp: {{{2 +fun! s:DrawUp() +" call Dfunc("s:DrawUp()") + let curline = getline(".") + let curcol = virtcol(".") + let b:lastdir = 3 + + " replace + if curcol == 1 && virtcol("$") == 1 + exe "norm! i".b:di_vert."\" + else + let curchar= strpart(curline,curcol-1,1) + if curchar == b:di_horiz || curchar == b:di_plus + exe "norm! r".b:di_plus + else + exe "norm! r".b:di_vert + endif + endif + + " move and replace/insert + call s:MoveUp() + let curline= getline(".") + let curchar= strpart(curline,curcol-1,1) + + if curcol == 1 && virtcol("$") == 1 + exe "norm! i".b:di_vert."\" + elseif curchar == b:di_horiz || curchar == b:di_plus + exe "norm! r".b:di_plus + else + exe "norm! r".b:di_vert + endif + endif +" call Dret("s:DrawUp") +endfun + +" --------------------------------------------------------------------- +" s:DrawDown: {{{2 +fun! s:DrawDown() +" call Dfunc("s:DrawDown()") + let curline = getline(".") + let curcol = virtcol(".") + let b:lastdir = 4 + + " replace + if curcol == 1 && virtcol("$") == 1 + exe "norm! i".b:di_vert."\" + else + let curchar= strpart(curline,curcol-1,1) + if curchar == b:di_horiz || curchar == b:di_plus + exe "norm! r".b:di_plus + else + exe "norm! r".b:di_vert + endif + endif + + " move and replace/insert + call s:MoveDown() + let curline= getline(".") + let curchar= strpart(curline,curcol-1,1) + if curcol == 1 && virtcol("$") == 1 + exe "norm! i".b:di_vert."\" + elseif curchar == b:di_horiz || curchar == b:di_plus + exe "norm! r".b:di_plus + else + exe "norm! r".b:di_vert + endif +" call Dret("s:DrawDown") +endfun + +" --------------------------------------------------------------------- +" s:DrawErase: toggle [DrawIt on] and [DrawIt erase] modes {{{2 +fun! s:DrawErase() +" call Dfunc("s:DrawErase() b:di_erase=".b:di_erase) + if b:di_erase == 0 + let b:di_erase= 1 + echo "[DrawIt erase]" + let b:di_vert_save = b:di_vert + let b:di_horiz_save = b:di_horiz + let b:di_plus_save = b:di_plus + let b:di_upright_save = b:di_upright + let b:di_upleft_save = b:di_upleft + let b:di_cross_save = b:di_cross + let b:di_ellipse_save = b:di_ellipse + call SetDrawIt(' ',' ',' ',' ',' ',' ',' ') + else + let b:di_erase= 0 + echo "[DrawIt]" + call SetDrawIt(b:di_vert_save,b:di_horiz_save,b:di_plus_save,b:di_upleft_save,b:di_upright_save,b:di_cross_save,b:di_ellipse_save) + endif +" call Dret("s:DrawErase") +endfun + +" --------------------------------------------------------------------- +" s:DrawSpace: clear character and move right {{{2 +fun! s:DrawSpace(chr,dir) +" call Dfunc("s:DrawSpace(chr<".a:chr."> dir<".a:dir.">)") + let curcol= virtcol(".") + + " replace current location with arrowhead/space + if curcol == virtcol("$")-1 + exe "norm! r".a:chr + else + exe "norm! r".a:chr + endif + + if a:dir == 0 + let dir= b:lastdir + else + let dir= a:dir + endif + + " perform specified move + if dir == 1 + call s:MoveRight() + elseif dir == 2 + call s:MoveLeft() + elseif dir == 3 + call s:MoveUp() + else + call s:MoveDown() + endif +" call Dret("s:DrawSpace") +endfun + +" --------------------------------------------------------------------- +" s:DrawSlantDownLeft: / {{{2 +fun! s:DrawSlantDownLeft() +" call Dfunc("s:DrawSlantDownLeft()") + call s:ReplaceDownLeft() " replace + call s:MoveDown() " move + call s:MoveLeft() " move + call s:ReplaceDownLeft() " replace +" call Dret("s:DrawSlantDownLeft") +endfun + +" --------------------------------------------------------------------- +" s:DrawSlantDownRight: \ {{{2 +fun! s:DrawSlantDownRight() +" call Dfunc("s:DrawSlantDownRight()") + call s:ReplaceDownRight() " replace + call s:MoveDown() " move + call s:MoveRight() " move + call s:ReplaceDownRight() " replace +" call Dret("s:DrawSlantDownRight") +endfun + +" --------------------------------------------------------------------- +" s:DrawSlantUpLeft: \ {{{2 +fun! s:DrawSlantUpLeft() +" call Dfunc("s:DrawSlantUpLeft()") + call s:ReplaceDownRight() " replace + call s:MoveUp() " move + call s:MoveLeft() " move + call s:ReplaceDownRight() " replace +" call Dret("s:DrawSlantUpLeft") +endfun + +" --------------------------------------------------------------------- +" s:DrawSlantUpRight: / {{{2 +fun! s:DrawSlantUpRight() +" call Dfunc("s:DrawSlantUpRight()") + call s:ReplaceDownLeft() " replace + call s:MoveUp() " move + call s:MoveRight() " replace + call s:ReplaceDownLeft() " replace +" call Dret("s:DrawSlantUpRight") +endfun + +" --------------------------------------------------------------------- +" s:MoveLeft: {{{2 +fun! s:MoveLeft() +" call Dfunc("s:MoveLeft()") + norm! h + let b:lastdir= 2 +" call Dret("s:MoveLeft : b:lastdir=".b:lastdir) +endfun + +" --------------------------------------------------------------------- +" s:MoveRight: {{{2 +fun! s:MoveRight() +" call Dfunc("s:MoveRight()") + if virtcol(".") >= virtcol("$") - 1 + exe "norm! A \" + else + norm! l + endif + let b:lastdir= 1 +" call Dret("s:MoveRight : b:lastdir=".b:lastdir) +endfun + +" --------------------------------------------------------------------- +" s:MoveUp: {{{2 +fun! s:MoveUp() +" call Dfunc("s:MoveUp()") + if line(".") == 1 + let curcol= virtcol(".") - 1 + if curcol == 0 && virtcol("$") == 1 + exe "norm! i \" + elseif curcol == 0 + exe "norm! YP:s/./ /ge\0r " + else + exe "norm! YP:s/./ /ge\0".curcol."lr " + endif + else + let curcol= virtcol(".") + norm! k + while virtcol("$") <= curcol + exe "norm! A \" + endwhile + endif + let b:lastdir= 3 +" call Dret("s:MoveUp : b:lastdir=".b:lastdir) +endfun + +" --------------------------------------------------------------------- +" s:MoveDown: {{{2 +fun! s:MoveDown() +" call Dfunc("s:MoveDown()") + if line(".") == line("$") + let curcol= virtcol(".") - 1 + if curcol == 0 && virtcol("$") == 1 + exe "norm! i \" + elseif curcol == 0 + exe "norm! Yp:s/./ /ge\0r " + else + exe "norm! Yp:s/./ /ge\0".curcol."lr " + endif + else + let curcol= virtcol(".") + norm! j + while virtcol("$") <= curcol + exe "norm! A \" + endwhile + endif + let b:lastdir= 4 +" call Dret("s:MoveDown : b:lastdir=".b:lastdir) +endfun + +" --------------------------------------------------------------------- +" s:ReplaceDownLeft: / X (upright) {{{2 +fun! s:ReplaceDownLeft() +" call Dfunc("s:ReplaceDownLeft()") + let curcol = virtcol(".") + if curcol != virtcol("$") + let curchar= strpart(getline("."),curcol-1,1) + if curchar == "\\" || curchar == "X" + exe "norm! r".b:di_cross + else + exe "norm! r".b:di_upright + endif + else + exe "norm! i".b:di_upright."\" + endif +" call Dret("s:ReplaceDownLeft") +endfun + +" --------------------------------------------------------------------- +" s:ReplaceDownRight: \ X (upleft) {{{2 +fun! s:ReplaceDownRight() +" call Dfunc("s:ReplaceDownRight()") + let curcol = virtcol(".") + if curcol != virtcol("$") + let curchar= strpart(getline("."),curcol-1,1) + if curchar == "/" || curchar == "X" + exe "norm! r".b:di_cross + else + exe "norm! r".b:di_upleft + endif + else + exe "norm! i".b:di_upleft."\" + endif +" call Dret("s:ReplaceDownRight") +endfun + +" --------------------------------------------------------------------- +" s:DrawFatRArrow: ----|> {{{2 +fun! s:DrawFatRArrow() +" call Dfunc("s:DrawFatRArrow()") + call s:MoveRight() + norm! r| + call s:MoveRight() + norm! r> +" call Dret("s:DrawFatRArrow") +endfun + +" --------------------------------------------------------------------- +" s:DrawFatLArrow: <|---- {{{2 +fun! s:DrawFatLArrow() +" call Dfunc("s:DrawFatLArrow()") + call s:MoveLeft() + norm! r| + call s:MoveLeft() + norm! r< +" call Dret("s:DrawFatLArrow") +endfun + +" --------------------------------------------------------------------- +" . +" s:DrawFatUArrow: /_\ {{{2 +" | +fun! s:DrawFatUArrow() +" call Dfunc("s:DrawFatUArrow()") + call s:MoveUp() + norm! r_ + call s:MoveRight() + norm! r\ + call s:MoveLeft() + call s:MoveLeft() + norm! r/ + call s:MoveRight() + call s:MoveUp() + norm! r. +" call Dret("s:DrawFatUArrow") +endfun + +" --------------------------------------------------------------------- +" s:DrawFatDArrow: _|_ {{{2 +" \ / +" ' +fun! s:DrawFatDArrow() +" call Dfunc("s:DrawFatDArrow()") + call s:MoveRight() + norm! r_ + call s:MoveLeft() + call s:MoveLeft() + norm! r_ + call s:MoveDown() + norm! r\ + call s:MoveRight() + call s:MoveRight() + norm! r/ + call s:MoveDown() + call s:MoveLeft() + norm! r' +" call Dret("s:DrawFatDArrow") +endfun + +" --------------------------------------------------------------------- +" s:DrawEllipse: Bresenham-like ellipse drawing algorithm {{{2 +" 2 2 can +" x y be 2 2 2 2 2 2 +" - + - = 1 rewritten b x + a y = a b +" a b as +" +" Take step which has minimum error +" (x,y-1) (x+1,y) (x+1,y-1) +" +" 2 2 2 2 2 2 +" Ei = | b x + a y - a b | +" +" Algorithm only draws arc from (0,b) to (a,0) and uses +" DrawFour() to reflect points to other three quadrants +fun! s:DrawEllipse(x0,y0,x1,y1) +" call Dfunc("s:DrawEllipse(x0=".a:x0." y0=".a:y0." x1=".a:x1." y1=".a:y1.")") + let x0 = a:x0 + let y0 = a:y0 + let x1 = a:x1 + let y1 = a:y1 + let xoff = (x0+x1)/2 + let yoff = (y0+y1)/2 + let a = s:Abs(x1-x0)/2 + let b = s:Abs(y1-y0)/2 + let a2 = a*a + let b2 = b*b + let twoa2= a2 + a2 + let twob2= b2 + b2 + + let xi= 0 + let yi= b + let ei= 0 + call s:DrawFour(xi,yi,xoff,yoff,a,b) + while xi <= a && yi >= 0 + + let dy= a2 - twoa2*yi + let ca= ei + twob2*xi + b2 + let cb= ca + dy + let cc= ei + dy + + let aca= s:Abs(ca) + let acb= s:Abs(cb) + let acc= s:Abs(cc) + + " pick case: (xi+1,yi) (xi,yi-1) (xi+1,yi-1) + if aca <= acb && aca <= acc + let xi= xi + 1 + let ei= ca + elseif acb <= aca && acb <= acc + let ei= cb + let xi= xi + 1 + let yi= yi - 1 + else + let ei= cc + let yi= yi - 1 + endif + if xi > a:x1 + break + endif + call s:DrawFour(xi,yi,xoff,yoff,a,b) + endw +" call Dret("s:DrawEllipse") +endf + +" --------------------------------------------------------------------- +" s:DrawFour: reflect a point to four quadrants {{{2 +fun! s:DrawFour(x,y,xoff,yoff,a,b) +" call Dfunc("s:DrawFour(xy[".a:x.",".a:y."] off[".a:xoff.",".a:yoff."] a=".a:a." b=".a:b.")") + let x = a:xoff + a:x + let y = a:yoff + a:y + let lx = a:xoff - a:x + let by = a:yoff - a:y + call s:SetCharAt(b:di_ellipse, x, y) + call s:SetCharAt(b:di_ellipse, lx, y) + call s:SetCharAt(b:di_ellipse, lx,by) + call s:SetCharAt(b:di_ellipse, x,by) +" call Dret("s:DrawFour") +endf + +" --------------------------------------------------------------------- +" s:SavePosn: saves position of cursor on screen so NetWrite can restore it {{{2 +fun! s:SavePosn() +" call Dfunc("s:SavePosn() saveposn_count=".s:saveposn_count.' ['.line('.').','.virtcol('.').']') + let s:saveposn_count= s:saveposn_count + 1 + + " Save current line and column + let b:drawit_line_{s:saveposn_count} = line(".") + let b:drawit_col_{s:saveposn_count} = virtcol(".") - 1 + + " Save top-of-screen line + norm! H + let b:drawit_hline_{s:saveposn_count}= line(".") + + " restore position + exe "norm! ".b:drawit_hline_{s:saveposn_count}."G0z\" + if b:drawit_col_{s:saveposn_count} == 0 + exe "norm! ".b:drawit_line_{s:saveposn_count}."G0" + else + exe "norm! ".b:drawit_line_{s:saveposn_count}."G0".b:drawit_col_{s:saveposn_count}."l" + endif +" call Dret("s:SavePosn : saveposn_count=".s:saveposn_count) +endfun + +" ------------------------------------------------------------------------ +" s:RestorePosn: {{{2 +fun! s:RestorePosn() +" call Dfunc("s:RestorePosn() saveposn_count=".s:saveposn_count) + if s:saveposn_count <= 0 +" call Dret("s:RestorePosn : s:saveposn_count<=0") + return + endif + " restore top-of-screen line + exe "norm! ".b:drawit_hline_{s:saveposn_count}."G0z\" + + " restore position + if b:drawit_col_{s:saveposn_count} == 0 + exe "norm! ".b:drawit_line_{s:saveposn_count}."G0" + else + exe "norm! ".b:drawit_line_{s:saveposn_count}."G0".b:drawit_col_{s:saveposn_count}."l" + endif + if s:saveposn_count > 0 + unlet b:drawit_hline_{s:saveposn_count} + unlet b:drawit_line_{s:saveposn_count} + unlet b:drawit_col_{s:saveposn_count} + let s:saveposn_count= s:saveposn_count - 1 + endif +" call Dret("s:RestorePosn : saveposn_count=".s:saveposn_count) +endfun + +" ------------------------------------------------------------------------ +" s:Flood: this function begins a flood of a region {{{2 +" based on b:di... characters as boundaries +" and starting at the current cursor location. +fun! s:Flood() +" call Dfunc("s:Flood()") + + let s:bndry = b:di_vert.b:di_horiz.b:di_plus.b:di_upright.b:di_upleft.b:di_cross.b:di_ellipse + let row = line(".") + let col = virtcol(".") + let athold = @0 + let s:DIrows = line("$") + call s:SavePosn() + + " get fill character from user + " Put entire fillchar string into the s:bndry (boundary characters), + " although only use the first such character for filling + call inputsave() + let s:fillchar= input("Enter fill character: ") + call inputrestore() + let s:bndry= "[".escape(s:bndry.s:fillchar,'\-]^')."]" + if strlen(s:fillchar) > 1 + let s:fillchar= strpart(s:fillchar,0,1) + endif + + " flood the region + call s:DI_Flood(row,col) + + " restore + call s:RestorePosn() + let @0= athold + unlet s:DIrows s:bndry s:fillchar + +" call Dret("s:Flood") +endfun + +" ------------------------------------------------------------------------ +" s:DI_Flood: fill up to the boundaries all characters to the left and right. {{{2 +" Then, based on the left/right column extents reached, check +" adjacent rows to see if any characters there need filling. +fun! s:DI_Flood(frow,fcol) +" call Dfunc("s:DI_Flood(frow=".a:frow." fcol=".a:fcol.")") + if a:frow <= 0 || a:fcol <= 0 || s:SetPosn(a:frow,a:fcol) || s:IsBoundary(a:frow,a:fcol) +" call Dret("s:DI_Flood") + return + endif + + " fill current line + let colL= s:DI_FillLeft(a:frow,a:fcol) + let colR= s:DI_FillRight(a:frow,a:fcol+1) + + " do a filladjacent on the next line up + if a:frow > 1 + call s:DI_FillAdjacent(a:frow-1,colL,colR) + endif + + " do a filladjacent on the next line down + if a:frow < s:DIrows + call s:DI_FillAdjacent(a:frow+1,colL,colR) + endif + +" call Dret("s:DI_Flood") +endfun + +" ------------------------------------------------------------------------ +" s:DI_FillLeft: Starting at (frow,fcol), non-boundary locations are {{{2 +" filled with the fillchar. The leftmost extent reached +" is returned. +fun! s:DI_FillLeft(frow,fcol) +" call Dfunc("s:DI_FillLeft(frow=".a:frow." fcol=".a:fcol.")") + if s:SetPosn(a:frow,a:fcol) +" call Dret("s:DI_FillLeft ".a:fcol) + return a:fcol + endif + + let Lcol= a:fcol + while Lcol >= 1 + if !s:IsBoundary(a:frow,Lcol) + exe "silent! norm! r".s:fillchar."h" + else + break + endif + let Lcol= Lcol - 1 + endwhile + + let Lcol= (Lcol < 1)? 1 : Lcol + 1 + +" call Dret("s:DI_FillLeft ".Lcol) + return Lcol +endfun + +" --------------------------------------------------------------------- +" s:DI_FillRight: Starting at (frow,fcol), non-boundary locations are {{{2 +" filled with the fillchar. The rightmost extent reached +" is returned. +fun! s:DI_FillRight(frow,fcol) +" call Dfunc("s:DI_FillRight(frow=".a:frow." fcol=".a:fcol.")") + if s:SetPosn(a:frow,a:fcol) +" call Dret("s:DI_FillRight ".a:fcol) + return a:fcol + endif + + let Rcol = a:fcol + while Rcol <= virtcol("$") + if !s:IsBoundary(a:frow,Rcol) + exe "silent! norm! r".s:fillchar."l" + else + break + endif + let Rcol= Rcol + 1 + endwhile + + let DIcols = virtcol("$") + let Rcol = (Rcol > DIcols)? DIcols : Rcol - 1 + +" call Dret("s:DI_FillRight ".Rcol) + return Rcol +endfun + +" --------------------------------------------------------------------- +" s:DI_FillAdjacent: {{{2 +" DI_Flood does FillLeft and FillRight, so the run from left to right +" (fcolL to fcolR) is known to have been filled. FillAdjacent is called +" from (fcolL to fcolR) on the lines one row up and down; if any character +" on the run is not a boundary character, then a flood is needed on that +" location. +fun! s:DI_FillAdjacent(frow,fcolL,fcolR) +" call Dfunc("s:DI_FillAdjacent(frow=".a:frow." fcolL=".a:fcolL." fcolR=".a:fcolR.")") + + let icol = a:fcolL + while icol <= a:fcolR + if !s:IsBoundary(a:frow,icol) + call s:DI_Flood(a:frow,icol) + endif + let icol= icol + 1 + endwhile + +" call Dret("s:DI_FillAdjacent") +endfun + +" --------------------------------------------------------------------- +" s:SetPosn: set cursor to given position on screen {{{2 +" srow,scol: -s-creen row and column +" Returns 1 : failed sanity check +" 0 : otherwise +fun! s:SetPosn(row,col) +" call Dfunc("s:SetPosn(row=".a:row." col=".a:col.")") + " sanity checks + if a:row < 1 +" call Dret("s:SetPosn 1") + return 1 + endif + if a:col < 1 +" call Dret("s:SetPosn 1") + return 1 + endif + + exe "norm! ".a:row."G".a:col."\" + +" call Dret("s:SetPosn 0") + return 0 +endfun + +" --------------------------------------------------------------------- +" s:IsBoundary: returns 0 if not on boundary, 1 if on boundary {{{2 +" The "boundary" also includes the fill character. +fun! s:IsBoundary(row,col) +" call Dfunc("s:IsBoundary(row=".a:row." col=".a:col.")") + + let orow= line(".") + let ocol= virtcol(".") + exe "norm! ".a:row."G".a:col."\" + norm! vy + let ret= @0 =~ s:bndry + if a:row != orow || a:col != ocol + exe "norm! ".orow."G".ocol."\" + endif + +" call Dret("s:IsBoundary ".ret." : @0<".@0.">") + return ret +endfun + +" --------------------------------------------------------------------- +" s:PutBlock: puts a register's contents into the text at the current {{{2 +" cursor location +" replace= 0: Blanks are transparent +" = 1: Blanks copy over +" = 2: Erase all drawing characters +" +fun! s:PutBlock(block,replace) +" call Dfunc("s:PutBlock(block<".a:block."> replace=".a:replace.")") + call s:SavePosn() + exe "let block = @".a:block + let blocklen = strlen(block) + let drawit_line = line('.') + let drawchars = '['.escape(b:di_vert.b:di_horiz.b:di_plus.b:di_upright.b:di_upleft.b:di_cross,'\-').']' + + " insure that putting a block will do so in a region containing spaces out to textwidth + exe "let blockrows= strlen(substitute(@".a:block.",'[^[:cntrl:]]','','g'))" + exe 'let blockcols= strlen(substitute(@'.a:block.",'^\\(.\\{-}\\)\\n\\_.*$','\\1',''))" + let curline= line('.') + let curcol = virtcol('.') +" call Decho("blockrows=".blockrows." blockcols=".blockcols." curline=".curline." curcol=".curcol) + call s:AutoCanvas(curline-1,curline + blockrows+1,curcol + blockcols) + + let iblock = 0 + while iblock < blocklen + let chr= strpart(block,iblock,1) + + if char2nr(chr) == 10 + " handle newline + let drawit_line= drawit_line + 1 + if b:drawit_col_{s:saveposn_count} == 0 + exe "norm! ".drawit_line."G0" + else + exe "norm! ".drawit_line."G0".b:drawit_col_{s:saveposn_count}."l" + endif + + elseif a:replace == 2 + " replace all drawing characters with blanks + if match(chr,drawchars) != -1 + norm! r l + else + norm! l + endif + + elseif chr == ' ' && a:replace == 0 + " allow blanks to be transparent + norm! l + + else + " usual replace character + exe "norm! r".chr."l" + endif + let iblock = iblock + 1 + endwhile + call s:RestorePosn() + +" call Dret("s:PutBlock") +endfun + +" --------------------------------------------------------------------- +" s:AutoCanvas: automatic "Canvas" routine {{{2 +fun! s:AutoCanvas(linestart,linestop,cols) +" call Dfunc("s:AutoCanvas(linestart=".a:linestart." linestop=".a:linestop." cols=".a:cols.") line($)=".line("$")) + + " insure there's enough blank lines at end-of-file + if line("$") < a:linestop +" call Decho("append ".(a:linestop - line("$"))." empty lines") + call s:SavePosn() + exe "norm! G".(a:linestop - line("$"))."o\" + call s:RestorePosn() + endif + + " insure that any tabs contained within the selected region are converted to blanks + let etkeep= &et + set et +" call Decho("exe ".a:linestart.",".a:linestop."retab") + exe a:linestart.",".a:linestop."retab" + let &et= etkeep + + " insure that there's whitespace to textwidth/screenwidth/a:cols + if a:cols <= 0 + let tw= &tw + if tw <= 0 + let tw= &columns + endif + else + let tw= a:cols + endif +" Decho("tw=".tw) + if search('^$\|.\%<'.(tw+1).'v$',"cn",(a:linestop+1)) > 0 +" call Decho("append trailing whitespace") + call s:Spacer(a:linestart,a:linestop,tw) + endif + +" call Dret("s:AutoCanvas : tw=".tw) +endfun + +" ===================================================================== +" DrawIt Functions: (by Sylvain Viart) {{{1 +" ===================================================================== + +" --------------------------------------------------------------------- +" s:Canvas: {{{2 +fun! s:Canvas() +" call Dfunc("s:Canvas()") + + let lines = input("how many lines under the cursor? ") + let curline= line('.') + if curline < line('$') + exe "norm! ".lines."o\" + endif + call s:Spacer(curline+1,curline+lines,0) + let b:drawit_canvas_used= 1 + +" call Dret("s:Canvas") +endf + +" --------------------------------------------------------------------- +" s:Spacer: fill end of line with space {{{2 +" if a:cols >0: to the virtual column specified by a:cols +" <=0: to textwidth (if nonzero), otherwise +" to display width (&columns) +fun! s:Spacer(debut, fin, cols) range +" call Dfunc("s:Spacer(debut=".a:debut." fin=".a:fin." cols=".a:cols.")") + call s:SavePosn() + + if a:cols <= 0 + let width = &textwidth + if width <= 0 + let width= &columns + endif + else + let width= a:cols + endif + + let l= a:debut + while l <= a:fin + call setline(l,printf('%-'.width.'s',getline(l))) + let l = l + 1 + endwhile + + call s:RestorePosn() + +" call Dret("s:Spacer") +endf + +" --------------------------------------------------------------------- +" s:CallBox: call the specified function using the current visual selection box {{{2 +fun! s:CallBox(func_name) +" call Dfunc("s:CallBox(func_name<".a:func_name.">)") + + let xdep = b:xmouse_start + let ydep = b:ymouse_start + let col0 = virtcol("'<") + let row0 = line("'<") + let col1 = virtcol("'>") + let row1 = line("'>") +" call Decho("TL corner[".row0.",".col0."] original") +" call Decho("BR corner[".row1.",".col1."] original") +" call Decho("xydep [".ydep.",".xdep."]") + + if col1 == xdep && row1 == ydep + let col1 = col0 + let row1 = row0 + let col0 = xdep + let row0 = ydep + endif +" call Decho("TL corner[".row0.",".col0."]") +" call Decho("BR corner[".row1.",".col1."]") + + " insure that the selected region has blanks to that specified by col1 + call s:AutoCanvas((row0 < row1)? row0 : row1,(row1 > row0)? row1 : row0,(col1 > col0)? col1 : col0) + +" call Decho("exe call s:".a:func_name."(".col0.','.row0.','.col1.','.row1.")") + exe "call s:".a:func_name."(".col0.','.row0.','.col1.','.row1.")" + let b:xmouse_start= 0 + let b:ymouse_start= 0 + +" call Dret("s:CallBox") +endf + +" --------------------------------------------------------------------- +" s:DrawBox: {{{2 +fun! s:DrawBox(x0, y0, x1, y1) +" call Dfunc("s:DrawBox(xy0[".a:x0.",".a:y0." xy1[".a:x1.",".a:y1."])") + " loop each line + let l = a:y0 + while l <= a:y1 + let c = a:x0 + while c <= a:x1 + if l == a:y0 || l == a:y1 + let remp = '-' + if c == a:x0 || c == a:x1 + let remp = '+' + endif + else + let remp = '|' + if c != a:x0 && c != a:x1 + let remp = '.' + endif + endif + + if remp != '.' + call s:SetCharAt(remp, c, l) + endif + let c = c + 1 + endw + let l = l + 1 + endw + +" call Dret("s:DrawBox") +endf + +" --------------------------------------------------------------------- +" s:SetCharAt: set the character at the specified position (must exist) {{{2 +fun! s:SetCharAt(char, x, y) +" call Dfunc("s:SetCharAt(char<".a:char."> xy[".a:x.",".a:y."])") + + let content = getline(a:y) + let long = strlen(content) + let deb = strpart(content, 0, a:x - 1) + let fin = strpart(content, a:x, long) + call setline(a:y, deb.a:char.fin) + +" call Dret("s:SetCharAt") +endf + +" --------------------------------------------------------------------- +" s:DrawLine: Bresenham line-drawing algorithm {{{2 +" taken from : +" http://www.graphics.lcs.mit.edu/~mcmillan/comp136/Lecture6/Lines.html +fun! s:DrawLine(x0, y0, x1, y1, horiz) +" call Dfunc("s:DrawLine(xy0[".a:x0.",".a:y0."] xy1[".a:x1.",".a:y1."] horiz=".a:horiz.")") + + if ( a:x0 < a:x1 && a:y0 > a:y1 ) || ( a:x0 > a:x1 && a:y0 > a:y1 ) + " swap direction + let x0 = a:x1 + let y0 = a:y1 + let x1 = a:x0 + let y1 = a:y0 + else + let x0 = a:x0 + let y0 = a:y0 + let x1 = a:x1 + let y1 = a:y1 + endif + let dy = y1 - y0 + let dx = x1 - x0 + + if dy < 0 + let dy = -dy + let stepy = -1 + else + let stepy = 1 + endif + + if dx < 0 + let dx = -dx + let stepx = -1 + else + let stepx = 1 + endif + + let dy = 2*dy + let dx = 2*dx + + if dx > dy + " move under x + let char = a:horiz + call s:SetCharAt(char, x0, y0) + let fraction = dy - (dx / 2) " same as 2*dy - dx + while x0 != x1 + let char = a:horiz + if fraction >= 0 + if stepx > 0 + let char = '\' + else + let char = '/' + endif + let y0 = y0 + stepy + let fraction = fraction - dx " same as fraction -= 2*dx + endif + let x0 = x0 + stepx + let fraction = fraction + dy " same as fraction = fraction - 2*dy + call s:SetCharAt(char, x0, y0) + endw + else + " move under y + let char = '|' + call s:SetCharAt(char, x0, y0) + let fraction = dx - (dy / 2) + while y0 != y1 + let char = '|' + if fraction >= 0 + if stepy > 0 || stepx < 0 + let char = '\' + else + let char = '/' + endif + let x0 = x0 + stepx + let fraction = fraction - dy + endif + let y0 = y0 + stepy + let fraction = fraction + dx + call s:SetCharAt(char, x0, y0) + endw + endif + +" call Dret("s:DrawLine") +endf + +" --------------------------------------------------------------------- +" s:Arrow: {{{2 +fun! s:Arrow(x0, y0, x1, y1) +" call Dfunc("s:Arrow(xy0[".a:x0.",".a:y0."] xy1[".a:x1.",".a:y1."])") + + call s:DrawLine(a:x0, a:y0, a:x1, a:y1,'-') + let dy = a:y1 - a:y0 + let dx = a:x1 - a:x0 + if s:Abs(dx) > Abs(dy) + " move x + if dx > 0 + call s:SetCharAt('>', a:x1, a:y1) + else + call s:SetCharAt('<', a:x1, a:y1) + endif + else + " move y + if dy > 0 + call s:SetCharAt('v', a:x1, a:y1) + else + call s:SetCharAt('^', a:x1, a:y1) + endif + endif + +" call Dret("s:Arrow") +endf + +" --------------------------------------------------------------------- +" s:Abs: return absolute value {{{2 +fun! s:Abs(val) + if a:val < 0 + return - a:val + else + return a:val + endif +endf + +" --------------------------------------------------------------------- +" s:DrawPlainLine: {{{2 +fun! s:DrawPlainLine(x0,y0,x1,y1) +" call Dfunc("s:DrawPlainLine(xy0[".a:x0.",".a:y0."] xy1[".a:x1.",".a:y1."])") + +" call Decho("exe call s:DrawLine(".a:x0.','.a:y0.','.a:x1.','.a:y1.',"_")') + exe "call s:DrawLine(".a:x0.','.a:y0.','.a:x1.','.a:y1.',"_")' + +" call Dret("s:DrawPlainLine") +endf + +" ===================================================================== +" Mouse Functions: {{{1 +" ===================================================================== + +" --------------------------------------------------------------------- +" s:LeftStart: Read visual drag mapping {{{2 +" The visual start point is saved in b:xmouse_start and b:ymouse_start +fun! s:LeftStart() +" call Dfunc("s:LeftStart()") + let b:xmouse_start = virtcol('.') + let b:ymouse_start = line('.') + vnoremap :call LeftRelease()gv +" call Dret("s:LeftStart : [".b:ymouse_start.",".b:xmouse_start."]") +endf! + +" --------------------------------------------------------------------- +" s:LeftRelease: {{{2 +fun! s:LeftRelease() +" call Dfunc("s:LeftRelease()") + vunmap +" call Dret("s:LeftRelease : [".line('.').','.virtcol('.').']') +endf + +" --------------------------------------------------------------------- +" s:SLeftStart: begin drawing with a brush {{{2 +fun! s:SLeftStart() + if !exists("b:drawit_brush") + let b:drawit_brush= "a" + endif +" call Dfunc("s:SLeftStart() brush=".b:drawit_brush.' ['.line('.').','.virtcol('.').']') + noremap :call SLeftDrag() + noremap :call SLeftRelease() +" call Dret("s:SLeftStart") +endfun + +" --------------------------------------------------------------------- +" s:SLeftDrag: {{{2 +fun! s:SLeftDrag() +" call Dfunc("s:SLeftDrag() brush=".b:drawit_brush.' ['.line('.').','.virtcol('.').']') + call s:SavePosn() + call s:PutBlock(b:drawit_brush,0) + call s:RestorePosn() +" call Dret("s:SLeftDrag") +endfun + +" --------------------------------------------------------------------- +" s:SLeftRelease: {{{2 +fun! s:SLeftRelease() +" call Dfunc("s:SLeftRelease() brush=".b:drawit_brush.' ['.line('.').','.virtcol('.').']') + call s:SLeftDrag() + nunmap + nunmap +" call Dret("s:SLeftRelease") +endfun + +" --------------------------------------------------------------------- +" s:CLeftStart: begin moving a block of text {{{2 +fun! s:CLeftStart() + if !exists("b:drawit_brush") + let b:drawit_brush= "a" + endif +" call Dfunc("s:CLeftStart() brush=".b:drawit_brush) + if !line("'<") || !line("'>") + redraw! + echohl Error + echo "must visual-block select a region first" +" call Dret("s:CLeftStart : must visual-block select a region first") + return + endif + '<,'>call DrawIt#SetBrush(b:drawit_brush) + let s:cleft_width= virtcol("'>") - virtcol("'<") + if s:cleft_width < 0 + let s:cleft_width= -s:cleft_width + endif + let s:cleft_height= line("'>") - line("'<") + if s:cleft_height < 0 + let s:cleft_height= -s:cleft_height + endif +" call Decho("blocksize: ".s:cleft_height."x".s:cleft_width) + noremap :call CLeftDrag() + noremap :call CLeftRelease() +" call Dret("s:CLeftStart") +endfun + +" --------------------------------------------------------------------- +" s:CLeftDrag: {{{2 +fun! s:CLeftDrag() +" call Dfunc("s:CLeftDrag() cleft_width=".s:cleft_width." cleft_height=".s:cleft_height) + exe 'let keepbrush= @'.b:drawit_brush +" call Decho("keepbrush<".keepbrush.">") + + " restore prior contents of block zone + if exists("s:cleft_oldblock") +" call Decho("draw prior contents: [".line(".").",".virtcol(".")."] line($)=".line("$")) +" call Decho("draw prior contents<".s:cleft_oldblock.">") + exe 'let @'.b:drawit_brush.'=s:cleft_oldblock' + call s:PutBlock(b:drawit_brush,1) + else + " first move; put blanks where text had been +" call Decho("first move, put blanks where text was") + norm! gvr + endif + + " move cursor to position + exe "norm! \" + + " save new block zone contents +" call Decho("save contents: [".line(".").",".virtcol(".")."] - [".(line(".")+s:cleft_height).",".(virtcol(".")+s:cleft_width)."]") + let curline= line(".") + call s:AutoCanvas(curline,curline + s:cleft_height,virtcol(".")+s:cleft_width) + if s:cleft_width > 0 && s:cleft_height > 0 + exe "silent! norm! \".s:cleft_width."l".s:cleft_height.'j"'.b:drawit_brush.'y' + elseif s:cleft_width > 0 + exe "silent! norm! \".s:cleft_width.'l"'.b:drawit_brush.'y' + else + exe "silent! norm! \".s:cleft_height.'j"'.b:drawit_brush.'y' + endif + exe "let s:cleft_oldblock= @".b:drawit_brush +" call Decho("cleft_height=".s:cleft_height." cleft_width=".s:cleft_width) +" call Decho("save contents<".s:cleft_oldblock.">") + + " draw the brush +" call Decho("draw brush") +" call Decho("draw brush ".b:drawit_brush.": [".line(".").",".virtcol(".")."] line($)=".line("$")) + exe 'let @'.b:drawit_brush.'=keepbrush' + call s:PutBlock(b:drawit_brush,1) + +" call Dret("s:CLeftDrag") +endfun + +" --------------------------------------------------------------------- +" s:CLeftRelease: {{{2 +fun! s:CLeftRelease() +" call Dfunc("s:CLeftRelease()") + call s:CLeftDrag() + nunmap + nunmap + unlet s:cleft_oldblock s:cleft_height s:cleft_width +" call Dret("s:CLeftRelease") +endfun + +" --------------------------------------------------------------------- +" DrawIt#SetBrush: {{{2 +fun! DrawIt#SetBrush(brush) range +" call Dfunc("DrawIt#SetBrush(brush<".a:brush.">)") + let b:drawit_brush= a:brush +" call Decho("visualmode<".visualmode()."> range[".a:firstline.",".a:lastline."] visrange[".line("'<").",".line("'>")."]") + if visualmode() == "\" && ((a:firstline == line("'>") && a:lastline == line("'<")) || (a:firstline == line("'<") && a:lastline == line("'>"))) + " last visual mode was visual block mode, and + " either [firstline,lastline] == ['<,'>] or ['>,'<] + " Assuming that SetBrush called from a visual-block selection! + " Yank visual block into selected register (brush) +" call Decho("yanking visual block into register ".b:drawit_brush) + exe 'norm! gv"'.b:drawit_brush.'y' + endif +" call Dret("DrawIt#SetBrush : b:drawit_brush=".b:drawit_brush) +endfun + +" ------------------------------------------------------------------------ +" Modelines: {{{1 +" vim: fdm=marker +let &cpo= s:keepcpo +unlet s:keepcpo diff --git a/.vim/autoload/pythoncomplete.vim b/.vim/autoload/pythoncomplete.vim new file mode 100644 index 0000000..1474493 --- /dev/null +++ b/.vim/autoload/pythoncomplete.vim @@ -0,0 +1,606 @@ +"pythoncomplete.vim - Omni Completion for python +" Maintainer: Aaron Griffin +" Version: 0.8 +" Last Updated: 8 Oct 2007 +" +" Changes +" TODO: +" User defined docstrings aren't handled right... +" 'info' item output can use some formatting work +" Add an "unsafe eval" mode, to allow for return type evaluation +" Complete basic syntax along with import statements +" i.e. "import url" +" Continue parsing on invalid line?? +" +" v 0.8 +" * Fixed an issue where the FIRST assignment was always used instead of +" using a subsequent assignment for a variable +" * Fixed a scoping issue when working inside a parameterless function +" +" +" v 0.7 +" * Fixed function list sorting (_ and __ at the bottom) +" * Removed newline removal from docs. It appears vim handles these better in +" recent patches +" +" v 0.6: +" * Fixed argument completion +" * Removed the 'kind' completions, as they are better indicated +" with real syntax +" * Added tuple assignment parsing (whoops, that was forgotten) +" * Fixed import handling when flattening scope +" +" v 0.5: +" Yeah, I skipped a version number - 0.4 was never public. +" It was a bugfix version on top of 0.3. This is a complete +" rewrite. +" + +if !has('python') + echo "Error: Required vim compiled with +python" + finish +endif + +function! pythoncomplete#Complete(findstart, base) + "findstart = 1 when we need to get the text length + if a:findstart == 1 + let line = getline('.') + let idx = col('.') + while idx > 0 + let idx -= 1 + let c = line[idx] + if c =~ '\w' + continue + elseif ! c =~ '\.' + let idx = -1 + break + else + break + endif + endwhile + + return idx + "findstart = 0 when we need to return the list of completions + else + "vim no longer moves the cursor upon completion... fix that + let line = getline('.') + let idx = col('.') + let cword = '' + while idx > 0 + let idx -= 1 + let c = line[idx] + if c =~ '\w' || c =~ '\.' || c == '(' + let cword = c . cword + continue + elseif strlen(cword) > 0 || idx == 0 + break + endif + endwhile + execute "python vimcomplete('" . cword . "', '" . a:base . "')" + return g:pythoncomplete_completions + endif +endfunction + +function! s:DefPython() +python << PYTHONEOF +import sys, tokenize, cStringIO, types +from token import NAME, DEDENT, NEWLINE, STRING + +debugstmts=[] +def dbg(s): debugstmts.append(s) +def showdbg(): + for d in debugstmts: print "DBG: %s " % d + +def vimcomplete(context,match): + global debugstmts + debugstmts = [] + try: + import vim + def complsort(x,y): + try: + xa = x['abbr'] + ya = y['abbr'] + if xa[0] == '_': + if xa[1] == '_' and ya[0:2] == '__': + return xa > ya + elif ya[0:2] == '__': + return -1 + elif y[0] == '_': + return xa > ya + else: + return 1 + elif ya[0] == '_': + return -1 + else: + return xa > ya + except: + return 0 + cmpl = Completer() + cmpl.evalsource('\n'.join(vim.current.buffer),vim.eval("line('.')")) + all = cmpl.get_completions(context,match) + all.sort(complsort) + dictstr = '[' + # have to do this for double quoting + for cmpl in all: + dictstr += '{' + for x in cmpl: dictstr += '"%s":"%s",' % (x,cmpl[x]) + dictstr += '"icase":0},' + if dictstr[-1] == ',': dictstr = dictstr[:-1] + dictstr += ']' + #dbg("dict: %s" % dictstr) + vim.command("silent let g:pythoncomplete_completions = %s" % dictstr) + #dbg("Completion dict:\n%s" % all) + except vim.error: + dbg("VIM Error: %s" % vim.error) + +class Completer(object): + def __init__(self): + self.compldict = {} + self.parser = PyParser() + + def evalsource(self,text,line=0): + sc = self.parser.parse(text,line) + src = sc.get_code() + dbg("source: %s" % src) + try: exec(src) in self.compldict + except: dbg("parser: %s, %s" % (sys.exc_info()[0],sys.exc_info()[1])) + for l in sc.locals: + try: exec(l) in self.compldict + except: dbg("locals: %s, %s [%s]" % (sys.exc_info()[0],sys.exc_info()[1],l)) + + def _cleanstr(self,doc): + return doc.replace('"',' ').replace("'",' ') + + def get_arguments(self,func_obj): + def _ctor(obj): + try: return class_ob.__init__.im_func + except AttributeError: + for base in class_ob.__bases__: + rc = _find_constructor(base) + if rc is not None: return rc + return None + + arg_offset = 1 + if type(func_obj) == types.ClassType: func_obj = _ctor(func_obj) + elif type(func_obj) == types.MethodType: func_obj = func_obj.im_func + else: arg_offset = 0 + + arg_text='' + if type(func_obj) in [types.FunctionType, types.LambdaType]: + try: + cd = func_obj.func_code + real_args = cd.co_varnames[arg_offset:cd.co_argcount] + defaults = func_obj.func_defaults or '' + defaults = map(lambda name: "=%s" % name, defaults) + defaults = [""] * (len(real_args)-len(defaults)) + defaults + items = map(lambda a,d: a+d, real_args, defaults) + if func_obj.func_code.co_flags & 0x4: + items.append("...") + if func_obj.func_code.co_flags & 0x8: + items.append("***") + arg_text = (','.join(items)) + ')' + + except: + dbg("arg completion: %s: %s" % (sys.exc_info()[0],sys.exc_info()[1])) + pass + if len(arg_text) == 0: + # The doc string sometimes contains the function signature + # this works for alot of C modules that are part of the + # standard library + doc = func_obj.__doc__ + if doc: + doc = doc.lstrip() + pos = doc.find('\n') + if pos > 0: + sigline = doc[:pos] + lidx = sigline.find('(') + ridx = sigline.find(')') + if lidx > 0 and ridx > 0: + arg_text = sigline[lidx+1:ridx] + ')' + if len(arg_text) == 0: arg_text = ')' + return arg_text + + def get_completions(self,context,match): + dbg("get_completions('%s','%s')" % (context,match)) + stmt = '' + if context: stmt += str(context) + if match: stmt += str(match) + try: + result = None + all = {} + ridx = stmt.rfind('.') + if len(stmt) > 0 and stmt[-1] == '(': + result = eval(_sanitize(stmt[:-1]), self.compldict) + doc = result.__doc__ + if doc == None: doc = '' + args = self.get_arguments(result) + return [{'word':self._cleanstr(args),'info':self._cleanstr(doc)}] + elif ridx == -1: + match = stmt + all = self.compldict + else: + match = stmt[ridx+1:] + stmt = _sanitize(stmt[:ridx]) + result = eval(stmt, self.compldict) + all = dir(result) + + dbg("completing: stmt:%s" % stmt) + completions = [] + + try: maindoc = result.__doc__ + except: maindoc = ' ' + if maindoc == None: maindoc = ' ' + for m in all: + if m == "_PyCmplNoType": continue #this is internal + try: + dbg('possible completion: %s' % m) + if m.find(match) == 0: + if result == None: inst = all[m] + else: inst = getattr(result,m) + try: doc = inst.__doc__ + except: doc = maindoc + typestr = str(inst) + if doc == None or doc == '': doc = maindoc + + wrd = m[len(match):] + c = {'word':wrd, 'abbr':m, 'info':self._cleanstr(doc)} + if "function" in typestr: + c['word'] += '(' + c['abbr'] += '(' + self._cleanstr(self.get_arguments(inst)) + elif "method" in typestr: + c['word'] += '(' + c['abbr'] += '(' + self._cleanstr(self.get_arguments(inst)) + elif "module" in typestr: + c['word'] += '.' + elif "class" in typestr: + c['word'] += '(' + c['abbr'] += '(' + completions.append(c) + except: + i = sys.exc_info() + dbg("inner completion: %s,%s [stmt='%s']" % (i[0],i[1],stmt)) + return completions + except: + i = sys.exc_info() + dbg("completion: %s,%s [stmt='%s']" % (i[0],i[1],stmt)) + return [] + +class Scope(object): + def __init__(self,name,indent): + self.subscopes = [] + self.docstr = '' + self.locals = [] + self.parent = None + self.name = name + self.indent = indent + + def add(self,sub): + #print 'push scope: [%s@%s]' % (sub.name,sub.indent) + sub.parent = self + self.subscopes.append(sub) + return sub + + def doc(self,str): + """ Clean up a docstring """ + d = str.replace('\n',' ') + d = d.replace('\t',' ') + while d.find(' ') > -1: d = d.replace(' ',' ') + while d[0] in '"\'\t ': d = d[1:] + while d[-1] in '"\'\t ': d = d[:-1] + self.docstr = d + + def local(self,loc): + self._checkexisting(loc) + self.locals.append(loc) + + def copy_decl(self,indent=0): + """ Copy a scope's declaration only, at the specified indent level - not local variables """ + return Scope(self.name,indent) + + def _checkexisting(self,test): + "Convienance function... keep out duplicates" + if test.find('=') > -1: + var = test.split('=')[0].strip() + for l in self.locals: + if l.find('=') > -1 and var == l.split('=')[0].strip(): + self.locals.remove(l) + + def get_code(self): + # we need to start with this, to fix up broken completions + # hopefully this name is unique enough... + str = '"""'+self.docstr+'"""\n' + for l in self.locals: + if l.startswith('import'): str += l+'\n' + str += 'class _PyCmplNoType:\n def __getattr__(self,name):\n return None\n' + for sub in self.subscopes: + str += sub.get_code() + for l in self.locals: + if not l.startswith('import'): str += l+'\n' + + return str + + def pop(self,indent): + #print 'pop scope: [%s] to [%s]' % (self.indent,indent) + outer = self + while outer.parent != None and outer.indent >= indent: + outer = outer.parent + return outer + + def currentindent(self): + #print 'parse current indent: %s' % self.indent + return ' '*self.indent + + def childindent(self): + #print 'parse child indent: [%s]' % (self.indent+1) + return ' '*(self.indent+1) + +class Class(Scope): + def __init__(self, name, supers, indent): + Scope.__init__(self,name,indent) + self.supers = supers + def copy_decl(self,indent=0): + c = Class(self.name,self.supers,indent) + for s in self.subscopes: + c.add(s.copy_decl(indent+1)) + return c + def get_code(self): + str = '%sclass %s' % (self.currentindent(),self.name) + if len(self.supers) > 0: str += '(%s)' % ','.join(self.supers) + str += ':\n' + if len(self.docstr) > 0: str += self.childindent()+'"""'+self.docstr+'"""\n' + if len(self.subscopes) > 0: + for s in self.subscopes: str += s.get_code() + else: + str += '%spass\n' % self.childindent() + return str + + +class Function(Scope): + def __init__(self, name, params, indent): + Scope.__init__(self,name,indent) + self.params = params + def copy_decl(self,indent=0): + return Function(self.name,self.params,indent) + def get_code(self): + str = "%sdef %s(%s):\n" % \ + (self.currentindent(),self.name,','.join(self.params)) + if len(self.docstr) > 0: str += self.childindent()+'"""'+self.docstr+'"""\n' + str += "%spass\n" % self.childindent() + return str + +class PyParser: + def __init__(self): + self.top = Scope('global',0) + self.scope = self.top + + def _parsedotname(self,pre=None): + #returns (dottedname, nexttoken) + name = [] + if pre == None: + tokentype, token, indent = self.next() + if tokentype != NAME and token != '*': + return ('', token) + else: token = pre + name.append(token) + while True: + tokentype, token, indent = self.next() + if token != '.': break + tokentype, token, indent = self.next() + if tokentype != NAME: break + name.append(token) + return (".".join(name), token) + + def _parseimportlist(self): + imports = [] + while True: + name, token = self._parsedotname() + if not name: break + name2 = '' + if token == 'as': name2, token = self._parsedotname() + imports.append((name, name2)) + while token != "," and "\n" not in token: + tokentype, token, indent = self.next() + if token != ",": break + return imports + + def _parenparse(self): + name = '' + names = [] + level = 1 + while True: + tokentype, token, indent = self.next() + if token in (')', ',') and level == 1: + names.append(name) + name = '' + if token == '(': + level += 1 + elif token == ')': + level -= 1 + if level == 0: break + elif token == ',' and level == 1: + pass + else: + name += str(token) + return names + + def _parsefunction(self,indent): + self.scope=self.scope.pop(indent) + tokentype, fname, ind = self.next() + if tokentype != NAME: return None + + tokentype, open, ind = self.next() + if open != '(': return None + params=self._parenparse() + + tokentype, colon, ind = self.next() + if colon != ':': return None + + return Function(fname,params,indent) + + def _parseclass(self,indent): + self.scope=self.scope.pop(indent) + tokentype, cname, ind = self.next() + if tokentype != NAME: return None + + super = [] + tokentype, next, ind = self.next() + if next == '(': + super=self._parenparse() + elif next != ':': return None + + return Class(cname,super,indent) + + def _parseassignment(self): + assign='' + tokentype, token, indent = self.next() + if tokentype == tokenize.STRING or token == 'str': + return '""' + elif token == '(' or token == 'tuple': + return '()' + elif token == '[' or token == 'list': + return '[]' + elif token == '{' or token == 'dict': + return '{}' + elif tokentype == tokenize.NUMBER: + return '0' + elif token == 'open' or token == 'file': + return 'file' + elif token == 'None': + return '_PyCmplNoType()' + elif token == 'type': + return 'type(_PyCmplNoType)' #only for method resolution + else: + assign += token + level = 0 + while True: + tokentype, token, indent = self.next() + if token in ('(','{','['): + level += 1 + elif token in (']','}',')'): + level -= 1 + if level == 0: break + elif level == 0: + if token in (';','\n'): break + assign += token + return "%s" % assign + + def next(self): + type, token, (lineno, indent), end, self.parserline = self.gen.next() + if lineno == self.curline: + #print 'line found [%s] scope=%s' % (line.replace('\n',''),self.scope.name) + self.currentscope = self.scope + return (type, token, indent) + + def _adjustvisibility(self): + newscope = Scope('result',0) + scp = self.currentscope + while scp != None: + if type(scp) == Function: + slice = 0 + #Handle 'self' params + if scp.parent != None and type(scp.parent) == Class: + slice = 1 + p = scp.params[0] + i = p.find('=') + if i != -1: p = p[:i] + newscope.local('%s = %s' % (scp.params[0],scp.parent.name)) + for p in scp.params[slice:]: + i = p.find('=') + if len(p) == 0: continue + if i == -1: + newscope.local('%s = _PyCmplNoType()' % p) + else: + newscope.local('%s = %s' % (p[:i],_sanitize(p[i+1]))) + + for s in scp.subscopes: + ns = s.copy_decl(0) + newscope.add(ns) + for l in scp.locals: newscope.local(l) + scp = scp.parent + + self.currentscope = newscope + return self.currentscope + + #p.parse(vim.current.buffer[:],vim.eval("line('.')")) + def parse(self,text,curline=0): + self.curline = int(curline) + buf = cStringIO.StringIO(''.join(text) + '\n') + self.gen = tokenize.generate_tokens(buf.readline) + self.currentscope = self.scope + + try: + freshscope=True + while True: + tokentype, token, indent = self.next() + #dbg( 'main: token=[%s] indent=[%s]' % (token,indent)) + + if tokentype == DEDENT or token == "pass": + self.scope = self.scope.pop(indent) + elif token == 'def': + func = self._parsefunction(indent) + if func == None: + print "function: syntax error..." + continue + freshscope = True + self.scope = self.scope.add(func) + elif token == 'class': + cls = self._parseclass(indent) + if cls == None: + print "class: syntax error..." + continue + freshscope = True + self.scope = self.scope.add(cls) + + elif token == 'import': + imports = self._parseimportlist() + for mod, alias in imports: + loc = "import %s" % mod + if len(alias) > 0: loc += " as %s" % alias + self.scope.local(loc) + freshscope = False + elif token == 'from': + mod, token = self._parsedotname() + if not mod or token != "import": + print "from: syntax error..." + continue + names = self._parseimportlist() + for name, alias in names: + loc = "from %s import %s" % (mod,name) + if len(alias) > 0: loc += " as %s" % alias + self.scope.local(loc) + freshscope = False + elif tokentype == STRING: + if freshscope: self.scope.doc(token) + elif tokentype == NAME: + name,token = self._parsedotname(token) + if token == '=': + stmt = self._parseassignment() + dbg("parseassignment: %s = %s" % (name, stmt)) + if stmt != None: + self.scope.local("%s = %s" % (name,stmt)) + freshscope = False + except StopIteration: #thrown on EOF + pass + except: + dbg("parse error: %s, %s @ %s" % + (sys.exc_info()[0], sys.exc_info()[1], self.parserline)) + return self._adjustvisibility() + +def _sanitize(str): + val = '' + level = 0 + for c in str: + if c in ('(','{','['): + level += 1 + elif c in (']','}',')'): + level -= 1 + elif level == 0: + val += c + return val + +sys.path.extend(['.','..']) +PYTHONEOF +endfunction + +call s:DefPython() +" vim: set et ts=4: diff --git a/.vim/colors/barak.vim b/.vim/colors/barak.vim index 98f9ba1..4898464 100644 --- a/.vim/colors/barak.vim +++ b/.vim/colors/barak.vim @@ -1,9 +1,6 @@ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " File: "/home/michener/.vim/barak.vim" -" Version: 1.4 -" Created: "Sun Jul 30 23:54:41 PDT 2006" -" Updated: "Sun Jan 7 02:12:52 PST 2007" -" Copyright (C) 2006, Barak Michener +" Copyright (C) 2008, Barak Michener " Modified from colorscheme "dante": " Copyright (C) 2002, Caciano Machado """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -56,12 +53,14 @@ endif " syntax hi colors hi Comment term=bold ctermfg=darkgreen guifg=ForestGreen hi PreProc term=underline ctermfg=darkmagenta guifg=magenta3 -hi Constant term=underline ctermfg=red guifg=firebrick3 +hi Constant term=underline ctermfg=red guifg=#b62f61 +hi String term=underline ctermfg=red guifg=firebrick3 +hi Boolean term=underline ctermfg=magenta guifg=LightSalmon1 "hi Type term=underline ctermfg=darkcyan gui=none guifg=CadetBlue3 -hi Type term=underline ctermfg=darkcyan gui=none guifg=turquoise3 -hi Statement term=bold ctermfg=blue gui=none guifg=RoyalBlue1 +hi Type term=underline ctermfg=darkcyan gui=bold guifg=turquoise3 +hi Statement term=bold ctermfg=blue gui=bold guifg=RoyalBlue1 hi Identifier term=underline ctermfg=darkcyan guifg=DeepSkyBlue -hi Function ctermfg=darkcyan guifg=MediumPurple2 +hi Function ctermfg=darkcyan gui=bold guifg=MediumPurple2 hi Ignore term=bold ctermfg=darkgray gui=bold guifg=gray45 hi Special term=underline ctermfg=brown guifg=khaki3 hi Error term=reverse ctermfg=gray ctermbg=red guifg=gray guibg=red3 @@ -72,7 +71,8 @@ hi Number term=underline ctermfg=darkyellow guifg=goldenrod1 hi link String Constant hi link Character Constant hi link Number Constant -hi link Boolean Constant +"hi link Boolean Constant +hi link javaScriptNull Special hi link Float Number "hi link Function Identifier hi link Number Constant @@ -83,7 +83,8 @@ hi link Keyword Statement hi link Exception Statement hi link Operator Statement hi link Include PreProc -hi link Define PreProc +"hi link Define PreProc +hi link Define Statement hi link Macro PreProc hi link PreCondit PreProc "hi link StorageClass Type diff --git a/.vim/colors/zenburn.vim b/.vim/colors/zenburn.vim new file mode 100644 index 0000000..73a18e4 --- /dev/null +++ b/.vim/colors/zenburn.vim @@ -0,0 +1,245 @@ +" Vim color file +" Maintainer: Jani Nurminen +" Last Change: $Id: zenburn.vim,v 1.15 2006/09/07 15:57:46 jnurmine Exp $ +" URL: http://slinky.imukuppi.org/zenburn/ +" License: GPL +" +" Nothing too fancy, just some alien fruit salad to keep you in the zone. +" This syntax file was designed to be used with dark environments and +" low light situations. Of course, if it works during a daybright office, go +" ahead :) +" +" Owes heavily to other Vim color files! With special mentions +" to "BlackDust", "Camo" and "Desert". +" +" To install, copy to ~/.vim/colors directory. Then :colorscheme zenburn. +" See also :help syntax +" +" Credits: +" - Jani Nurminen - original Zenburn +" - Steve Hall & Cream posse - higher-contrast Visual selection +" - Kurt Maier - 256 color console coloring, low and high contrast toggle, +" bug fixing +" +" CONFIGURABLE PARAMETERS: +" +" You can use the default (don't set any parameters), or you can +" set some parameters to tweak the Zenburn colours. +" +" * You can now set a darker background for bright environments. To activate, use: +" contrast Zenburn, use: +" +" let g:zenburn_high_Contrast = 1 +" +" * To get more contrast to the Visual selection, use +" +" let g:zenburn_alternate_Visual = 1 +" +" * To use alternate colouring for Error message, use +" +" let g:zenburn_alternate_Error = 1 +" +" * The new default for Include is a duller orange. To use the original +" colouring for Include, use +" +" let g:zenburn_alternate_Include = 1 +" +" * To turn the parameter(s) back to defaults, use UNLET: +" +" unlet g:zenburn_alternate_Include +" +" Setting to 0 won't work! +" +" That's it, enjoy! +" +" TODO +" - Visual alternate color is broken? Try GVim >= 7.0.66 if you have trouble +" - IME colouring (CursorIM) +" - obscure syntax groups: check and colourize +" - add more groups if necessary + +set background=dark +hi clear +if exists("syntax_on") + syntax reset +endif +let g:colors_name="zenburn" + +hi Boolean guifg=#dca3a3 +hi Character guifg=#dca3a3 gui=bold +hi Comment guifg=#7f9f7f gui=italic +hi Conditional guifg=#f0dfaf gui=bold +hi Constant guifg=#dca3a3 gui=bold +hi Cursor guifg=#000d18 guibg=#8faf9f gui=bold +hi Debug guifg=#bca3a3 gui=bold +hi Define guifg=#ffcfaf gui=bold +hi Delimiter guifg=#8f8f8f +hi DiffAdd guifg=#709080 guibg=#313c36 gui=bold +hi DiffChange guibg=#333333 +hi DiffDelete guifg=#333333 guibg=#464646 +hi DiffText guifg=#ecbcbc guibg=#41363c gui=bold +hi Directory guifg=#dcdccc gui=bold +hi ErrorMsg guifg=#80d4aa guibg=#2f2f2f gui=bold +hi Exception guifg=#c3bf9f gui=bold +hi Float guifg=#c0bed1 +hi FoldColumn guifg=#93b3a3 guibg=#3f4040 +hi Folded guifg=#93b3a3 guibg=#3f4040 +hi Function guifg=#efef8f +hi Identifier guifg=#efdcbc +hi IncSearch guibg=#f8f893 guifg=#385f38 +hi Keyword guifg=#f0dfaf gui=bold +hi Label guifg=#dfcfaf gui=underline +hi LineNr guifg=#9fafaf guibg=#262626 +hi Macro guifg=#ffcfaf gui=bold +hi ModeMsg guifg=#ffcfaf gui=none +hi MoreMsg guifg=#ffffff gui=bold +hi NonText guifg=#404040 +hi Number guifg=#8cd0d3 +hi Operator guifg=#f0efd0 +hi PreCondit guifg=#dfaf8f gui=bold +hi PreProc guifg=#ffcfaf gui=bold +hi Question guifg=#ffffff gui=bold +hi Repeat guifg=#ffd7a7 gui=bold +hi Search guifg=#ffffe0 guibg=#284f28 +hi SpecialChar guifg=#dca3a3 gui=bold +hi SpecialComment guifg=#82a282 gui=bold +hi Special guifg=#cfbfaf +hi SpecialKey guifg=#9ece9e +hi Statement guifg=#e3ceab gui=none +hi StatusLine guifg=#2e4340 guibg=#ccdc90 +hi StatusLineNC guifg=#2e3330 guibg=#88b090 +hi StorageClass guifg=#c3bf9f gui=bold +hi String guifg=#cc9393 +hi Structure guifg=#efefaf gui=bold +hi Tag guifg=#e89393 gui=bold +hi Title guifg=#efefef gui=bold +hi Todo guifg=#dfdfdf guibg=bg gui=bold +hi Typedef guifg=#dfe4cf gui=bold +hi Type guifg=#dfdfbf gui=bold +hi Underlined guifg=#dcdccc gui=underline +hi VertSplit guifg=#303030 guibg=#688060 +hi VisualNOS guifg=#333333 guibg=#f18c96 gui=bold,underline +hi WarningMsg guifg=#ffffff guibg=#333333 gui=bold +hi WildMenu guibg=#2c302d guifg=#cbecd0 gui=underline + +" Entering Kurt zone +if &t_Co > 255 + hi Boolean ctermfg=181 + hi Character ctermfg=181 cterm=bold + hi Comment ctermfg=108 + hi Conditional ctermfg=223 cterm=bold + hi Constant ctermfg=181 cterm=bold + hi Cursor ctermfg=233 ctermbg=109 cterm=bold + hi Debug ctermfg=181 cterm=bold + hi Define ctermfg=223 cterm=bold + hi Delimiter ctermfg=245 + hi DiffAdd ctermfg=66 ctermbg=237 cterm=bold + hi DiffChange ctermbg=236 + hi DiffDelete ctermfg=236 ctermbg=238 + hi DiffText ctermfg=217 ctermbg=237 cterm=bold + hi Directory ctermfg=188 cterm=bold + hi ErrorMsg ctermfg=115 ctermbg=236 cterm=bold + hi Exception ctermfg=249 cterm=bold + hi Float ctermfg=251 + hi FoldColumn ctermfg=109 ctermbg=238 + hi Folded ctermfg=109 ctermbg=238 + hi Function ctermfg=228 + hi Identifier ctermfg=223 + hi IncSearch ctermbg=228 ctermfg=238 + hi Keyword ctermfg=223 cterm=bold + hi Label ctermfg=187 cterm=underline + hi LineNr ctermfg=248 ctermbg=235 + hi Macro ctermfg=223 cterm=bold + hi ModeMsg ctermfg=223 cterm=none + hi MoreMsg ctermfg=15 cterm=bold + hi NonText ctermfg=238 + hi Number ctermfg=116 + hi Operator ctermfg=230 + hi PreCondit ctermfg=180 cterm=bold + hi PreProc ctermfg=223 cterm=bold + hi Question ctermfg=15 cterm=bold + hi Repeat ctermfg=223 cterm=bold + hi Search ctermfg=230 ctermbg=236 + hi SpecialChar ctermfg=181 cterm=bold + hi SpecialComment ctermfg=108 cterm=bold + hi Special ctermfg=181 + hi SpecialKey ctermfg=151 + hi Statement ctermfg=187 ctermbg=234 cterm=none + hi StatusLine ctermfg=237 ctermbg=186 + hi StatusLineNC ctermfg=236 ctermbg=108 + hi StorageClass ctermfg=249 cterm=bold + hi String ctermfg=174 + hi Structure ctermfg=229 cterm=bold + hi Tag ctermfg=181 cterm=bold + hi Title ctermfg=7 ctermbg=234 cterm=bold + hi Todo ctermfg=108 ctermbg=234 cterm=bold + hi Typedef ctermfg=253 cterm=bold + hi Type ctermfg=187 cterm=bold + hi Underlined ctermfg=188 ctermbg=234 cterm=bold + hi VertSplit ctermfg=236 ctermbg=65 + hi VisualNOS ctermfg=236 ctermbg=210 cterm=bold + hi WarningMsg ctermfg=15 ctermbg=236 cterm=bold + hi WildMenu ctermbg=236 ctermfg=194 cterm=bold + if exists("g:zenburn_high_Contrast") + hi Normal ctermfg=188 ctermbg=234 + else + hi Normal ctermfg=188 ctermbg=237 + hi Cursor ctermbg=109 + hi diffadd ctermbg=237 + hi diffdelete ctermbg=238 + hi difftext ctermbg=237 + hi errormsg ctermbg=237 + hi foldcolumn ctermbg=238 + hi folded ctermbg=238 + hi incsearch ctermbg=228 + hi linenr ctermbg=238 + hi search ctermbg=238 + hi statement ctermbg=237 + hi statusline ctermbg=144 + hi statuslinenc ctermbg=108 + hi title ctermbg=237 + hi todo ctermbg=237 + hi underlined ctermbg=237 + hi vertsplit ctermbg=65 + hi visualnos ctermbg=210 + hi warningmsg ctermbg=236 + hi wildmenu ctermbg=236 + endif +endif + + +if exists("g:zenburn_high_Contrast") + " use new darker background + hi Normal guifg=#dcdccc guibg=#1f1f1f +else + " Original, lighter background + hi Normal guifg=#dcdccc guibg=#3f3f3f +endif + +if exists("g:zenburn_alternate_Visual") + " Visual with more contrast, thanks to Steve Hall & Cream posse + " gui=none fixes weird highlight problem in at least GVim 7.0.66, thanks to Kurt Maier + hi Visual guifg=#000000 guibg=#71d3b4 gui=none + hi VisualNOS guifg=#000000 guibg=#71d3b4 gui=none +else + " use default visual + hi Visual guifg=#233323 guibg=#71d3b4 gui=none + hi VisualNOS guifg=#233323 guibg=#71d3b4 gui=none +endif + +if exists("g:zenburn_alternate_Error") + " use a bit different Error + hi Error guifg=#ef9f9f guibg=#201010 gui=bold +else + " default + hi Error guifg=#e37170 guibg=#332323 gui=none +endif + +if exists("g:zenburn_alternate_Include") + " original setting + hi Include guifg=#ffcfaf gui=bold +else + " new, less contrasted one + hi Include guifg=#dfaf8f gui=bold +endif + " TODO check every syntax group that they're ok diff --git a/.vim/doc/DrawIt.txt b/.vim/doc/DrawIt.txt new file mode 100644 index 0000000..6bc5bf2 --- /dev/null +++ b/.vim/doc/DrawIt.txt @@ -0,0 +1,397 @@ +*drawit.txt* The DrawIt Tool Sep 14, 2007 + +Authors: Charles E. Campbell, Jr. {{{1 + Sylvain Viart + (remove NOSPAM from Campbell's email first) +Copyright: Copyright (C) 2004-2007 Charles E. Campbell, Jr. {{{1 + Permission is hereby granted to use and distribute this code, + with or without modifications, provided that this copyright + notice is copied with it. Like anything else that's free, + DrawIt.vim is provided *as is* and comes with no warranty + of any kind, either expressed or implied. By using this + plugin, you agree that in no event will the copyright + holder be liable for any damages resulting from the use + of this software. + + +============================================================================== +1. Contents *drawit-contents* {{{1 + + 1. Contents......................: |drawit-contents| + 2. DrawIt Manual.................: |drawit| + 3. DrawIt Usage..................: |drawit-usage| + Starting....................: |drawit-start| + Stopping....................: |drawit-stop| + User Map Protection.........: |drawit-protect| + Drawing.....................: |drawit-drawing| + Changing Drawing Characters.: |drawit-setdrawit| + Moving......................: |drawit-moving| + Erasing.....................: |drawit-erase| + Example.....................: |drawit-example| + Visual Block Mode...........: |drawit-visblock| + Brushes.....................: |drawit-brush| + DrawIt Modes................: |drawit-modes| + 4. DrawIt History................: |drawit-history| + + +============================================================================== +2. DrawIt Manual *drawit* {{{1 + *drawit-manual* + /===============+============================================================\ + || Starting & | || + || Stopping | Explanation || + ++--------------+-----------------------------------------------------------++ + || \di | start DrawIt |drawit-start| || + || \ds | stop DrawIt |drawit-stop| || + || :DIstart | start DrawIt |drawit-start| || + || :DIstop | stop DrawIt |drawit-stop| || + || | || + ++==============+===========================================================++ + || Maps | Explanation || + ++--------------+-----------------------------------------------------------++ + || | The DrawIt routines use a replace, move, and || + || | replace/insert strategy. The package also lets one insert|| + || | spaces, draw arrows by using the following characters or || + || | keypad characters: || + || +-----------------------------------------------------------++ + || | move and draw left |drawit-drawing| || + || | move and draw right, inserting lines/space as needed || + || | move and draw up, inserting lines/space as needed || + || | move and draw down, inserting lines/space as needed || + || | move cursor left |drawit-move| || + || | move cursor right, inserting lines/space as needed || + || | move cursor up, inserting lines/space as needed || + || | move cursor down, inserting lines/space as needed || + || | toggle into and out of erase mode || + || > | insert a > and move right (draw -> arrow) || + || < | insert a < and move left (draw <- arrow) || + || ^ | insert a ^ and move up (draw ^ arrow) || + || v | insert a v and move down (draw v arrow) || + || | replace with a \, move down and right, and insert a \ || + || | replace with a /, move down and left, and insert a / || + || | replace with a /, move up and right, and insert a / || + || | replace with a \, move up and left, and insert a \ || + || \> | insert a fat > and move right (draw -> arrow) || + || \< | insert a fat < and move left (draw <- arrow) || + || \^ | insert a fat ^ and move up (draw ^ arrow) || + || \v | insert a fat v and move down (draw v arrow) || + || | drag and draw with current brush |drawit-brush| || + || | drag and move current brush |drawit-brush| || + || | || + ||==============+===========================================================++ + ||Visual Cmds | Explanation || + ||--------------+-----------------------------------------------------------++ + || | The drawing mode routines use visual-block mode to || + || | select endpoints for lines, arrows, and ellipses. Bresen- || + || | ham and Bresenham-like algorithms are used for this. || + || | || + || | These routines need a block of spaces, and so the canvas || + || | routine must first be used to create such a block. The || + || | canvas routine will query the user for the number of || + || | lines to hold |'textwidth'| spaces. || + || +-----------------------------------------------------------++ + || \a | draw arrow from corners of visual-block selected region || + || \b | draw box on visual-block selected region || + || \c | the canvas routine (will query user, see above) || + || \e | draw an ellipse on visual-block selected region || + || \f | flood figure with a character (you will be prompted) || + || \l | draw line from corners of visual-block selected region || + || \s | spacer: appends spaces up to the textwidth (default: 78) || + || | || + ++==============+===========================================================++ + || Function and Explanation || + ++--------------+-----------------------------------------------------------++ + || :call SetDrawIt('vertical','horizontal','crossing','\','/','X','*') || + || set drawing characters for motions for moving || + || and for the ellipse drawing boundary || + || default motion || + || | up/down, || + || - left/right, || + || + -| crossing, || + || \ downright, || + || / downleft, and || + || X \/ crossing || + ++=======================+==================================================++ + || Commands | Explanation || + ++-----------------------+--------------------------------------------------++ + || :SetBrush a-z | sets brush (register) to given register || + || :'<,'>SetBrush a-z | yanks visual block to brush (register) || + \============================================================================/ + + +============================================================================== +3. DrawIt Usage *drawit-usage* {{{1 + +STARTING *drawit-start* {{{2 +\di + +Typically one puts into the .vim/plugin directory +(vimfiles\plugin for Windows) where it becomes always available. It uses a +minimal interface (\di: you can think of it as *D*raw*I*t or *D*rawIt +*I*nitialize) to start it and (\ds: *D*rawIt *S*top) to stop it. Instead of +using "\" you may specify your own preference for a map leader (see +|mapleader|). + +A message, "[DrawIt]", will appear on the message line. + + +STOPPING *drawit-stop* {{{2 +\ds + +When you are done with DrawIt, use \ds to stop DrawIt mode. Stopping DrawIt +will restore your usual options and remove the maps DrawIt set up. + +A message, "[DrawIt off]", will appear on the message line. + + +USER MAP PROTECTION *drawit-protect* {{{2 + +Starting DrawIt causes it to set up a number of maps which facilitate drawing. +DrawIt accomodates users with conflicting maps by saving both maps and user +options and before setting them to what DrawIt needs. When you stop DrawIt +(|drawit-stop|), DrawIt will restore the user's maps and options as they were +before DrawIt was started. + + +OPTIONS *drawit-options* {{{2 + + *g:drawit_insertmode* +g:drawit_insertmode : if this variable exists and is 1 then maps are + made which make cursor-control drawing available + while in insert mode, too. Otherwise, DrawIt's + maps only affect normal mode. + +DRAWING *drawit-drawing* {{{2 + +After DrawIt is started, use the number pad or arrow keys to move the cursor +about. As the cursor moves, DrawIt will then leave appropriate "line" +characters behind as you move horizontally, vertically, or diagonally, and +will transparently enlarge your file to accommodate your drawing as needed. +The trail will consist of -, |, \, / characters (depending on which direction +and SetDrawIt() changes), and + and X characters where line crossings occur. +You may use h-j-k-l to move about your display and generally use editing +commands as you wish even while in DrawIt mode. + + +CHANGING DRAWING CHARACTERS *drawit-setdrawit* {{{2 + +The SetDrawIt() function is available for those who wish to change the +characters that DrawIt uses. > + + ex. :call SetDrawIt('*','*','*','*','*','*','*') + ex. :call SetDrawIt('-','|','-','\','/','/','*') +< +The first example shows how to change all the DrawIt drawing characters to +asterisks, and the second shows how to give crossing priority to - and /. +The default setting is equivalent to: > + + :call SetDrawIt('|','-','+','\','/','X','*') +< +where SetDrawit()'s arguments refer, in order, to the > + + vertical drawing character + horizontal drawing character + horizontal/vertical crossing drawing character + down right drawing character + down left drawing character + diagonal crossing drawing character + ellipse boundary drawing character +< + +MOVING *drawit-move* *drawit-moving* {{{2 + +DrawIt supports shifting the arrow keys to cause motion of the cursor. The +motion of the cursor will not modify what's below the cursor. The cursor +will move and lines and/or spaces will be inserted to support the move as +required. Your terminal may not support shifted arrow keys, however, or Vim +may not catch them as such. For example, on the machine I use, shift-up +() produced [161q, but vim didn't know that sequence was a . +I merely made a nmap: + + nmap [161q + +and vim thereafter recognized the command. + + +ERASING *drawit-erase* {{{2 + + +The key will toggle DrawIt's erase mode/DrawIt mode. When in [DrawIt +erase] mode, a message "[DrawIt erase]" will appear and the number pad will +now cause spaces to be drawn instead of the usual drawing characters. The +drawing behavior will be restored when the key toggles DrawIt back +to regular DrawIt mode. + + +EXAMPLES *drawit-example* {{{2 + +Needless to say, the square spirals which follow were done with DrawIt and +a bit of block editing with Vim: > + + +------------ -----------+ +------------ -----------+ +------------ + |+----------+ +---------+| |+----------+ +---------+| |+----------+ + ||+--------+| |+-------+|| ||+--------+| |+-------+|| ||+--------+| + |||-------+|| ||+------||| |||-------+|| ||+------||| |||-------+|| + ||+-------+|| ||+------+|| ||+-------+|| ||+------+|| ||+-------+|| + |+---------+| |+--------+| |+---------+| |+--------+| |+---------+| + +-----------+ +----------+ +-----------+ +----------+ +-----------+ + +VISUAL BLOCK MODE FOR ARROWS LINES BOXES AND ELLIPSES *drawit-visblock* {{{2 + +\a : draw arrow from corners of visual-block selected region *drawit-a* +\b : draw box on visual-block selected region *drawit-b* +\c : the canvas routine (will query user, see above) *drawit-c* +\e : draw an ellipse on visual-block selected region *drawit-e* +\f : flood figure with a character (you will be prompted) *drawit-f* +\l : draw line from corners of visual-block selected region *drawit-l* +\s : spacer: appends spaces up to the textwidth (default: 78) *drawit-s* + +The DrawIt package has been merged with Sylvain Viart's drawing package (by +permission) which provides DrawIt with visual-block selection of +starting/ending point drawing of arrows (\a), lines (\l), and boxes (\b). +Additionally I wrote an ellipse drawing function using visual block +specification (|drawit-e|). + +One may create a block of spaces for these maps to operate in; the "canvas" +routine (\c) will help create such blocks. First, the s:Canvas() routine will +query the user for the number of lines s/he wishes to have, and will then fill +those lines with spaces out to the |'textwidth'| if user has specified it; +otherwise, the display width will be used. + +The Sylvain Viart functions and the ellipse drawing function depend +upon using visual block mode. As a typical use: > + + Example: * \h + DrawIt asks: how many lines under the cursor? 10 + DrawIt then appends 10 lines filled with blanks + out to textwidth (if defined) or 78 columns. + * ctrl-v (move) \b + DrawIt then draws a box + * ctrl-v (move) \e + DrawIt then draws an ellipse +< +Select the first endpoint with ctrl-v and then move to the other endpoint. +One may then select \a for arrows, \b for boxes, \e for ellipses, or \l for +lines. The internal s:AutoCanvas() will convert tabs to spaces and will +extend with spaces as needed to support the visual block. Note that when +DrawIt is enabled, virtualedit is also enabled (to "all"). +> + Examples: + + __ _ *************** +-------+ + \_ _/ **** **** | | + \_ _/ ** ---------> ** | | + \_ _/ **** **** | | + \__/ <------- *************** +-------+ + + \l \a \e and \a \b +< + *drawit-setbrush* +BRUSHES *drawit-brush* {{{2 +> + :SetBrush a-z +< + Set the current brush to the given letter (actually, its + a named register). Default brush: a > + ex. :SetBrush b + + :'<,'>SetBrush a-z +< + Set the current brush to the given letter, and yank the visual + block to that named register). Default brush: a +> + +< + Select a visual-block region. One may use "ay, for example, + to yank selected text to register a. +> + +< + One may drag and draw with the current brush (default brush: a) + by holding down the shift key and the leftmouse button and moving + the mouse. Blanks in the brush are considered to be transparent. +> + +< + One may drag and move a selection with . First, + select the region using the . Release the mouse button, + then press ctrl and the button; while continuing to press + the button, move the mouse. The selected block of text will then + move along with the cursor. +> + \ra ... \rz +< + Replace text with the given register's contents (ie. the brush). +> + \pa ... \pz +< + Like \ra ... \rz, except that blanks are considered to be transparent. + + Example: Draw the following > + \ \ + o o + * + --- +< Then use ctrl-v, move, "ay to grab a copy into register a. + By default, the current brush uses register a (change brush + with :SetBrush [reg]). Hold the and + keys down and move the mouse; as you move, a copy of the + brush will be left behind. + + +DRAWIT MODES *drawit-modes* {{{2 + + -[DrawIt] regular DrawIt mode (|drawit-start|) + -[DrawIt off] DrawIt is off (|drawit-stop| ) + -[DrawIt erase] DrawIt will erase using the number pad (|drawit-erase|) + + g:DrChipTopLvlMenu: by default its "DrChip"; you may set this to whatever + you like in your <.vimrc>. This variable controls where + DrawIt's menu items are placed. + + +============================================================================== +4. History *drawit-history* {{{1 + + 9 Sep 14, 2007 * Johann-Guenter Simon fixed a bug with s:DrawErase(); + it called SetDrawIt() and that call hadn't been + updated to account for the new b:di_ellipse + parameter. + 8 Feb 12, 2007 * fixed a bug which prevented multi-character user + maps from being restored properly + May 03, 2007 * Extended SetDrawIt() to handle b:di_ellipse, the + ellipse boundary drawing character + * Changed "Holer" to "Canvas", and wrote AutoCanvas(), + which allow one to use the visual-block drawing + maps without creating a canvas first. + * DrawIt now uses the ctrl-leftmouse to move a visual + block selected region. + * Floods can now be done inside an ellipse + * DrawIt's maps are now all users of + 7 Feb 16, 2005 * now checks that "m" is in &go before attempting to + use menus + Aug 17, 2005 * report option workaround + Nov 01, 2005 * converted DrawIt to use autoload feature of vim 7.0 + Dec 28, 2005 * now uses cecutil to save/restore user maps + Jan 18, 2006 * cecutil now updated to use keepjumps + Jan 23, 2006 * :DIstart and :DIstop commands provided; thus users + using "set noremap" can still use DrawIt. + Jan 26, 2006 * DrawIt menu entry now keeps its place + Apr 10, 2006 * Brushes were implemented + 6 Feb 24, 2003 * The latest DrawIt now provides a fill function. + \f will ask for a character to fill the figure + surrounding the current cursor location. Plus + I suggest reading :he drawit-tip for those whose + home/pageup/pagedown/end keys aren't all working + properly with DrawIt. + 08/18/03 : \p[a-z] and \r[a-z] implemented + 08/04/03 : b:..keep variables renamed to b:di_..keep variables + StopDrawIt() now insures that erase mode is off + 03/11/03 : included g:drawit_insertmode handling + 02/21/03 : included flood function + 12/11/02 : deletes trailing whitespace only if holer used + 8/27/02 : fat arrowheads included + : shift-arrow keys move but don't modify + + --------------------------------------------------------------------- +vim:tw=78:ts=8:ft=help:fdm=marker diff --git a/.vim/doc/tags b/.vim/doc/tags index 06182d0..a90d741 100644 --- a/.vim/doc/tags +++ b/.vim/doc/tags @@ -46,7 +46,35 @@ b:VCSCommandSourceFile vcscommand.txt /*b:VCSCommandSourceFile* b:VCSCommandVCSType vcscommand.txt /*b:VCSCommandVCSType* cs surround.txt /*cs* cvscommand-changes vcscommand.txt /*cvscommand-changes* +drawit DrawIt.txt /*drawit* +drawit-a DrawIt.txt /*drawit-a* +drawit-b DrawIt.txt /*drawit-b* +drawit-brush DrawIt.txt /*drawit-brush* +drawit-c DrawIt.txt /*drawit-c* +drawit-contents DrawIt.txt /*drawit-contents* +drawit-drawing DrawIt.txt /*drawit-drawing* +drawit-e DrawIt.txt /*drawit-e* +drawit-erase DrawIt.txt /*drawit-erase* +drawit-example DrawIt.txt /*drawit-example* +drawit-f DrawIt.txt /*drawit-f* +drawit-history DrawIt.txt /*drawit-history* +drawit-l DrawIt.txt /*drawit-l* +drawit-manual DrawIt.txt /*drawit-manual* +drawit-modes DrawIt.txt /*drawit-modes* +drawit-move DrawIt.txt /*drawit-move* +drawit-moving DrawIt.txt /*drawit-moving* +drawit-options DrawIt.txt /*drawit-options* +drawit-protect DrawIt.txt /*drawit-protect* +drawit-s DrawIt.txt /*drawit-s* +drawit-setbrush DrawIt.txt /*drawit-setbrush* +drawit-setdrawit DrawIt.txt /*drawit-setdrawit* +drawit-start DrawIt.txt /*drawit-start* +drawit-stop DrawIt.txt /*drawit-stop* +drawit-usage DrawIt.txt /*drawit-usage* +drawit-visblock DrawIt.txt /*drawit-visblock* +drawit.txt DrawIt.txt /*drawit.txt* ds surround.txt /*ds* +g:drawit_insertmode DrawIt.txt /*g:drawit_insertmode* i_CTRL-G_S surround.txt /*i_CTRL-G_S* i_CTRL-G_s surround.txt /*i_CTRL-G_s* project project.txt /*project* diff --git a/.vim/plugin/DrawItPlugin.vim b/.vim/plugin/DrawItPlugin.vim new file mode 100644 index 0000000..1260097 --- /dev/null +++ b/.vim/plugin/DrawItPlugin.vim @@ -0,0 +1,65 @@ +" DrawItPlugin.vim: a simple way to draw things in Vim -- just put this file in +" your plugin directory, use \di to start (\ds to stop), and +" just move about using the cursor keys. +" +" You may also use visual-block mode to select endpoints and +" draw lines, arrows, and ellipses. +" +" Date: Jul 18, 2006 +" Maintainer: Charles E. Campbell, Jr. (Charles.E.Campbell.1@gsfc.nasa.gov) +" Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1 +" Permission is hereby granted to use and distribute this code, +" with or without modifications, provided that this copyright +" notice is copied with it. Like anything else that's free, +" DrawIt.vim is provided *as is* and comes with no warranty +" of any kind, either expressed or implied. By using this +" plugin, you agree that in no event will the copyright +" holder be liable for any damages resulting from the use +" of this software. +" +" Required: this script requires Vim 7.0 (or later) {{{1 +" To Enable: simply put this plugin into your ~/.vim/plugin directory {{{2 +" +" GetLatestVimScripts: 40 1 :AutoInstall: DrawIt.vim +" +" (Zeph 3:1,2 WEB) Woe to her who is rebellious and polluted, the {{{1 +" oppressing city! She didn't obey the voice. She didn't receive +" correction. She didn't trust in Yahweh. She didn't draw near to her God. + +" --------------------------------------------------------------------- +" Load Once: {{{1 +if &cp || exists("g:loaded_DrawItPlugin") + finish +endif +let g:loaded_DrawItPlugin = 1 +let s:keepcpo = &cpo +set cpo&vim + +" --------------------------------------------------------------------- +" DrChip Menu Support: {{{1 +if has("gui_running") && has("menu") && &go =~ 'm' + if !exists("g:DrChipTopLvlMenu") + let g:DrChipTopLvlMenu= "DrChip." + endif + exe 'menu '.g:DrChipTopLvlMenu.'DrawIt.Start\ DrawIt\\di di' +endif + +" --------------------------------------------------------------------- +" Public Interface: {{{1 +if !hasmapto('StartDrawIt') + map di StartDrawIt +endif +map StartDrawIt :set lz:call DrawIt#StartDrawIt():set nolz +com! -nargs=0 DIstart set lz|call DrawIt#StartDrawIt()|set nolz + +if !hasmapto('StopDrawIt') + map ds StopDrawIt +endif +map StopDrawIt :set lz:call DrawIt#StopDrawIt():set nolz +com! -nargs=0 DIstop set lz|call DrawIt#StopDrawIt()|set nolz + +" --------------------------------------------------------------------- +" Cleanup And Modelines: +" vim: fdm=marker +let &cpo= s:keepcpo +unlet s:keepcpo diff --git a/.vim/plugin/camelcasemotion.vim b/.vim/plugin/camelcasemotion.vim new file mode 100644 index 0000000..ae9cbd6 --- /dev/null +++ b/.vim/plugin/camelcasemotion.vim @@ -0,0 +1,449 @@ +" camelcasemotion.vim: Mappings for motion through CamelCaseWords and +" underscore_notation. +" +" DESCRIPTION: {{{1 +" VIM provides many built-in motions, e.g. to move to the next word, or +" end of the current word. Most programming languages use either CamelCase +" ("anIdentifier") or underscore_notation ("an_identifier") naming +" conventions for identifiers. The best way to navigate inside those +" identifiers using VIM built-in motions is the '[count]f{char}' motion, i.e. +" 'f' or 'f_', respectively. But we can make this easier: +" +" This script defines motions ',w', ',b' and ',e' (similar to 'w', 'b', 'e'), +" which do not move word-wise (forward/backward), but Camel-wise; i.e. to word +" boundaries and uppercase letters. The motions also work on underscore +" notation, where words are delimited by underscore ('_') characters. +" From here on, both CamelCase and underscore_notation entities are referred +" to as "words" (in double quotes). Just like with the regular motions, a +" [count] can be prepended to move over multiple "words" at once. +" Outside of "words" (e.g. in non-keyword characters like // or ;), the new +" motions move just like the regular motions. +" +" VIM provides a built-in text object called 'inner word' ('iw'), which works +" in operator-pending and visual mode. Analog to that, this script defines +" inner "word" motions 'i,w', 'i,b' and 'i,e', which select the "word" (or +" multiple "words" if a [count] is given) where the cursor is located. +" +" USAGE: +" Use the new motions ',w', ',b' and ',e' in normal mode, operator-pending +" mode (cp. :help operator), and visual mode. For example, type 'bc,w' to +" change 'Camel' in 'CamelCase' to something else. +" +" EXAMPLE: motions +" Given the following CamelCase identifiers in a source code fragment: +" set Script31337PathAndNameWithoutExtension11=%~dpn0 +" set Script31337PathANDNameWITHOUTExtension11=%~dpn0 +" and the corresponding identifiers in underscore_notation: +" set script_31337_path_and_name_without_extension_11=%~dpn0 +" set SCRIPT_31337_PATH_AND_NAME_WITHOUT_EXTENSION_11=%~dpn0 +" +" ,w moves to ([x] is cursor position): [s]et, [s]cript, [3]1337, [p]ath, +" [a]nd, [n]ame, [w]ithout, [e]xtension, [1]1, [d]pn0, dpn[0], [s]et +" ,b moves to: [d]pn0, [1]1, [e]xtension, [w]ithout, ... +" ,e moves to: se[t], scrip[t], 3133[7], pat[h], an[d], nam[e], withou[t], +" extensio[n], 1[1], dpn[0] +" +" EXAMPLE: inner motions +" Given the following identifier, with the cursor positioned at [x]: +" script_31337_path_and_na[m]e_without_extension_11 +" +" v3i,w selects script_31337_path_and_[name_without_extension_]11 +" v3i,b selects script_31337_[path_and_name]_without_extension_11 +" v3i,e selects script_31337_path_and_[name_without_extension]_11 +" Instead of visual mode, you can also use c3i,w to change, d3i,w to delete, +" gU3i,w to upper-case, and so on. +" +" INSTALLATION: {{{1 +" Put the script into your user or system VIM plugin directory (e.g. +" ~/.vim/plugin). +" +" DEPENDENCIES: +" - Requires VIM 7.0 or higher. +" +" CONFIGURATION: +" If you want to use different mappings, map your keys to the +" CamelCaseMotion_? mapping targets _before_ sourcing this script +" (e.g. in your .vimrc). +" +" Example: Replace the default 'w', 'b' and 'e' mappings instead of defining +" additional mappings ',w', ',b' and ',e': +" map w CamelCaseMotion_w +" map b CamelCaseMotion_b +" map e CamelCaseMotion_e +" +" Example: Replace default 'iw' text-object and define 'ib' and 'ie' motions: +" omap iw CamelCaseMotion_iw +" vmap iw CamelCaseMotion_iw +" omap ib CamelCaseMotion_ib +" vmap ib CamelCaseMotion_ib +" omap ie CamelCaseMotion_ie +" vmap ie CamelCaseMotion_ie +" +" LIMITATIONS: +" +" ASSUMPTIONS: +" +" KNOWN PROBLEMS: +" - A degenerate CamelCaseWord containing '\U\u\d' (e.g. "MaP1Roblem") +" confuses the operator-pending and visual mode ,e mapping if 'selection' is +" not set to "exclusive". It'll skip "P" and select "P1" in one step. As a +" workaround, use ',w' instead of ',e'; those two mappings have the same +" effect inside CamelCaseWords, anyway. +" - The operator-pending and visual mode ,e mapping doesn't work properly when +" it reaches the end of the buffer; the final character of the moved-over +" "word" remains. As a workaround, use the default 'e' motion instead of +" ',e'. +" - When the VIM setting 'selection' is not set to "exclusive", a +" forward-backward combination in visual mode (e.g. 'v,w,b') selects one +" additional character to the left, instead of only the character where the +" motion started. Likewise, extension of the visual selection from the front +" end is off by one additional character. +" +" TODO: +" +" Copyright: (C) 2007-2008 by Ingo Karkat +" The VIM LICENSE applies to this script; see ':help copyright'. +" +" Source: Based on vimtip #1016 by Anthony Van Ham. +" Maintainer: Ingo Karkat +" REVISION DATE REMARKS {{{1 +" 1.40.017 19-May-2008 BF: Now using :normal! to be independent from +" any user mappings. Thanks to Neil Walker for the +" patch. +" 1.40.016 28-Apr-2008 BF: Wrong forward motion stop at the second +" digit if a word starts with multiple numbers +" (e.g. 1234.56789). Thanks to Wasim Ahmed for +" reporting this. +" 1.40.015 24-Apr-2008 ENH: Added inner "word" text objects 'i,w' etc. +" that work analoguous to the built-in 'iw' text +" object. Thanks to David Kotchan for this +" suggestion. +" 1.30.014 20-Apr-2008 The motions now also stop at non-keyword +" boundaries, just like the regular motions. This +" has no effect inside a CamelCaseWord or inside +" underscore_notation, but it makes the motions +" behave like the regular motions (which is +" important if you replace the default motions). +" Thanks to Mun Johl for reporting this. +" Now using non-capturing parentheses \%() in the +" patterns. +" 1.30.013 09-Apr-2008 Refactored away s:VisualCamelCaseMotion(). +" Allowing users to use mappings different than +" ,w ,b ,e by defining CamelCaseMotion_? +" target mappings. This can even be used to +" replace the default 'w', 'b' and 'e' mappings, +" as suggested by Mun Johl. +" Mappings are now created in a generic function. +" Now requires VIM 7.0 or higher. +" 1.20.012 02-Jun-2007 BF: Corrected motions through mixed +" CamelCase_and_UnderScore words by re-ordering +" and narrowing the search patterns. +" 1.20.011 02-Jun-2007 Thanks again to Joseph Barker for discussing the +" complicated visual mode mapping on the vim-dev +" mailing list and coming up with a great +" simplification: +" Removed s:CheckForChangesToTheSelectionSetting(). +" Introduced s:VisualCamelCaseMotion(), which +" handles the differences depending on the +" 'selection' setting. +" Visual mode mappings now directly map to the +" s:VisualCamelCaseMotion() function; no mark is +" clobbered, the complex mapping with the inline +" expression has been retired. +" 1.20.010 29-May-2007 BF: The operator-pending and visual mode ,e +" mapping doesn't work properly when it reaches +" the end of line; the final character of the +" moved-over "word" remains. Fixed this problem +" unless the "word" is at the very end of the +" buffer. +" ENH: The visual mode motions now also (mostly) +" work with the (default) setting +" 'set selection=inclusive', instead of selecting +" one character too much. +" ENH: All mappings will check for changes to the +" 'selection' setting and remap the visual mode +" mappings via function +" s:SetupVisualModeMappings(). We cannot rely on +" the setting while sourcing camelcasemotion.vim +" because the mswin.vim script may be sourced +" afterwards, and its 'behave mswin' changes +" 'selection'. +" Refactored the arguments of function +" s:CamelCaseMotion(...). +" 1.10.009 28-May-2007 BF: Degenerate CamelCaseWords that consist of +" only a single uppercase letter (e.g. "P" in +" "MapPRoblem") are skipped by all motions. Thanks +" to Joseph Barker for reporting this. +" BF: In CamelCaseWords that consist of uppercase +" letters followed by decimals (e.g. +" "MyUPPER123Problem", the uppercase "word" is +" skipped by all motions. +" 1.10.008 28-May-2007 Incorporated major improvements and +" simplifications done by Joseph Barker: +" Operator-pending and visual mode motions now +" accept [count] of more than 9. +" Visual selections can now be extended from +" either end. +" Instead of misusing the :[range], the special +" variable v:count1 is used. Custom commands are +" not needed anymore. +" Operator-pending and visual mode mappings are +" now generic: There's only a single mapping for +" ,w that can be repeated, rather than having a +" separate mapping for 1,w 2,w 3,w ... +" 1.00.007 22-May-2007 Added documentation for publication. +" 006 20-May-2007 BF: visual mode [1,2,3],e on pure CamelCase +" mistakenly marks [2,4,6] words. If the cursor is +" on a uppercase letter, the search pattern +" '\u\l\+' doesn't match at the cursor position, +" so another match won. Changed search pattern +" from '\l\+', +" 005 16-May-2007 Added support for underscore notation. +" Added support for "forward to end of word" +" (',e') motion. +" 004 16-May-2007 Improved search pattern so that +" UppercaseWORDSInBetween and digits are handled, +" too. +" 003 15-May-2007 Changed mappings from w to ,w; +" other \w mappings interfere here, because it's +" irritating when the cursor jump doesn't happen +" immediately, because VIM waits whether the +" mapping is complete. ,w is faster to type that +" \w (and, because of the left-right touch, +" preferred over gw). +" Added visual mode mappings. +" 0.02 15-Feb-2006 BF: missing for omaps. +" 0.01 11-Oct-2005 file creation + +" Avoid installing twice or when in compatible mode +if exists("loaded_camelcasemotion") || (v:version < 700) + finish +endif +let loaded_camelcasemotion = 1 +" }}}1 + +"- functions ------------------------------------------------------------------" +function! s:CamelCaseMove( direction, count, mode ) " {{{1 + " Note: There is no inversion of the regular expression character class + " 'keyword character' (\k). We need an inversion "non-keyword" defined as + " "any non-whitespace character that is not a keyword character (e.g. + " [!@#$%^&*()]. This can be specified via a non-whitespace character in + " whose place no keyword character matches (\k\@!\S). + + "echo "count is " . a:count + let l:i = 0 + while l:i < a:count + if a:direction == 'e' + " "Forward to end" motion. + "call search( '\>\|\(\a\|\d\)\+\ze_', 'We' ) + " end of ... + " number | ACRONYM followed by CamelCase or number | CamelCase | underscore_notation | non-keyword | word + call search( '\d\+\|\u\+\ze\%(\u\l\|\d\)\|\u\l\+\|\%(\a\|\d\)\+\ze_\|\%(\k\@!\S\)\+\|\%(_\@!\k\)\+\>', 'We' ) + " Note: word must be defined as '\k\>'; '\>' on its own somehow + " dominates over the previous branch. Plus, \k must exclude the + " underscore, or a trailing one will be incorrectly moved over: + " '\%(_\@!\k\)'. + if a:mode == 'o' + " Note: Special additional treatment for operator-pending mode + " "forward to end" motion. + " The difference between normal mode, operator-pending and visual + " mode is that in the latter two, the motion must go _past_ the + " final "word" character, so that all characters of the "word" are + " selected. This is done by appending a 'l' motion after the + " search for the next "word". + " + " In operator-pending mode, the 'l' motion only works properly + " at the end of the line (i.e. when the moved-over "word" is at + " the end of the line) when the 'l' motion is allowed to move + " over to the next line. Thus, the 'l' motion is added + " temporarily to the global 'whichwrap' setting. + " Without this, the motion would leave out the last character in + " the line. I've also experimented with temporarily setting + " "set virtualedit=onemore" , but that didn't work. + let l:save_ww = &whichwrap + set whichwrap+=l + normal! l + let &whichwrap = l:save_ww + endif + else + " Forward (a:direction == '') and backward (a:direction == 'b') + " motion. + + let l:direction = (a:direction == 'w' ? '' : a:direction) + + " CamelCase: Jump to beginning of either (start of word, Word, WORD, + " 123). + " Underscore_notation: Jump to the beginning of an underscore-separated + " word or number. + "call search( '\<\|\u', 'W' . l:direction ) + "call search( '\<\|\u\(\l\+\|\u\+\ze\u\)\|\d\+', 'W' . l:direction ) + "call search( '\<\|\u\(\l\+\|\u\+\ze\u\)\|\d\+\|_\zs\(\a\|\d\)\+', 'W' . l:direction ) + " beginning of ... + " word | empty line | non-keyword after whitespaces | non-whitespace after word | number | ACRONYM followed by CamelCase or number | CamelCase | underscore followed by ACRONYM, Camel, lowercase or number + call search( '\<\D\|^$\|\%(^\|\s\)\+\zs\k\@!\S\|\>\S\|\d\+\|\u\+\ze\%(\u\l\|\d\)\|\u\l\+\|_\zs\%(\u\+\|\u\l\+\|\l\+\|\d\+\)', 'W' . l:direction ) + " Note: word must be defined as '\<\D' to avoid that a word like + " 1234Test is moved over as [1][2]34[T]est instead of [1]234[T]est + " because \< matches with zero width, and \d\+ will then start + " matching '234'. To fix that, we make \d\+ be solely responsible + " for numbers by taken this away from \< via \<\D. (An alternative + " would be to replace \d\+ with \D\%#\zs\d\+, but that one is more + " complex.) All other branches are not affected, because they match + " multiple characters and not the same character multiple times. + endif + let l:i = l:i + 1 + endwhile +endfunction +" }}}1 + +function! s:CamelCaseMotion( direction, count, mode ) " {{{1 +"******************************************************************************* +"* PURPOSE: +" Perform the motion over CamelCaseWords or underscore_notation. +"* ASSUMPTIONS / PRECONDITIONS: +" none +"* EFFECTS / POSTCONDITIONS: +" Move cursor / change selection. +"* INPUTS: +" a:direction one of 'w', 'b', 'e' +" a:count number of "words" to move over +" a:mode one of 'n', 'o', 'v', 'iv' (latter one is a special visual mode +" when inside the inner "word" text objects. +"* RETURN VALUES: +" none +"******************************************************************************* + " Visual mode needs special preparations and postprocessing; + " normal and operator-pending mode breeze through to s:CamelCaseMove(). + + if a:mode == 'v' + " Visual mode was left when calling this function. Reselecting the current + " selection returns to visual mode and allows to call search() and issue + " normal mode motions while staying in visual mode. + normal! gv + endif + if a:mode == 'v' || a:mode == 'iv' + + " Note_1a: + if &selection != 'exclusive' && a:direction == 'w' + normal! l + endif + endif + + call s:CamelCaseMove( a:direction, a:count, a:mode ) + + if a:mode == 'v' || a:mode == 'iv' + " Note: 'selection' setting. + if &selection == 'exclusive' && a:direction == 'e' + " When set to 'exclusive', the "forward to end" motion (',e') does not + " include the last character of the moved-over "word". To include that, an + " additional 'l' motion is appended to the motion; similar to the + " special treatment in operator-pending mode. + normal! l + elseif &selection != 'exclusive' && a:direction != 'e' + " Note_1b: + " The forward and backward motions move to the beginning of the next "word". + " When 'selection' is set to 'inclusive' or 'old', this is one character too far. + " The appended 'h' motion undoes this. Because of this backward step, + " though, the forward motion finds the current "word" again, and would + " be stuck on the current "word". An 'l' motion before the CamelCase + " motion (see Note_1a) fixes that. + normal! h + end + endif +endfunction +" }}}1 + +function! s:CamelCaseInnerMotion( direction, count ) " {{{1 + " If the cursor is positioned on the first character of a CamelWord, the + " backward motion would move to the previous word, which would result in a + " wrong selection. To fix this, first move the cursor to the right, so that + " the backward motion definitely will cover the current "word" under the + " cursor. + normal! l + + " Move "word" backwards, enter visual mode, then move "word" forward. This + " selects the inner "word" in visual mode; the operator-pending mode takes + " this selection as the area covered by the motion. + if a:direction == 'b' + " Do not do the selection backwards, because the backwards "word" motion + " in visual mode + selection=inclusive has an off-by-one error. + call s:CamelCaseMotion( 'b', a:count, 'n' ) + normal! v + " We decree that 'b' is the opposite of 'e', not 'w'. This makes more + " sense at the end of a line and for underscore_notation. + call s:CamelCaseMotion( 'e', a:count, 'iv' ) + else + call s:CamelCaseMotion( 'b', 1, 'n' ) + normal! v + call s:CamelCaseMotion( a:direction, a:count, 'iv' ) + endif +endfunction +" }}}1 + +"- mappings ------------------------------------------------------------------- +" The count is passed into the function through the special variable 'v:count1', +" which is easier than misusing the :[range] that :call supports. +" is used to delete the unused range. +" Another option would be to use a custom 'command! -count=1', but that doesn't +" work with the normal mode mapping: When a count is typed before the mapping, +" the ':' will convert a count of 3 into ':.,+2MyCommand', but ':3MyCommand' +" would be required to use -count and . +" +" We do not provide the fourth "backward to end" motion (,E), because it is +" seldomly used. + +function! s:CreateMotionMappings() "{{{1 + " Create mappings according to this template: + " (* stands for the mode [nov], ? for the underlying motion [wbe].) + " + " *noremap