Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

vimrc調整

  • Loading branch information...
commit 3451c4bc7a49fbf0b736b0b608f9068a3efa9584 1 parent 0ae4e87
@yuroyoro authored
Showing with 28,822 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +1,029 −0 .vim/autoload/Align.vim
  3. +330 −0 .vim/autoload/AlignMaps.vim
  4. +1,992 −0 .vim/autoload/SQLUtilities.vim
  5. +1,469 −0 .vim/doc/Align.txt
  6. +991 −0 .vim/doc/NERD_commenter.txt
  7. +1,077 −0 .vim/doc/NERD_tree.txt
  8. +718 −0 .vim/doc/SQLUtilities.txt
  9. +1,271 −0 .vim/doc/autocmd.jax
  10. +442 −0 .vim/doc/bufexplorer.txt
  11. +1,523 −0 .vim/doc/change.jax
  12. +1,004 −0 .vim/doc/cmdline.jax
  13. +156 −0 .vim/doc/debug.jax
  14. +134 −0 .vim/doc/debugger.jax
  15. +494 −0 .vim/doc/develop.jax
  16. +399 −0 .vim/doc/diff.jax
  17. +347 −0 .vim/doc/digraph.jax
  18. +1,541 −0 .vim/doc/editing.jax
  19. +7,105 −0 .vim/doc/eval.jax
  20. +51 −0 .vim/doc/evim-ja.UTF-8.1
  21. +274 −0 .vim/doc/farsi.jax
  22. +568 −0 .vim/doc/filetype.jax
  23. +563 −0 .vim/doc/fold.jax
  24. +505 −0 .vim/doc/ft_ada.jax
  25. +967 −0 .vim/doc/fuzzyfinder.jax
  26. +1,293 −0 .vim/doc/fuzzyfinder.txt
  27. +1,003 −0 .vim/doc/gui.jax
  28. +183 −0 .vim/doc/gui_w16.jax
  29. +484 −0 .vim/doc/gui_w32.jax
  30. +580 −0 .vim/doc/gui_x11.jax
  31. +104 −0 .vim/doc/hangulin.jax
  32. +221 −0 .vim/doc/help.jax
