comparison runtime/autoload/vimball.vim @ 844:d3bbb5dd3913 v7.0f02

updated for version 7.0f02
author vimboss
date Thu, 27 Apr 2006 00:02:13 +0000
parents 9f279ebda751
children 0fe7765dcb8e
comparison
equal deleted inserted replaced
843:9f279ebda751 844:d3bbb5dd3913
1 " vimball : construct a file containing both paths and files 1 " vimball : construct a file containing both paths and files
2 " Author: Charles E. Campbell, Jr. 2 " Author: Charles E. Campbell, Jr.
3 " Date: Apr 25, 2006 3 " Date: Apr 26, 2006
4 " Version: 8 4 " Version: 9
5 " GetLatestVimScripts: 1502 1 :AutoInstall: vimball.vim 5 " GetLatestVimScripts: 1502 1 :AutoInstall: vimball.vim
6 " Copyright: (c) 2004-2006 by Charles E. Campbell, Jr. 6 " Copyright: (c) 2004-2006 by Charles E. Campbell, Jr.
7 " The VIM LICENSE applies to Vimball.vim, and Vimball.txt 7 " The VIM LICENSE applies to Vimball.vim, and Vimball.txt
8 " (see |copyright|) except use "Vimball" instead of "Vim". 8 " (see |copyright|) except use "Vimball" instead of "Vim".
9 " No warranty, express or implied. 9 " No warranty, express or implied.
13 " Load Once: {{{1 13 " Load Once: {{{1
14 if &cp || exists("g:loaded_vimball") 14 if &cp || exists("g:loaded_vimball")
15 finish 15 finish
16 endif 16 endif
17 let s:keepcpo = &cpo 17 let s:keepcpo = &cpo
18 let g:loaded_vimball = "v8" 18 let g:loaded_vimball = "v9"
19 set cpo&vim 19 set cpo&vim
20 20
21 " ===================================================================== 21 " =====================================================================
22 " Functions: {{{1 22 " Functions: {{{1
23 23
38 " call Dret("MkVimball : file<".vbname."> already exists; use ! to insist") 38 " call Dret("MkVimball : file<".vbname."> already exists; use ! to insist")
39 return 39 return
40 endif 40 endif
41 41
42 " user option bypass 42 " user option bypass
43 let eikeep= &ei 43 let eikeep = &ei
44 set ei=all 44 let acdkeep = &acd
45 45 set ei=all noacd
46 let home = substitute(&rtp,',.*$','','') 46
47 " go to vim plugin home
48 for home in split(&rtp,',') + ['']
49 if isdirectory(home) | break | endif
50 endfor
51 if home == ""
52 let home= substitute(&rtp,',.*$','','')
53 endif
54 if (has("win32") || has("win95") || has("win64") || has("win16"))
55 let home= substitute(home,'/','\\','ge')
56 endif
57 " call Decho("home<".home.">")
58
59 " save current directory
47 let curdir = getcwd() 60 let curdir = getcwd()
48 exe "cd ".home 61 call s:ChgDir(home)
49 62
50 " record current tab, initialize while loop index 63 " record current tab, initialize while loop index
51 let curtabnr = tabpagenr() 64 let curtabnr = tabpagenr()
52 let linenr = a:line1 65 let linenr = a:line1
53 " call Decho("curtabnr=".curtabnr) 66 " call Decho("curtabnr=".curtabnr)
56 let svfile = getline(linenr) 69 let svfile = getline(linenr)
57 " call Decho("svfile<".svfile.">") 70 " call Decho("svfile<".svfile.">")
58 71
59 if !filereadable(svfile) 72 if !filereadable(svfile)
60 echohl Error | echo "unable to read file<".svfile.">" | echohl None 73 echohl Error | echo "unable to read file<".svfile.">" | echohl None
61 let &ei= eikeep 74 call s:ChgDir(curdir)
62 exe "cd ".curdir 75 let &ei = eikeep
76 let &acd = acdkeep
63 " call Dret("MkVimball") 77 " call Dret("MkVimball")
64 return 78 return
65 endif 79 endif
66 80
67 " create/switch to mkvimball tab 81 " create/switch to mkvimball tab
80 call setline(3,'finish') 94 call setline(3,'finish')
81 let lastline= 4 95 let lastline= 4
82 endif 96 endif
83 call setline(lastline ,svfile) 97 call setline(lastline ,svfile)
84 call setline(lastline+1,0) 98 call setline(lastline+1,0)
85 exe "$r ".svfile 99
100 " write the file from the tab
101 let svfilepath= s:Path(svfile,'')
102 " call Decho("exe $r ".svfilepath)
103 exe "$r ".svfilepath
104
86 call setline(lastline+1,line("$") - lastline - 1) 105 call setline(lastline+1,line("$") - lastline - 1)
87 " call Decho("lastline=".lastline." line$=".line("$")) 106 " call Decho("lastline=".lastline." line$=".line("$"))
88 107
89 " restore to normal tab 108 " restore to normal tab
90 exe "tabn ".curtabnr 109 exe "tabn ".curtabnr
91 let linenr= linenr + 1 110 let linenr= linenr + 1
92 endwhile 111 endwhile
93 112
94 " write the vimball 113 " write the vimball
95 exe "tabn ".vbtabnr 114 exe "tabn ".vbtabnr
96 exe "cd ".curdir 115 call s:ChgDir(curdir)
97 if a:writelevel 116 if a:writelevel
98 exe "w! ".vbname 117 let vbnamepath= s:Path(vbname,'')
118 " call Decho("exe w! ".vbnamepath)
119 exe "w! ".vbnamepath
99 else 120 else
100 exe "w ".vbname 121 let vbnamepath= s:Path(vbname,'')
122 " call Decho("exe w ".vbnamepath)
123 exe "w ".vbnamepath
101 endif 124 endif
102 " call Decho("Vimball<".vbname."> created") 125 " call Decho("Vimball<".vbname."> created")
103 echo "Vimball<".vbname."> created" 126 echo "Vimball<".vbname."> created"
104 127
105 " remove the evidence 128 " remove the evidence
106 setlocal nomod bh=wipe 129 setlocal nomod bh=wipe
107 exe "tabn ".curtabnr 130 exe "tabn ".curtabnr
108 exe "tabc ".vbtabnr 131 exe "tabc ".vbtabnr
109 132
110 " restore options 133 " restore options
111 let &ei= eikeep 134 let &ei = eikeep
135 let &acd = acdkeep
112 136
113 " call Dret("MkVimball") 137 " call Dret("MkVimball")
114 endfun 138 endfun
115 139
116 " --------------------------------------------------------------------- 140 " ---------------------------------------------------------------------
123 " call Dret("Vimball") 147 " call Dret("Vimball")
124 return 148 return
125 endif 149 endif
126 150
127 " initialize 151 " initialize
152 let acdkeep = &acd
128 let fenkeep = &fen 153 let fenkeep = &fen
129 let regakeep = @a 154 let regakeep = @a
130 let eikeep = &ei 155 let eikeep = &ei
131 let vekeep = &ve 156 let vekeep = &ve
132 let makeep = getpos("'a") 157 let makeep = getpos("'a")
133 let curtabnr = tabpagenr() 158 let curtabnr = tabpagenr()
134 set ei=all ve=all nofen 159 set ei=all ve=all nofen noacd
135 160
136 " set up vimball tab 161 " set up vimball tab
137 tabnew 162 tabnew
138 silent! file Vimball 163 silent! file Vimball
139 let vbtabnr= tabpagenr() 164 let vbtabnr= tabpagenr()
140 let didhelp= "" 165 let didhelp= ""
141 166
142 " go to vim plugin home 167 " go to vim plugin home
143 let home = substitute(&rtp,',.*$','','') 168 for home in split(&rtp,',') + ['']
169 if isdirectory(home) | break | endif
170 endfor
171 if home == ""
172 let home= substitute(&rtp,',.*$','','')
173 endif
174 if (has("win32") || has("win95") || has("win64") || has("win16"))
175 let home= substitute(home,'/','\\','ge')
176 endif
177 " call Decho("home<".home.">")
178
179 " save current directory
144 let curdir = getcwd() 180 let curdir = getcwd()
145 " call Decho("exe cd ".home) 181 call s:ChgDir(home)
146 exe "cd ".home 182
147 let linenr = 4 183 let linenr = 4
148 let filecnt = 0 184 let filecnt = 0
149 185
150 " give title to listing of (extracted) files from Vimball Archive 186 " give title to listing of (extracted) files from Vimball Archive
151 if a:really 187 if a:really
172 208
173 " make directories if they don't exist yet 209 " make directories if they don't exist yet
174 " call Decho("making directories if they don't exist yet") 210 " call Decho("making directories if they don't exist yet")
175 let fnamebuf= fname 211 let fnamebuf= fname
176 while fnamebuf =~ '/' 212 while fnamebuf =~ '/'
177 let dirname = substitute(fnamebuf,'/.*$','','e') 213 let dirname = home."/".substitute(fnamebuf,'/.*$','','e')
178 let fnamebuf = substitute(fnamebuf,'^.\{-}/\(.*\)$','\1','e') 214 let fnamebuf = substitute(fnamebuf,'^.\{-}/\(.*\)$','\1','e')
179 if !isdirectory(dirname) 215 if !isdirectory(dirname)
180 " call Decho("making <".dirname.">") 216 " call Decho("making <".dirname.">")
181 call mkdir(dirname) 217 call mkdir(dirname)
182 endif 218 endif
183 exe "cd ".dirname
184 endwhile 219 endwhile
185 exe "cd ".home 220 call s:ChgDir(home)
186 221
187 " grab specified qty of lines and place into "a" buffer 222 " grab specified qty of lines and place into "a" buffer
188 " (skip over path/filename and qty-lines) 223 " (skip over path/filename and qty-lines)
189 let linenr = linenr + 2 224 let linenr = linenr + 2
190 let lastline = linenr + fsize - 1 225 let lastline = linenr + fsize - 1
191 " call Decho("exe ".linenr.",".lastline."yank a") 226 " call Decho("exe ".linenr.",".lastline."yank a")
192 exe linenr.",".lastline."yank a" 227 exe "silent ".linenr.",".lastline."yank a"
193 228
194 " copy "a" buffer into tab 229 " copy "a" buffer into tab
195 " call Decho('copy "a buffer into tab#'.vbtabnr) 230 " call Decho('copy "a buffer into tab#'.vbtabnr)
196 exe "tabn ".vbtabnr 231 exe "tabn ".vbtabnr
197 silent! %d 232 silent! %d
198 put a 233 silent put a
199 1 234 1
200 d 235 silent d
201 236
202 " write tab to file 237 " write tab to file
203 if a:really 238 if a:really
204 " call Decho("exe w! ".fname) 239 let fnamepath= s:Path(home."/".fname,'')
205 exe "silent w! ".fname 240 " call Decho("exe w! ".fnamepath)
241 exe "silent w! ".fnamepath
242 echo "wrote ".fnamepath
206 endif 243 endif
207 244
208 " return to tab with vimball 245 " return to tab with vimball
209 " call Decho("exe tabn ".curtabnr) 246 " call Decho("exe tabn ".curtabnr)
210 exe "tabn ".curtabnr 247 exe "tabn ".curtabnr
223 endwhile 260 endwhile
224 261
225 " set up help 262 " set up help
226 " call Decho("about to set up help: didhelp<".didhelp.">") 263 " call Decho("about to set up help: didhelp<".didhelp.">")
227 if didhelp != "" 264 if didhelp != ""
228 " call Decho("exe helptags ".home."/".didhelp) 265 let htpath= escape(substitute(s:Path(home."/".didhelp,'"'),'"','','ge'),' ')
229 exe "helptags ".home."/".didhelp 266 " call Decho("exe helptags ".htpath)
230 echomsg "did helptags" 267 exe "helptags ".htpath
268 echo "did helptags"
231 endif 269 endif
232 270
233 " make sure a "Press ENTER..." prompt appears to keep the messages showing! 271 " make sure a "Press ENTER..." prompt appears to keep the messages showing!
234 while filecnt <= &ch 272 while filecnt <= &ch
235 echomsg " " 273 echomsg " "
242 exe "tabn ".curtabnr 280 exe "tabn ".curtabnr
243 exe "tabc ".vbtabnr 281 exe "tabc ".vbtabnr
244 let &ei = eikeep 282 let &ei = eikeep
245 let @a = regakeep 283 let @a = regakeep
246 let &fen = fenkeep 284 let &fen = fenkeep
285 let &acd = acdkeep
247 if makeep[0] != 0 286 if makeep[0] != 0
248 " restore mark a 287 " restore mark a
249 " call Decho("restore mark-a: makeep=".string(makeep)) 288 " call Decho("restore mark-a: makeep=".string(makeep))
250 call setpos("'a",makeep) 289 call setpos("'a",makeep)
251 ka 290 ka
252 endif 291 endif
253 exe "cd ".curdir 292 call s:ChgDir(curdir)
254 293
255 " call Dret("Vimball") 294 " call Dret("Vimball")
256 endfun 295 endfun
257 296
258 " --------------------------------------------------------------------- 297 " ---------------------------------------------------------------------
262 301
263 " decompression: 302 " decompression:
264 if expand("%") =~ '.*\.gz' && executable("gunzip") 303 if expand("%") =~ '.*\.gz' && executable("gunzip")
265 exe "!gunzip ".a:fname 304 exe "!gunzip ".a:fname
266 let fname= substitute(a:fname,'\.gz$','','') 305 let fname= substitute(a:fname,'\.gz$','','')
267 exe "e ".fname 306 exe "e ".escape(fname,' \')
268 echohl WarningMsg | echo "Source this file to extract it! (:so ".fname.")" | echohl None 307 call vimball#ShowMesg("Source this file to extract it! (:so %)")
269 elseif expand("%") =~ '.*\.bz2' && executable("bunzip2") 308 elseif expand("%") =~ '.*\.bz2' && executable("bunzip2")
270 exe "!bunzip2 ".a:fname 309 exe "!bunzip2 ".a:fname
271 let fname= substitute(a:fname,'\.bz2$','','') 310 let fname= substitute(a:fname,'\.bz2$','','')
272 exe "e ".fname 311 exe "e ".escape(fname,' \')
273 echohl WarningMsg | echo "Source this file to extract it! (:so ".fname.")" | echohl None 312 call vimball#ShowMesg("Source this file to extract it! (:so %)")
274 elseif expand("%") =~ '.*\.zip' && executable("unzip") 313 elseif expand("%") =~ '.*\.zip' && executable("unzip")
275 exe "!unzip ".a:fname 314 exe "!unzip ".a:fname
276 let fname= substitute(a:fname,'\.zip$','','') 315 let fname= substitute(a:fname,'\.zip$','','')
277 exe "e ".fname 316 exe "e ".escape(fname,' \')
278 echohl WarningMsg | echo "Source this file to extract it! (:so ".fname.")" | echohl None 317 call vimball#ShowMesg("Source this file to extract it! (:so %)")
279 endif 318 endif
280 319
281 " call Dret("Decompress") 320 " call Dret("Decompress")
282 endfun 321 endfun
283 322
323 " ---------------------------------------------------------------------
324 " ChgDir: change directory (in spite of Windoze) {{{2
325 fun! s:ChgDir(newdir)
326 " call Dfunc("ChgDir(newdir<".a:newdir.">)")
327 if (has("win32") || has("win95") || has("win64") || has("win16"))
328 exe 'silent cd '.escape(substitute(a:newdir,'/','\\','g'),' ')
329 else
330 exe 'silent cd '.escape(a:newdir,' ')
331 endif
332 " call Dret("ChgDir")
333 endfun
334
335 " ---------------------------------------------------------------------
336 " Path: {{{2
337 fun! s:Path(cmd,quote)
338 " call Dfunc("Path(cmd<".a:cmd."> quote<".a:quote.">)")
339 if (has("win32") || has("win95") || has("win64") || has("win16"))
340 let cmdpath= a:quote.substitute(a:cmd,'/','\\','ge').a:quote
341 else
342 let cmdpath= a:quote.a:cmd.a:quote
343 endif
344 if a:quote == ""
345 let cmdpath= escape(cmdpath,' ')
346 endif
347 " call Dret("Path <".cmdpath.">")
348 return cmdpath
349 endfun
350
351 " ---------------------------------------------------------------------
352 " vimball#ShowMesg: {{{2
353 fun! vimball#ShowMesg(msg)
354 " call Dfunc("vimball#ShowMesg(msg<".a:msg.">)")
355 let ich= 1
356 echohl WarningMsg | echo a:msg | echohl None
357 while ich < &ch
358 echo " "
359 let ich= ich + 1
360 endwhile
361 " call Dret("vimball#ShowMesg")
362 endfun
363
364 " ---------------------------------------------------------------------
284 let &cpo= s:keepcpo 365 let &cpo= s:keepcpo
285 unlet s:keepcpo 366 unlet s:keepcpo
286 " ===================================================================== 367 " =====================================================================
287 " Modelines: {{{1 368 " Modelines: {{{1
288 " vim: fdm=marker 369 " vim: fdm=marker