792
|
1 " vimball : construct a file containing both paths and files
|
|
2 " Author: Charles E. Campbell, Jr.
|
842
|
3 " Date: Apr 24, 2006
|
|
4 " Version: 7
|
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
|
|
14 if &cp || exists("g:loaded_vimball")
|
|
15 finish
|
|
16 endif
|
|
17 let s:keepcpo = &cpo
|
842
|
18 let g:loaded_vimball = "v7"
|
792
|
19 set cpo&vim
|
|
20
|
|
21 " =====================================================================
|
|
22 " Functions: {{{1
|
|
23
|
|
24 " ---------------------------------------------------------------------
|
|
25 " MkVimball: creates a vimball given a list of paths to files {{{2
|
|
26 " Vimball Format:
|
|
27 " path
|
|
28 " filesize
|
|
29 " [file]
|
|
30 " path
|
|
31 " filesize
|
|
32 " [file]
|
|
33 fun! vimball#MkVimball(line1,line2,writelevel,vimballname) range
|
|
34 " call Dfunc("MkVimball(line1=".a:line1." line2=".a:line2." writelevel=".a:writelevel." vimballname<".a:vimballname.">")
|
|
35 let vbname= substitute(a:vimballname,'\.[^.]*$','','e').'.vba'
|
|
36 if !a:writelevel && filereadable(vbname)
|
|
37 echohl Error | echoerr "(MkVimball) file<".vbname."> exists; use ! to insist" | echohl None
|
|
38 " call Dret("MkVimball : file<".vbname."> already exists; use ! to insist")
|
|
39 return
|
|
40 endif
|
|
41
|
|
42 " user option bypass
|
|
43 let eikeep= &ei
|
|
44 set ei=all
|
|
45
|
|
46 let home = substitute(&rtp,',.*$','','')
|
|
47 let curdir = getcwd()
|
|
48 exe "cd ".home
|
|
49
|
|
50 " record current tab, initialize while loop index
|
|
51 let curtabnr = tabpagenr()
|
|
52 let linenr = a:line1
|
|
53 " call Decho("curtabnr=".curtabnr)
|
|
54
|
|
55 while linenr <= a:line2
|
|
56 let svfile = getline(linenr)
|
|
57 " call Decho("svfile<".svfile.">")
|
|
58
|
|
59 if !filereadable(svfile)
|
|
60 echohl Error | echo "unable to read file<".svfile.">" | echohl None
|
|
61 let &ei= eikeep
|
|
62 exe "cd ".curdir
|
|
63 " call Dret("MkVimball")
|
|
64 return
|
|
65 endif
|
|
66
|
|
67 " create/switch to mkvimball tab
|
|
68 if !exists("vbtabnr")
|
|
69 tabnew
|
|
70 silent! file Vimball
|
|
71 let vbtabnr= tabpagenr()
|
|
72 else
|
|
73 exe "tabn ".vbtabnr
|
|
74 endif
|
|
75
|
|
76 let lastline= line("$") + 1
|
|
77 if lastline == 2 && getline("$") == ""
|
|
78 call setline(1,'" Vimball Archiver by Charles E. Campbell, Jr., Ph.D.')
|
|
79 call setline(2,'UseVimball')
|
|
80 call setline(3,'finish')
|
|
81 let lastline= 4
|
|
82 endif
|
|
83 call setline(lastline ,svfile)
|
|
84 call setline(lastline+1,0)
|
|
85 exe "$r ".svfile
|
|
86 call setline(lastline+1,line("$") - lastline - 1)
|
|
87 " call Decho("lastline=".lastline." line$=".line("$"))
|
|
88
|
|
89 " restore to normal tab
|
|
90 exe "tabn ".curtabnr
|
|
91 let linenr= linenr + 1
|
|
92 endwhile
|
|
93
|
|
94 " write the vimball
|
|
95 exe "tabn ".vbtabnr
|
|
96 exe "cd ".curdir
|
796
|
97 if a:writelevel
|
|
98 exe "w! ".vbname
|
|
99 else
|
|
100 exe "w ".vbname
|
792
|
101 endif
|
|
102 " call Decho("Vimball<".vbname."> created")
|
|
103 echo "Vimball<".vbname."> created"
|
|
104
|
|
105 " remove the evidence
|
|
106 setlocal nomod bh=wipe
|
|
107 exe "tabn ".curtabnr
|
|
108 exe "tabc ".vbtabnr
|
|
109
|
|
110 " restore options
|
|
111 let &ei= eikeep
|
|
112
|
|
113 " call Dret("MkVimball")
|
|
114 endfun
|
|
115
|
|
116 " ---------------------------------------------------------------------
|
|
117 " Vimball: {{{2
|
|
118 fun! vimball#Vimball(really)
|
|
119 " call Dfunc("Vimball(really=".a:really.")")
|
|
120
|
|
121 if getline(1) !~ '^" Vimball Archiver by Charles E. Campbell, Jr., Ph.D.$'
|
|
122 echoerr "(Vimball) The current file does not appear to be a Vimball!"
|
|
123 " call Dret("Vimball")
|
|
124 return
|
|
125 endif
|
|
126
|
|
127 " initialize
|
842
|
128 let fenkeep = &fen
|
792
|
129 let regakeep = @a
|
|
130 let eikeep = &ei
|
|
131 let vekeep = &ve
|
|
132 let makeep = getpos("'a")
|
|
133 let curtabnr = tabpagenr()
|
842
|
134 set ei=all ve=all nofen
|
792
|
135
|
|
136 " set up vimball tab
|
|
137 tabnew
|
|
138 silent! file Vimball
|
|
139 let vbtabnr= tabpagenr()
|
|
140 let didhelp= ""
|
|
141
|
|
142 " go to vim plugin home
|
|
143 let home = substitute(&rtp,',.*$','','')
|
|
144 let curdir = getcwd()
|
|
145 " call Decho("exe cd ".home)
|
|
146 exe "cd ".home
|
|
147 let linenr = 4
|
|
148 let filecnt = 0
|
|
149
|
|
150 " give title to listing of (extracted) files from Vimball Archive
|
|
151 if a:really
|
|
152 echohl Title | echomsg "Vimball Archive" | echohl None
|
|
153 else
|
|
154 echohl Title | echomsg "Vimball Archive Listing" | echohl None
|
|
155 endif
|
|
156
|
|
157 " apportion vimball contents to various files
|
|
158 " call Decho("exe tabn ".curtabnr)
|
|
159 exe "tabn ".curtabnr
|
|
160 " call Decho("linenr=".linenr." line$=".line("$"))
|
|
161 while 1 < linenr && linenr < line("$")
|
|
162 let fname = getline(linenr)
|
|
163 let fsize = getline(linenr+1)
|
|
164 let filecnt = filecnt + 1
|
|
165 if a:really
|
|
166 echomsg "extracted <".fname.">: ".fsize." lines"
|
|
167 else
|
|
168 echomsg "would extract <".fname.">: ".fsize." lines"
|
|
169 endif
|
842
|
170 " call Decho("using L#".linenr.": will extract file<".fname.">")
|
|
171 " call Decho("using L#".(linenr+1).": fsize=".fsize)
|
792
|
172
|
|
173 " make directories if they don't exist yet
|
842
|
174 " call Decho("making directories if they don't exist yet")
|
792
|
175 let fnamebuf= fname
|
|
176 while fnamebuf =~ '/'
|
|
177 let dirname = substitute(fnamebuf,'/.*$','','e')
|
|
178 let fnamebuf = substitute(fnamebuf,'^.\{-}/\(.*\)$','\1','e')
|
|
179 if !isdirectory(dirname)
|
|
180 " call Decho("making <".dirname.">")
|
|
181 call mkdir(dirname)
|
|
182 endif
|
|
183 exe "cd ".dirname
|
|
184 endwhile
|
|
185 exe "cd ".home
|
|
186
|
|
187 " grab specified qty of lines and place into "a" buffer
|
842
|
188 " (skip over path/filename and qty-lines)
|
|
189 let linenr = linenr + 2
|
|
190 let lastline = linenr + fsize - 1
|
|
191 " call Decho("exe ".linenr.",".lastline."yank a")
|
|
192 exe linenr.",".lastline."yank a"
|
792
|
193
|
|
194 " copy "a" buffer into tab
|
|
195 " call Decho('copy "a buffer into tab#'.vbtabnr)
|
|
196 exe "tabn ".vbtabnr
|
|
197 silent! %d
|
842
|
198 put a
|
|
199 1
|
|
200 d
|
792
|
201
|
|
202 " write tab to file
|
796
|
203 if a:really
|
|
204 " call Decho("exe w! ".fname)
|
|
205 exe "silent w! ".fname
|
|
206 endif
|
792
|
207
|
842
|
208 " return to tab with vimball
|
792
|
209 " call Decho("exe tabn ".curtabnr)
|
|
210 exe "tabn ".curtabnr
|
842
|
211
|
|
212 " set up help if its a doc/*.txt file
|
|
213 " call Decho("didhelp<".didhelp."> fname<".fname.">")
|
|
214 if a:really && didhelp == "" && fname =~ 'doc/[^/]\+\.txt$'
|
|
215 let didhelp= substitute(fname,'^\(.*\<doc\)[/\\][^.]*\.txt$','\1','e')
|
|
216 " call Decho("didhelp<".didhelp.">")
|
|
217 endif
|
|
218
|
|
219 " update for next file
|
792
|
220 " let oldlinenr = linenr " Decho
|
842
|
221 let linenr = linenr + fsize
|
|
222 " call Decho("update linenr= [linenr=".oldlinenr."] + [fsize=".fsize."] = ".linenr)
|
792
|
223 endwhile
|
|
224
|
|
225 " set up help
|
|
226 " call Decho("about to set up help: didhelp<".didhelp.">")
|
|
227 if didhelp != ""
|
|
228 " call Decho("exe helptags ".home."/".didhelp)
|
|
229 exe "helptags ".home."/".didhelp
|
|
230 echomsg "did helptags"
|
|
231 endif
|
|
232
|
|
233 " make sure a "Press ENTER..." prompt appears to keep the messages showing!
|
796
|
234 while filecnt <= &ch
|
792
|
235 echomsg " "
|
|
236 let filecnt= filecnt + 1
|
|
237 endwhile
|
|
238
|
|
239 " restore events, delete tab and buffer
|
|
240 exe "tabn ".vbtabnr
|
|
241 setlocal nomod bh=wipe
|
|
242 exe "tabn ".curtabnr
|
|
243 exe "tabc ".vbtabnr
|
842
|
244 let &ei = eikeep
|
|
245 let @a = regakeep
|
|
246 let &fen = fenkeep
|
792
|
247 if makeep[0] != 0
|
|
248 " restore mark a
|
|
249 " call Decho("restore mark-a: makeep=".string(makeep))
|
|
250 call setpos("'a",makeep)
|
|
251 ka
|
|
252 endif
|
|
253 exe "cd ".curdir
|
|
254
|
|
255 " call Dret("Vimball")
|
|
256 endfun
|
|
257
|
|
258 let &cpo= s:keepcpo
|
|
259 unlet s:keepcpo
|
|
260 " =====================================================================
|
|
261 " Modelines: {{{1
|
|
262 " vim: fdm=marker
|