Permalink
Browse files

My modifications to the Janus VIM distribution that are vital for my …

…workflow.

That's why I put them into a public repository.
Feel free to cherry-pick what you might like.
  • Loading branch information...
1 parent 26a4860 commit 473b33bff9054bddc13536e085fc277df5b82156 @mre committed Dec 1, 2011
Showing with 24,444 additions and 17 deletions.
  1. BIN .DS_Store
  2. +2 −16 .gitignore
  3. +6 −0 .netrwhist
  4. +40 −0 after/plugin/snipMate.vim
  5. +1,029 −0 autoload/Align.vim
  6. +330 −0 autoload/AlignMaps.vim
  7. +380 −0 autoload/ZoomWin.vim
  8. +1,590 −0 autoload/conque_term.vim
  9. +4,656 −0 autoload/rails.vim
  10. +435 −0 autoload/snipMate.vim
  11. +1 −1 bootstrap.sh
  12. BIN bundle/.DS_Store
  13. +1 −0 bundle/JSLint
  14. +1 −0 bundle/Replay
  15. +1 −0 bundle/rainbow_parentheses.vim
  16. +1 −0 bundle/vim-easymotion
  17. +1 −0 bundle/vimspell
  18. +1 −0 bundle/vundle
  19. +72 −0 colors/adaryn.vim
  20. +97 −0 colors/adrian.vim
  21. +37 −0 colors/aiseered.vim
  22. +108 −0 colors/anotherdark.vim
  23. +44 −0 colors/aqua.vim
  24. +164 −0 colors/astronaut.vim
  25. +59 −0 colors/asu1dark.vim
  26. +69 −0 colors/autumn.vim
  27. +88 −0 colors/autumn2.vim
  28. +154 −0 colors/autumnleaf.vim
  29. +319 −0 colors/baycomb.vim
  30. +67 −0 colors/bclear.vim
  31. +115 −0 colors/biogoo.vim
  32. +37 −0 colors/blacksea.vim
  33. +50 −0 colors/bluegreen.vim
  34. +60 −0 colors/borland.vim
  35. +70 −0 colors/breeze.vim
  36. +83 −0 colors/brookstream.vim
  37. +59 −0 colors/buttercream.vim
  38. +247 −0 colors/calmar256-dark.vim
  39. +247 −0 colors/calmar256-light.vim
  40. +76 −0 colors/camo.vim
  41. +78 −0 colors/candy.vim
  42. +174 −0 colors/candycode.vim
  43. +110 −0 colors/chela_light.vim
  44. +36 −0 colors/chocolateliquor.vim
  45. +52 −0 colors/clarity.vim
  46. +81 −0 colors/cleanphp.vim
  47. +79 −0 colors/colorer.vim
  48. +83 −0 colors/dante.vim
  49. +91 −0 colors/darkZ.vim
  50. +105 −0 colors/darkblue2.vim
  51. +102 −0 colors/darkbone.vim
  52. +117 −0 colors/darkslategray.vim
  53. +130 −0 colors/darkspectrum.vim
  54. +78 −0 colors/dawn.vim
  55. +141 −0 colors/denim.vim
  56. +338 −0 colors/desert256.vim
  57. +98 −0 colors/desertEx.vim
  58. +71 −0 colors/dusk.vim
  59. +66 −0 colors/dw_blue.vim
  60. +66 −0 colors/dw_cyan.vim
  61. +66 −0 colors/dw_green.vim
  62. +66 −0 colors/dw_orange.vim
  63. +66 −0 colors/dw_purple.vim
  64. +66 −0 colors/dw_red.vim
  65. +66 −0 colors/dw_yellow.vim
  66. +159 −0 colors/earendel.vim
  67. +92 −0 colors/eclipse.vim
  68. +105 −0 colors/ekvoli.vim
  69. +71 −0 colors/fine_blue.vim
  70. +71 −0 colors/fine_blue2.vim
  71. +67 −0 colors/fnaqevan.vim
  72. +170 −0 colors/fog.vim
  73. +79 −0 colors/freya.vim
  74. +69 −0 colors/fruit.vim
  75. +147 −0 colors/fruity.vim
  76. +70 −0 colors/golden.vim
  77. +103 −0 colors/guardian.vim
  78. +138 −0 colors/habilight.vim
  79. +385 −0 colors/herald.vim
  80. +66 −0 colors/impact.vim
  81. +216 −0 colors/inkpot.vim
  82. +212 −0 colors/ir_black.vim
  83. +133 −0 colors/ironman.vim
  84. +111 −0 colors/jammy.vim
  85. +6 −0 colors/jellybeans+.vim
  86. +410 −0 colors/jellybeans.vim
  87. +236 −0 colors/kellys.vim
  88. +150 −0 colors/leo.vim
  89. +215 −0 colors/lettuce.vim
  90. +346 −0 colors/lucius.vim
  91. +47 −0 colors/manxome.vim
  92. +174 −0 colors/marklar.vim
  93. +594 −0 colors/maroloccio.vim
  94. +397 −0 colors/martin_krischik.vim
  95. +80 −0 colors/matrix.vim
  96. +592 −0 colors/mirodark.vim
  97. +211 −0 colors/molokai.vim
  98. +247 −0 colors/moria.vim
  99. +109 −0 colors/moss.vim
  100. +66 −0 colors/motus.vim
  101. +57 −0 colors/mustang.vim
  102. +119 −0 colors/navajo-night.vim
  103. +65 −0 colors/navajo.vim
  104. +70 −0 colors/neon.vim
  105. +141 −0 colors/neverness.vim
  106. +70 −0 colors/night.vim
  107. +111 −0 colors/nightshimmer.vim
  108. +134 −0 colors/no_quarter.vim
  109. +149 −0 colors/northland.vim
  110. +107 −0 colors/nuvola.vim
  111. +115 −0 colors/oceanblack.vim
  112. +140 −0 colors/oceandeep.vim
  113. +105 −0 colors/oceanlight.vim
  114. +119 −0 colors/olive.vim
  115. +31 −0 colors/papayawhip.vim
  116. +597 −0 colors/peaksea.vim
  117. +65 −0 colors/print_bw.vim
  118. +92 −0 colors/pyte.vim
  119. +8 −0 colors/railscasts+.vim
  120. +124 −0 colors/railscasts.vim
  121. +124 −0 colors/railscasts2.vim
  122. +159 −0 colors/rdark.vim
  123. +112 −0 colors/relaxedgreen.vim
  124. +103 −0 colors/robinhood.vim
  125. +98 −0 colors/rootwater.vim
  126. +47 −0 colors/satori.vim
  127. +69 −0 colors/sea.vim
  128. +53 −0 colors/settlemyer.vim
  129. +150 −0 colors/sienna.vim
  130. +116 −0 colors/silent.vim
  131. +65 −0 colors/simpleandfriendly.vim
  132. +45 −0 colors/softblue.vim
  133. +67 −0 colors/soso.vim
  134. +71 −0 colors/spring.vim
  135. +322 −0 colors/summerfruit256.vim
  136. +81 −0 colors/synic.vim
  137. +698 −0 colors/tabula.vim
  138. +78 −0 colors/tango.vim
