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