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