Sorry, we could not display the entire diff because too many files (1,097) changed.
View
BIN .DS_Store
Binary file not shown.
View
18 .gitignore
@@ -1,16 +1,2 @@
-.netrwhist
-tmp
-nerdtree_plugin
-
-after
-autoload
-doc
-plugin
-ruby
-snippets
-syntax
-ftdetect
-ftplugin
-colors
-indent
-.VimballRecord
+view/
+view/*
View
6 .netrwhist
@@ -0,0 +1,6 @@
+let g:netrw_dirhistmax =10
+let g:netrw_dirhist_cnt =4
+let g:netrw_dirhist_1='/Users/matthiasendler/Dropbox'
+let g:netrw_dirhist_2='/Users/matthiasendler/Design/Matthias Endler/.git'
+let g:netrw_dirhist_3='/Users/matthiasendler/Dropbox/creamy/creamy'
+let g:netrw_dirhist_4='/Users/matthiasendler/.vim'
View
40 after/plugin/snipMate.vim
@@ -0,0 +1,40 @@
+" These are the mappings for snipMate.vim. Putting it here ensures that it
+" will be mapped after other plugins such as supertab.vim.
+if !exists('loaded_snips') || exists('s:did_snips_mappings')
+ finish
+endif
+let s:did_snips_mappings = 1
+
+" This is put here in the 'after' directory in order for snipMate to override
+" other plugin mappings (e.g., supertab).
+"
+" You can safely adjust these mappings to your preferences (as explained in
+" :help snipMate-remap).
+ino <silent> <tab> <c-r>=TriggerSnippet()<cr>
+snor <silent> <tab> <esc>i<right><c-r>=TriggerSnippet()<cr>
+ino <silent> <s-tab> <c-r>=BackwardsSnippet()<cr>
+snor <silent> <s-tab> <esc>i<right><c-r>=BackwardsSnippet()<cr>
+ino <silent> <c-r><tab> <c-r>=ShowAvailableSnips()<cr>
+
+" The default mappings for these are annoying & sometimes break snipMate.
+" You can change them back if you want, I've put them here for convenience.
+snor <bs> b<bs>
+snor <right> <esc>a
+snor <left> <esc>bi
+snor ' b<bs>'
+snor ` b<bs>`
+snor % b<bs>%
+snor U b<bs>U
+snor ^ b<bs>^
+snor \ b<bs>\
+snor <c-x> b<bs><c-x>
+
+" By default load snippets in snippets_dir
+if empty(snippets_dir)
+ finish
+endif
+
+call GetSnippets(snippets_dir, '_') " Get global snippets
+
+au FileType * if &ft != 'help' | call GetSnippets(snippets_dir, &ft) | endif
+" vim:noet:sw=4:ts=4:ft=vim
View
1,029 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 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
380 autoload/ZoomWin.vim
@@ -0,0 +1,380 @@
+" ZoomWin: Brief-like ability to zoom into/out-of a window
+" Author: Charles Campbell
+" original version by Ron Aaron
+" Date: Jan 26, 2009
+" Version: 23
+" History: see :help zoomwin-history {{{1
+" GetLatestVimScripts: 508 1 :AutoInstall: ZoomWin.vim
+
+" ---------------------------------------------------------------------
+" Load Once: {{{1
+if &cp || exists("g:loaded_ZoomWin")
+ finish
+endif
+if v:version < 702
+ echohl WarningMsg
+ echo "***warning*** this version of ZoomWin needs vim 7.2"
+ echohl Normal
+ finish
+endif
+let s:keepcpo = &cpo
+let g:loaded_ZoomWin = "v23"
+set cpo&vim
+"DechoTabOn
+
+" =====================================================================
+" Functions: {{{1
+
+" ---------------------------------------------------------------------
+" ZoomWin#ZoomWin: toggles between a single-window and a multi-window layout {{{2
+" The original version was by Ron Aaron.
+fun! ZoomWin#ZoomWin()
+" let g:decho_hide= 1 "Decho
+" call Dfunc("ZoomWin#ZoomWin() winbufnr(2)=".winbufnr(2))
+
+ " if the vim doesn't have +mksession, only a partial zoom is available {{{3
+ if !has("mksession")
+ if !exists("s:partialzoom")
+ echomsg "missing the +mksession feature; only a partial zoom is available"
+ let s:partialzoom= 0
+ endif
+ if v:version < 630
+ echoerr "***sorry*** you need an updated vim, preferably with +mksession"
+ elseif s:partialzoom
+ " partial zoom out
+ let s:partialzoom= 0
+ exe s:winrestore
+ else
+ " partial zoom in
+ let s:partialzoom= 1
+ let s:winrestore = winrestcmd()
+ res
+ endif
+" call Dret("ZoomWin#ZoomWin : partialzoom=".s:partialzoom)
+ return
+ endif
+
+ " Close certain windows {{{3
+ call s:ZoomWinPreserve(0)
+
+ " save options. Force window minimum height/width to be >= 1 {{{3
+ let keep_hidden = &hidden
+ let keep_write = &write
+
+ if v:version < 603
+ if &wmh == 0 || &wmw == 0
+ let keep_wmh = &wmh
+ let keep_wmw = &wmw
+ silent! set wmh=1 wmw=1
+ endif
+ endif
+ set hidden write
+
+ if winbufnr(2) == -1
+ " there's only one window - restore to multiple-windows mode {{{3
+" call Decho("there's only one window - restore to multiple windows")
+
+ if exists("s:sessionfile") && filereadable(s:sessionfile)
+ " save position in current one-window-only
+" call Decho("save position in current one-window-only in sponly")
+ let sponly = s:SavePosn(0)
+ let s:origline = line(".")
+ let s:origcol = virtcol(".")
+
+ " source session file to restore window layout
+ let ei_keep= &ei
+ set ei=all
+ exe 'silent! so '.fnameescape(s:sessionfile)
+" Decho("@@<".@@.">")
+ let v:this_session= s:sesskeep
+
+ if exists("s:savedposn1")
+ " restore windows' positioning and buffers
+" call Decho("restore windows, positions, buffers")
+ windo call s:RestorePosn(s:savedposn{winnr()})|unlet s:savedposn{winnr()}
+ call s:GotoWinNum(s:winkeep)
+ unlet s:winkeep
+ endif
+
+ if line(".") != s:origline || virtcol(".") != s:origcol
+ " If the cursor hasn't moved from the original position,
+ " then let the position remain what it was in the original
+ " multi-window layout.
+" call Decho("restore position using sponly")
+ call s:RestorePosn(sponly)
+ endif
+
+ " delete session file and variable holding its name
+" call Decho("delete session file")
+ call delete(s:sessionfile)
+ unlet s:sessionfile
+ let &ei=ei_keep
+ endif
+
+ else " there's more than one window - go to only-one-window mode {{{3
+" call Decho("there's multiple windows - goto one-window-only")
+
+ let s:winkeep = winnr()
+ let s:sesskeep = v:this_session
+
+ " doesn't work with the command line window (normal mode q:)
+ if &bt == "nofile" && expand("%") == (v:version < 702 ? 'command-line' : '[Command Line]')
+ echoerr "***error*** ZoomWin#ZoomWin doesn't work with the ".expand("%")." window"
+" call Dret("ZoomWin#ZoomWin : ".expand('%')." window error")
+ return
+ endif
+" call Decho("1: @@<".@@.">")
+
+ " disable all events (autocmds)
+" call Decho("disable events")
+ let ei_keep= &ei
+ set ei=all
+" call Decho("2: @@<".@@.">")
+
+ " save window positioning commands
+" call Decho("save window positioning commands")
+ windo let s:savedposn{winnr()}= s:SavePosn(1)
+ call s:GotoWinNum(s:winkeep)
+
+ " set up name of session file
+" call Decho("3: @@<".@@.">")
+ let s:sessionfile= tempname()
+" call Decho("4: @@<".@@.">")
+
+ " save session
+" call Decho("save session")
+ let ssop_keep = &ssop
+ let &ssop = 'blank,help,winsize,folds,globals,localoptions,options'
+" call Decho("5: @@<".@@.">")
+ exe 'mksession! '.fnameescape(s:sessionfile)
+" call Decho("6: @@<".@@.">")
+ let keepyy= @@
+ let keepy0= @0
+ let keepy1= @1
+ let keepy2= @2
+ let keepy3= @3
+ let keepy4= @4
+ let keepy5= @5
+ let keepy6= @6
+ let keepy7= @7
+ let keepy8= @8
+ let keepy9= @9
+ set lz ei=all bh=
+ if v:version >= 700
+ try
+ exe "keepalt keepmarks new! ".fnameescape(s:sessionfile)
+ catch /^Vim\%((\a\+)\)\=:E/
+ echoerr "Too many windows"
+ silent! call delete(s:sessionfile)
+ unlet s:sessionfile
+" call Dret("ZoomWin#ZoomWin : too many windows")
+ return
+ endtry
+ silent! keepjumps keepmarks v/wincmd\|split\|resize/d
+ keepalt w!
+ keepalt bw!
+ else
+ exe "new! ".fnameescape(s:sessionfile)
+ v/wincmd\|split\|resize/d
+ w!
+ bw!
+ endif
+ let @@= keepyy
+ let @0= keepy0
+ let @1= keepy1
+ let @2= keepy2
+ let @3= keepy3
+ let @4= keepy4
+ let @5= keepy5
+ let @6= keepy6
+ let @7= keepy7
+ let @8= keepy8
+ let @9= keepy9
+ call histdel('search', -1)
+ let @/ = histget('search', -1)
+" call Decho("7: @@<".@@.">")
+
+ " restore user's session options and restore event handling
+" call Decho("restore user session options and event handling")
+ set nolz
+ let &ssop = ssop_keep
+ silent! only!
+" call Decho("8: @@<".@@.">")
+ let &ei = ei_keep
+ echomsg expand("%")
+" call Decho("9: @@<".@@.">")
+ endif
+
+ " restore user option settings {{{3
+" call Decho("restore user option settings")
+ let &hidden= keep_hidden
+ let &write = keep_write
+ if v:version < 603
+ if exists("keep_wmw")
+ let &wmh= keep_wmh
+ let &wmw= keep_wmw
+ endif
+ endif
+
+ " Re-open certain windows {{{3
+ call s:ZoomWinPreserve(1)
+
+" call Dret("ZoomWin#ZoomWin")
+endfun
+
+" ---------------------------------------------------------------------
+" SavePosn: this function sets up a savedposn variable that {{{2
+" has the commands necessary to restore the view
+" of the current window.
+fun! s:SavePosn(savewinhoriz)
+" call Dfunc("SavePosn(savewinhoriz=".a:savewinhoriz.") file<".expand("%").">")
+ let swline = line(".")
+ if swline == 1 && getline(1) == ""
+ " empty buffer
+ let savedposn= "silent b ".winbufnr(0)
+" call Dret("SavePosn savedposn<".savedposn.">")
+ return savedposn
+ endif
+ let swcol = col(".")
+ let swwline = winline()-1
+ let swwcol = virtcol(".") - wincol()
+ let savedposn = "silent b ".winbufnr(0)."|".swline."|silent norm! z\<cr>"
+ if swwline > 0
+ let savedposn= savedposn.":silent norm! ".swwline."\<c-y>\<cr>:silent norm! zs\<cr>"
+ endif
+ let savedposn= savedposn.":silent call cursor(".swline.",".swcol.")\<cr>"
+
+ if a:savewinhoriz
+ if swwcol > 0
+ let savedposn= savedposn.":silent norm! ".swwcol."zl\<cr>"
+ endif
+
+ " handle certain special settings for the multi-window savedposn call
+ " bufhidden buftype buflisted
+ let settings= ""
+ if &bh != ""
+ let settings="bh=".&bh
+ setlocal bh=hide
+ endif
+ if !&bl
+ let settings= settings." nobl"
+ setlocal bl
+ endif
+ if &bt != ""
+ let settings= settings." bt=".&bt
+ setlocal bt=
+ endif
+ if settings != ""
+ let savedposn= savedposn.":setlocal ".settings."\<cr>"
+ endif
+
+ endif
+" call Dret("SavePosn savedposn<".savedposn.">")
+ return savedposn
+endfun
+
+" ---------------------------------------------------------------------
+" s:RestorePosn: this function restores noname and scratch windows {{{2
+fun! s:RestorePosn(savedposn)
+" call Dfunc("RestorePosn(savedposn<".a:savedposn.">) file<".expand("%").">")
+ if &scb
+ setlocal noscb
+ exe a:savedposn
+ setlocal scb
+ else
+ exe a:savedposn
+ endif
+" call Dret("RestorePosn")
+endfun
+
+" ---------------------------------------------------------------------
+" CleanupSessionFile: if you exit Vim before cleaning up the {{{2
+" supposed-to-be temporary session file
+fun! ZoomWin#CleanupSessionFile()
+" call Dfunc("ZoomWin#CleanupSessionFile()")
+ if exists("s:sessionfile") && filereadable(s:sessionfile)
+" call Decho("sessionfile exists and is readable; deleting it")
+ silent! call delete(s:sessionfile)
+ unlet s:sessionfile
+ endif
+" call Dret("ZoomWin#CleanupSessionFile")
+endfun
+
+" ---------------------------------------------------------------------
+" GotoWinNum: this function puts cursor into specified window {{{2
+fun! s:GotoWinNum(winnum)
+" call Dfunc("GotoWinNum(winnum=".a:winnum.") winnr=".winnr())
+ if a:winnum != winnr()
+ exe a:winnum."wincmd w"
+ endif
+" call Dret("GotoWinNum")
+endfun
+
+
+" ---------------------------------------------------------------------
+" ZoomWinPreserve: This function, largely written by David Fishburn, {{{2
+" allows ZoomWin to "preserve" certain windows:
+"
+" TagList, by Yegappan Lakshmanan
+" http://vim.sourceforge.net/scripts/script.php?script_id=273
+"
+" WinManager, by Srinath Avadhanula
+" http://vim.sourceforge.net/scripts/script.php?script_id=95
+"
+" It does so by closing the associated window upon entry to ZoomWin
+" and re-opening it upon exit by using commands provided by the
+" utilities themselves.
+fun! s:ZoomWinPreserve(open)
+" call Dfunc("ZoomWinPreserve(open=".a:open.")")
+
+ if a:open == 0
+
+ " Close Taglist
+ if exists('g:zoomwin_preserve_taglist') && exists('g:loaded_taglist')
+ " If taglist window is open then close it.
+ let s:taglist_winnum = bufwinnr(g:TagList_title)
+ if s:taglist_winnum != -1
+ " Close the window
+ exec "silent! Tlist"
+ endif
+ endif
+
+ " Close Winmanager
+ if exists('g:zoomwin_preserve_winmanager') && exists('g:loaded_winmanager')
+ " If the winmanager window is open then close it.
+ let s:is_winmgr_vis = IsWinManagerVisible()
+ if s:is_winmgr_vis == 1
+ exec "WMClose"
+ endif
+ endif
+
+ else
+
+ " Re-open Taglist
+ if exists('g:zoomwin_preserve_taglist') && exists('g:loaded_taglist')
+ " If taglist window was open, open it again
+ if s:taglist_winnum != -1
+ exec "silent! Tlist"
+ endif
+ endif
+
+ " Re-Open Winmanager
+ if exists('g:zoomwin_preserve_winmanager') && exists('g:loaded_winmanager')
+ " If the winmanager window is open then close it.
+ if s:is_winmgr_vis == 1
+ exec "WManager"
+ endif
+ endif
+ endif
+
+" call Dret("ZoomWinPreserve")
+endfun
+
+" =====================================================================
+" Restore: {{{1
+let &cpo= s:keepcpo
+unlet s:keepcpo
+
+" ---------------------------------------------------------------------
+" Modelines: {{{1
+" vim: ts=4 fdm=marker
View
1,590 autoload/conque_term.vim
@@ -0,0 +1,1590 @@
+" FILE: plugin/conque_term.vim {{{
+"
+" AUTHOR: Nico Raffo <nicoraffo@gmail.com>
+" MODIFIED: 2010-05-27
+" VERSION: 1.1, for Vim 7.0
+" LICENSE:
+" Conque - pty interaction in Vim
+" Copyright (C) 2009-2010 Nico Raffo
+"
+" MIT License
+"
+" Permission is hereby granted, free of charge, to any person obtaining a copy
+" of this software and associated documentation files (the "Software"), to deal
+" in the Software without restriction, including without limitation the rights
+" to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+" copies of the Software, and to permit persons to whom the Software is
+" furnished to do so, subject to the following conditions:
+"
+" The above copyright notice and this permission notice shall be included in
+" all copies or substantial portions of the Software.
+"
+" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+" OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+" THE SOFTWARE.
+" }}}
+
+
+" **********************************************************************************************************
+" **** VIM FUNCTIONS ***************************************************************************************
+" **********************************************************************************************************
+
+" launch conque
+function! conque_term#open(...) "{{{
+ let command = get(a:000, 0, '')
+ let hooks = get(a:000, 1, [])
+
+ " bare minimum validation
+ if has('python') != 1
+ echohl WarningMsg | echomsg "Conque requires the Python interface to be installed" | echohl None
+ return 0
+ endif
+ if empty(command)
+ echohl WarningMsg | echomsg "No command found" | echohl None
+ return 0
+ else
+ let l:cargs = split(command, '\s')
+ if !executable(l:cargs[0])
+ echohl WarningMsg | echomsg "Not an executable: " . l:cargs[0] | echohl None
+ return 0
+ endif
+ endif
+
+ " set buffer window options
+ let g:ConqueTerm_BufName = substitute(command, ' ', '\\ ', 'g') . "\\ -\\ " . g:ConqueTerm_Idx
+ call conque_term#set_buffer_settings(command, hooks)
+ let b:ConqueTerm_Var = 'ConqueTerm_' . g:ConqueTerm_Idx
+ let g:ConqueTerm_Var = 'ConqueTerm_' . g:ConqueTerm_Idx
+ let g:ConqueTerm_Idx += 1
+
+ " open command
+ try
+ let l:config = '{"color":' . string(g:ConqueTerm_Color) . ',"TERM":"' . g:ConqueTerm_TERM . '"}'
+ execute 'python ' . b:ConqueTerm_Var . ' = Conque()'
+ execute "python " . b:ConqueTerm_Var . ".open('" . conque_term#python_escape(command) . "', " . l:config . ")"
+ catch
+ echohl WarningMsg | echomsg "Unable to open command: " . command | echohl None
+ return 0
+ endtry
+
+ " set buffer mappings and auto commands
+ call conque_term#set_mappings('start')
+
+ startinsert!
+ return 1
+endfunction "}}}
+
+" set buffer options
+function! conque_term#set_buffer_settings(command, pre_hooks) "{{{
+
+ " optional hooks to execute, e.g. 'split'
+ for h in a:pre_hooks
+ sil exe h
+ endfor
+ sil exe "edit " . g:ConqueTerm_BufName
+
+ " buffer settings
+ setlocal nocompatible " conque won't work in compatible mode
+ setlocal nopaste " conque won't work in paste mode
+ setlocal buftype=nofile " this buffer is not a file, you can't save it
+ setlocal nonumber " hide line numbers
+ setlocal foldcolumn=0 " reasonable left margin
+ setlocal nowrap " default to no wrap (esp with MySQL)
+ setlocal noswapfile " don't bother creating a .swp file
+ setlocal updatetime=50 " trigger cursorhold event after 50ms / XXX - global
+ setlocal scrolloff=0 " don't use buffer lines. it makes the 'clear' command not work as expected
+ setlocal sidescrolloff=0 " don't use buffer lines. it makes the 'clear' command not work as expected
+ setlocal sidescroll=1 " don't use buffer lines. it makes the 'clear' command not work as expected
+ setlocal foldmethod=manual " don't fold on {{{}}} and stuff
+ setlocal bufhidden=hide " when buffer is no longer displayed, don't wipe it out
+ setfiletype conque_term " useful
+ sil exe "setlocal syntax=" . g:ConqueTerm_Syntax
+
+endfunction " }}}
+
+" set key mappings and auto commands
+function! conque_term#set_mappings(action) "{{{
+
+ " set action
+ if a:action == 'toggle'
+ if exists('b:conque_on') && b:conque_on == 1
+ let l:action = 'stop'
+ echohl WarningMsg | echomsg "Terminal is paused" | echohl None
+ else
+ let l:action = 'start'
+ echohl WarningMsg | echomsg "Terminal is resumed" | echohl None
+ endif
+ else
+ let l:action = a:action
+ endif
+
+ " if mappings are being removed, add 'un'
+ let map_modifier = 'nore'
+ if l:action == 'stop'
+ let map_modifier = 'un'
+ endif
+
+ " remove all auto commands
+ if l:action == 'stop'
+ execute 'autocmd! ' . b:ConqueTerm_Var
+
+ else
+ execute 'augroup ' . b:ConqueTerm_Var
+
+ " handle unexpected closing of shell, passes HUP to parent and all child processes
+ execute 'autocmd ' . b:ConqueTerm_Var . ' BufUnload <buffer> python ' . b:ConqueTerm_Var . '.proc.signal(1)'
+
+ " check for resized/scrolled buffer when entering buffer
+ execute 'autocmd ' . b:ConqueTerm_Var . ' BufEnter <buffer> python ' . b:ConqueTerm_Var . '.update_window_size()'
+ execute 'autocmd ' . b:ConqueTerm_Var . ' VimResized python ' . b:ConqueTerm_Var . '.update_window_size()'
+
+ " set/reset updatetime on entering/exiting buffer
+ autocmd BufEnter <buffer> set updatetime=50
+ autocmd BufLeave <buffer> set updatetime=2000
+
+ " check for resized/scrolled buffer when entering insert mode
+ " XXX - messed up since we enter insert mode at each updatetime
+ "execute 'autocmd InsertEnter <buffer> python ' . b:ConqueTerm_Var . '.screen.align()'
+
+ " read more output when this isn't the current buffer
+ if g:ConqueTerm_ReadUnfocused == 1
+ execute 'autocmd ' . b:ConqueTerm_Var . ' CursorHold * call conque_term#read_all()'
+ endif
+
+ " poll for more output
+ sil execute 'autocmd ' . b:ConqueTerm_Var . ' CursorHoldI <buffer> python ' . b:ConqueTerm_Var . '.auto_read()'
+ endif
+
+ " use F22 key to get more input
+ if l:action == 'start'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <expr> <F22> "\<left>\<right>"'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <expr> <F23> "\<right>\<left>"'
+ else
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <expr> <F22>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <expr> <F23>'
+ endif
+
+ " map ASCII 1-31
+ for c in range(1, 31)
+ " <Esc>
+ if c == 27
+ continue
+ endif
+ if l:action == 'start'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <C-' . nr2char(64 + c) . '> <C-o>:python ' . b:ConqueTerm_Var . '.write(chr(' . c . '))<CR>'
+ else
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <C-' . nr2char(64 + c) . '>'
+ endif
+ endfor
+ if l:action == 'start'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> <C-c> <C-o>:python ' . b:ConqueTerm_Var . '.write(chr(3))<CR>'
+ else
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> <C-c>'
+ endif
+
+ " leave insert mode
+ if !exists('g:ConqueTerm_EscKey') || g:ConqueTerm_EscKey == '<Esc>'
+ " use <Esc><Esc> to send <Esc> to terminal
+ if l:action == 'start'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Esc><Esc> <C-o>:python ' . b:ConqueTerm_Var . '.write(chr(27))<CR>'
+ else
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Esc><Esc>'
+ endif
+ else
+ " use <Esc> to send <Esc> to terminal
+ if l:action == 'start'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> ' . g:ConqueTerm_EscKey . ' <Esc>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Esc> <C-o>:python ' . b:ConqueTerm_Var . '.write(chr(27))<CR>'
+ else
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> ' . g:ConqueTerm_EscKey
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Esc>'
+ endif
+ endif
+
+ " Map <C-w> in insert mode
+ if exists('g:ConqueTerm_CWInsert') && g:ConqueTerm_CWInsert == 1
+ inoremap <silent> <buffer> <C-w>j <Esc><C-w>j
+ inoremap <silent> <buffer> <C-w>k <Esc><C-w>k
+ inoremap <silent> <buffer> <C-w>h <Esc><C-w>h
+ inoremap <silent> <buffer> <C-w>l <Esc><C-w>l
+ inoremap <silent> <buffer> <C-w>w <Esc><C-w>w
+ endif
+
+ " map ASCII 33-127
+ for i in range(33, 127)
+ " <Bar>
+ if i == 124
+ if l:action == 'start'
+ sil exe "i" . map_modifier . "map <silent> <buffer> <Bar> <C-o>:python " . b:ConqueTerm_Var . ".write(chr(124))<CR>"
+ else
+ sil exe "i" . map_modifier . "map <silent> <buffer> <Bar>"
+ endif
+ continue
+ endif
+ if l:action == 'start'
+ sil exe "i" . map_modifier . "map <silent> <buffer> " . nr2char(i) . " <C-o>:python " . b:ConqueTerm_Var . ".write(chr(" . i . "))<CR>"
+ else
+ sil exe "i" . map_modifier . "map <silent> <buffer> " . nr2char(i)
+ endif
+ endfor
+
+ " map ASCII 128-255
+ for i in range(128, 255)
+ if l:action == 'start'
+ sil exe "i" . map_modifier . "map <silent> <buffer> " . nr2char(i) . " <C-o>:python " . b:ConqueTerm_Var . ".write('" . nr2char(i) . "')<CR>"
+ else
+ sil exe "i" . map_modifier . "map <silent> <buffer> " . nr2char(i)
+ endif
+ endfor
+
+ " Special cases
+ if l:action == 'start'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <BS> <C-o>:python ' . b:ConqueTerm_Var . '.write(u"\u0008")<CR>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Space> <C-o>:python ' . b:ConqueTerm_Var . '.write(" ")<CR>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Up> <C-o>:python ' . b:ConqueTerm_Var . '.write(u"\u001b[A")<CR>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Down> <C-o>:python ' . b:ConqueTerm_Var . '.write(u"\u001b[B")<CR>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Right> <C-o>:python ' . b:ConqueTerm_Var . '.write(u"\u001b[C")<CR>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Left> <C-o>:python ' . b:ConqueTerm_Var . '.write(u"\u001b[D")<CR>'
+ else
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <BS>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Space>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Up>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Down>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Right>'
+ sil exe 'i' . map_modifier . 'map <silent> <buffer> <Left>'
+ endif
+
+ " send selected text into conque
+ if l:action == 'start'
+ sil exe 'v' . map_modifier . 'map <silent> <F9> :<C-u>call conque_term#send_selected(visualmode())<CR>'
+ else
+ sil exe 'v' . map_modifier . 'map <silent> <F9>'
+ endif
+
+ " remap paste keys
+ if l:action == 'start'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> p :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))<CR>a'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> P :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))<CR>a'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> ]p :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))<CR>a'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> [p :python ' . b:ConqueTerm_Var . '.write(vim.eval("@@"))<CR>a'
+ else
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> p'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> P'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> ]p'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> [p'
+ endif
+ if has('gui_running')
+ if l:action == 'start'
+ sil exe 'i' . map_modifier . 'map <buffer> <S-Insert> <Esc>:<C-u>python ' . b:ConqueTerm_Var . ".write(vim.eval('@+'))<CR>a"
+ else
+ sil exe 'i' . map_modifier . 'map <buffer> <S-Insert>'
+ endif
+ endif
+
+ " disable other normal mode keys which insert text
+ if l:action == 'start'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> r :echo "Replace mode disabled in shell."<CR>'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> R :echo "Replace mode disabled in shell."<CR>'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> c :echo "Change mode disabled in shell."<CR>'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> C :echo "Change mode disabled in shell."<CR>'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> s :echo "Change mode disabled in shell."<CR>'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> S :echo "Change mode disabled in shell."<CR>'
+ else
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> r'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> R'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> c'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> C'
+ sil exe 'n' . map_modifier . 'map <silent> <buffer> s'