Sorry, we could not display the entire diff because it was too big.
View
4 .gitignore
@@ -14,3 +14,7 @@ Session.vim
*.log
*.dvi
*.aux
+*.elc
+.zshrc_local
+.zsh_alias
+
View
1,029 .vim/autoload/Align.vim
@@ -0,0 +1,1029 @@
+" Align: tool to align multiple fields based on one or more separators
+" Author: Charles E. Campbell, Jr.
+" Date: Mar 03, 2009
+" Version: 35
+" GetLatestVimScripts: 294 1 :AutoInstall: Align.vim
+" GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim
+" Copyright: Copyright (C) 1999-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,
+" Align.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.
+"
+" Romans 1:16,17a : For I am not ashamed of the gospel of Christ, for it is {{{1
+" the power of God for salvation for everyone who believes; for the Jew first,
+" and also for the Greek. For in it is revealed God's righteousness from
+" faith to faith.
+
+" ---------------------------------------------------------------------
+" Load Once: {{{1
+if exists("g:loaded_Align") || &cp
+ finish
+endif
+let g:loaded_Align = "v35"
+if v:version < 700
+ echohl WarningMsg
+ echo "***warning*** this version of Align needs vim 7.0"
+ echohl Normal
+ finish
+endif
+let s:keepcpo= &cpo
+set cpo&vim
+"DechoTabOn
+
+" ---------------------------------------------------------------------
+" Debugging Support: {{{1
+"if !exists("g:loaded_Decho") | runtime plugin/Decho.vim | endif
+
+" ---------------------------------------------------------------------
+" Options: {{{1
+if !exists("g:Align_xstrlen")
+ if &enc == "latin1" || $LANG == "en_US.UTF-8" || !has("multi_byte")
+ let g:Align_xstrlen= 0
+ else
+ let g:Align_xstrlen= 1
+ endif
+endif
+
+" ---------------------------------------------------------------------
+" Align#AlignCtrl: enter alignment patterns here {{{1
+"
+" Styles = all alignment-break patterns are equivalent
+" C cycle through alignment-break pattern(s)
+" l left-justified alignment
+" r right-justified alignment
+" c center alignment
+" - skip separator, treat as part of field
+" : treat rest of line as field
+" + repeat previous [lrc] style
+" < left justify separators
+" > right justify separators
+" | center separators
+"
+" Builds = s:AlignPat s:AlignCtrl s:AlignPatQty
+" C s:AlignPat s:AlignCtrl s:AlignPatQty
+" p s:AlignPrePad
+" P s:AlignPostPad
+" w s:AlignLeadKeep
+" W s:AlignLeadKeep
+" I s:AlignLeadKeep
+" l s:AlignStyle
+" r s:AlignStyle
+" - s:AlignStyle
+" + s:AlignStyle
+" : s:AlignStyle
+" c s:AlignStyle
+" g s:AlignGPat
+" v s:AlignVPat
+" < s:AlignSep
+" > s:AlignSep
+" | s:AlignSep
+fun! Align#AlignCtrl(...)
+
+" call Dfunc("AlignCtrl(...) a:0=".a:0)
+
+ " save options that will be changed
+ let keep_search = @/
+ let keep_ic = &ic
+
+ " turn ignorecase off
+ set noic
+
+ " clear visual mode so that old visual-mode selections don't
+ " get applied to new invocations of Align().
+ if v:version < 602
+ if !exists("s:Align_gavemsg")
+ let s:Align_gavemsg= 1
+ echomsg "Align needs at least Vim version 6.2 to clear visual-mode selection"
+ endif
+ elseif exists("s:dovisclear")
+" call Decho("clearing visual mode a:0=".a:0." a:1<".a:1.">")
+ let clearvmode= visualmode(1)
+ endif
+
+ " set up a list akin to an argument list
+ if a:0 > 0
+ let A= s:QArgSplitter(a:1)
+ else
+ let A=[0]
+ endif
+
+ if A[0] > 0
+ let style = A[1]
+
+ " Check for bad separator patterns (zero-length matches)
+ " (but zero-length patterns for g/v is ok)
+ if style !~# '[gv]'
+ let ipat= 2
+ while ipat <= A[0]
+ if "" =~ A[ipat]
+ echoerr "AlignCtrl: separator<".A[ipat]."> matches zero-length string"
+ let &ic= keep_ic
+" call Dret("AlignCtrl")
+ return
+ endif
+ let ipat= ipat + 1
+ endwhile
+ endif
+ endif
+
+" call Decho("AlignCtrl() A[0]=".A[0])
+ if !exists("s:AlignStyle")
+ let s:AlignStyle= "l"
+ endif
+ if !exists("s:AlignPrePad")
+ let s:AlignPrePad= 0
+ endif
+ if !exists("s:AlignPostPad")
+ let s:AlignPostPad= 0
+ endif
+ if !exists("s:AlignLeadKeep")
+ let s:AlignLeadKeep= 'w'
+ endif
+
+ if A[0] == 0
+ " ----------------------
+ " List current selection
+ " ----------------------
+ if !exists("s:AlignPatQty")
+ let s:AlignPatQty= 0
+ endif
+ echo "AlignCtrl<".s:AlignCtrl."> qty=".s:AlignPatQty." AlignStyle<".s:AlignStyle."> Padding<".s:AlignPrePad."|".s:AlignPostPad."> LeadingWS=".s:AlignLeadKeep." AlignSep=".s:AlignSep
+" call Decho("AlignCtrl<".s:AlignCtrl."> qty=".s:AlignPatQty." AlignStyle<".s:AlignStyle."> Padding<".s:AlignPrePad."|".s:AlignPostPad."> LeadingWS=".s:AlignLeadKeep." AlignSep=".s:AlignSep)
+ if exists("s:AlignGPat") && !exists("s:AlignVPat")
+ echo "AlignGPat<".s:AlignGPat.">"
+ elseif !exists("s:AlignGPat") && exists("s:AlignVPat")
+ echo "AlignVPat<".s:AlignVPat.">"
+ elseif exists("s:AlignGPat") && exists("s:AlignVPat")
+ echo "AlignGPat<".s:AlignGPat."> AlignVPat<".s:AlignVPat.">"
+ endif
+ let ipat= 1
+ while ipat <= s:AlignPatQty
+ echo "Pat".ipat."<".s:AlignPat_{ipat}.">"
+" call Decho("Pat".ipat."<".s:AlignPat_{ipat}.">")
+ let ipat= ipat + 1
+ endwhile
+
+ else
+ " ----------------------------------
+ " Process alignment control settings
+ " ----------------------------------
+" call Decho("process the alignctrl settings")
+" call Decho("style<".style.">")
+
+ if style ==? "default"
+ " Default: preserve initial leading whitespace, left-justified,
+ " alignment on '=', one space padding on both sides
+ if exists("s:AlignCtrlStackQty")
+ " clear AlignCtrl stack
+ while s:AlignCtrlStackQty > 0
+ call Align#AlignPop()
+ endwhile
+ unlet s:AlignCtrlStackQty
+ endif
+ " Set AlignCtrl to its default value
+ call Align#AlignCtrl("Ilp1P1=<",'=')
+ call Align#AlignCtrl("g")
+ call Align#AlignCtrl("v")
+ let s:dovisclear = 1
+ let &ic = keep_ic
+ let @/ = keep_search
+" call Dret("AlignCtrl")
+ return
+ endif
+
+ if style =~# 'm'
+ " map support: Do an AlignPush now and the next call to Align()
+ " will do an AlignPop at exit
+" call Decho("style case m: do AlignPush")
+ call Align#AlignPush()
+ let s:DoAlignPop= 1
+ endif
+
+ " = : record a list of alignment patterns that are equivalent
+ if style =~# "="
+" call Decho("style case =: record list of equiv alignment patterns")
+ let s:AlignCtrl = '='
+ if A[0] >= 2
+ let s:AlignPatQty= 1
+ let s:AlignPat_1 = A[2]
+ let ipat = 3
+ while ipat <= A[0]
+ let s:AlignPat_1 = s:AlignPat_1.'\|'.A[ipat]
+ let ipat = ipat + 1
+ endwhile
+ let s:AlignPat_1= '\('.s:AlignPat_1.'\)'
+" call Decho("AlignCtrl<".s:AlignCtrl."> AlignPat<".s:AlignPat_1.">")
+ endif
+
+ "c : cycle through alignment pattern(s)
+ elseif style =~# 'C'
+" call Decho("style case C: cycle through alignment pattern(s)")
+ let s:AlignCtrl = 'C'
+ if A[0] >= 2
+ let s:AlignPatQty= A[0] - 1
+ let ipat = 1
+ while ipat < A[0]
+ let s:AlignPat_{ipat}= A[ipat+1]
+" call Decho("AlignCtrl<".s:AlignCtrl."> AlignQty=".s:AlignPatQty." AlignPat_".ipat."<".s:AlignPat_{ipat}.">")
+ let ipat= ipat + 1
+ endwhile
+ endif
+ endif
+
+ if style =~# 'p'
+ let s:AlignPrePad= substitute(style,'^.*p\(\d\+\).*$','\1','')
+" call Decho("style case p".s:AlignPrePad.": pre-separator padding")
+ if s:AlignPrePad == ""
+ echoerr "AlignCtrl: 'p' needs to be followed by a numeric argument'
+ let @/ = keep_search
+ let &ic= keep_ic
+" call Dret("AlignCtrl")
+ return
+ endif
+ endif
+
+ if style =~# 'P'
+ let s:AlignPostPad= substitute(style,'^.*P\(\d\+\).*$','\1','')
+" call Decho("style case P".s:AlignPostPad.": post-separator padding")
+ if s:AlignPostPad == ""
+ echoerr "AlignCtrl: 'P' needs to be followed by a numeric argument'
+ let @/ = keep_search
+ let &ic= keep_ic
+" call Dret("AlignCtrl")
+ return
+ endif
+ endif
+
+ if style =~# 'w'
+" call Decho("style case w: ignore leading whitespace")
+ let s:AlignLeadKeep= 'w'
+ elseif style =~# 'W'
+" call Decho("style case w: keep leading whitespace")
+ let s:AlignLeadKeep= 'W'
+ elseif style =~# 'I'
+" call Decho("style case w: retain initial leading whitespace")
+ let s:AlignLeadKeep= 'I'
+ endif
+
+ if style =~# 'g'
+ " first list item is a "g" selector pattern
+" call Decho("style case g: global selector pattern")
+ if A[0] < 2
+ if exists("s:AlignGPat")
+ unlet s:AlignGPat
+" call Decho("unlet s:AlignGPat")
+ endif
+ else
+ let s:AlignGPat= A[2]
+" call Decho("s:AlignGPat<".s:AlignGPat.">")
+ endif
+ elseif style =~# 'v'
+ " first list item is a "v" selector pattern
+" call Decho("style case v: global selector anti-pattern")
+ if A[0] < 2
+ if exists("s:AlignVPat")
+ unlet s:AlignVPat
+" call Decho("unlet s:AlignVPat")
+ endif
+ else
+ let s:AlignVPat= A[2]
+" call Decho("s:AlignVPat<".s:AlignVPat.">")
+ endif
+ endif
+
+ "[-lrc+:] : set up s:AlignStyle
+ if style =~# '[-lrc+:]'
+" call Decho("style case [-lrc+:]: field justification")
+ let s:AlignStyle= substitute(style,'[^-lrc:+]','','g')
+" call Decho("AlignStyle<".s:AlignStyle.">")
+ endif
+
+ "[<>|] : set up s:AlignSep
+ if style =~# '[<>|]'
+" call Decho("style case [-lrc+:]: separator justification")
+ let s:AlignSep= substitute(style,'[^<>|]','','g')
+" call Decho("AlignSep ".s:AlignSep)
+ endif
+ endif
+
+ " sanity
+ if !exists("s:AlignCtrl")
+ let s:AlignCtrl= '='
+ endif
+
+ " restore search and options
+ let @/ = keep_search
+ let &ic= keep_ic
+
+" call Dret("AlignCtrl ".s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle)
+ return s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle
+endfun
+
+" ---------------------------------------------------------------------
+" s:MakeSpace: returns a string with spacecnt blanks {{{1
+fun! s:MakeSpace(spacecnt)
+" call Dfunc("MakeSpace(spacecnt=".a:spacecnt.")")
+ let str = ""
+ let spacecnt = a:spacecnt
+ while spacecnt > 0
+ let str = str . " "
+ let spacecnt = spacecnt - 1
+ endwhile
+" call Dret("MakeSpace <".str.">")
+ return str
+endfun
+
+" ---------------------------------------------------------------------
+" Align#Align: align selected text based on alignment pattern(s) {{{1
+fun! Align#Align(hasctrl,...) range
+" call Dfunc("Align#Align(hasctrl=".a:hasctrl.",...) a:0=".a:0)
+
+ " sanity checks
+ if string(a:hasctrl) != "0" && string(a:hasctrl) != "1"
+ echohl Error|echo 'usage: Align#Align(hasctrl<'.a:hasctrl.'> (should be 0 or 1),"separator(s)" (you have '.a:0.') )'|echohl None
+" call Dret("Align#Align")
+ return
+ endif
+ if exists("s:AlignStyle") && s:AlignStyle == ":"
+ echohl Error |echo '(Align#Align) your AlignStyle is ":", which implies "do-no-alignment"!'|echohl None
+" call Dret("Align#Align")
+ return
+ endif
+
+ " set up a list akin to an argument list
+ if a:0 > 0
+ let A= s:QArgSplitter(a:1)
+ else
+ let A=[0]
+ endif
+
+ " if :Align! was used, then the first argument is (should be!) an AlignCtrl string
+ " Note that any alignment control set this way will be temporary.
+ let hasctrl= a:hasctrl
+" call Decho("hasctrl=".hasctrl)
+ if a:hasctrl && A[0] >= 1
+" call Decho("Align! : using A[1]<".A[1]."> for AlignCtrl")
+ if A[1] =~ '[gv]'
+ let hasctrl= hasctrl + 1
+ call Align#AlignCtrl('m')
+ call Align#AlignCtrl(A[1],A[2])
+" call Decho("Align! : also using A[2]<".A[2]."> for AlignCtrl")
+ elseif A[1] !~ 'm'
+ call Align#AlignCtrl(A[1]."m")
+ else
+ call Align#AlignCtrl(A[1])
+ endif
+ endif
+
+ " Check for bad separator patterns (zero-length matches)
+ let ipat= 1 + hasctrl
+ while ipat <= A[0]
+ if "" =~ A[ipat]
+ echoerr "Align: separator<".A[ipat]."> matches zero-length string"
+" call Dret("Align#Align")
+ return
+ endif
+ let ipat= ipat + 1
+ endwhile
+
+ " record current search pattern for subsequent restoration
+ let keep_search= @/
+ let keep_ic = &ic
+ let keep_report= &report
+ set noic report=10000
+
+ if A[0] > hasctrl
+ " Align will accept a list of separator regexps
+" call Decho("A[0]=".A[0].": accepting list of separator regexp")
+
+ if s:AlignCtrl =~# "="
+ "= : consider all separators to be equivalent
+" call Decho("AlignCtrl: record list of equivalent alignment patterns")
+ let s:AlignCtrl = '='
+ let s:AlignPat_1 = A[1 + hasctrl]
+ let s:AlignPatQty= 1
+ let ipat = 2 + hasctrl
+ while ipat <= A[0]
+ let s:AlignPat_1 = s:AlignPat_1.'\|'.A[ipat]
+ let ipat = ipat + 1
+ endwhile
+ let s:AlignPat_1= '\('.s:AlignPat_1.'\)'
+" call Decho("AlignCtrl<".s:AlignCtrl."> AlignPat<".s:AlignPat_1.">")
+
+ elseif s:AlignCtrl =~# 'C'
+ "c : cycle through alignment pattern(s)
+" call Decho("AlignCtrl: cycle through alignment pattern(s)")
+ let s:AlignCtrl = 'C'
+ let s:AlignPatQty= A[0] - hasctrl
+ let ipat = 1
+ while ipat <= s:AlignPatQty
+ let s:AlignPat_{ipat}= A[(ipat + hasctrl)]
+" call Decho("AlignCtrl<".s:AlignCtrl."> AlignQty=".s:AlignPatQty." AlignPat_".ipat."<".s:AlignPat_{ipat}.">")
+ let ipat= ipat + 1
+ endwhile
+ endif
+ endif
+
+ " Initialize so that begline<endline and begcol<endcol.
+ " Ragged right: check if the column associated with '< or '>
+ " is greater than the line's string length -> ragged right.
+ " Have to be careful about visualmode() -- it returns the last visual
+ " mode used whether or not it was used currently.
+ let begcol = virtcol("'<")-1
+ let endcol = virtcol("'>")-1
+ if begcol > endcol
+ let begcol = virtcol("'>")-1
+ let endcol = virtcol("'<")-1
+ endif
+" call Decho("begcol=".begcol." endcol=".endcol)
+ let begline = a:firstline
+ let endline = a:lastline
+ if begline > endline
+ let begline = a:lastline
+ let endline = a:firstline
+ endif
+" call Decho("begline=".begline." endline=".endline)
+ let fieldcnt = 0
+ if (begline == line("'>") && endline == line("'<")) || (begline == line("'<") && endline == line("'>"))
+ let vmode= visualmode()
+" call Decho("vmode=".vmode)
+ if vmode == "\<c-v>"
+ if exists("g:Align_xstrlen") && g:Align_xstrlen
+ let ragged = ( col("'>") > s:Strlen(getline("'>")) || col("'<") > s:Strlen(getline("'<")) )
+ else
+ let ragged = ( col("'>") > strlen(getline("'>")) || col("'<") > strlen(getline("'<")) )
+ endif
+ else
+ let ragged= 1
+ endif
+ else
+ let ragged= 1
+ endif
+ if ragged
+ let begcol= 0
+ endif
+" call Decho("lines[".begline.",".endline."] col[".begcol.",".endcol."] ragged=".ragged." AlignCtrl<".s:AlignCtrl.">")
+
+ " Keep user options
+ let etkeep = &l:et
+ let pastekeep= &l:paste
+ setlocal et paste
+
+ " convert selected range of lines to use spaces instead of tabs
+ " but if first line's initial white spaces are to be retained
+ " then use 'em
+ if begcol <= 0 && s:AlignLeadKeep == 'I'
+ " retain first leading whitespace for all subsequent lines
+ let bgntxt= substitute(getline(begline),'^\(\s*\).\{-}$','\1','')
+" call Decho("retaining 1st leading whitespace: bgntxt<".bgntxt.">")
+ set noet
+ endif
+ exe begline.",".endline."ret"
+
+ " Execute two passes
+ " First pass: collect alignment data (max field sizes)
+ " Second pass: perform alignment
+ let pass= 1
+ while pass <= 2
+" call Decho(" ")
+" call Decho("---- Pass ".pass.": ----")
+
+ let line= begline
+ while line <= endline
+ " Process each line
+ let txt = getline(line)
+" call Decho(" ")
+" call Decho("Pass".pass.": Line ".line." <".txt.">")
+
+ " AlignGPat support: allows a selector pattern (akin to g/selector/cmd )
+ if exists("s:AlignGPat")
+" call Decho("Pass".pass.": AlignGPat<".s:AlignGPat.">")
+ if match(txt,s:AlignGPat) == -1
+" call Decho("Pass".pass.": skipping")
+ let line= line + 1
+ continue
+ endif
+ endif
+
+ " AlignVPat support: allows a selector pattern (akin to v/selector/cmd )
+ if exists("s:AlignVPat")
+" call Decho("Pass".pass.": AlignVPat<".s:AlignVPat.">")
+ if match(txt,s:AlignVPat) != -1
+" call Decho("Pass".pass.": skipping")
+ let line= line + 1
+ continue
+ endif
+ endif
+
+ " Always skip blank lines
+ if match(txt,'^\s*$') != -1
+" call Decho("Pass".pass.": skipping")
+ let line= line + 1
+ continue
+ endif
+
+ " Extract visual-block selected text (init bgntxt, endtxt)
+ if exists("g:Align_xstrlen") && g:Align_xstrlen
+ let txtlen= s:Strlen(txt)
+ else
+ let txtlen= strlen(txt)
+ endif
+ if begcol > 0
+ " Record text to left of selected area
+ let bgntxt= strpart(txt,0,begcol)
+" call Decho("Pass".pass.": record text to left: bgntxt<".bgntxt.">")
+ elseif s:AlignLeadKeep == 'W'
+ let bgntxt= substitute(txt,'^\(\s*\).\{-}$','\1','')
+" call Decho("Pass".pass.": retaining all leading ws: bgntxt<".bgntxt.">")
+ elseif s:AlignLeadKeep == 'w' || !exists("bgntxt")
+ " No beginning text
+ let bgntxt= ""
+" call Decho("Pass".pass.": no beginning text")
+ endif
+ if ragged
+ let endtxt= ""
+ else
+ " Elide any text lying outside selected columnar region
+ let endtxt= strpart(txt,endcol+1,txtlen-endcol)
+ let txt = strpart(txt,begcol,endcol-begcol+1)
+ endif
+" call Decho(" ")
+" call Decho("Pass".pass.": bgntxt<".bgntxt.">")
+" call Decho("Pass".pass.": txt<". txt .">")
+" call Decho("Pass".pass.": endtxt<".endtxt.">")
+ if !exists("s:AlignPat_{1}")
+ echohl Error|echo "no separators specified!"|echohl None
+" call Dret("Align#Align")
+ return
+ endif
+
+ " Initialize for both passes
+ let seppat = s:AlignPat_{1}
+ let ifield = 1
+ let ipat = 1
+ let bgnfield = 0
+ let endfield = 0
+ let alignstyle = s:AlignStyle
+ let doend = 1
+ let newtxt = ""
+ let alignprepad = s:AlignPrePad
+ let alignpostpad= s:AlignPostPad
+ let alignsep = s:AlignSep
+ let alignophold = " "
+ let alignop = "l"
+" call Decho("Pass".pass.": initial alignstyle<".alignstyle."> seppat<".seppat.">")
+
+ " Process each field on the line
+ while doend > 0
+
+ " C-style: cycle through pattern(s)
+ if s:AlignCtrl == 'C' && doend == 1
+ let seppat = s:AlignPat_{ipat}
+" call Decho("Pass".pass.": processing field: AlignCtrl=".s:AlignCtrl." ipat=".ipat." seppat<".seppat.">")
+ let ipat = ipat + 1
+ if ipat > s:AlignPatQty
+ let ipat = 1
+ endif
+ endif
+
+ " cyclic alignment/justification operator handling
+ let alignophold = alignop
+ let alignop = strpart(alignstyle,0,1)
+ if alignop == '+' || doend == 2
+ let alignop= alignophold
+ else
+ let alignstyle = strpart(alignstyle,1).strpart(alignstyle,0,1)
+ let alignopnxt = strpart(alignstyle,0,1)
+ if alignop == ':'
+ let seppat = '$'
+ let doend = 2
+" call Decho("Pass".pass.": alignop<:> case: setting seppat<$> doend==2")
+ endif
+ endif
+
+ " cylic separator alignment specification handling
+ let alignsepop= strpart(alignsep,0,1)
+ let alignsep = strpart(alignsep,1).alignsepop
+
+ " mark end-of-field and the subsequent end-of-separator.
+ " Extend field if alignop is '-'
+ let endfield = match(txt,seppat,bgnfield)
+ let sepfield = matchend(txt,seppat,bgnfield)
+ let skipfield= sepfield
+" call Decho("Pass".pass.": endfield=match(txt<".txt.">,seppat<".seppat.">,bgnfield=".bgnfield.")=".endfield)
+ while alignop == '-' && endfield != -1
+ let endfield = match(txt,seppat,skipfield)
+ let sepfield = matchend(txt,seppat,skipfield)
+ let skipfield = sepfield
+ let alignop = strpart(alignstyle,0,1)
+ let alignstyle= strpart(alignstyle,1).strpart(alignstyle,0,1)
+" call Decho("Pass".pass.": extend field: endfield<".strpart(txt,bgnfield,endfield-bgnfield)."> alignop<".alignop."> alignstyle<".alignstyle.">")
+ endwhile
+ let seplen= sepfield - endfield
+" call Decho("Pass".pass.": seplen=[sepfield=".sepfield."] - [endfield=".endfield."]=".seplen)
+
+ if endfield != -1
+ if pass == 1
+ " ---------------------------------------------------------------------
+ " Pass 1: Update FieldSize to max
+" call Decho("Pass".pass.": before lead/trail remove: field<".strpart(txt,bgnfield,endfield-bgnfield).">")
+ let field = substitute(strpart(txt,bgnfield,endfield-bgnfield),'^\s*\(.\{-}\)\s*$','\1','')
+ if s:AlignLeadKeep == 'W'
+ let field = bgntxt.field
+ let bgntxt= ""
+ endif
+ if exists("g:Align_xstrlen") && g:Align_xstrlen
+ let fieldlen = s:Strlen(field)
+ else
+ let fieldlen = strlen(field)
+ endif
+ let sFieldSize = "FieldSize_".ifield
+ if !exists(sFieldSize)
+ let FieldSize_{ifield}= fieldlen
+" call Decho("Pass".pass.": set FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">")
+ elseif fieldlen > FieldSize_{ifield}
+ let FieldSize_{ifield}= fieldlen
+" call Decho("Pass".pass.": oset FieldSize_{".ifield."}=".FieldSize_{ifield}." <".field.">")
+ endif
+ let sSepSize= "SepSize_".ifield
+ if !exists(sSepSize)
+ let SepSize_{ifield}= seplen
+" call Decho(" set SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">")
+ elseif seplen > SepSize_{ifield}
+ let SepSize_{ifield}= seplen
+" call Decho("Pass".pass.": oset SepSize_{".ifield."}=".SepSize_{ifield}." <".field.">")
+ endif
+
+ else
+ " ---------------------------------------------------------------------
+ " Pass 2: Perform Alignment
+ let prepad = strpart(alignprepad,0,1)
+ let postpad = strpart(alignpostpad,0,1)
+ let alignprepad = strpart(alignprepad,1).strpart(alignprepad,0,1)
+ let alignpostpad = strpart(alignpostpad,1).strpart(alignpostpad,0,1)
+ let field = substitute(strpart(txt,bgnfield,endfield-bgnfield),'^\s*\(.\{-}\)\s*$','\1','')
+ if s:AlignLeadKeep == 'W'
+ let field = bgntxt.field
+ let bgntxt= ""
+ endif
+ if doend == 2
+ let prepad = 0
+ let postpad= 0
+ endif
+ if exists("g:Align_xstrlen") && g:Align_xstrlen
+ let fieldlen = s:Strlen(field)
+ else
+ let fieldlen = strlen(field)
+ endif
+ let sep = s:MakeSpace(prepad).strpart(txt,endfield,sepfield-endfield).s:MakeSpace(postpad)
+ if seplen < SepSize_{ifield}
+ if alignsepop == "<"
+ " left-justify separators
+ let sep = sep.s:MakeSpace(SepSize_{ifield}-seplen)
+ elseif alignsepop == ">"
+ " right-justify separators
+ let sep = s:MakeSpace(SepSize_{ifield}-seplen).sep
+ else
+ " center-justify separators
+ let sepleft = (SepSize_{ifield} - seplen)/2
+ let sepright = SepSize_{ifield} - seplen - sepleft
+ let sep = s:MakeSpace(sepleft).sep.s:MakeSpace(sepright)
+ endif
+ endif
+ let spaces = FieldSize_{ifield} - fieldlen
+" call Decho("Pass".pass.": Field #".ifield."<".field."> spaces=".spaces." be[".bgnfield.",".endfield."] pad=".prepad.','.postpad." FS_".ifield."<".FieldSize_{ifield}."> sep<".sep."> ragged=".ragged." doend=".doend." alignop<".alignop.">")
+
+ " Perform alignment according to alignment style justification
+ if spaces > 0
+ if alignop == 'c'
+ " center the field
+ let spaceleft = spaces/2
+ let spaceright= FieldSize_{ifield} - spaceleft - fieldlen
+ let newtxt = newtxt.s:MakeSpace(spaceleft).field.s:MakeSpace(spaceright).sep
+ elseif alignop == 'r'
+ " right justify the field
+ let newtxt= newtxt.s:MakeSpace(spaces).field.sep
+ elseif ragged && doend == 2
+ " left justify rightmost field (no trailing blanks needed)
+ let newtxt= newtxt.field
+ else
+ " left justfiy the field
+ let newtxt= newtxt.field.s:MakeSpace(spaces).sep
+ endif
+ elseif ragged && doend == 2
+ " field at maximum field size and no trailing blanks needed
+ let newtxt= newtxt.field
+ else
+ " field is at maximum field size already
+ let newtxt= newtxt.field.sep
+ endif
+" call Decho("Pass".pass.": newtxt<".newtxt.">")
+ endif " pass 1/2
+
+ " bgnfield indexes to end of separator at right of current field
+ " Update field counter
+ let bgnfield= sepfield
+ let ifield = ifield + 1
+ if doend == 2
+ let doend= 0
+ endif
+ " handle end-of-text as end-of-field
+ elseif doend == 1
+ let seppat = '$'
+ let doend = 2
+ else
+ let doend = 0
+ endif " endfield != -1
+ endwhile " doend loop (as well as regularly separated fields)
+
+ if pass == 2
+ " Write altered line to buffer
+" call Decho("Pass".pass.": bgntxt<".bgntxt."> line=".line)
+" call Decho("Pass".pass.": newtxt<".newtxt.">")
+" call Decho("Pass".pass.": endtxt<".endtxt.">")
+ call setline(line,bgntxt.newtxt.endtxt)
+ endif
+
+ let line = line + 1
+ endwhile " line loop
+
+ let pass= pass + 1
+ endwhile " pass loop
+" call Decho("end of two pass loop")
+
+ " Restore user options
+ let &l:et = etkeep
+ let &l:paste = pastekeep
+
+ if exists("s:DoAlignPop")
+ " AlignCtrl Map support
+ call Align#AlignPop()
+ unlet s:DoAlignPop
+ endif
+
+ " restore current search pattern
+ let @/ = keep_search
+ let &ic = keep_ic
+ let &report = keep_report
+
+" call Dret("Align#Align")
+ return
+endfun
+
+" ---------------------------------------------------------------------
+" Align#AlignPush: this command/function pushes an alignment control string onto a stack {{{1
+fun! Align#AlignPush()
+" call Dfunc("AlignPush()")
+
+ " initialize the stack
+ if !exists("s:AlignCtrlStackQty")
+ let s:AlignCtrlStackQty= 1
+ else
+ let s:AlignCtrlStackQty= s:AlignCtrlStackQty + 1
+ endif
+
+ " construct an AlignCtrlStack entry
+ if !exists("s:AlignSep")
+ let s:AlignSep= ''
+ endif
+ let s:AlignCtrlStack_{s:AlignCtrlStackQty}= s:AlignCtrl.'p'.s:AlignPrePad.'P'.s:AlignPostPad.s:AlignLeadKeep.s:AlignStyle.s:AlignSep
+" call Decho("AlignPush: AlignCtrlStack_".s:AlignCtrlStackQty."<".s:AlignCtrlStack_{s:AlignCtrlStackQty}.">")
+
+ " push [GV] patterns onto their own stack
+ if exists("s:AlignGPat")
+ let s:AlignGPat_{s:AlignCtrlStackQty}= s:AlignGPat
+ else
+ let s:AlignGPat_{s:AlignCtrlStackQty}= ""
+ endif
+ if exists("s:AlignVPat")
+ let s:AlignVPat_{s:AlignCtrlStackQty}= s:AlignVPat
+ else
+ let s:AlignVPat_{s:AlignCtrlStackQty}= ""
+ endif
+
+" call Dret("AlignPush")
+endfun
+
+" ---------------------------------------------------------------------
+" Align#AlignPop: this command/function pops an alignment pattern from a stack {{{1
+" and into the AlignCtrl variables.
+fun! Align#AlignPop()
+" call Dfunc("Align#AlignPop()")
+
+ " sanity checks
+ if !exists("s:AlignCtrlStackQty")
+ echoerr "AlignPush needs to be used prior to AlignPop"
+" call Dret("Align#AlignPop <> : AlignPush needs to have been called first")
+ return ""
+ endif
+ if s:AlignCtrlStackQty <= 0
+ unlet s:AlignCtrlStackQty
+ echoerr "AlignPush needs to be used prior to AlignPop"
+" call Dret("Align#AlignPop <> : AlignPop needs to have been called first")
+ return ""
+ endif
+
+ " pop top of AlignCtrlStack and pass value to AlignCtrl
+ let retval=s:AlignCtrlStack_{s:AlignCtrlStackQty}
+ unlet s:AlignCtrlStack_{s:AlignCtrlStackQty}
+ call Align#AlignCtrl(retval)
+
+ " pop G pattern stack
+ if s:AlignGPat_{s:AlignCtrlStackQty} != ""
+ call Align#AlignCtrl('g',s:AlignGPat_{s:AlignCtrlStackQty})
+ else
+ call Align#AlignCtrl('g')
+ endif
+ unlet s:AlignGPat_{s:AlignCtrlStackQty}
+
+ " pop V pattern stack
+ if s:AlignVPat_{s:AlignCtrlStackQty} != ""
+ call Align#AlignCtrl('v',s:AlignVPat_{s:AlignCtrlStackQty})
+ else
+ call Align#AlignCtrl('v')
+ endif
+
+ unlet s:AlignVPat_{s:AlignCtrlStackQty}
+ let s:AlignCtrlStackQty= s:AlignCtrlStackQty - 1
+
+" call Dret("Align#AlignPop <".retval."> : AlignCtrlStackQty=".s:AlignCtrlStackQty)
+ return retval
+endfun
+
+" ---------------------------------------------------------------------
+" Align#AlignReplaceQuotedSpaces: {{{1
+fun! Align#AlignReplaceQuotedSpaces()
+" call Dfunc("AlignReplaceQuotedSpaces()")
+
+ let l:line = getline(line("."))
+ if exists("g:Align_xstrlen") && g:Align_xstrlen
+ let l:linelen = s:Strlen(l:line)
+ else
+ let l:linelen = strlen(l:line)
+ endif
+ let l:startingPos = 0
+ let l:startQuotePos = 0
+ let l:endQuotePos = 0
+ let l:spacePos = 0
+ let l:quoteRe = '\\\@<!"'
+
+" "call Decho("in replace spaces. line=" . line('.'))
+ while (1)
+ let l:startQuotePos = match(l:line, l:quoteRe, l:startingPos)
+ if (l:startQuotePos < 0)
+" "call Decho("No more quotes to the end of line")
+ break
+ endif
+ let l:endQuotePos = match(l:line, l:quoteRe, l:startQuotePos + 1)
+ if (l:endQuotePos < 0)
+" "call Decho("Mismatched quotes")
+ break
+ endif
+ let l:spaceReplaceRe = '^.\{' . (l:startQuotePos + 1) . '}.\{-}\zs\s\ze.*.\{' . (linelen - l:endQuotePos) . '}$'
+" "call Decho('spaceReplaceRe="' . l:spaceReplaceRe . '"')
+ let l:newStr = substitute(l:line, l:spaceReplaceRe, '%', '')
+ while (l:newStr != l:line)
+" "call Decho('newstr="' . l:newStr . '"')
+ let l:line = l:newStr
+ let l:newStr = substitute(l:line, l:spaceReplaceRe, '%', '')
+ endwhile
+ let l:startingPos = l:endQuotePos + 1
+ endwhile
+ call setline(line('.'), l:line)
+
+" call Dret("AlignReplaceQuotedSpaces")
+endfun
+
+" ---------------------------------------------------------------------
+" s:QArgSplitter: to avoid \ processing by <f-args>, <q-args> is needed. {{{1
+" However, <q-args> doesn't split at all, so this function returns a list
+" of arguments which has been:
+" * split at whitespace
+" * unless inside "..."s. One may escape characters with a backslash inside double quotes.
+" along with a leading length-of-list.
+"
+" Examples: %Align "\"" will align on "s
+" %Align " " will align on spaces
+"
+" The resulting list: qarglist[0] corresponds to a:0
+" qarglist[i] corresponds to a:{i}
+fun! s:QArgSplitter(qarg)
+" call Dfunc("s:QArgSplitter(qarg<".a:qarg.">)")
+
+ if a:qarg =~ '".*"'
+ " handle "..." args, which may include whitespace
+ let qarglist = []
+ let args = a:qarg
+" call Decho("handle quoted arguments: args<".args.">")
+ while args != ""
+ let iarg = 0
+ let arglen = strlen(args)
+" call Decho("args[".iarg."]<".args[iarg]."> arglen=".arglen)
+ " find index to first not-escaped '"'
+ while args[iarg] != '"' && iarg < arglen
+ if args[iarg] == '\'
+ let args= strpart(args,1)
+ endif
+ let iarg= iarg + 1
+ endwhile
+" call Decho("args<".args."> iarg=".iarg." arglen=".arglen)
+
+ if iarg > 0
+ " handle left of quote or remaining section
+" call Decho("handle left of quote or remaining section")
+ if args[iarg] == '"'
+ let qarglist= qarglist + split(strpart(args,0,iarg-1))
+ else
+ let qarglist= qarglist + split(strpart(args,0,iarg))
+ endif
+ let args = strpart(args,iarg)
+ let arglen = strlen(args)
+
+ elseif iarg < arglen && args[0] == '"'
+ " handle "quoted" section
+" call Decho("handle quoted section")
+ let iarg= 1
+ while args[iarg] != '"' && iarg < arglen
+ if args[iarg] == '\'
+ let args= strpart(args,1)
+ endif
+ let iarg= iarg + 1
+ endwhile
+" call Decho("args<".args."> iarg=".iarg." arglen=".arglen)
+ if args[iarg] == '"'
+ call add(qarglist,strpart(args,1,iarg-1))
+ let args= strpart(args,iarg+1)
+ else
+ let qarglist = qarglist + split(args)
+ let args = ""
+ endif
+ endif
+" call Decho("qarglist".string(qarglist)." iarg=".iarg." args<".args.">")
+ endwhile
+
+ else
+ " split at all whitespace
+ let qarglist= split(a:qarg)
+ endif
+
+ let qarglistlen= len(qarglist)
+ let qarglist = insert(qarglist,qarglistlen)
+" call Dret("s:QArgSplitter ".string(qarglist))
+ return qarglist
+endfun
+
+" ---------------------------------------------------------------------
+" s:Strlen: this function returns the length of a string, even if its {{{1
+" using two-byte etc characters.
+" Currently, its only used if g:Align_xstrlen is set to a
+" nonzero value. Solution from Nicolai Weibull, vim docs
+" (:help strlen()), Tony Mechelynck, and my own invention.
+fun! s:Strlen(x)
+" call Dfunc("s:Strlen(x<".a:x.">")
+ if g:Align_xstrlen == 1
+ " number of codepoints (Latin a + combining circumflex is two codepoints)
+ " (comment from TM, solution from NW)
+ let ret= strlen(substitute(a:x,'.','c','g'))
+
+ elseif g:Align_xstrlen == 2
+ " number of spacing codepoints (Latin a + combining circumflex is one spacing
+ " codepoint; a hard tab is one; wide and narrow CJK are one each; etc.)
+ " (comment from TM, solution from TM)
+ let ret=strlen(substitute(a:x, '.\Z', 'x', 'g'))
+
+ elseif g:Align_xstrlen == 3
+ " virtual length (counting, for instance, tabs as anything between 1 and
+ " 'tabstop', wide CJK as 2 rather than 1, Arabic alif as zero when immediately
+ " preceded by lam, one otherwise, etc.)
+ " (comment from TM, solution from me)
+ let modkeep= &l:mod
+ exe "norm! o\<esc>"
+ call setline(line("."),a:x)
+ let ret= virtcol("$") - 1
+ d
+ let &l:mod= modkeep
+
+ else
+ " at least give a decent default
+ ret= strlen(a:x)
+ endif
+" call Dret("s:Strlen ".ret)
+ return ret
+endfun
+
+" ---------------------------------------------------------------------
+" Set up default values: {{{1
+"call Decho("-- Begin AlignCtrl Initialization --")
+call Align#AlignCtrl("default")
+"call Decho("-- End AlignCtrl Initialization --")
+
+" ---------------------------------------------------------------------
+" Restore: {{{1
+let &cpo= s:keepcpo
+unlet s:keepcpo
+" vim: ts=4 fdm=marker
View
330 .vim/autoload/AlignMaps.vim
@@ -0,0 +1,330 @@
+" AlignMaps.vim : support functions for AlignMaps
+" Author: Charles E. Campbell, Jr.
+" Date: Mar 03, 2009
+" Version: 41
+" ---------------------------------------------------------------------
+" Load Once: {{{1
+if &cp || exists("g:loaded_AlignMaps")
+ finish
+endif
+let g:loaded_AlignMaps= "v41"
+let s:keepcpo = &cpo
+set cpo&vim
+
+" =====================================================================
+" Functions: {{{1
+
+" ---------------------------------------------------------------------
+" AlignMaps#WrapperStart: {{{2
+fun! AlignMaps#WrapperStart(vis) range
+" call Dfunc("AlignMaps#WrapperStart(vis=".a:vis.")")
+
+ if a:vis
+ norm! '<ma'>
+ endif
+
+ if line("'y") == 0 || line("'z") == 0 || !exists("s:alignmaps_wrapcnt") || s:alignmaps_wrapcnt <= 0
+" call Decho("wrapper initialization")
+ let s:alignmaps_wrapcnt = 1
+ let s:alignmaps_keepgd = &gdefault
+ let s:alignmaps_keepsearch = @/
+ let s:alignmaps_keepch = &ch
+ let s:alignmaps_keepmy = SaveMark("'y")
+ let s:alignmaps_keepmz = SaveMark("'z")
+ let s:alignmaps_posn = SaveWinPosn(0)
+ " set up fencepost blank lines
+ put =''
+ norm! mz'a
+ put! =''
+ ky
+ let s:alignmaps_zline = line("'z")
+ exe "'y,'zs/@/\177/ge"
+ else
+" call Decho("embedded wrapper")
+ let s:alignmaps_wrapcnt = s:alignmaps_wrapcnt + 1
+ norm! 'yjma'zk
+ endif
+
+ " change some settings to align-standard values
+ set nogd
+ set ch=2
+ AlignPush
+ norm! 'zk
+" call Dret("AlignMaps#WrapperStart : alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z"))
+endfun
+
+" ---------------------------------------------------------------------
+" AlignMaps#WrapperEnd: {{{2
+fun! AlignMaps#WrapperEnd() range
+" call Dfunc("AlignMaps#WrapperEnd() alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z"))
+
+ " remove trailing white space introduced by whatever in the modification zone
+ 'y,'zs/ \+$//e
+
+ " restore AlignCtrl settings
+ AlignPop
+
+ let s:alignmaps_wrapcnt= s:alignmaps_wrapcnt - 1
+ if s:alignmaps_wrapcnt <= 0
+ " initial wrapper ending
+ exe "'y,'zs/\177/@/ge"
+
+ " if the 'z line hasn't moved, then go ahead and restore window position
+ let zstationary= s:alignmaps_zline == line("'z")
+
+ " remove fencepost blank lines.
+ " restore 'a
+ norm! 'yjmakdd'zdd
+
+ " restore original 'y, 'z, and window positioning
+ call RestoreMark(s:alignmaps_keepmy)
+ call RestoreMark(s:alignmaps_keepmz)
+ if zstationary > 0
+ call RestoreWinPosn(s:alignmaps_posn)
+" call Decho("restored window positioning")
+ endif
+
+ " restoration of options
+ let &gd= s:alignmaps_keepgd
+ let &ch= s:alignmaps_keepch
+ let @/ = s:alignmaps_keepsearch
+
+ " remove script variables
+ unlet s:alignmaps_keepch
+ unlet s:alignmaps_keepsearch
+ unlet s:alignmaps_keepmy
+ unlet s:alignmaps_keepmz
+ unlet s:alignmaps_keepgd
+ unlet s:alignmaps_posn
+ endif
+
+" call Dret("AlignMaps#WrapperEnd : alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z"))
+endfun
+
+" ---------------------------------------------------------------------
+" AlignMaps#StdAlign: some semi-standard align calls {{{2
+fun! AlignMaps#StdAlign(mode) range
+" call Dfunc("AlignMaps#StdAlign(mode=".a:mode.")")
+ if a:mode == 1
+ " align on @
+" call Decho("align on @")
+ AlignCtrl mIp1P1=l @
+ 'a,.Align
+ elseif a:mode == 2
+ " align on @, retaining all initial white space on each line
+" call Decho("align on @, retaining all initial white space on each line")
+ AlignCtrl mWp1P1=l @
+ 'a,.Align
+ elseif a:mode == 3
+ " like mode 2, but ignore /* */-style comments
+" call Decho("like mode 2, but ignore /* */-style comments")
+ AlignCtrl v ^\s*/[/*]
+ AlignCtrl mWp1P1=l @
+ 'a,.Align
+ else
+ echoerr "(AlignMaps) AlignMaps#StdAlign doesn't support mode#".a:mode
+ endif
+" call Dret("AlignMaps#StdAlign")
+endfun
+
+" ---------------------------------------------------------------------
+" AlignMaps#CharJoiner: joins lines which end in the given character (spaces {{{2
+" at end are ignored)
+fun! AlignMaps#CharJoiner(chr)
+" call Dfunc("AlignMaps#CharJoiner(chr=".a:chr.")")
+ let aline = line("'a")
+ let rep = line(".") - aline
+ while rep > 0
+ norm! 'a
+ while match(getline(aline),a:chr . "\s*$") != -1 && rep >= 0
+ " while = at end-of-line, delete it and join with next
+ norm! 'a$
+ j!
+ let rep = rep - 1
+ endwhile
+ " update rep(eat) count
+ let rep = rep - 1
+ if rep <= 0
+ " terminate loop if at end-of-block
+ break
+ endif
+ " prepare for next line
+ norm! jma
+ let aline = line("'a")
+ endwhile
+" call Dret("AlignMaps#CharJoiner")
+endfun
+
+" ---------------------------------------------------------------------
+" AlignMaps#Equals: supports \t= and \T= {{{2
+fun! AlignMaps#Equals() range
+" call Dfunc("AlignMaps#Equals()")
+ 'a,'zs/\s\+\([*/+\-%|&\~^]\==\)/ \1/e
+ 'a,'zs@ \+\([*/+\-%|&\~^]\)=@\1=@ge
+ 'a,'zs/==/\="\<Char-0x0f>\<Char-0x0f>"/ge
+ 'a,'zs/\([!<>:]\)=/\=submatch(1)."\<Char-0x0f>"/ge
+ norm g'zk
+ AlignCtrl mIp1P1=l =
+ AlignCtrl g =
+ 'a,'z-1Align
+ 'a,'z-1s@\([*/+\-%|&\~^!=]\)\( \+\)=@\2\1=@ge
+ 'a,'z-1s/\( \+\);/;\1/ge
+ if &ft == "c" || &ft == "cpp"
+" call Decho("exception for ".&ft)
+ 'a,'z-1v/^\s*\/[*/]/s/\/[*/]/@&@/e
+ 'a,'z-1v/^\s*\/[*/]/s/\*\//@&/e
+ if exists("g:mapleader")
+ exe "norm 'zk"
+ call AlignMaps#StdAlign(1)
+ else
+ exe "norm 'zk"
+ call AlignMaps#StdAlign(1)
+ endif
+ 'y,'zs/^\(\s*\) @/\1/e
+ endif
+ 'a,'z-1s/\%x0f/=/ge
+ 'y,'zs/ @//eg
+" call Dret("AlignMaps#Equals")
+endfun
+
+" ---------------------------------------------------------------------
+" AlignMaps#Afnc: useful for splitting one-line function beginnings {{{2
+" into one line per argument format
+fun! AlignMaps#Afnc()
+" call Dfunc("AlignMaps#Afnc()")
+
+ " keep display quiet
+ let chkeep = &ch
+ let gdkeep = &gd
+ let vekeep = &ve
+ set ch=2 nogd ve=
+
+ " will use marks y,z ; save current values
+ let mykeep = SaveMark("'y")
+ let mzkeep = SaveMark("'z")
+
+ " Find beginning of function -- be careful to skip over comments
+ let cmmntid = synIDtrans(hlID("Comment"))
+ let stringid = synIDtrans(hlID("String"))
+ exe "norm! ]]"
+ while search(")","bW") != 0
+" call Decho("line=".line(".")." col=".col("."))
+ let parenid= synIDtrans(synID(line("."),col("."),1))
+ if parenid != cmmntid && parenid != stringid
+ break
+ endif
+ endwhile
+ norm! %my
+ s/(\s*\(\S\)/(\r \1/e
+ exe "norm! `y%"
+ s/)\s*\(\/[*/]\)/)\r\1/e
+ exe "norm! `y%mz"
+ 'y,'zs/\s\+$//e
+ 'y,'zs/^\s\+//e
+ 'y+1,'zs/^/ /
+
+ " insert newline after every comma only one parenthesis deep
+ sil! exe "norm! `y\<right>h"
+ let parens = 1
+ let cmmnt = 0
+ let cmmntline= -1
+ while parens >= 1
+" call Decho("parens=".parens." @a=".@a)
+ exe 'norm! ma "ay`a '
+ if @a == "("
+ let parens= parens + 1
+ elseif @a == ")"
+ let parens= parens - 1
+
+ " comment bypass: /* ... */ or //...
+ elseif cmmnt == 0 && @a == '/'
+ let cmmnt= 1
+ elseif cmmnt == 1
+ if @a == '/'
+ let cmmnt = 2 " //...
+ let cmmntline= line(".")
+ elseif @a == '*'
+ let cmmnt= 3 " /*...
+ else
+ let cmmnt= 0
+ endif
+ elseif cmmnt == 2 && line(".") != cmmntline
+ let cmmnt = 0
+ let cmmntline= -1
+ elseif cmmnt == 3 && @a == '*'
+ let cmmnt= 4
+ elseif cmmnt == 4
+ if @a == '/'
+ let cmmnt= 0 " ...*/
+ elseif @a != '*'
+ let cmmnt= 3
+ endif
+
+ elseif @a == "," && parens == 1 && cmmnt == 0
+ exe "norm! i\<CR>\<Esc>"
+ endif
+ endwhile
+ norm! `y%mz%
+ sil! 'y,'zg/^\s*$/d
+
+ " perform substitutes to mark fields for Align
+ sil! 'y+1,'zv/^\//s/^\s\+\(\S\)/ \1/e
+ sil! 'y+1,'zv/^\//s/\(\S\)\s\+/\1 /eg
+ sil! 'y+1,'zv/^\//s/\* \+/*/ge
+ sil! 'y+1,'zv/^\//s/\w\zs\s*\*/ */ge
+ " func
+ " ws <- declaration -> <-ptr -> <-var-> <-[array][] -> <-glop-> <-end->
+ sil! 'y+1,'zv/^\//s/^\s*\(\(\K\k*\s*\)\+\)\s\+\([(*]*\)\s*\(\K\k*\)\s*\(\(\[.\{-}]\)*\)\s*\(.\{-}\)\=\s*\([,)]\)\s*$/ \1@#\3@\4\5@\7\8/e
+ sil! 'y+1,'z+1g/^\s*\/[*/]/norm! kJ
+ sil! 'y+1,'z+1s%/[*/]%@&@%ge
+ sil! 'y+1,'z+1s%*/%@&%ge
+ AlignCtrl mIp0P0=l @
+ sil! 'y+1,'zAlign
+ sil! 'y,'zs%@\(/[*/]\)@%\t\1 %e
+ sil! 'y,'zs%@\*/% */%e
+ sil! 'y,'zs/@\([,)]\)/\1/
+ sil! 'y,'zs/@/ /
+ AlignCtrl mIlrp0P0= # @
+ sil! 'y+1,'zAlign
+ sil! 'y+1,'zs/#/ /
+ sil! 'y+1,'zs/@//
+ sil! 'y+1,'zs/\(\s\+\)\([,)]\)/\2\1/e
+
+ " Restore
+ call RestoreMark(mykeep)
+ call RestoreMark(mzkeep)
+ let &ch= chkeep
+ let &gd= gdkeep
+ let &ve= vekeep
+
+" call Dret("AlignMaps#Afnc")
+endfun
+
+" ---------------------------------------------------------------------
+" AlignMaps#FixMultiDec: converts a type arg,arg,arg; line to multiple lines {{{2
+fun! AlignMaps#FixMultiDec()
+" call Dfunc("AlignMaps#FixMultiDec()")
+
+ " save register x
+ let xkeep = @x
+ let curline = getline(".")
+" call Decho("curline<".curline.">")
+
+ " Get the type. I'm assuming one type per line (ie. int x; double y; on one line will not be handled properly)
+ let @x=substitute(curline,'^\(\s*[a-zA-Z_ \t][a-zA-Z0-9_ \t]*\)\s\+[(*]*\h.*$','\1','')
+" call Decho("@x<".@x.">")
+
+ " transform line
+ exe 's/,/;\r'.@x.' /ge'
+
+ "restore register x
+ let @x= xkeep
+
+" call Dret("AlignMaps#FixMultiDec : my=".line("'y")." mz=".line("'z"))
+endfun
+
+" ---------------------------------------------------------------------
+" Restore: {{{1
+let &cpo= s:keepcpo
+unlet s:keepcpo
+" vim: ts=4 fdm=marker
View
1,992 .vim/autoload/SQLUtilities.vim
@@ -0,0 +1,1992 @@
+" SQLUtilities: Variety of tools for writing SQL
+" Author: David Fishburn <dfishburn dot vim at gmail dot com>
+" Date: Nov 23, 2002
+" Last Changed: 2008 Nov 14
+" Version: 3.0
+" Script: http://www.vim.org/script.php?script_id=492
+" License: GPL (http://www.gnu.org/licenses/gpl.html)
+"
+" Dependencies:
+" Align.vim - Version 15 (as a minimum)
+" - Author: Charles E. Campbell, Jr.
+" - http://www.vim.org/script.php?script_id=294
+" Documentation:
+" :h SQLUtilities.txt
+"
+
+" Prevent duplicate loading
+if exists("g:loaded_sqlutilities_auto") || &cp
+ finish
+endif
+if v:version < 700
+ echomsg "SQLUtilities: Version 2.0.0 or higher requires Vim7. Version 1.4.1 can stil be used with Vim6."
+ finish
+endif
+let g:loaded_sqlutilities_auto = 300
+
+" SQLU_Formatter: align selected text based on alignment pattern(s)
+function! SQLUtilities#SQLU_Formatter(...) range
+ let mode = 'n'
+ if a:0 > 0
+ let mode = (a:1 == ''?'n':(a:1))
+ endif
+
+ call s:SQLU_WrapperStart( a:firstline, a:lastline, mode )
+ " Store pervious value of highlight search
+ let hlsearch = &hlsearch
+ let &hlsearch = 0
+
+ " save previous search string
+ let saveSearch = @/
+
+ " save previous format options and turn off automatic formating
+ let saveFormatOptions = &formatoptions
+ silent execute 'setlocal formatoptions-=a'
+
+ " Use the mark locations instead of storing the line numbers
+ " since these values can changes based on the reformatting
+ " of the lines
+ let ret = s:SQLU_ReformatStatement()
+ if ret > -1
+ if g:sqlutil_wrap_expressions == 1
+ let ret = s:SQLU_WrapExpressions()
+ endif
+ if ret > -1
+ let ret = s:SQLU_IndentNestedBlocks()
+ if ret > -1
+ let ret = s:SQLU_WrapLongLines()
+ endif
+ endif
+ endif
+
+ " Restore default value
+ " And restore cursor position
+ let &hlsearch = hlsearch
+ call s:SQLU_WrapperEnd(mode)
+
+ " restore previous format options
+ let &formatoptions = saveFormatOptions
+
+ " restore previous search string
+ let @/ = saveSearch
+
+endfunction
+
+" SQLU_FormatStmts:
+" For a given range (default entire file), it find each SQL
+" statement an run SQLFormatter against it.
+"
+function! SQLUtilities#SQLU_FormatStmts(...) range
+ let mode = 'n'
+ if a:0 > 0
+ let mode = (a:1 == ''?'n':(a:1))
+ endif
+
+ let curline = line(".")
+ let curcol = virtcol(".")
+ let keepline_ms = line("'s")
+ let keepcol_ms = virtcol("'s")
+ let keepline_me = line("'e")
+ let keepcol_me = virtcol("'e")
+
+ silent! exec 'norm! '.a:lastline."G\<bar>0\<bar>"
+ " Add a new line to the bottom of the mark to be removed latter
+ put =''
+ silent! exec "ma e"
+ silent! exec 'norm! '.a:firstline."G\<bar>0\<bar>"
+ " Add a new line above the mark to be removed latter
+ put! = ''
+ silent! exec "ma s"
+ silent! exec "norm! 'sj"
+
+ " Store pervious value of highlight search
+ let hlsearch = &hlsearch
+ let &hlsearch = 0
+
+ " save previous search string
+ let saveSearch = @/
+
+ " save previous format options and turn off automatic formating
+ let saveFormatOptions = &formatoptions
+ silent execute 'setlocal formatoptions-=a'
+
+ " Must default the statements to query
+ let stmt_keywords = g:sqlutil_stmt_keywords
+
+ " Verify the string is in the correct format
+ " Strip off any trailing commas
+ let stmt_keywords =
+ \ substitute(stmt_keywords, ',$','','')
+ " Convert commas to regex ors
+ let stmt_keywords =
+ \ substitute(stmt_keywords, '\s*,\s*', '\\|', 'g')
+
+ let sql_commands = '\c\<\('.stmt_keywords.'\)\>'
+
+ " Find a line starting with SELECT|UPDATE|DELETE
+ " .,- - From that line backup one line due to :g
+ " /; - find the ending command delimiter
+ " SQLUFormatter - Use the SQLUtilities plugin to format it
+ let cmd = a:firstline.','.a:lastline.'g/^\s*\<\(' .
+ \ stmt_keywords . '\)\>/.,-/' .
+ \ g:sqlutil_cmd_terminator . '/SQLUFormatter'
+ exec cmd
+
+ " Restore default value
+ " And restore cursor position
+ let &hlsearch = hlsearch
+
+ " restore previous format options
+ let &formatoptions = saveFormatOptions
+
+ " restore previous search string
+ let @/ = saveSearch
+
+ silent! exe 'norm! '.curline."G\<bar>".(curcol-1).
+ \ ((curcol-1)>0 ? 'l' : '' )
+
+ if (mode != 'n')
+ " Reselect the visual area, so the user can us gv
+ " to operate over the region again
+ exec 'normal! '.(line("'s")+1).'gg'.'|'.
+ \ 'V'.(line("'e")-2-line("'s")).'j|'."\<Esc>"
+ endif
+
+ " Delete blanks lines added around the visually selected range
+ silent! exe "norm! 'sdd'edd"
+
+ silent! exe 'norm! '.curline."G\<bar>".(curcol-1).
+ \ ((curcol-1)>0 ? 'l' : '' )
+
+endfunction
+
+" This function will return a count of unmatched parenthesis
+" ie ( this ( funtion ) - will return 1 in this case
+function! s:SQLU_CountUnbalancedParan( line, paran_to_check )
+ let l = a:line
+ let lp = substitute(l, '[^(]', '', 'g')
+ let l = a:line
+ let rp = substitute(l, '[^)]', '', 'g')
+
+ if a:paran_to_check =~ ')'
+ " echom 'SQLU_CountUnbalancedParan ) returning: '
+ " \ . (strlen(rp) - strlen(lp))
+ return (strlen(rp) - strlen(lp))
+ elseif a:paran_to_check =~ '('
+ " echom 'SQLU_CountUnbalancedParan ( returning: '
+ " \ . (strlen(lp) - strlen(rp))
+ return (strlen(lp) - strlen(rp))
+ else
+ " echom 'SQLU_CountUnbalancedParan unknown paran to check: ' .
+ " \ a:paran_to_check
+ return 0
+ endif
+endfunction
+
+" WS: wrapper start (internal) Creates guard lines,
+" stores marks y and z, and saves search pattern
+function! s:SQLU_WrapperStart( beginline, endline, mode )
+ let b:curline = line(".")
+ let b:curcol = virtcol(".")
+ let b:keepsearch = @/
+ let b:keepline_my = line("'y")
+ let b:keepcol_my = virtcol("'y")
+ let b:keepline_mz = line("'z")
+ let b:keepcol_mz = virtcol("'z")
+
+ silent! exec 'norm! '.a:endline."G\<bar>0\<bar>"
+ " Add a new line to the bottom of the mark to be removed later
+ put =''
+ silent! exec "ma z"
+ silent! exec 'norm! '.a:beginline."G\<bar>0\<bar>"
+ " Add a new line above the mark to be removed later
+ put! = ''
+ silent! exec "ma y"
+ let b:cmdheight= &cmdheight
+ set cmdheight=2
+ silent! exec "norm! 'zk"
+endfunction
+
+" WE: wrapper end (internal) Removes guard lines,
+" restores marks y and z, and restores search pattern
+function! s:SQLU_WrapperEnd(mode)
+ if (a:mode != 'n')
+ " Reselect the visual area, so the user can us gv
+ " to operate over the region again
+ exec 'normal! '.(line("'y")+1).'gg'.'|'.
+ \ 'V'.(line("'z")-2-line("'y")).'j|'."\<Esc>"
+ endif
+
+ " Delete blanks lines added around the visually selected range
+ silent! exe "norm! 'ydd'zdd"
+ silent! exe "set cmdheight=".b:cmdheight
+ unlet b:cmdheight
+ let @/= b:keepsearch
+
+ silent! exe 'norm! '.b:curline."G\<bar>".(b:curcol-1).
+ \ ((b:curcol-1)>0 ? 'l' : '' )
+
+ unlet b:keepline_my b:keepcol_my
+ unlet b:keepline_mz b:keepcol_mz
+ unlet b:curline b:curcol
+endfunction
+
+" Reformats the statements
+" 1. Keywords (FROM, WHERE, AND, ... ) " are on new lines
+" 2. Keywords are right justified
+" 3. CASE statements are setup for alignment.
+" 4. Operators are lined up
+"
+function! s:SQLU_ReformatStatement()
+ " Remove any lines that have comments on them since the comments
+ " could spill onto new lines and no longer have comment markers
+ " which would result in syntax errors
+ " Comments could also contain keywords, which would be split
+ " on to new lines
+ silent! 'y+1,'z-1s/.*\zs--.*//e
+ " Join block of text into 1 line
+ silent! 'y+1,'z-1j
+ " Reformat the commas, to remove any spaces before them
+ silent! 'y+1,'z-1s/\s*,/,/ge
+ " And add a space following them, this allows the line to be
+ " split using gqq
+ silent! 'y+1,'z-1s/,\(\w\)/, \1/ge
+ " Change more than 1 space with just one except spaces at
+ " the beginning of the range
+ " silent! 'y+1,'z-1s/\s\+/ /ge
+ silent! 'y+1,'z-1s/\(\S\+\)\(\s\+\)/\1 /g
+ " Go to the start of the block
+ silent! 'y+1
+
+ " Place an UPDATE on a newline, but not if it is preceeded by
+ " the existing statement. Example:
+ " INSERT INTO T1 (...)
+ " ON EXISTING UPDATE
+ " VALUES (...);
+ " SELECT ...
+ " FOR UPDATE
+ let sql_update_keywords = '' .
+ \ '\%(\%(\<\%(for\|existing\)\s\+\)\@<!update\)'
+ " WINDOW clauses can be used in both the SELECT list
+ " and after the HAVING clause.
+ let sql_window_keywords = '' .
+ \ 'over\|partition\s\+by\|' .
+ \ '\%(rows\|range\)\s\+' .
+ \ '\%(between\|unbounded\|current\|preceding\|following\)'
+ " INTO clause can be used in a SELECT statement as well
+ " as an INSERT statement. We do not want to place INTO
+ " on a newline if it is preceeded by INSERT
+ let sql_into_keywords = '' .
+ \ '\%(\%(\<\%(insert\|merge\)\s\+\)\@<!into\)'
+ " Normally you would add put an AND statement on a new
+ " line. But in the cases where you are dealing with
+ " a BETWEEN '1963-1-1' AND '1965-3-31', we no not want
+ " to put the AND on a new line
+ " Do not put AND on a new line if preceeded by
+ " between<space><some text not including space><space>AND
+ let sql_and_between_keywords = '' .
+ \ '\%(\%(\<between\s\+[^ ]\+\s\+\)\@<!and\)'
+ " For SQL Remote (ASA), this is valid syntax
+ " SUBSCRIBE BY
+ " OLD SUBSCRIBE BY
+ " NEW SUBSCRIBE BY
+ let sql_subscribe_keywords = '' .
+ \ '\%(\%(\<\%(old\|new\)\s\+\)\?subscribe\)'
+ " Oracle CONNECT BY statement
+ let sql_connect_by_keywords = '' .
+ \ 'connect\s\+by\s\+\w\+'
+ " Oracle MERGE INTO statement
+ " MERGE INTO ...
+ " WHEN MATCHED THEN ...
+ " WHEN NOT MATCHED THEN ....
+ " Match on the WHEN clause (with zero width) if it is followed
+ " by [not] matched
+ let sql_merge_keywords = '' .
+ \ '\%(merge\s\+into\)\|\%(when\(\s\+\%(not\s\+\)\?matched\)\@=\)'
+ " Some additional Oracle keywords from the SQL Reference for SELECT
+ let sql_ora_keywords = '' .
+ \ '\%(dimension\s\+by\|' .
+ \ 'measures\s*(\|' .
+ \ 'iterate\s*(\|' .
+ \ 'within\s\+group\|' .
+ \ '\%(ignore\|keep\)\s\+nav\|' .
+ \ 'return\s\+\%(updated\|all\)\|' .
+ \ 'rules\s\+\%(upsert\|update\)\)'
+ " FROM clause can be used in a DELETE statement as well
+ " as a SELECT statement. We do not want to place FROM
+ " on a newline if it is preceeded by DELETE
+ let sql_from_keywords = '' .
+ \ '\%(\%(\<delete\s\+\)\@<!from\)'
+ " Only place order on a newline if followed by "by"
+ " let sql_order_keywords = '' . \ '\%(\%(\<order\s\+\)\@<!into\)'
+
+ " join type syntax from ASA help file
+ " INNER
+ " | LEFT [ OUTER ]
+ " | RIGHT [ OUTER ]
+ " | FULL [ OUTER ]
+ " LEFT, RIGHT, FULL can optional be followed by OUTER
+ " The entire expression is optional
+ let sql_join_type_keywords = '' .
+ \ '\%(' .
+ \ '\%(inner\|' .
+ \ '\%(\%(\%(left\|right\|full\)\%(\s\+outer\)\?\s*\)\?\)' .
+ \ '\)\?\s*\)\?'
+ " Decho 'join types: ' . sql_join_type_keywords
+ " join operator syntax
+ " [ KEY | NATURAL ] [ join_type ] JOIN
+ " | CROSS JOIN
+ let sql_join_operator = '' .
+ \ '\%(' .
+ \ '\%(\%(\%(key\|natural\)\?\s*\)\?' .
+ \ sql_join_type_keywords .
+ \ 'join\)\|' .
+ \ '\%(\%(\%(cross\)\?\s*\)\?join\)' .
+ \ '\)'
+ " Decho 'join types: ' . sql_join_type_keywords
+ " join operator syntax
+ " [ KEY | NATURAL ] [ join_type ] JOIN
+ " | CROSS JOIN
+ " force each keyword onto a newline
+ let sql_keywords = '\<\%(create\|drop\|call\|select\|set\|values\|' .
+ \ sql_update_keywords . '\|' .
+ \ sql_into_keywords . '\|' .
+ \ sql_and_between_keywords . '\|' .
+ \ sql_from_keywords . '\|' .
+ \ sql_join_operator . '\|' .
+ \ sql_subscribe_keywords . '\|' .
+ \ sql_connect_by_keywords . '\|' .
+ \ sql_merge_keywords . '\|' .
+ \ sql_ora_keywords . '\|' .
+ \ 'on\|where\|or\|\%(order\|group\)\s\+\%(\w\+\s\+\)\?\<by\>\|'.
+ \ sql_window_keywords . '\|' .
+ \ 'having\|for\|insert\|using\|' .
+ \ 'intersect\|except\|window\|' .
+ \ '\%(union\%(\s\+all\)\?\)\|' .
+ \ 'start\s\+with\|' .
+ \ '\%(\%(\<start\s\+\)\@<!with\)\)\>'
+ " The user can specify whether to align the statements based on
+ " the first word, or on the matching string.
+ " let g:sqlutil_align_first_word = 0
+ " select
+ " from
+ " union all
+ " let g:sqlutil_align_first_word = 1
+ " select
+ " from
+ " union all
+ let cmd = "'y+1,'z-1".'s/\%(^\s*\)\@<!\zs\<\(' .
+ \ sql_keywords .
+ \ '\)\>\s*/' .
+ \ '\r\1' .
+ \ ( g:sqlutil_align_first_word==0 ? '-@-' : ' ' ) .
+ \ '/gei'
+ " Decho cmd
+ silent! exec cmd
+
+ " Ensure keywords at the beginning of a line have a space after them
+ " This will ensure the Align program lines them up correctly
+ " silent! 'y+1,'z-1s/^\([a-zA-Z0-9_]*\)(/\1 (/e
+ " Delete any non empty lines
+ " Do NOT delete empty lines, since that can affect the marks
+ " and change which lines get formatted
+ " 'y+1,'z-1g/^\s*$/d
+
+ " If g:sqlutil_align_first_word == 0, then we need only add the -@-
+ " on the first word, else we need to do it to the first word
+ " on each line
+ silent! exec "'y+1," .
+ \ ( g:sqlutil_align_first_word==0 ? "'y+1" : "'z-1" ) .
+ \ 's/^\s*\<\w\+\>\zs\s*/-@-'
+
+ " Ensure CASE statements also start on new lines
+ " CASE statements can also be nested, but we want these to align
+ " with column lists, not keywords, so the -@- is placed BEFORE
+ " the CASE keywords, not after
+ "
+ " The CASE statement and the Oracle MERGE statement are very similar.
+ " I have changed the WHEN clause to check to see if it is followed
+ " by [NOT] MATCHED, if so, do not match the WHEN
+ let sql_case_keywords = '\(\<end\s\+\)\@<!case' .
+ \ '\|\<when\>\(\%(-@-\)\?\s*\%(not\s\+\)\?matched\)\@!' .
+ \ '\|else\|end\(\s\+case\)\?'
+
+ " echom 'case: '.sql_case_keywords
+ " The case keywords must not be proceeded by a -@-
+ silent! exec "'y+1,'z-1".'s/'.
+ \ '\%(-@-\)\@<!'.
+ \ '\<\('.
+ \ sql_case_keywords.
+ \ '\)\>/\r-@-\1/gei'
+
+ " AlignPush
+
+ " Using the Align.vim plugin, reformat the lines
+ " so that the keywords are RIGHT justified
+ AlignCtrl default
+
+ if g:sqlutil_align_comma == 1
+ call s:SQLU_WrapAtCommas()
+ endif
+
+ call s:SQLU_WrapFunctionCalls()
+
+ let ret = s:SQLU_SplitUnbalParan()
+ if ret < 0
+ " Undo any changes made so far since an error occurred
+ " silent! exec 'u'
+ return ret
+ endif
+
+ " Align these based on the special charater
+ " and the column names are LEFT justified
+ AlignCtrl Ip0P0rl:
+ silent! 'y+1,'z-1Align -@-
+ silent! 'y+1,'z-1s/-@-/ /ge
+
+ " Now that we have removed the special alignment marker
+ " upper or lower case all the keywords only if the user
+ " has specified an override.
+ if g:sqlutil_keyword_case != ''
+ let cmd = "'y+1,'z-1".'s/\<\(' .
+ \ sql_keywords .
+ \ '\|' .
+ \ sql_case_keywords .
+ \ '\|' .
+ \ sql_join_type_keywords .
+ \ '\)\>/' .
+ \ g:sqlutil_keyword_case .
+ \ '\1/gei'
+ silent! exec cmd
+ endif
+
+ " Now align the operators
+ " and the operators are CENTER justified
+ if g:sqlutil_align_where == 1
+ AlignCtrl default
+ AlignCtrl g [!<>=]
+ AlignCtrl Wp1P1l
+
+ " Change this to only attempt to align the last WHERE clause
+ " and not the entire SQL statement
+ " Valid operators are:
+ " =, =, >, <, >=, <=, !=, !<, !>, <>
+ " The align below was extended to allow the last character
+ " to be either =,<,>
+ silent! 'y+1,'z-1Align [!<>=]\(<\|>\|=\)\=
+ endif
+
+ " Reset back to defaults
+ AlignCtrl default
+
+ " Reset the alignment to what it was prior to
+ " this function
+ " AlignPop
+
+ return 1
+endfunction
+
+" Check through the selected text for open ( and
+" indent if necessary
+function! s:SQLU_IndentNestedBlocks()
+
+ let org_textwidth = &textwidth
+ if &textwidth == 0
+ " Get the width of the window
+ let &textwidth = winwidth(winnr())
+ endif
+
+ let sql_keywords = '\<\%(select\|set\|\%(insert\s\+\)\?into\|from\|values'.
+ \ '\|order\|group\|having\|return\|call\)\>'
+
+ " Indent nested blocks surrounded by ()s.
+ let linenum = line("'y+1")
+ while linenum <= line("'z-1")
+ let line = getline(linenum)
+ if line =~ '(\s*$'
+ let begin_paran = match( line, '(\s*$' )
+ if begin_paran > -1
+ let curline = line(".")
+ let curcol = begin_paran + 1
+ " echom 'begin_paran: '.begin_paran.
+ " \ ' line: '.curline.
+ " \ ' col: '.curcol
+ silent! exe 'norm! '.linenum."G\<bar>".curcol."l"
+ " v - visual
+ " ib - inner block
+ " k - backup on line
+ " > - right shift
+ " . - shift again
+ " silent! exe 'norm! vibk>.'
+ silent! exe 'norm! vibk>'
+
+ " If the following line begins with a keyword,
+ " indent one additional time. This is necessary since
+ " keywords are right justified, so they need an extra
+ " indent
+ if getline(linenum+1) =~? '^\s*\('.sql_keywords.'\)'
+ silent! exe 'norm! .'
+ endif
+ " echom 'SQLU_IndentNestedBlocks - from: '.line("'<").' to: ' .
+ " \ line("'>")
+ " echom 'SQLU_IndentNestedBlocks - no match: '.getline(linenum)
+ endif
+ endif
+
+ let linenum = linenum + 1
+ endwhile
+
+ let ret = linenum
+
+ "
+ " Indent nested CASE blocks
+ "
+ let linenum = line("'y+1")
+ " Search for the beginning of a CASE statement
+ let begin_case = '\<\(\<end\s\+\)\@<!case\>'
+
+ silent! exe 'norm! '.linenum."G\<bar>0\<bar>"
+
+ while( search( begin_case, 'W' ) > 0 )
+ " Check to see if the CASE statement is inside a string
+ if synID(line("."),col("."),1) > 0
+ continue
+ endif
+ let curline = line(".")
+ if( (curline < line("'y+1")) || (curline > line("'z-1" )) )
+ " echom 'No case statements, leaving loop'
+ silent! exe 'norm! '.line("'y+1")."G\<bar>0\<bar>"
+ break
+ endif
+ " echom 'begin CASE found at: '.curline
+ let curline = curline + 1
+ let end_of_case = s:SQLU_IndentNestedCase( begin_case, curline,
+ \ line("'z-1") )
+ let end_of_case = end_of_case + 1
+ let ret = end_of_case
+ if( ret < 0 )
+ break
+ endif
+ silent! exe 'norm! '.end_of_case."G\<bar>0\<bar>"
+ endwhile
+
+ "
+ " Indent Oracle nested MERGE blocks
+ "
+ let linenum = line("'y+1")
+ " Search for the beginning of a CASE statement
+ let begin_merge = '\<merge\s\+into\>'
+
+ silent! exe 'norm! '.linenum."G\<bar>0\<bar>"
+
+ if( search( begin_merge, 'W' ) > 0 )
+ let curline = line(".")
+ if( (curline < line("'y+1")) || (curline > line("'z-1" )) )
+ " echom 'No case statements, leaving loop'
+ silent! exe 'norm! '.line("'y+1")."G\<bar>0\<bar>"
+ else
+ " echom 'begin CASE found at: '.curline
+ let curline = curline + 1
+
+ while 1==1
+ " Find the matching when statement
+ " let match_merge = searchpair('\<merge\s\+into\>',
+ let match_merge = searchpair('\<merge\>', '',
+ \ '\<\%(when\s\+\%(not\s\+\)\?matched\)',
+ \ 'W', '' )
+ if( (match_merge < curline) || (match_merge > line("'z-1")) )
+ silent! exec curline . "," . line("'z-1") . ">>"
+ break
+ else
+ if match_merge > (curline+1)
+ let savePos = 'normal! '.line(".").'G'.col(".")."\<bar>"
+ silent! exec curline . "," . (match_merge-1) . ">>"
+ silent! exec savePos
+ endif
+ let curline = match_merge + 1
+ endif
+ endwhile
+ endif
+ endif
+
+ let &textwidth = org_textwidth
+ return ret
+endfunction
+
+" Recursively indent nested case statements
+function! s:SQLU_IndentNestedCase( begin_case, start_line, end_line )
+
+ " Indent nested CASE blocks
+ let linenum = a:start_line
+
+ " Find the matching end case statement
+ let end_of_prev_case = searchpair(a:begin_case, '',
+ \ '\<end\( case\)\?\>', 'W', '' )
+
+ if( (end_of_prev_case < a:start_line) || (end_of_prev_case > a:end_line) )
+ call s:SQLU_WarningMsg(
+ \ 'SQLU_IndentNestedCase - No matching end case for: ' .
+ \ getline((linenum-1))
+ \ )
+ return -1
+ " else
+ " echom 'Matching END found at: '.end_of_prev_case
+ endif
+
+ silent! exe 'norm! '.linenum."G\<bar>0\<bar>"
+
+ if( search( a:begin_case, 'W' ) > 0 )
+ let curline = line(".")
+ if( (curline > a:start_line) && (curline < end_of_prev_case) )
+ let curline = curline + 1
+ let end_of_case = s:SQLU_IndentNestedCase( a:begin_case, curline,
+ \ line("'z-1") )
+ " echom 'SQLU_IndentNestedCase from: '.linenum.' to: '.end_of_case
+ silent! exec (curline-1) . "," . end_of_case . ">>"
+ " else
+ " echom 'SQLU_IndentNestedCase No case statements, '.
+ " \ 'leaving SQLU_IndentNestedCase: '.linenum
+ endif
+ endif
+
+ return end_of_prev_case
+endfunction
+
+" For certain keyword lines (SELECT, ORDER BY, GROUP BY, ...)
+" Ensure the lines fit in the textwidth (or default 80), wrap
+" the lines where necessary and left justify the column names
+function! s:SQLU_WrapFunctionCalls()
+ " Check if this is a statement that can often by longer than 80 characters
+ " (select, set and so on), if so, ensure the column list is broken over as
+ " many lines as necessary and lined up with the other columns
+ let linenum = line("'y+1")
+
+ let org_textwidth = &textwidth
+ if org_textwidth == 0
+ " Get the width of the window
+ let curr_textwidth = winwidth(winnr())
+ else
+ let curr_textwidth = org_textwidth
+ endif
+
+ let sql_keywords = '\<\%(select\|set\|\%(insert\(-@-\)\?\)into' .
+ \ '\|from\|values'.
+ \ '\|order\|group\|having\|return\|with\)\>'
+
+ " Useful in the debugger
+ " echo linenum.' '.func_call.' '.virtcol(".").'
+ " '.','.substitute(getline("."), '^ .*\(\%'.(func_call-1).'c...\).*',
+ " '\1', '' ).', '.getline(linenum)
+
+ " call Decho(" Before column splitter 'y+1=".line("'<").
+ " \ ":".col("'<")." 'z-1=".line("'>").":".col("'>"))
+ while linenum <= line("'z-1")
+ let line = getline(linenum)
+
+ if strlen(line) < curr_textwidth
+ let linenum = linenum + 1
+ continue
+ endif
+
+ let get_func_nm = '[a-zA-Z_.]\+\s*('
+
+ " Use a special line textwidth, since if we split function calls
+ " any text within the parantheses will be indented 2 &shiftwidths
+ " so when calculating where to split, we must take that into
+ " account
+ let keyword_str = matchstr(
+ \ getline(linenum), '^\s*\('.sql_keywords.'\)' )
+
+ let line_textwidth = curr_textwidth - strlen(keyword_str)
+ let func_call = 0
+ while( strlen(getline(linenum)) > line_textwidth )
+
+ " Find the column # of the start of the function name
+ let func_call = match( getline(linenum), get_func_nm, func_call )
+ if func_call < 0
+ " If no functions found, move on to next line
+ break
+ endif
+
+ let prev_func_call = func_call
+
+ " Position cursor at func_call
+ silent! exe 'norm! '.linenum."G\<bar>".func_call."l"
+
+ if search('(', 'W') > linenum
+ call s:SQLU_WarningMsg(
+ \ 'SQLU_WrapFunctionCalls - should have found a ('
+ \ )
+ let linenum = linenum + 1
+ break
+ endif
+
+ " Check to ensure the paran is not part of a string
+ " Otherwise ignore and move on to the next paran
+ if synID(line("."),col("."),1) == 0
+ " let end_paran = searchpair( '(', '', ')', '' )
+ " Ignore parans that are inside of strings
+ let end_paran = searchpair( '(', '', ')', '',
+ \ 'synID(line("."),col("."),1)>0' )
+ if end_paran < linenum || end_paran > linenum
+ " call s:SQLU_WarningMsg(
+ " \ 'SQLU_WrapFunctionCalls - ' .
+ " \ 'should have found a matching ) for :' .
+ " \ getline(linenum)
+ " \ )
+ let linenum = linenum + 1
+ break
+ endif
+
+ " If the matching ) is past the textwidth
+ if virtcol(".") > line_textwidth
+ if (virtcol(".")-func_call) > line_textwidth
+ " Place the closing brace on a new line only if
+ " the entire length of the function call and
+ " parameters is longer than a line
+ silent! exe "norm! i\r-@-\<esc>"
+ endif
+ " If the SQL keyword preceeds the function name dont
+ " bother placing it on a new line
+ let preceeded_by_keyword =
+ \ '^\s*' .
+ \ '\(' .
+ \ sql_keywords .
+ \ '\|,' .
+ \ '\)' .
+ \ '\(-@-\)\?' .
+ \ '\s*' .
+ \ '\%'.(func_call+1).'c'
+ " echom 'preceeded_by_keyword: '.preceeded_by_keyword
+ " echom 'func_call:'.func_call.' Current
+ " character:"'.getline(linenum)[virtcol(func_call)].'" -
+ " '.getline(linenum)
+ if getline(linenum) !~? preceeded_by_keyword
+ " if line =~? '^\s*\('.sql_keywords.'\)'
+ " Place the function name on a new line
+ silent! exe linenum.'s/\%'.(func_call+1).'c/\r-@-'
+ let linenum = linenum + 1
+ " These lines will be indented since they are wrapped
+ " in parantheses. Decrease the line_textwidth by
+ " that amount to determine where to split nested
+ " function calls
+ let line_textwidth = line_textwidth - (2 * &shiftwidth)
+ let func_call = 0
+ " Get the new offset of this function from the start
+ " of the newline it is on
+ let prev_func_call = match(
+ \ getline(linenum),get_func_nm,func_call)
+ endif
+ endif
+ endif
+
+ " Get the name of the previous function
+ let prev_func_call_str = matchstr(
+ \ getline(linenum), get_func_nm, prev_func_call )
+ " Advance the column by its length to find the next function
+ let func_call = prev_func_call +
+ \ strlen(prev_func_call_str)
+
+ endwhile
+
+ let linenum = linenum + 1
+ endwhile
+
+ let &textwidth = org_textwidth
+ return linenum
+endfunction
+
+" For certain keyword lines (SELECT, SET, INTO, FROM, VALUES)
+" put each comma on a new line and align it with the keyword
+" SELECT c1
+" , c2
+" , c3
+function! s:SQLU_WrapAtCommas()
+ let linenum = line("'y+1")
+
+ let sql_keywords = '\<\%(select\|set\|into\|from\|values\)\>'
+
+ " call Decho(" Before column splitter 'y+1=".line("'<").
+ " \ ":".col("'<")." 'z-1=".line("'>").":".col("'>"))
+ while linenum <= line("'z-1")
+ let line = getline(linenum)
+ " if line =~? '^\s*\('.sql_keywords.'\)'
+ if line =~? '\w'
+ " if line =~? '^\s*\<\('.sql_keywords.'\)\>'
+ silent! exec linenum
+ " Mark the start of the line
+ silent! exec "normal mb"
+ " echom "line b - ".getline("'b")
+ " Mark the next line
+ silent! exec "normal jmek"
+
+ let saved_linenum = linenum
+ let index = match(getline(linenum), '[,(]')
+ while index > -1
+ " Go to character
+ call cursor(linenum, (index+1))
+
+ " Make sure the paran is not a string
+ if getline(linenum)[col(".")-1] == '(' &&
+ \ synID(line("."),col("."),1) == 0
+ " if searchpair( '(', '', ')', '' ) > 0
+ " Ignore parans that are inside of strings
+ if searchpair( '(', '', ')', '',
+ \ 'synID(line("."),col("."),1)>0' ) > 0
+ let linenum = line(".")
+ let index = col(".")
+ endif
+ else
+ " Only do this if the comma at this offset
+ " is not already at the start of the line
+ if match(getline(linenum), '\S') != index
+ " Given the current cursor position, replace
+ " the , and any following whitespace
+ " with a newline and the special -@- character
+ " for Align
+ silent! exec linenum . ',' . linenum .
+ \ 's/\%' . (index + 1) . 'c,\s*' .
+ \ '/\r,-@-'
+ let linenum = linenum + 1
+ endif
+ " Find the index of the first non-white space
+ " which should be the , we just put on the
+ " newline
+ let index = match(getline(linenum), '\S')
+ let index = index + 1
+ endif
+
+ " then continue on for the remainder of the line
+ " looking for the next , or (
+ "
+ " Must figure out what index value to start from
+ let index = match( getline(linenum), '[,(]', index )
+ endwhile
+ let linenum = saved_linenum
+
+ " Go to the end of the new lines
+ silent! exec "'e-"
+ let linenum = line("'e")-1
+ " endif
+ endif
+
+ let linenum = linenum + 1
+ endwhile
+
+ return linenum
+endfunction
+
+" For certain keyword lines (SELECT, ORDER BY, GROUP BY, ...)
+" Ensure the lines fit in the textwidth (or default 80), wrap
+" the lines where necessary and left justify the column names
+function! s:SQLU_WrapExpressions()
+ " Check if this is a statement that can often by longer than 80 characters
+ " (select, set and so on), if so, ensure the column list is broken over as
+ " many lines as necessary and lined up with the other columns
+ let linenum = line("'y+1")
+
+ let sql_keywords = '\<\%(select\)\>'
+ let sql_expression_operator = '' .
+ \ '\<\%(' .
+ \ '\%(end\s\+\)\@<!if\|else\%(if\)\?\|endif\|case\|when\|end' .
+ \ '\)\>'
+
+ " call Decho(" Before column splitter 'y+1=".line("'<").
+ " \ ":".col("'<")." 'z-1=".line("'>").":".col("'>"))
+ while linenum <= line("'z-1")
+ let line = getline(linenum)
+ " if line =~? '^\s*\('.sql_keywords.'\)'
+ if line =~? '\w'
+ " if line =~? '^\s*\('.sql_keywords.'\)'
+ " Decho 'linenum: ' . linenum . ' strlen: ' .
+ " \ strlen(line) . ' textwidth: ' . &textwidth .
+ " \ ' line: ' . line
+ " go to the current line
+ silent! exec linenum
+ " Mark the start of the wide line
+ silent! exec "normal mb"
+ let markb = linenum
+ " echom "line b - ".getline("'b")
+ " Mark the next line
+ silent! exec "normal jmek"
+ " echom "line e - ".getline("'e")
+
+
+ if line =~? '\('.sql_expression_operator.'\)'
+ silent! exec linenum . ',' . linenum .
+ \ 's/^\s*\('.sql_keywords.'\)\s*'.
+ \ '/\1-@-'
+ " Create a special marker for Align.vim
+ " to line up the columns with
+ silent! exec linenum . ',' . linenum .
+ \ 's/'.sql_expression_operator.'/'.
+ \ '\r-@-&'
+
+ endif
+
+ " echom "end_line_nbr - ".end_line_nbr
+ " echom "normal end_line_nbr - ".line(end_line_nbr)
+
+ " Append the special marker to the beginning of the line
+ " for Align.vim
+ " silent! exec "'b+," .end_line_nbr. 's/\s*\(.*\)/-@-\1'
+ " silent! exec "'b+," .end_line_nbr. 's/^\s*/-@-'
+ silent! exec ''.(markb+1)."," .end_line_nbr. 's/^\s*/-@-/g'
+ " silent! exec "'b+,'e-" . 's/\s*\(.*\)/-@-\1'
+ AlignCtrl Ip0P0rl:
+ " silent! 'b,'e-Align -@-
+ " silent! exec "'b,".end_line_nbr.'Align -@-'
+ silent! exec markb.",'e".'Align -@-'
+ " silent! 'b,'e-s/-@-/ /
+ silent! exec markb.",'e".'s/-@-/ /ge'
+ AlignCtrl default
+
+ " Advance the linenum to the end of the range
+ let linenum = line("'e")
+ " endif
+ endif
+
+ let linenum = linenum + 1
+ endwhile
+
+ return linenum
+endfunction
+
+" For certain keyword lines (SELECT, ORDER BY, GROUP BY, ...)
+" Ensure the lines fit in the textwidth (or default 80), wrap
+" the lines where necessary and left justify the column names
+function! s:SQLU_WrapLongLines()
+ " Check if this is a statement that can often by longer than 80 characters
+ " (select, set and so on), if so, ensure the column list is broken over as
+ " many lines as necessary and lined up with the other columns
+ let linenum = line("'y+1")
+
+ let org_textwidth = &textwidth
+ if &textwidth == 0
+ " Get the width of the window
+ let &textwidth = winwidth(winnr())
+ endif
+
+ let sql_keywords = '\<\%(select\|set\|into\|from\|values'.
+ \ '\|order\|group\|having\|call\|with\)\>'
+
+ " call Decho(" Before column splitter 'y+1=".line("'<").
+ " \ ":".col("'<")." 'z-1=".line("'>").":".col("'>"))
+ while linenum <= line("'z-1")
+ let line = getline(linenum)
+ " if line =~? '^\s*\('.sql_keywords.'\)'
+ if line =~? '\w'
+ " Set the textwidth to current value
+ " minus an adjustment for select and set
+ " minus any indent value this may have
+ " echo 'tw: '.&textwidth.' indent: '.indent(line)
+ " Decho 'line: '.line
+ " Decho 'tw: '.&textwidth.' match at: '.
+ " \ matchend(line, sql_keywords )
+ " let &textwidth = &textwidth - 10 - indent(line)
+ if line =~? '^\s*\('.sql_keywords.'\)'
+ let &textwidth = &textwidth - matchend(line, sql_keywords ) - 2
+ let line_length = strlen(line) - matchend(line, sql_keywords )
+ else
+ let line_length = strlen(line)
+ endif
+
+ if( line_length > &textwidth )
+ " Decho 'linenum: ' . linenum . ' strlen: ' .
+ " \ strlen(line) . ' textwidth: ' . &textwidth .
+ " \ ' line: ' . line
+ " go to the current line
+ silent! exec linenum
+ " Mark the start of the wide line
+ silent! exec "normal mb"
+ let markb = linenum
+ " echom "line b - ".getline("'b")
+ " Mark the next line
+ silent! exec "normal jmek"
+ " echom "line e - ".getline("'e")
+ " echom "line length- ".strlen(getline(".")).
+ " \ " tw=".&textwidth
+
+
+ if line =~