vimball.vim (23031B)
1 " vimball.vim : construct a file containing both paths and files 2 " Author: Charles E. Campbell, Jr. 3 " Date: Dec 28, 2009 4 " Version: 30 5 " GetLatestVimScripts: 1502 1 :AutoInstall: vimball.vim 6 " Copyright: (c) 2004-2009 by Charles E. Campbell, Jr. 7 " The VIM LICENSE applies to Vimball.vim, and Vimball.txt 8 " (see |copyright|) except use "Vimball" instead of "Vim". 9 " No warranty, express or implied. 10 " *** *** Use At-Your-Own-Risk! *** *** 11 12 " --------------------------------------------------------------------- 13 " Load Once: {{{1 14 if &cp || exists("g:loaded_vimball") 15 finish 16 endif 17 let g:loaded_vimball = "v30" 18 if v:version < 702 19 echohl WarningMsg 20 echo "***warning*** this version of vimball needs vim 7.2" 21 echohl Normal 22 finish 23 endif 24 let s:keepcpo= &cpo 25 set cpo&vim 26 "DechoTabOn 27 28 " ===================================================================== 29 " Constants: {{{1 30 if !exists("s:USAGE") 31 let s:USAGE = 0 32 let s:WARNING = 1 33 let s:ERROR = 2 34 35 " determine if cygwin is in use or not 36 if !exists("g:netrw_cygwin") 37 if has("win32") || has("win95") || has("win64") || has("win16") 38 if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$' 39 let g:netrw_cygwin= 1 40 else 41 let g:netrw_cygwin= 0 42 endif 43 else 44 let g:netrw_cygwin= 0 45 endif 46 endif 47 48 " set up g:vimball_mkdir if the mkdir() call isn't defined 49 if !exists("*mkdir") 50 if exists("g:netrw_local_mkdir") 51 let g:vimball_mkdir= g:netrw_local_mkdir 52 elseif executable("mkdir") 53 let g:vimball_mkdir= "mkdir" 54 elseif executable("makedir") 55 let g:vimball_mkdir= "makedir" 56 endif 57 if !exists(g:vimball_mkdir) 58 call vimball#ShowMesg(s:WARNING,"(vimball) g:vimball_mkdir undefined") 59 endif 60 endif 61 endif 62 63 " ===================================================================== 64 " Functions: {{{1 65 66 " --------------------------------------------------------------------- 67 " vimball#MkVimball: creates a vimball given a list of paths to files {{{2 68 " Input: 69 " line1,line2: a range of lines containing paths to files to be included in the vimball 70 " writelevel : if true, force a write to filename.vba, even if it exists 71 " (usually accomplished with :MkVimball! ... 72 " filename : base name of file to be created (ie. filename.vba) 73 " Output: a filename.vba using vimball format: 74 " path 75 " filesize 76 " [file] 77 " path 78 " filesize 79 " [file] 80 fun! vimball#MkVimball(line1,line2,writelevel,...) range 81 " call Dfunc("MkVimball(line1=".a:line1." line2=".a:line2." writelevel=".a:writelevel." vimballname<".a:1.">) a:0=".a:0) 82 if a:1 =~ '\.vim$' || a:1 =~ '\.txt$' 83 let vbname= substitute(a:1,'\.\a\{3}$','.vba','') 84 else 85 let vbname= a:1 86 endif 87 if vbname !~ '\.vba$' 88 let vbname= vbname.'.vba' 89 endif 90 " call Decho("vbname<".vbname.">") 91 if !a:writelevel && a:1 =~ '[\/]' 92 call vimball#ShowMesg(s:ERROR,"(MkVimball) vimball name<".a:1."> should not include slashes; use ! to insist") 93 " call Dret("MkVimball : vimball name<".a:1."> should not include slashes") 94 return 95 endif 96 if !a:writelevel && filereadable(vbname) 97 call vimball#ShowMesg(s:ERROR,"(MkVimball) file<".vbname."> exists; use ! to insist") 98 " call Dret("MkVimball : file<".vbname."> already exists; use ! to insist") 99 return 100 endif 101 102 " user option bypass 103 call vimball#SaveSettings() 104 105 if a:0 >= 2 106 " allow user to specify where to get the files 107 let home= expand(a:2) 108 else 109 " use first existing directory from rtp 110 let home= vimball#VimballHome() 111 endif 112 113 " save current directory 114 let curdir = getcwd() 115 call s:ChgDir(home) 116 117 " record current tab, initialize while loop index 118 let curtabnr = tabpagenr() 119 let linenr = a:line1 120 " call Decho("curtabnr=".curtabnr) 121 122 while linenr <= a:line2 123 let svfile = getline(linenr) 124 " call Decho("svfile<".svfile.">") 125 126 if !filereadable(svfile) 127 call vimball#ShowMesg(s:ERROR,"unable to read file<".svfile.">") 128 call s:ChgDir(curdir) 129 call vimball#RestoreSettings() 130 " call Dret("MkVimball") 131 return 132 endif 133 134 " create/switch to mkvimball tab 135 if !exists("vbtabnr") 136 tabnew 137 silent! file Vimball 138 let vbtabnr= tabpagenr() 139 else 140 exe "tabn ".vbtabnr 141 endif 142 143 let lastline= line("$") + 1 144 if lastline == 2 && getline("$") == "" 145 call setline(1,'" Vimball Archiver by Charles E. Campbell, Jr., Ph.D.') 146 call setline(2,'UseVimball') 147 call setline(3,'finish') 148 let lastline= line("$") + 1 149 endif 150 call setline(lastline ,substitute(svfile,'$',' [[[1','')) 151 call setline(lastline+1,0) 152 153 " write the file from the tab 154 " call Decho("exe $r ".fnameescape(svfile)) 155 exe "$r ".fnameescape(svfile) 156 157 call setline(lastline+1,line("$") - lastline - 1) 158 " call Decho("lastline=".lastline." line$=".line("$")) 159 160 " restore to normal tab 161 exe "tabn ".curtabnr 162 let linenr= linenr + 1 163 endwhile 164 165 " write the vimball 166 exe "tabn ".vbtabnr 167 call s:ChgDir(curdir) 168 setlocal ff=unix 169 if a:writelevel 170 " call Decho("exe w! ".fnameescape(vbname)) 171 exe "w! ".fnameescape(vbname) 172 else 173 " call Decho("exe w ".fnameescape(vbname)) 174 exe "w ".fnameescape(vbname) 175 endif 176 " call Decho("Vimball<".vbname."> created") 177 echo "Vimball<".vbname."> created" 178 179 " remove the evidence 180 setlocal nomod bh=wipe 181 exe "tabn ".curtabnr 182 exe "tabc ".vbtabnr 183 184 " restore options 185 call vimball#RestoreSettings() 186 187 " call Dret("MkVimball") 188 endfun 189 190 " --------------------------------------------------------------------- 191 " vimball#Vimball: extract and distribute contents from a vimball {{{2 192 " (invoked the the UseVimball command embedded in 193 " vimballs' prologue) 194 fun! vimball#Vimball(really,...) 195 " call Dfunc("vimball#Vimball(really=".a:really.") a:0=".a:0) 196 197 if v:version < 701 || (v:version == 701 && !exists('*fnameescape')) 198 echoerr "your vim is missing the fnameescape() function" 199 " call Dret("vimball#Vimball : needs 7.1 with patch 299") 200 return 201 endif 202 203 if getline(1) !~ '^" Vimball Archiver' 204 echoerr "(Vimball) The current file does not appear to be a Vimball!" 205 " call Dret("vimball#Vimball") 206 return 207 endif 208 209 " set up standard settings 210 call vimball#SaveSettings() 211 let curtabnr = tabpagenr() 212 let vimballfile = expand("%:tr") 213 214 " set up vimball tab 215 " call Decho("setting up vimball tab") 216 tabnew 217 silent! file Vimball 218 let vbtabnr= tabpagenr() 219 let didhelp= "" 220 221 " go to vim plugin home 222 if a:0 > 0 223 let home= expand(a:1) 224 else 225 let home= vimball#VimballHome() 226 endif 227 " call Decho("home<".home.">") 228 229 " save current directory and remove older same-named vimball, if any 230 let curdir = getcwd() 231 " call Decho("home<".home.">") 232 " call Decho("curdir<".curdir.">") 233 234 call s:ChgDir(home) 235 let s:ok_unablefind= 1 236 call vimball#RmVimball(vimballfile) 237 unlet s:ok_unablefind 238 239 let linenr = 4 240 let filecnt = 0 241 242 " give title to listing of (extracted) files from Vimball Archive 243 if a:really 244 echohl Title | echomsg "Vimball Archive" | echohl None 245 else 246 echohl Title | echomsg "Vimball Archive Listing" | echohl None 247 echohl Statement | echomsg "files would be placed under: ".home | echohl None 248 endif 249 250 " apportion vimball contents to various files 251 " call Decho("exe tabn ".curtabnr) 252 exe "tabn ".curtabnr 253 " call Decho("linenr=".linenr." line$=".line("$")) 254 while 1 < linenr && linenr < line("$") 255 let fname = substitute(getline(linenr),'\t\[\[\[1$','','') 256 let fname = substitute(fname,'\\','/','g') 257 " let fsize = getline(linenr+1)+0 258 let fsize = substitute(getline(linenr+1),'^\(\d\+\).\{-}$','\1','')+0 259 let fenc = substitute(getline(linenr+1),'^\d\+\s*\(\S\+\)$','\1','') 260 let filecnt = filecnt + 1 261 " call Decho("fname<".fname."> fsize=".fsize." filecnt=".filecnt) 262 263 if a:really 264 echomsg "extracted <".fname.">: ".fsize." lines" 265 else 266 echomsg "would extract <".fname.">: ".fsize." lines" 267 endif 268 " call Decho("using L#".linenr.": will extract file<".fname.">") 269 " call Decho("using L#".(linenr+1).": fsize=".fsize) 270 271 " Allow AsNeeded/ directory to take place of plugin/ directory 272 " when AsNeeded/filename is filereadable or was present in VimballRecord 273 if fname =~ '\<plugin/' 274 let anfname= substitute(fname,'\<plugin/','AsNeeded/','') 275 if filereadable(anfname) || (exists("s:VBRstring") && s:VBRstring =~ anfname) 276 " call Decho("using anfname<".anfname."> instead of <".fname.">") 277 let fname= anfname 278 endif 279 endif 280 281 " make directories if they don't exist yet 282 if a:really 283 " call Decho("making directories if they don't exist yet (fname<".fname.">)") 284 let fnamebuf= substitute(fname,'\\','/','g') 285 let dirpath = substitute(home,'\\','/','g') 286 while fnamebuf =~ '/' 287 let dirname = dirpath."/".substitute(fnamebuf,'/.*$','','') 288 let dirpath = dirname 289 let fnamebuf = substitute(fnamebuf,'^.\{-}/\(.*\)$','\1','') 290 " call Decho("dirname<".dirname.">") 291 if !isdirectory(dirname) 292 " call Decho("making <".dirname.">") 293 if exists("g:vimball_mkdir") 294 call system(g:vimball_mkdir." ".shellescape(dirname)) 295 else 296 call mkdir(dirname) 297 endif 298 call s:RecordInVar(home,"rmdir('".dirname."')") 299 endif 300 endwhile 301 endif 302 call s:ChgDir(home) 303 304 " grab specified qty of lines and place into "a" buffer 305 " (skip over path/filename and qty-lines) 306 let linenr = linenr + 2 307 let lastline = linenr + fsize - 1 308 " call Decho("exe ".linenr.",".lastline."yank a") 309 exe "silent ".linenr.",".lastline."yank a" 310 311 " copy "a" buffer into tab 312 " call Decho('copy "a buffer into tab#'.vbtabnr) 313 exe "tabn ".vbtabnr 314 setlocal ma 315 silent! %d 316 silent put a 317 1 318 silent d 319 320 " write tab to file 321 if a:really 322 let fnamepath= home."/".fname 323 " call Decho("exe w! ".fnameescape(fnamepath)) 324 if fenc != "" 325 exe "silent w! ++enc=".fnameescape(fenc)." ".fnameescape(fnamepath) 326 else 327 exe "silent w! ".fnameescape(fnamepath) 328 endif 329 echo "wrote ".fnameescape(fnamepath) 330 call s:RecordInVar(home,"call delete('".fnamepath."')") 331 endif 332 333 " return to tab with vimball 334 " call Decho("exe tabn ".curtabnr) 335 exe "tabn ".curtabnr 336 337 " set up help if its a doc/*.txt file 338 " call Decho("didhelp<".didhelp."> fname<".fname.">") 339 if a:really && didhelp == "" && fname =~ 'doc/[^/]\+\.\(txt\|..x\)$' 340 let didhelp= substitute(fname,'^\(.*\<doc\)[/\\][^.]*\.\(txt\|..x\)$','\1','') 341 " call Decho("didhelp<".didhelp.">") 342 endif 343 344 " update for next file 345 " call Decho("update linenr= [linenr=".linenr."] + [fsize=".fsize."] = ".(linenr+fsize)) 346 let linenr= linenr + fsize 347 endwhile 348 349 " set up help 350 " call Decho("about to set up help: didhelp<".didhelp.">") 351 if didhelp != "" 352 let htpath= home."/".didhelp 353 " call Decho("exe helptags ".htpath) 354 exe "helptags ".fnameescape(htpath) 355 echo "did helptags" 356 endif 357 358 " make sure a "Press ENTER..." prompt appears to keep the messages showing! 359 while filecnt <= &ch 360 echomsg " " 361 let filecnt= filecnt + 1 362 endwhile 363 364 " record actions in <.VimballRecord> 365 call s:RecordInFile(home) 366 367 " restore events, delete tab and buffer 368 exe "tabn ".vbtabnr 369 setlocal nomod bh=wipe 370 exe "tabn ".curtabnr 371 exe "tabc ".vbtabnr 372 call vimball#RestoreSettings() 373 call s:ChgDir(curdir) 374 375 " call Dret("vimball#Vimball") 376 endfun 377 378 " --------------------------------------------------------------------- 379 " vimball#RmVimball: remove any files, remove any directories made by any {{{2 380 " previous vimball extraction based on a file of the current 381 " name. 382 " Usage: RmVimball (assume current file is a vimball; remove) 383 " RmVimball vimballname 384 fun! vimball#RmVimball(...) 385 " call Dfunc("vimball#RmVimball() a:0=".a:0) 386 if exists("g:vimball_norecord") 387 " call Dret("vimball#RmVimball : (g:vimball_norecord)") 388 return 389 endif 390 391 if a:0 == 0 392 let curfile= expand("%:tr") 393 " call Decho("case a:0=0: curfile<".curfile."> (used expand(%:tr))") 394 else 395 if a:1 =~ '[\/]' 396 call vimball#ShowMesg(s:USAGE,"RmVimball vimballname [path]") 397 " call Dret("vimball#RmVimball : suspect a:1<".a:1.">") 398 return 399 endif 400 let curfile= a:1 401 " call Decho("case a:0=".a:0.": curfile<".curfile.">") 402 endif 403 if curfile =~ '\.vba$' 404 let curfile= substitute(curfile,'\.vba','','') 405 endif 406 if a:0 >= 2 407 let home= expand(a:2) 408 else 409 let home= vimball#VimballHome() 410 endif 411 let curdir = getcwd() 412 " call Decho("home <".home.">") 413 " call Decho("curfile<".curfile.">") 414 " call Decho("curdir <".curdir.">") 415 416 call s:ChgDir(home) 417 if filereadable(".VimballRecord") 418 " call Decho(".VimballRecord is readable") 419 " call Decho("curfile<".curfile.">") 420 keepalt keepjumps 1split 421 silent! keepalt keepjumps e .VimballRecord 422 let keepsrch= @/ 423 " call Decho('search for ^\M'.curfile.'.\m: ') 424 " call Decho('search for ^\M'.curfile.'.\mvba: ') 425 " call Decho('search for ^\M'.curfile.'\m[-0-9.]*\.vba: ') 426 if search('^\M'.curfile."\m: ".'cw') 427 let foundit= 1 428 elseif search('^\M'.curfile.".\mvba: ",'cw') 429 let foundit= 1 430 elseif search('^\M'.curfile.'\m[-0-9.]*\.vba: ','cw') 431 let foundit= 1 432 else 433 let foundit = 0 434 endif 435 if foundit 436 let exestring = substitute(getline("."),'^\M'.curfile.'\m\S\{-}\.vba: ','','') 437 let s:VBRstring= substitute(exestring,'call delete(','','g') 438 let s:VBRstring= substitute(s:VBRstring,"[')]",'','g') 439 " call Decho("exe ".exestring) 440 silent! keepalt keepjumps exe exestring 441 silent! keepalt keepjumps d 442 let exestring= strlen(substitute(exestring,'call delete(.\{-})|\=',"D","g")) 443 " call Decho("exestring<".exestring.">") 444 echomsg "removed ".exestring." files" 445 else 446 let s:VBRstring= '' 447 let curfile = substitute(curfile,'\.vba','','') 448 " call Decho("unable to find <".curfile."> in .VimballRecord") 449 if !exists("s:ok_unablefind") 450 call vimball#ShowMesg(s:WARNING,"(RmVimball) unable to find <".curfile."> in .VimballRecord") 451 endif 452 endif 453 silent! keepalt keepjumps g/^\s*$/d 454 silent! keepalt keepjumps wq! 455 let @/= keepsrch 456 endif 457 call s:ChgDir(curdir) 458 459 " call Dret("vimball#RmVimball") 460 endfun 461 462 " --------------------------------------------------------------------- 463 " vimball#Decompress: attempts to automatically decompress vimballs {{{2 464 fun! vimball#Decompress(fname,...) 465 " call Dfunc("Decompress(fname<".a:fname.">) a:0=".a:0) 466 467 " decompression: 468 if expand("%") =~ '.*\.gz' && executable("gunzip") 469 " handle *.gz with gunzip 470 silent exe "!gunzip ".shellescape(a:fname) 471 if v:shell_error != 0 472 call vimball#ShowMesg(s:WARNING,"(vimball#Decompress) gunzip may have failed with <".a:fname.">") 473 endif 474 let fname= substitute(a:fname,'\.gz$','','') 475 exe "e ".escape(fname,' \') 476 if a:0 == 0| call vimball#ShowMesg(s:USAGE,"Source this file to extract it! (:so %)") | endif 477 478 elseif expand("%") =~ '.*\.gz' && executable("gzip") 479 " handle *.gz with gzip -d 480 silent exe "!gzip -d ".shellescape(a:fname) 481 if v:shell_error != 0 482 call vimball#ShowMesg(s:WARNING,'(vimball#Decompress) "gzip -d" may have failed with <'.a:fname.">") 483 endif 484 let fname= substitute(a:fname,'\.gz$','','') 485 exe "e ".escape(fname,' \') 486 if a:0 == 0| call vimball#ShowMesg(s:USAGE,"Source this file to extract it! (:so %)") | endif 487 488 elseif expand("%") =~ '.*\.bz2' && executable("bunzip2") 489 " handle *.bz2 with bunzip2 490 silent exe "!bunzip2 ".shellescape(a:fname) 491 if v:shell_error != 0 492 call vimball#ShowMesg(s:WARNING,"(vimball#Decompress) bunzip2 may have failed with <".a:fname.">") 493 endif 494 let fname= substitute(a:fname,'\.bz2$','','') 495 exe "e ".escape(fname,' \') 496 if a:0 == 0| call vimball#ShowMesg(s:USAGE,"Source this file to extract it! (:so %)") | endif 497 498 elseif expand("%") =~ '.*\.bz2' && executable("bzip2") 499 " handle *.bz2 with bzip2 -d 500 silent exe "!bzip2 -d ".shellescape(a:fname) 501 if v:shell_error != 0 502 call vimball#ShowMesg(s:WARNING,'(vimball#Decompress) "bzip2 -d" may have failed with <'.a:fname.">") 503 endif 504 let fname= substitute(a:fname,'\.bz2$','','') 505 exe "e ".escape(fname,' \') 506 if a:0 == 0| call vimball#ShowMesg(s:USAGE,"Source this file to extract it! (:so %)") | endif 507 508 elseif expand("%") =~ '.*\.zip' && executable("unzip") 509 " handle *.zip with unzip 510 silent exe "!unzip ".shellescape(a:fname) 511 if v:shell_error != 0 512 call vimball#ShowMesg(s:WARNING,"(vimball#Decompress) unzip may have failed with <".a:fname.">") 513 endif 514 let fname= substitute(a:fname,'\.zip$','','') 515 exe "e ".escape(fname,' \') 516 if a:0 == 0| call vimball#ShowMesg(s:USAGE,"Source this file to extract it! (:so %)") | endif 517 endif 518 519 if a:0 == 0| setlocal noma bt=nofile fmr=[[[,]]] fdm=marker | endif 520 521 " call Dret("Decompress") 522 endfun 523 524 " --------------------------------------------------------------------- 525 " vimball#ShowMesg: {{{2 526 fun! vimball#ShowMesg(level,msg) 527 " call Dfunc("vimball#ShowMesg(level=".a:level." msg<".a:msg.">)") 528 529 let rulerkeep = &ruler 530 let showcmdkeep = &showcmd 531 set noruler noshowcmd 532 redraw! 533 534 if &fo =~ '[ta]' 535 echomsg "***vimball*** ".a:msg 536 else 537 if a:level == s:WARNING || a:level == s:USAGE 538 echohl WarningMsg 539 elseif a:level == s:ERROR 540 echohl Error 541 endif 542 echomsg "***vimball*** ".a:msg 543 echohl None 544 endif 545 546 if a:level != s:USAGE 547 call inputsave()|let ok= input("Press <cr> to continue")|call inputrestore() 548 endif 549 550 let &ruler = rulerkeep 551 let &showcmd = showcmdkeep 552 553 " call Dret("vimball#ShowMesg") 554 endfun 555 " ===================================================================== 556 " s:ChgDir: change directory (in spite of Windoze) {{{2 557 fun! s:ChgDir(newdir) 558 " call Dfunc("ChgDir(newdir<".a:newdir.">)") 559 if (has("win32") || has("win95") || has("win64") || has("win16")) 560 exe 'silent cd '.fnameescape(substitute(a:newdir,'/','\\','g')) 561 else 562 exe 'silent cd '.fnameescape(a:newdir) 563 endif 564 " call Dret("ChgDir : curdir<".getcwd().">") 565 endfun 566 567 " --------------------------------------------------------------------- 568 " s:RecordInVar: record a un-vimball command in the .VimballRecord file {{{2 569 fun! s:RecordInVar(home,cmd) 570 " call Dfunc("RecordInVar(home<".a:home."> cmd<".a:cmd.">)") 571 if a:cmd =~ '^rmdir' 572 " if !exists("s:recorddir") 573 " let s:recorddir= substitute(a:cmd,'^rmdir',"call s:Rmdir",'') 574 " else 575 " let s:recorddir= s:recorddir."|".substitute(a:cmd,'^rmdir',"call s:Rmdir",'') 576 " endif 577 elseif !exists("s:recordfile") 578 let s:recordfile= a:cmd 579 else 580 let s:recordfile= s:recordfile."|".a:cmd 581 endif 582 " call Dret("RecordInVar : s:recordfile<".(exists("s:recordfile")? s:recordfile : "")."> s:recorddir<".(exists("s:recorddir")? s:recorddir : "").">") 583 endfun 584 585 " --------------------------------------------------------------------- 586 " s:RecordInFile: {{{2 587 fun! s:RecordInFile(home) 588 " call Dfunc("s:RecordInFile()") 589 if exists("g:vimball_norecord") 590 " call Dret("s:RecordInFile : g:vimball_norecord") 591 return 592 endif 593 594 if exists("s:recordfile") || exists("s:recorddir") 595 let curdir= getcwd() 596 call s:ChgDir(a:home) 597 keepalt keepjumps 1split 598 599 let cmd= expand("%:tr").": " 600 " call Decho("cmd<".cmd.">") 601 602 silent! keepalt keepjumps e .VimballRecord 603 setlocal ma 604 $ 605 if exists("s:recordfile") && exists("s:recorddir") 606 let cmd= cmd.s:recordfile."|".s:recorddir 607 elseif exists("s:recorddir") 608 let cmd= cmd.s:recorddir 609 elseif exists("s:recordfile") 610 let cmd= cmd.s:recordfile 611 else 612 " call Dret("s:RecordInFile : neither recordfile nor recorddir exist") 613 return 614 endif 615 " call Decho("cmd<".cmd.">") 616 617 " put command into buffer, write .VimballRecord `file 618 keepalt keepjumps put=cmd 619 silent! keepalt keepjumps g/^\s*$/d 620 silent! keepalt keepjumps wq! 621 call s:ChgDir(curdir) 622 623 if exists("s:recorddir") 624 " call Decho("unlet s:recorddir<".s:recorddir.">") 625 unlet s:recorddir 626 endif 627 if exists("s:recordfile") 628 " call Decho("unlet s:recordfile<".s:recordfile.">") 629 unlet s:recordfile 630 endif 631 else 632 " call Decho("s:record[file|dir] doesn't exist") 633 endif 634 635 " call Dret("s:RecordInFile") 636 endfun 637 638 " --------------------------------------------------------------------- 639 " vimball#VimballHome: determine/get home directory path (usually from rtp) {{{2 640 fun! vimball#VimballHome() 641 " call Dfunc("vimball#VimballHome()") 642 if exists("g:vimball_home") 643 let home= g:vimball_home 644 else 645 " go to vim plugin home 646 for home in split(&rtp,',') + [''] 647 if isdirectory(home) && filewritable(home) | break | endif 648 let basehome= substitute(home,'[/\\]\.vim$','','') 649 if isdirectory(basehome) && filewritable(basehome) 650 let home= basehome."/.vim" 651 break 652 endif 653 endfor 654 if home == "" 655 " just pick the first directory 656 let home= substitute(&rtp,',.*$','','') 657 endif 658 if (has("win32") || has("win95") || has("win64") || has("win16")) 659 let home= substitute(home,'/','\\','g') 660 endif 661 endif 662 " insure that the home directory exists 663 " call Decho("picked home<".home.">") 664 if !isdirectory(home) 665 if exists("g:vimball_mkdir") 666 " call Decho("home<".home."> isn't a directory -- making it now with g:vimball_mkdir<".g:vimball_mkdir.">") 667 " call Decho("system(".g:vimball_mkdir." ".shellescape(home).")") 668 call system(g:vimball_mkdir." ".shellescape(home)) 669 else 670 " call Decho("home<".home."> isn't a directory -- making it now with mkdir()") 671 call mkdir(home) 672 endif 673 endif 674 " call Dret("vimball#VimballHome <".home.">") 675 return home 676 endfun 677 678 " --------------------------------------------------------------------- 679 " vimball#SaveSettings: {{{2 680 fun! vimball#SaveSettings() 681 " call Dfunc("SaveSettings()") 682 let s:makeep = getpos("'a") 683 let s:regakeep= @a 684 if exists("&acd") 685 let s:acdkeep = &acd 686 endif 687 let s:eikeep = &ei 688 let s:fenkeep = &l:fen 689 let s:hidkeep = &hidden 690 let s:ickeep = &ic 691 let s:lzkeep = &lz 692 let s:pmkeep = &pm 693 let s:repkeep = &report 694 let s:vekeep = &ve 695 let s:ffkeep = &l:ff 696 if exists("&acd") 697 setlocal ei=all ve=all noacd nofen noic report=999 nohid bt= ma lz pm= ff=unix 698 else 699 setlocal ei=all ve=all nofen noic report=999 nohid bt= ma lz pm= ff=unix 700 endif 701 " vimballs should be in unix format 702 setlocal ff=unix 703 " call Dret("SaveSettings") 704 endfun 705 706 " --------------------------------------------------------------------- 707 " vimball#RestoreSettings: {{{2 708 fun! vimball#RestoreSettings() 709 " call Dfunc("RestoreSettings()") 710 let @a = s:regakeep 711 if exists("&acd") 712 let &acd = s:acdkeep 713 endif 714 let &l:fen = s:fenkeep 715 let &hidden = s:hidkeep 716 let &ic = s:ickeep 717 let &lz = s:lzkeep 718 let &pm = s:pmkeep 719 let &report = s:repkeep 720 let &ve = s:vekeep 721 let &ei = s:eikeep 722 let &l:ff = s:ffkeep 723 if s:makeep[0] != 0 724 " restore mark a 725 " call Decho("restore mark-a: makeep=".string(makeep)) 726 call setpos("'a",s:makeep) 727 endif 728 if exists("&acd") 729 unlet s:acdkeep 730 endif 731 unlet s:regakeep s:eikeep s:fenkeep s:hidkeep s:ickeep s:repkeep s:vekeep s:makeep s:lzkeep s:pmkeep s:ffkeep 732 " call Dret("RestoreSettings") 733 endfun 734 735 " --------------------------------------------------------------------- 736 " Modelines: {{{1 737 " vim: fdm=marker