├── plugin ├── AlignPlugin.vim ├── cecutil.vim └── AlignMapsPlugin.vim ├── doc ├── tags └── Align.txt └── autoload ├── AlignMaps.vim └── Align.vim /plugin/AlignPlugin.vim: -------------------------------------------------------------------------------- 1 | " AlignPlugin: tool to align multiple fields based on one or more separators 2 | " Author: Charles E. Campbell, Jr. 3 | " Date: Nov 02, 2008 4 | " GetLatestVimScripts: 294 1 :AutoInstall: Align.vim 5 | " GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim 6 | " Copyright: Copyright (C) 1999-2007 Charles E. Campbell, Jr. {{{1 7 | " Permission is hereby granted to use and distribute this code, 8 | " with or without modifications, provided that this copyright 9 | " notice is copied with it. Like anything else that's free, 10 | " Align.vim is provided *as is* and comes with no warranty 11 | " of any kind, either expressed or implied. By using this 12 | " plugin, you agree that in no event will the copyright 13 | " holder be liable for any damages resulting from the use 14 | " of this software. 15 | " 16 | " Romans 1:16,17a : For I am not ashamed of the gospel of Christ, for it is {{{1 17 | " the power of God for salvation for everyone who believes; for the Jew first, 18 | " and also for the Greek. For in it is revealed God's righteousness from 19 | " faith to faith. 20 | " --------------------------------------------------------------------- 21 | " Load Once: {{{1 22 | if &cp || exists("g:loaded_AlignPlugin") 23 | finish 24 | endif 25 | let g:loaded_AlignPlugin = "v35" 26 | let s:keepcpo = &cpo 27 | set cpo&vim 28 | 29 | " --------------------------------------------------------------------- 30 | " Public Interface: {{{1 31 | com! -bang -range -nargs=* Align ,call Align#Align(0,) 32 | com! -range -nargs=0 AlignReplaceQuotedSpaces ,call Align#AlignReplaceQuotedSpaces() 33 | com! -nargs=* AlignCtrl call Align#AlignCtrl() 34 | com! -nargs=0 AlignPush call Align#AlignPush() 35 | com! -nargs=0 AlignPop call Align#AlignPop() 36 | 37 | " --------------------------------------------------------------------- 38 | " Restore: {{{1 39 | let &cpo= s:keepcpo 40 | unlet s:keepcpo 41 | " vim: ts=4 fdm=marker 42 | -------------------------------------------------------------------------------- /doc/tags: -------------------------------------------------------------------------------- 1 | Align-copyright Align.txt /*Align-copyright* 2 | align Align.txt /*align* 3 | align-align Align.txt /*align-align* 4 | align-codepoint Align.txt /*align-codepoint* 5 | align-command Align.txt /*align-command* 6 | align-commands Align.txt /*align-commands* 7 | align-concept Align.txt /*align-concept* 8 | align-concepts Align.txt /*align-concepts* 9 | align-contents Align.txt /*align-contents* 10 | align-control Align.txt /*align-control* 11 | align-history Align.txt /*align-history* 12 | align-manual Align.txt /*align-manual* 13 | align-maps Align.txt /*align-maps* 14 | align-multibyte Align.txt /*align-multibyte* 15 | align-option Align.txt /*align-option* 16 | align-options Align.txt /*align-options* 17 | align-strlen Align.txt /*align-strlen* 18 | align-usage Align.txt /*align-usage* 19 | align-userguide Align.txt /*align-userguide* 20 | align-utf Align.txt /*align-utf* 21 | align-utf8 Align.txt /*align-utf8* 22 | align.txt Align.txt /*align.txt* 23 | alignctrl Align.txt /*alignctrl* 24 | alignctrl- Align.txt /*alignctrl-* 25 | alignctrl-+ Align.txt /*alignctrl-+* 26 | alignctrl-- Align.txt /*alignctrl--* 27 | alignctrl-: Align.txt /*alignctrl-:* 28 | alignctrl-< Align.txt /*alignctrl-<* 29 | alignctrl-= Align.txt /*alignctrl-=* 30 | alignctrl-> Align.txt /*alignctrl->* 31 | alignctrl-C Align.txt /*alignctrl-C* 32 | alignctrl-I Align.txt /*alignctrl-I* 33 | alignctrl-P Align.txt /*alignctrl-P* 34 | alignctrl-W Align.txt /*alignctrl-W* 35 | alignctrl-c Align.txt /*alignctrl-c* 36 | alignctrl-g Align.txt /*alignctrl-g* 37 | alignctrl-l Align.txt /*alignctrl-l* 38 | alignctrl-m Align.txt /*alignctrl-m* 39 | alignctrl-no-option Align.txt /*alignctrl-no-option* 40 | alignctrl-p Align.txt /*alignctrl-p* 41 | alignctrl-r Align.txt /*alignctrl-r* 42 | alignctrl-separators Align.txt /*alignctrl-separators* 43 | alignctrl-settings Align.txt /*alignctrl-settings* 44 | alignctrl-v Align.txt /*alignctrl-v* 45 | alignctrl-w Align.txt /*alignctrl-w* 46 | alignman Align.txt /*alignman* 47 | alignmanual Align.txt /*alignmanual* 48 | alignmap-Htd Align.txt /*alignmap-Htd* 49 | alignmap-T= Align.txt /*alignmap-T=* 50 | alignmap-Tsp Align.txt /*alignmap-Tsp* 51 | alignmap-a( Align.txt /*alignmap-a(* 52 | alignmap-a, Align.txt /*alignmap-a,* 53 | alignmap-a< Align.txt /*alignmap-a<* 54 | alignmap-a= Align.txt /*alignmap-a=* 55 | alignmap-a? Align.txt /*alignmap-a?* 56 | alignmap-abox Align.txt /*alignmap-abox* 57 | alignmap-acom Align.txt /*alignmap-acom* 58 | alignmap-adcom Align.txt /*alignmap-adcom* 59 | alignmap-adec Align.txt /*alignmap-adec* 60 | alignmap-adef Align.txt /*alignmap-adef* 61 | alignmap-afnc Align.txt /*alignmap-afnc* 62 | alignmap-anum Align.txt /*alignmap-anum* 63 | alignmap-aocom Align.txt /*alignmap-aocom* 64 | alignmap-ascom Align.txt /*alignmap-ascom* 65 | alignmap-history Align.txt /*alignmap-history* 66 | alignmap-m= Align.txt /*alignmap-m=* 67 | alignmap-t# Align.txt /*alignmap-t#* 68 | alignmap-t, Align.txt /*alignmap-t,* 69 | alignmap-t: Align.txt /*alignmap-t:* 70 | alignmap-t; Align.txt /*alignmap-t;* 71 | alignmap-t< Align.txt /*alignmap-t<* 72 | alignmap-t= Align.txt /*alignmap-t=* 73 | alignmap-t? Align.txt /*alignmap-t?* 74 | alignmap-tab Align.txt /*alignmap-tab* 75 | alignmap-tml Align.txt /*alignmap-tml* 76 | alignmap-ts, Align.txt /*alignmap-ts,* 77 | alignmap-ts: Align.txt /*alignmap-ts:* 78 | alignmap-ts< Align.txt /*alignmap-ts<* 79 | alignmap-ts= Align.txt /*alignmap-ts=* 80 | alignmap-tsp Align.txt /*alignmap-tsp* 81 | alignmap-tsq Align.txt /*alignmap-tsq* 82 | alignmap-tt Align.txt /*alignmap-tt* 83 | alignmap-t~ Align.txt /*alignmap-t~* 84 | alignmaps Align.txt /*alignmaps* 85 | alignusage Align.txt /*alignusage* 86 | -------------------------------------------------------------------------------- /autoload/AlignMaps.vim: -------------------------------------------------------------------------------- 1 | " AlignMaps.vim : support functions for AlignMaps 2 | " Author: Charles E. Campbell, Jr. 3 | " Date: Mar 03, 2009 4 | " Version: 41 5 | " --------------------------------------------------------------------- 6 | " Load Once: {{{1 7 | if &cp || exists("g:loaded_AlignMaps") 8 | finish 9 | endif 10 | let g:loaded_AlignMaps= "v41" 11 | let s:keepcpo = &cpo 12 | set cpo&vim 13 | 14 | " ===================================================================== 15 | " Functions: {{{1 16 | 17 | " --------------------------------------------------------------------- 18 | " AlignMaps#WrapperStart: {{{2 19 | fun! AlignMaps#WrapperStart(vis) range 20 | " call Dfunc("AlignMaps#WrapperStart(vis=".a:vis.")") 21 | 22 | if a:vis 23 | norm! ' 24 | endif 25 | 26 | if line("'y") == 0 || line("'z") == 0 || !exists("s:alignmaps_wrapcnt") || s:alignmaps_wrapcnt <= 0 27 | " call Decho("wrapper initialization") 28 | let s:alignmaps_wrapcnt = 1 29 | let s:alignmaps_keepgd = &gdefault 30 | let s:alignmaps_keepsearch = @/ 31 | let s:alignmaps_keepch = &ch 32 | let s:alignmaps_keepmy = SaveMark("'y") 33 | let s:alignmaps_keepmz = SaveMark("'z") 34 | let s:alignmaps_posn = SaveWinPosn(0) 35 | " set up fencepost blank lines 36 | put ='' 37 | norm! mz'a 38 | put! ='' 39 | ky 40 | let s:alignmaps_zline = line("'z") 41 | exe "'y,'zs/@/\177/ge" 42 | else 43 | " call Decho("embedded wrapper") 44 | let s:alignmaps_wrapcnt = s:alignmaps_wrapcnt + 1 45 | norm! 'yjma'zk 46 | endif 47 | 48 | " change some settings to align-standard values 49 | set nogd 50 | set ch=2 51 | AlignPush 52 | norm! 'zk 53 | " call Dret("AlignMaps#WrapperStart : alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z")) 54 | endfun 55 | 56 | " --------------------------------------------------------------------- 57 | " AlignMaps#WrapperEnd: {{{2 58 | fun! AlignMaps#WrapperEnd() range 59 | " call Dfunc("AlignMaps#WrapperEnd() alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z")) 60 | 61 | " remove trailing white space introduced by whatever in the modification zone 62 | 'y,'zs/ \+$//e 63 | 64 | " restore AlignCtrl settings 65 | AlignPop 66 | 67 | let s:alignmaps_wrapcnt= s:alignmaps_wrapcnt - 1 68 | if s:alignmaps_wrapcnt <= 0 69 | " initial wrapper ending 70 | exe "'y,'zs/\177/@/ge" 71 | 72 | " if the 'z line hasn't moved, then go ahead and restore window position 73 | let zstationary= s:alignmaps_zline == line("'z") 74 | 75 | " remove fencepost blank lines. 76 | " restore 'a 77 | norm! 'yjmakdd'zdd 78 | 79 | " restore original 'y, 'z, and window positioning 80 | call RestoreMark(s:alignmaps_keepmy) 81 | call RestoreMark(s:alignmaps_keepmz) 82 | if zstationary > 0 83 | call RestoreWinPosn(s:alignmaps_posn) 84 | " call Decho("restored window positioning") 85 | endif 86 | 87 | " restoration of options 88 | let &gd= s:alignmaps_keepgd 89 | let &ch= s:alignmaps_keepch 90 | let @/ = s:alignmaps_keepsearch 91 | 92 | " remove script variables 93 | unlet s:alignmaps_keepch 94 | unlet s:alignmaps_keepsearch 95 | unlet s:alignmaps_keepmy 96 | unlet s:alignmaps_keepmz 97 | unlet s:alignmaps_keepgd 98 | unlet s:alignmaps_posn 99 | endif 100 | 101 | " call Dret("AlignMaps#WrapperEnd : alignmaps_wrapcnt=".s:alignmaps_wrapcnt." my=".line("'y")." mz=".line("'z")) 102 | endfun 103 | 104 | " --------------------------------------------------------------------- 105 | " AlignMaps#StdAlign: some semi-standard align calls {{{2 106 | fun! AlignMaps#StdAlign(mode) range 107 | " call Dfunc("AlignMaps#StdAlign(mode=".a:mode.")") 108 | if a:mode == 1 109 | " align on @ 110 | " call Decho("align on @") 111 | AlignCtrl mIp1P1=l @ 112 | 'a,.Align 113 | elseif a:mode == 2 114 | " align on @, retaining all initial white space on each line 115 | " call Decho("align on @, retaining all initial white space on each line") 116 | AlignCtrl mWp1P1=l @ 117 | 'a,.Align 118 | elseif a:mode == 3 119 | " like mode 2, but ignore /* */-style comments 120 | " call Decho("like mode 2, but ignore /* */-style comments") 121 | AlignCtrl v ^\s*/[/*] 122 | AlignCtrl mWp1P1=l @ 123 | 'a,.Align 124 | else 125 | echoerr "(AlignMaps) AlignMaps#StdAlign doesn't support mode#".a:mode 126 | endif 127 | " call Dret("AlignMaps#StdAlign") 128 | endfun 129 | 130 | " --------------------------------------------------------------------- 131 | " AlignMaps#CharJoiner: joins lines which end in the given character (spaces {{{2 132 | " at end are ignored) 133 | fun! AlignMaps#CharJoiner(chr) 134 | " call Dfunc("AlignMaps#CharJoiner(chr=".a:chr.")") 135 | let aline = line("'a") 136 | let rep = line(".") - aline 137 | while rep > 0 138 | norm! 'a 139 | while match(getline(aline),a:chr . "\s*$") != -1 && rep >= 0 140 | " while = at end-of-line, delete it and join with next 141 | norm! 'a$ 142 | j! 143 | let rep = rep - 1 144 | endwhile 145 | " update rep(eat) count 146 | let rep = rep - 1 147 | if rep <= 0 148 | " terminate loop if at end-of-block 149 | break 150 | endif 151 | " prepare for next line 152 | norm! jma 153 | let aline = line("'a") 154 | endwhile 155 | " call Dret("AlignMaps#CharJoiner") 156 | endfun 157 | 158 | " --------------------------------------------------------------------- 159 | " AlignMaps#Equals: supports \t= and \T= {{{2 160 | fun! AlignMaps#Equals() range 161 | " call Dfunc("AlignMaps#Equals()") 162 | 'a,'zs/\s\+\([*/+\-%|&\~^]\==\)/ \1/e 163 | 'a,'zs@ \+\([*/+\-%|&\~^]\)=@\1=@ge 164 | 'a,'zs/==/\="\\"/ge 165 | 'a,'zs/\([!<>:]\)=/\=submatch(1)."\"/ge 166 | norm g'zk 167 | AlignCtrl mIp1P1=l = 168 | AlignCtrl g = 169 | 'a,'z-1Align 170 | 'a,'z-1s@\([*/+\-%|&\~^!=]\)\( \+\)=@\2\1=@ge 171 | 'a,'z-1s/\( \+\);/;\1/ge 172 | if &ft == "c" || &ft == "cpp" 173 | " call Decho("exception for ".&ft) 174 | 'a,'z-1v/^\s*\/[*/]/s/\/[*/]/@&@/e 175 | 'a,'z-1v/^\s*\/[*/]/s/\*\//@&/e 176 | if exists("g:mapleader") 177 | exe "norm 'zk" 178 | call AlignMaps#StdAlign(1) 179 | else 180 | exe "norm 'zk" 181 | call AlignMaps#StdAlign(1) 182 | endif 183 | 'y,'zs/^\(\s*\) @/\1/e 184 | endif 185 | 'a,'z-1s/\%x0f/=/ge 186 | 'y,'zs/ @//eg 187 | " call Dret("AlignMaps#Equals") 188 | endfun 189 | 190 | " --------------------------------------------------------------------- 191 | " AlignMaps#Afnc: useful for splitting one-line function beginnings {{{2 192 | " into one line per argument format 193 | fun! AlignMaps#Afnc() 194 | " call Dfunc("AlignMaps#Afnc()") 195 | 196 | " keep display quiet 197 | let chkeep = &ch 198 | let gdkeep = &gd 199 | let vekeep = &ve 200 | set ch=2 nogd ve= 201 | 202 | " will use marks y,z ; save current values 203 | let mykeep = SaveMark("'y") 204 | let mzkeep = SaveMark("'z") 205 | 206 | " Find beginning of function -- be careful to skip over comments 207 | let cmmntid = synIDtrans(hlID("Comment")) 208 | let stringid = synIDtrans(hlID("String")) 209 | exe "norm! ]]" 210 | while search(")","bW") != 0 211 | " call Decho("line=".line(".")." col=".col(".")) 212 | let parenid= synIDtrans(synID(line("."),col("."),1)) 213 | if parenid != cmmntid && parenid != stringid 214 | break 215 | endif 216 | endwhile 217 | norm! %my 218 | s/(\s*\(\S\)/(\r \1/e 219 | exe "norm! `y%" 220 | s/)\s*\(\/[*/]\)/)\r\1/e 221 | exe "norm! `y%mz" 222 | 'y,'zs/\s\+$//e 223 | 'y,'zs/^\s\+//e 224 | 'y+1,'zs/^/ / 225 | 226 | " insert newline after every comma only one parenthesis deep 227 | sil! exe "norm! `y\h" 228 | let parens = 1 229 | let cmmnt = 0 230 | let cmmntline= -1 231 | while parens >= 1 232 | " call Decho("parens=".parens." @a=".@a) 233 | exe 'norm! ma "ay`a ' 234 | if @a == "(" 235 | let parens= parens + 1 236 | elseif @a == ")" 237 | let parens= parens - 1 238 | 239 | " comment bypass: /* ... */ or //... 240 | elseif cmmnt == 0 && @a == '/' 241 | let cmmnt= 1 242 | elseif cmmnt == 1 243 | if @a == '/' 244 | let cmmnt = 2 " //... 245 | let cmmntline= line(".") 246 | elseif @a == '*' 247 | let cmmnt= 3 " /*... 248 | else 249 | let cmmnt= 0 250 | endif 251 | elseif cmmnt == 2 && line(".") != cmmntline 252 | let cmmnt = 0 253 | let cmmntline= -1 254 | elseif cmmnt == 3 && @a == '*' 255 | let cmmnt= 4 256 | elseif cmmnt == 4 257 | if @a == '/' 258 | let cmmnt= 0 " ...*/ 259 | elseif @a != '*' 260 | let cmmnt= 3 261 | endif 262 | 263 | elseif @a == "," && parens == 1 && cmmnt == 0 264 | exe "norm! i\\" 265 | endif 266 | endwhile 267 | norm! `y%mz% 268 | sil! 'y,'zg/^\s*$/d 269 | 270 | " perform substitutes to mark fields for Align 271 | sil! 'y+1,'zv/^\//s/^\s\+\(\S\)/ \1/e 272 | sil! 'y+1,'zv/^\//s/\(\S\)\s\+/\1 /eg 273 | sil! 'y+1,'zv/^\//s/\* \+/*/ge 274 | sil! 'y+1,'zv/^\//s/\w\zs\s*\*/ */ge 275 | " func 276 | " ws <- declaration -> <-ptr -> <-var-> <-[array][] -> <-glop-> <-end-> 277 | sil! 'y+1,'zv/^\//s/^\s*\(\(\K\k*\s*\)\+\)\s\+\([(*]*\)\s*\(\K\k*\)\s*\(\(\[.\{-}]\)*\)\s*\(.\{-}\)\=\s*\([,)]\)\s*$/ \1@#\3@\4\5@\7\8/e 278 | sil! 'y+1,'z+1g/^\s*\/[*/]/norm! kJ 279 | sil! 'y+1,'z+1s%/[*/]%@&@%ge 280 | sil! 'y+1,'z+1s%*/%@&%ge 281 | AlignCtrl mIp0P0=l @ 282 | sil! 'y+1,'zAlign 283 | sil! 'y,'zs%@\(/[*/]\)@%\t\1 %e 284 | sil! 'y,'zs%@\*/% */%e 285 | sil! 'y,'zs/@\([,)]\)/\1/ 286 | sil! 'y,'zs/@/ / 287 | AlignCtrl mIlrp0P0= # @ 288 | sil! 'y+1,'zAlign 289 | sil! 'y+1,'zs/#/ / 290 | sil! 'y+1,'zs/@// 291 | sil! 'y+1,'zs/\(\s\+\)\([,)]\)/\2\1/e 292 | 293 | " Restore 294 | call RestoreMark(mykeep) 295 | call RestoreMark(mzkeep) 296 | let &ch= chkeep 297 | let &gd= gdkeep 298 | let &ve= vekeep 299 | 300 | " call Dret("AlignMaps#Afnc") 301 | endfun 302 | 303 | " --------------------------------------------------------------------- 304 | " AlignMaps#FixMultiDec: converts a type arg,arg,arg; line to multiple lines {{{2 305 | fun! AlignMaps#FixMultiDec() 306 | " call Dfunc("AlignMaps#FixMultiDec()") 307 | 308 | " save register x 309 | let xkeep = @x 310 | let curline = getline(".") 311 | " call Decho("curline<".curline.">") 312 | 313 | " Get the type. I'm assuming one type per line (ie. int x; double y; on one line will not be handled properly) 314 | let @x=substitute(curline,'^\(\s*[a-zA-Z_ \t][a-zA-Z0-9_ \t]*\)\s\+[(*]*\h.*$','\1','') 315 | " call Decho("@x<".@x.">") 316 | 317 | " transform line 318 | exe 's/,/;\r'.@x.' /ge' 319 | 320 | "restore register x 321 | let @x= xkeep 322 | 323 | " call Dret("AlignMaps#FixMultiDec : my=".line("'y")." mz=".line("'z")) 324 | endfun 325 | 326 | " --------------------------------------------------------------------- 327 | " Restore: {{{1 328 | let &cpo= s:keepcpo 329 | unlet s:keepcpo 330 | " vim: ts=4 fdm=marker 331 | -------------------------------------------------------------------------------- /plugin/cecutil.vim: -------------------------------------------------------------------------------- 1 | " cecutil.vim : save/restore window position 2 | " save/restore mark position 3 | " save/restore selected user maps 4 | " Author: Charles E. Campbell, Jr. 5 | " Version: 18b ASTRO-ONLY 6 | " Date: Aug 27, 2008 7 | " 8 | " Saving Restoring Destroying Marks: {{{1 9 | " call SaveMark(markname) let savemark= SaveMark(markname) 10 | " call RestoreMark(markname) call RestoreMark(savemark) 11 | " call DestroyMark(markname) 12 | " commands: SM RM DM 13 | " 14 | " Saving Restoring Destroying Window Position: {{{1 15 | " call SaveWinPosn() let winposn= SaveWinPosn() 16 | " call RestoreWinPosn() call RestoreWinPosn(winposn) 17 | " \swp : save current window/buffer's position 18 | " \rwp : restore current window/buffer's previous position 19 | " commands: SWP RWP 20 | " 21 | " Saving And Restoring User Maps: {{{1 22 | " call SaveUserMaps(mapmode,maplead,mapchx,suffix) 23 | " call RestoreUserMaps(suffix) 24 | " 25 | " GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim 26 | " 27 | " You believe that God is one. You do well. The demons also {{{1 28 | " believe, and shudder. But do you want to know, vain man, that 29 | " faith apart from works is dead? (James 2:19,20 WEB) 30 | 31 | " --------------------------------------------------------------------- 32 | " Load Once: {{{1 33 | if &cp || exists("g:loaded_cecutil") 34 | finish 35 | endif 36 | let g:loaded_cecutil = "v18b" 37 | let s:keepcpo = &cpo 38 | set cpo&vim 39 | "DechoTabOn 40 | 41 | " ======================= 42 | " Public Interface: {{{1 43 | " ======================= 44 | 45 | " --------------------------------------------------------------------- 46 | " Map Interface: {{{2 47 | if !hasmapto('SaveWinPosn') 48 | map swp SaveWinPosn 49 | endif 50 | if !hasmapto('RestoreWinPosn') 51 | map rwp RestoreWinPosn 52 | endif 53 | nmap SaveWinPosn :call SaveWinPosn() 54 | nmap RestoreWinPosn :call RestoreWinPosn() 55 | 56 | " --------------------------------------------------------------------- 57 | " Command Interface: {{{2 58 | com! -bar -nargs=0 SWP call SaveWinPosn() 59 | com! -bar -nargs=0 RWP call RestoreWinPosn() 60 | com! -bar -nargs=1 SM call SaveMark() 61 | com! -bar -nargs=1 RM call RestoreMark() 62 | com! -bar -nargs=1 DM call DestroyMark() 63 | 64 | if v:version < 630 65 | let s:modifier= "sil " 66 | else 67 | let s:modifier= "sil keepj " 68 | endif 69 | 70 | " =============== 71 | " Functions: {{{1 72 | " =============== 73 | 74 | " --------------------------------------------------------------------- 75 | " SaveWinPosn: {{{2 76 | " let winposn= SaveWinPosn() will save window position in winposn variable 77 | " call SaveWinPosn() will save window position in b:cecutil_winposn{b:cecutil_iwinposn} 78 | " let winposn= SaveWinPosn(0) will *only* save window position in winposn variable (no stacking done) 79 | fun! SaveWinPosn(...) 80 | " call Dfunc("SaveWinPosn() a:0=".a:0) 81 | if line(".") == 1 && getline(1) == "" 82 | " call Dfunc("SaveWinPosn : empty buffer") 83 | return "" 84 | endif 85 | let so_keep = &l:so 86 | let siso_keep = &siso 87 | let ss_keep = &l:ss 88 | setlocal so=0 siso=0 ss=0 89 | 90 | let swline = line(".") 91 | let swcol = col(".") 92 | let swwline = winline() - 1 93 | let swwcol = virtcol(".") - wincol() 94 | let savedposn = "call GoWinbufnr(".winbufnr(0).")|silent ".swline 95 | let savedposn = savedposn."|".s:modifier."norm! 0z\" 96 | if swwline > 0 97 | let savedposn= savedposn.":".s:modifier."norm! ".swwline."\\" 98 | endif 99 | if swwcol > 0 100 | let savedposn= savedposn.":".s:modifier."norm! 0".swwcol."zl\" 101 | endif 102 | let savedposn = savedposn.":".s:modifier."call cursor(".swline.",".swcol.")\" 103 | 104 | " save window position in 105 | " b:cecutil_winposn_{iwinposn} (stack) 106 | " only when SaveWinPosn() is used 107 | if a:0 == 0 108 | if !exists("b:cecutil_iwinposn") 109 | let b:cecutil_iwinposn= 1 110 | else 111 | let b:cecutil_iwinposn= b:cecutil_iwinposn + 1 112 | endif 113 | " call Decho("saving posn to SWP stack") 114 | let b:cecutil_winposn{b:cecutil_iwinposn}= savedposn 115 | endif 116 | 117 | let &l:so = so_keep 118 | let &siso = siso_keep 119 | let &l:ss = ss_keep 120 | 121 | " if exists("b:cecutil_iwinposn") " Decho 122 | " call Decho("b:cecutil_winpos{".b:cecutil_iwinposn."}[".b:cecutil_winposn{b:cecutil_iwinposn}."]") 123 | " else " Decho 124 | " call Decho("b:cecutil_iwinposn doesn't exist") 125 | " endif " Decho 126 | " call Dret("SaveWinPosn [".savedposn."]") 127 | return savedposn 128 | endfun 129 | 130 | " --------------------------------------------------------------------- 131 | " RestoreWinPosn: {{{2 132 | " call RestoreWinPosn() 133 | " call RestoreWinPosn(winposn) 134 | fun! RestoreWinPosn(...) 135 | " call Dfunc("RestoreWinPosn() a:0=".a:0) 136 | " call Decho("getline(1)<".getline(1).">") 137 | " call Decho("line(.)=".line(".")) 138 | if line(".") == 1 && getline(1) == "" 139 | " call Dfunc("RestoreWinPosn : empty buffer") 140 | return "" 141 | endif 142 | let so_keep = &l:so 143 | let siso_keep = &l:siso 144 | let ss_keep = &l:ss 145 | setlocal so=0 siso=0 ss=0 146 | 147 | if a:0 == 0 || a:1 == "" 148 | " use saved window position in b:cecutil_winposn{b:cecutil_iwinposn} if it exists 149 | if exists("b:cecutil_iwinposn") && exists("b:cecutil_winposn{b:cecutil_iwinposn}") 150 | " call Decho("using stack b:cecutil_winposn{".b:cecutil_iwinposn."}<".b:cecutil_winposn{b:cecutil_iwinposn}.">") 151 | try 152 | exe "silent! ".b:cecutil_winposn{b:cecutil_iwinposn} 153 | catch /^Vim\%((\a\+)\)\=:E749/ 154 | " ignore empty buffer error messages 155 | endtry 156 | " normally drop top-of-stack by one 157 | " but while new top-of-stack doesn't exist 158 | " drop top-of-stack index by one again 159 | if b:cecutil_iwinposn >= 1 160 | unlet b:cecutil_winposn{b:cecutil_iwinposn} 161 | let b:cecutil_iwinposn= b:cecutil_iwinposn - 1 162 | while b:cecutil_iwinposn >= 1 && !exists("b:cecutil_winposn{b:cecutil_iwinposn}") 163 | let b:cecutil_iwinposn= b:cecutil_iwinposn - 1 164 | endwhile 165 | if b:cecutil_iwinposn < 1 166 | unlet b:cecutil_iwinposn 167 | endif 168 | endif 169 | else 170 | echohl WarningMsg 171 | echomsg "***warning*** need to SaveWinPosn first!" 172 | echohl None 173 | endif 174 | 175 | else " handle input argument 176 | " call Decho("using input a:1<".a:1.">") 177 | " use window position passed to this function 178 | exe "silent ".a:1 179 | " remove a:1 pattern from b:cecutil_winposn{b:cecutil_iwinposn} stack 180 | if exists("b:cecutil_iwinposn") 181 | let jwinposn= b:cecutil_iwinposn 182 | while jwinposn >= 1 " search for a:1 in iwinposn..1 183 | if exists("b:cecutil_winposn{jwinposn}") " if it exists 184 | if a:1 == b:cecutil_winposn{jwinposn} " and the pattern matches 185 | unlet b:cecutil_winposn{jwinposn} " unlet it 186 | if jwinposn == b:cecutil_iwinposn " if at top-of-stack 187 | let b:cecutil_iwinposn= b:cecutil_iwinposn - 1 " drop stacktop by one 188 | endif 189 | endif 190 | endif 191 | let jwinposn= jwinposn - 1 192 | endwhile 193 | endif 194 | endif 195 | 196 | " Seems to be something odd: vertical motions after RWP 197 | " cause jump to first column. The following fixes that. 198 | " Note: was using wincol()>1, but with signs, a cursor 199 | " at column 1 yields wincol()==3. Beeping ensued. 200 | if virtcol('.') > 1 201 | silent norm! hl 202 | elseif virtcol(".") < virtcol("$") 203 | silent norm! lh 204 | endif 205 | 206 | let &l:so = so_keep 207 | let &l:siso = siso_keep 208 | let &l:ss = ss_keep 209 | 210 | " call Dret("RestoreWinPosn") 211 | endfun 212 | 213 | " --------------------------------------------------------------------- 214 | " GoWinbufnr: go to window holding given buffer (by number) {{{2 215 | " Prefers current window; if its buffer number doesn't match, 216 | " then will try from topleft to bottom right 217 | fun! GoWinbufnr(bufnum) 218 | " call Dfunc("GoWinbufnr(".a:bufnum.")") 219 | if winbufnr(0) == a:bufnum 220 | " call Dret("GoWinbufnr : winbufnr(0)==a:bufnum") 221 | return 222 | endif 223 | winc t 224 | let first=1 225 | while winbufnr(0) != a:bufnum && (first || winnr() != 1) 226 | winc w 227 | let first= 0 228 | endwhile 229 | " call Dret("GoWinbufnr") 230 | endfun 231 | 232 | " --------------------------------------------------------------------- 233 | " SaveMark: sets up a string saving a mark position. {{{2 234 | " For example, SaveMark("a") 235 | " Also sets up a global variable, g:savemark_{markname} 236 | fun! SaveMark(markname) 237 | " call Dfunc("SaveMark(markname<".a:markname.">)") 238 | let markname= a:markname 239 | if strpart(markname,0,1) !~ '\a' 240 | let markname= strpart(markname,1,1) 241 | endif 242 | " call Decho("markname=".markname) 243 | 244 | let lzkeep = &lz 245 | set lz 246 | 247 | if 1 <= line("'".markname) && line("'".markname) <= line("$") 248 | let winposn = SaveWinPosn(0) 249 | exe s:modifier."norm! `".markname 250 | let savemark = SaveWinPosn(0) 251 | let g:savemark_{markname} = savemark 252 | let savemark = markname.savemark 253 | call RestoreWinPosn(winposn) 254 | else 255 | let g:savemark_{markname} = "" 256 | let savemark = "" 257 | endif 258 | 259 | let &lz= lzkeep 260 | 261 | " call Dret("SaveMark : savemark<".savemark.">") 262 | return savemark 263 | endfun 264 | 265 | " --------------------------------------------------------------------- 266 | " RestoreMark: {{{2 267 | " call RestoreMark("a") -or- call RestoreMark(savemark) 268 | fun! RestoreMark(markname) 269 | " call Dfunc("RestoreMark(markname<".a:markname.">)") 270 | 271 | if strlen(a:markname) <= 0 272 | " call Dret("RestoreMark : no such mark") 273 | return 274 | endif 275 | let markname= strpart(a:markname,0,1) 276 | if markname !~ '\a' 277 | " handles 'a -> a styles 278 | let markname= strpart(a:markname,1,1) 279 | endif 280 | " call Decho("markname=".markname." strlen(a:markname)=".strlen(a:markname)) 281 | 282 | let lzkeep = &lz 283 | set lz 284 | let winposn = SaveWinPosn(0) 285 | 286 | if strlen(a:markname) <= 2 287 | if exists("g:savemark_{markname}") && strlen(g:savemark_{markname}) != 0 288 | " use global variable g:savemark_{markname} 289 | " call Decho("use savemark list") 290 | call RestoreWinPosn(g:savemark_{markname}) 291 | exe "norm! m".markname 292 | endif 293 | else 294 | " markname is a savemark command (string) 295 | " call Decho("use savemark command") 296 | let markcmd= strpart(a:markname,1) 297 | call RestoreWinPosn(markcmd) 298 | exe "norm! m".markname 299 | endif 300 | 301 | call RestoreWinPosn(winposn) 302 | let &lz = lzkeep 303 | 304 | " call Dret("RestoreMark") 305 | endfun 306 | 307 | " --------------------------------------------------------------------- 308 | " DestroyMark: {{{2 309 | " call DestroyMark("a") -- destroys mark 310 | fun! DestroyMark(markname) 311 | " call Dfunc("DestroyMark(markname<".a:markname.">)") 312 | 313 | " save options and set to standard values 314 | let reportkeep= &report 315 | let lzkeep = &lz 316 | set lz report=10000 317 | 318 | let markname= strpart(a:markname,0,1) 319 | if markname !~ '\a' 320 | " handles 'a -> a styles 321 | let markname= strpart(a:markname,1,1) 322 | endif 323 | " call Decho("markname=".markname) 324 | 325 | let curmod = &mod 326 | let winposn = SaveWinPosn(0) 327 | 1 328 | let lineone = getline(".") 329 | exe "k".markname 330 | d 331 | put! =lineone 332 | let &mod = curmod 333 | call RestoreWinPosn(winposn) 334 | 335 | " restore options to user settings 336 | let &report = reportkeep 337 | let &lz = lzkeep 338 | 339 | " call Dret("DestroyMark") 340 | endfun 341 | 342 | " --------------------------------------------------------------------- 343 | " QArgSplitter: to avoid \ processing by , is needed. {{{2 344 | " However, doesn't split at all, so this one returns a list 345 | " with splits at all whitespace (only!), plus a leading length-of-list. 346 | " The resulting list: qarglist[0] corresponds to a:0 347 | " qarglist[i] corresponds to a:{i} 348 | fun! QArgSplitter(qarg) 349 | " call Dfunc("QArgSplitter(qarg<".a:qarg.">)") 350 | let qarglist = split(a:qarg) 351 | let qarglistlen = len(qarglist) 352 | let qarglist = insert(qarglist,qarglistlen) 353 | " call Dret("QArgSplitter ".string(qarglist)) 354 | return qarglist 355 | endfun 356 | 357 | " --------------------------------------------------------------------- 358 | " ListWinPosn: {{{2 359 | "fun! ListWinPosn() " Decho 360 | " if !exists("b:cecutil_iwinposn") || b:cecutil_iwinposn == 0 " Decho 361 | " call Decho("nothing on SWP stack") " Decho 362 | " else " Decho 363 | " let jwinposn= b:cecutil_iwinposn " Decho 364 | " while jwinposn >= 1 " Decho 365 | " if exists("b:cecutil_winposn{jwinposn}") " Decho 366 | " call Decho("winposn{".jwinposn."}<".b:cecutil_winposn{jwinposn}.">") " Decho 367 | " else " Decho 368 | " call Decho("winposn{".jwinposn."} -- doesn't exist") " Decho 369 | " endif " Decho 370 | " let jwinposn= jwinposn - 1 " Decho 371 | " endwhile " Decho 372 | " endif " Decho 373 | "endfun " Decho 374 | "com! -nargs=0 LWP call ListWinPosn() " Decho 375 | 376 | " --------------------------------------------------------------------- 377 | " SaveUserMaps: this function sets up a script-variable (s:restoremap) {{{2 378 | " which can be used to restore user maps later with 379 | " call RestoreUserMaps() 380 | " 381 | " mapmode - see :help maparg for details (n v o i c l "") 382 | " ex. "n" = Normal 383 | " The letters "b" and "u" are optional prefixes; 384 | " The "u" means that the map will also be unmapped 385 | " The "b" means that the map has a qualifier 386 | " ex. "un" = Normal + unmapping 387 | " ex. "bn" = Normal + 388 | " ex. "bun" = Normal + + unmapping 389 | " ex. "ubn" = Normal + + unmapping 390 | " maplead - see mapchx 391 | " mapchx - "" handled as a single map item. 392 | " ex. "" 393 | " - "string" a string of single letters which are actually 394 | " multiple two-letter maps (using the maplead: 395 | " maplead . each_character_in_string) 396 | " ex. maplead="\" and mapchx="abc" saves user mappings for 397 | " \a, \b, and \c 398 | " Of course, if maplead is "", then for mapchx="abc", 399 | " mappings for a, b, and c are saved. 400 | " - :something handled as a single map item, w/o the ":" 401 | " ex. mapchx= ":abc" will save a mapping for "abc" 402 | " suffix - a string unique to your plugin 403 | " ex. suffix= "DrawIt" 404 | fun! SaveUserMaps(mapmode,maplead,mapchx,suffix) 405 | " call Dfunc("SaveUserMaps(mapmode<".a:mapmode."> maplead<".a:maplead."> mapchx<".a:mapchx."> suffix<".a:suffix.">)") 406 | 407 | if !exists("s:restoremap_{a:suffix}") 408 | " initialize restoremap_suffix to null string 409 | let s:restoremap_{a:suffix}= "" 410 | endif 411 | 412 | " set up dounmap: if 1, then save and unmap (a:mapmode leads with a "u") 413 | " if 0, save only 414 | let mapmode = a:mapmode 415 | let dounmap = 0 416 | let dobuffer = "" 417 | while mapmode =~ '^[bu]' 418 | if mapmode =~ '^u' 419 | let dounmap= 1 420 | let mapmode= strpart(a:mapmode,1) 421 | elseif mapmode =~ '^b' 422 | let dobuffer= " " 423 | let mapmode= strpart(a:mapmode,1) 424 | endif 425 | endwhile 426 | " call Decho("dounmap=".dounmap." dobuffer<".dobuffer.">") 427 | 428 | " save single map :...something... 429 | if strpart(a:mapchx,0,1) == ':' 430 | " call Decho("save single map :...something...") 431 | let amap= strpart(a:mapchx,1) 432 | if amap == "|" || amap == "\" 433 | let amap= "\".amap 434 | endif 435 | let amap = a:maplead.amap 436 | let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|:silent! ".mapmode."unmap ".dobuffer.amap 437 | if maparg(amap,mapmode) != "" 438 | let maprhs = substitute(maparg(amap,mapmode),'|','','ge') 439 | let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|:".mapmode."map ".dobuffer.amap." ".maprhs 440 | endif 441 | if dounmap 442 | exe "silent! ".mapmode."unmap ".dobuffer.amap 443 | endif 444 | 445 | " save single map 446 | elseif strpart(a:mapchx,0,1) == '<' 447 | " call Decho("save single map ") 448 | let amap = a:mapchx 449 | if amap == "|" || amap == "\" 450 | let amap= "\".amap 451 | " call Decho("amap[[".amap."]]") 452 | endif 453 | let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|silent! ".mapmode."unmap ".dobuffer.amap 454 | if maparg(a:mapchx,mapmode) != "" 455 | let maprhs = substitute(maparg(amap,mapmode),'|','','ge') 456 | let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|".mapmode."map ".amap." ".dobuffer.maprhs 457 | endif 458 | if dounmap 459 | exe "silent! ".mapmode."unmap ".dobuffer.amap 460 | endif 461 | 462 | " save multiple maps 463 | else 464 | " call Decho("save multiple maps") 465 | let i= 1 466 | while i <= strlen(a:mapchx) 467 | let amap= a:maplead.strpart(a:mapchx,i-1,1) 468 | if amap == "|" || amap == "\" 469 | let amap= "\".amap 470 | endif 471 | let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|silent! ".mapmode."unmap ".dobuffer.amap 472 | if maparg(amap,mapmode) != "" 473 | let maprhs = substitute(maparg(amap,mapmode),'|','','ge') 474 | let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|".mapmode."map ".amap." ".dobuffer.maprhs 475 | endif 476 | if dounmap 477 | exe "silent! ".mapmode."unmap ".dobuffer.amap 478 | endif 479 | let i= i + 1 480 | endwhile 481 | endif 482 | " call Dret("SaveUserMaps : restoremap_".a:suffix.": ".s:restoremap_{a:suffix}) 483 | endfun 484 | 485 | " --------------------------------------------------------------------- 486 | " RestoreUserMaps: {{{2 487 | " Used to restore user maps saved by SaveUserMaps() 488 | fun! RestoreUserMaps(suffix) 489 | " call Dfunc("RestoreUserMaps(suffix<".a:suffix.">)") 490 | if exists("s:restoremap_{a:suffix}") 491 | let s:restoremap_{a:suffix}= substitute(s:restoremap_{a:suffix},'|\s*$','','e') 492 | if s:restoremap_{a:suffix} != "" 493 | " call Decho("exe ".s:restoremap_{a:suffix}) 494 | exe "silent! ".s:restoremap_{a:suffix} 495 | endif 496 | unlet s:restoremap_{a:suffix} 497 | endif 498 | " call Dret("RestoreUserMaps") 499 | endfun 500 | 501 | " ============== 502 | " Restore: {{{1 503 | " ============== 504 | let &cpo= s:keepcpo 505 | unlet s:keepcpo 506 | 507 | " ================ 508 | " Modelines: {{{1 509 | " ================ 510 | " vim: ts=4 fdm=marker 511 | -------------------------------------------------------------------------------- /plugin/AlignMapsPlugin.vim: -------------------------------------------------------------------------------- 1 | " AlignMapsPlugin: Alignment maps based upon and 2 | " Maintainer: Dr. Charles E. Campbell, Jr. 3 | " Date: Mar 03, 2009 4 | " 5 | " NOTE: the code herein needs vim 6.0 or later 6 | " needs v6 or later 7 | " needs v5 or later 8 | " Copyright: Copyright (C) 1999-2008 Charles E. Campbell, Jr. {{{1 9 | " Permission is hereby granted to use and distribute this code, 10 | " with or without modifications, provided that this copyright 11 | " notice is copied with it. Like anything else that's free, 12 | " AlignMaps.vim is provided *as is* and comes with no warranty 13 | " of any kind, either expressed or implied. By using this 14 | " plugin, you agree that in no event will the copyright 15 | " holder be liable for any damages resulting from the use 16 | " of this software. 17 | " 18 | " Usage: {{{1 19 | " Use 'a to mark beginning of to-be-aligned region, Alternative: use V 20 | " move cursor to end of region, and execute map. (linewise visual mode) to 21 | " The maps also set up marks 'y and 'z, and retain mark region, execute same 22 | " 'a at the beginning of region. map. Uses 'a, 'y, and 'z. 23 | " 24 | " The start/end wrappers save and restore marks 'y and 'z. 25 | " 26 | " Although the comments indicate the maps use a leading backslash, 27 | " actually they use (:he mapleader), so the user can 28 | " specify that the maps start how he or she prefers. 29 | " 30 | " Note: these maps all use . 31 | " 32 | " Romans 1:20 For the invisible things of Him since the creation of the {{{1 33 | " world are clearly seen, being perceived through the things that are 34 | " made, even His everlasting power and divinity; that they may be 35 | " without excuse. 36 | 37 | " --------------------------------------------------------------------- 38 | " Load Once: {{{1 39 | if &cp || exists("g:loaded_AlignMapsPlugin") 40 | finish 41 | endif 42 | let s:keepcpo = &cpo 43 | let g:loaded_AlignMapsPlugin = "v41" 44 | set cpo&vim 45 | 46 | " ===================================================================== 47 | " Maps: {{{1 48 | 49 | " --------------------------------------------------------------------- 50 | " WS: wrapper start map (internal) {{{2 51 | " Produces a blank line above and below, marks with 'y and 'z 52 | if !hasmapto('WrapperStart') 53 | map WS AlignMapsWrapperStart 54 | endif 55 | nmap