555
|
1 " netrwFileHandlers: contains various extension-based file handlers for
|
|
2 " netrw's browsers' x command ("eXecute launcher")
|
|
3 " Author: Charles E. Campbell, Jr.
|
1125
|
4 " Date: May 30, 2006
|
|
5 " Version: 9
|
555
|
6 " Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1
|
|
7 " Permission is hereby granted to use and distribute this code,
|
|
8 " with or without modifications, provided that this copyright
|
|
9 " notice is copied with it. Like anything else that's free,
|
|
10 " netrwFileHandlers.vim is provided *as is* and comes with no
|
|
11 " warranty of any kind, either expressed or implied. In no
|
|
12 " event will the copyright holder be liable for any damages
|
|
13 " resulting from the use of this software.
|
|
14 "
|
|
15 " Rom 6:23 (WEB) For the wages of sin is death, but the free gift of God {{{1
|
|
16 " is eternal life in Christ Jesus our Lord.
|
|
17
|
|
18 " ---------------------------------------------------------------------
|
|
19 " Load Once: {{{1
|
|
20 if exists("g:loaded_netrwFileHandlers") || &cp
|
|
21 finish
|
|
22 endif
|
|
23 let s:keepcpo= &cpo
|
|
24 set cpo&vim
|
1125
|
25 let g:loaded_netrwFileHandlers= "v9"
|
555
|
26
|
|
27 " ---------------------------------------------------------------------
|
857
|
28 " netrwFileHandlers#Invoke: {{{1
|
720
|
29 fun! netrwFileHandlers#Invoke(exten,fname)
|
|
30 " call Dfunc("netrwFileHandlers#Invoke(exten<".a:exten."> fname<".a:fname.">)")
|
1125
|
31 let fname= a:fname
|
|
32 " list of supported special characters. Consider rcs,v --- that can be
|
|
33 " supported with a NFH_rcsCOMMAv() handler
|
|
34 if a:fname =~ '[@:,$!=\-+%?;~]'
|
|
35 let specials= {
|
|
36 \ '@' : 'AT',
|
|
37 \ ':' : 'COLON',
|
|
38 \ ',' : 'COMMA',
|
|
39 \ '$' : 'DOLLAR',
|
|
40 \ '!' : 'EXCLAMATION',
|
|
41 \ '=' : 'EQUAL',
|
|
42 \ '-' : 'MINUS',
|
|
43 \ '+' : 'PLUS',
|
|
44 \ '%' : 'PERCENT',
|
|
45 \ '?' : 'QUESTION',
|
|
46 \ ';' : 'SEMICOLON',
|
|
47 \ '~' : 'TILDE'}
|
|
48 let fname= substitute(a:fname,'[@:,$!=\-+%?;~]','\=specials[submatch(0)]','ge')
|
|
49 " call Decho('fname<'.fname.'> done with dictionary')
|
|
50 endif
|
720
|
51
|
1125
|
52 if a:exten != "" && exists("*NFH_".a:exten)
|
|
53 " support user NFH_*() functions
|
|
54 " call Decho("let ret= netrwFileHandlers#NFH_".a:exten.'("'.fname.'")')
|
|
55 exe "let ret= NFH_".a:exten.'("'.fname.'")'
|
|
56 elseif a:exten != "" && exists("*s:NFH_".a:exten)
|
|
57 " use builtin-NFH_*() functions
|
|
58 " call Decho("let ret= netrwFileHandlers#NFH_".a:exten.'("'.fname.'")')
|
|
59 exe "let ret= s:NFH_".a:exten.'("'.fname.'")'
|
720
|
60 endif
|
|
61
|
|
62 " call Dret("netrwFileHandlers#Invoke 0 : ret=".ret)
|
|
63 return 0
|
555
|
64 endfun
|
|
65
|
|
66 " ---------------------------------------------------------------------
|
720
|
67 " s:NFH_html: handles html when the user hits "x" when the {{{1
|
555
|
68 " cursor is atop a *.html file
|
720
|
69 fun! s:NFH_html(pagefile)
|
|
70 " call Dfunc("s:NFH_html(".a:pagefile.")")
|
555
|
71
|
|
72 let page= substitute(a:pagefile,'^','file://','')
|
|
73
|
|
74 if executable("mozilla")
|
|
75 " call Decho("executing !mozilla ".page)
|
1125
|
76 exe "!mozilla ".g:netrw_shq.page.g:netrw_shq
|
555
|
77 elseif executable("netscape")
|
|
78 " call Decho("executing !netscape ".page)
|
1125
|
79 exe "!netscape ".g:netrw_shq..page.g:netrw_shq
|
555
|
80 else
|
720
|
81 " call Dret("s:NFH_html 0")
|
555
|
82 return 0
|
|
83 endif
|
|
84
|
720
|
85 " call Dret("s:NFH_html 1")
|
555
|
86 return 1
|
|
87 endfun
|
|
88
|
|
89 " ---------------------------------------------------------------------
|
720
|
90 " s:NFH_htm: handles html when the user hits "x" when the {{{1
|
555
|
91 " cursor is atop a *.htm file
|
720
|
92 fun! s:NFH_htm(pagefile)
|
|
93 " call Dfunc("s:NFH_htm(".a:pagefile.")")
|
555
|
94
|
|
95 let page= substitute(a:pagefile,'^','file://','')
|
|
96
|
|
97 if executable("mozilla")
|
|
98 " call Decho("executing !mozilla ".page)
|
1125
|
99 exe "!mozilla ".g:netrw_shq.page.g:netrw_shq
|
555
|
100 elseif executable("netscape")
|
|
101 " call Decho("executing !netscape ".page)
|
1125
|
102 exe "!netscape ".g:netrw_shq.page.g:netrw_shq
|
555
|
103 else
|
720
|
104 " call Dret("s:NFH_htm 0")
|
555
|
105 return 0
|
|
106 endif
|
|
107
|
720
|
108 " call Dret("s:NFH_htm 1")
|
555
|
109 return 1
|
|
110 endfun
|
|
111
|
|
112 " ---------------------------------------------------------------------
|
720
|
113 " s:NFH_jpg: {{{1
|
|
114 fun! s:NFH_jpg(jpgfile)
|
|
115 " call Dfunc("s:NFH_jpg(jpgfile<".a:jpgfile.">)")
|
555
|
116
|
|
117 if executable("gimp")
|
1125
|
118 exe "silent! !gimp -s ".g:netrw_shq.a:jpgfile.g:netrw_shq
|
555
|
119 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
|
|
120 " call Decho("silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".escape(a:jpgfile," []|'"))
|
1125
|
121 exe "!".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:jpgfile.g:netrw_shq
|
555
|
122 else
|
720
|
123 " call Dret("s:NFH_jpg 0")
|
555
|
124 return 0
|
|
125 endif
|
|
126
|
720
|
127 " call Dret("s:NFH_jpg 1")
|
555
|
128 return 1
|
|
129 endfun
|
|
130
|
|
131 " ---------------------------------------------------------------------
|
720
|
132 " s:NFH_gif: {{{1
|
|
133 fun! s:NFH_gif(giffile)
|
|
134 " call Dfunc("s:NFH_gif(giffile<".a:giffile.">)")
|
555
|
135
|
|
136 if executable("gimp")
|
1125
|
137 exe "silent! !gimp -s ".g:netrw_shq.a:giffile.g:netrw_shq
|
555
|
138 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
|
1125
|
139 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:giffile.g:netrw_shq
|
555
|
140 else
|
720
|
141 " call Dret("s:NFH_gif 0")
|
555
|
142 return 0
|
|
143 endif
|
|
144
|
720
|
145 " call Dret("s:NFH_gif 1")
|
555
|
146 return 1
|
|
147 endfun
|
|
148
|
|
149 " ---------------------------------------------------------------------
|
720
|
150 " s:NFH_png: {{{1
|
|
151 fun! s:NFH_png(pngfile)
|
|
152 " call Dfunc("s:NFH_png(pngfile<".a:pngfile.">)")
|
555
|
153
|
|
154 if executable("gimp")
|
1125
|
155 exe "silent! !gimp -s ".g:netrw_shq.a:pngfile.g:netrw_shq
|
555
|
156 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
|
1125
|
157 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:pngfile.g:netrw_shq
|
555
|
158 else
|
720
|
159 " call Dret("s:NFH_png 0")
|
555
|
160 return 0
|
|
161 endif
|
|
162
|
720
|
163 " call Dret("s:NFH_png 1")
|
555
|
164 return 1
|
|
165 endfun
|
|
166
|
|
167 " ---------------------------------------------------------------------
|
720
|
168 " s:NFH_pnm: {{{1
|
|
169 fun! s:NFH_pnm(pnmfile)
|
|
170 " call Dfunc("s:NFH_pnm(pnmfile<".a:pnmfile.">)")
|
555
|
171
|
|
172 if executable("gimp")
|
1125
|
173 exe "silent! !gimp -s ".g:netrw_shq.a:pnmfile.g:netrw_shq
|
555
|
174 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
|
1125
|
175 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:pnmfile.g:netrw_shq
|
555
|
176 else
|
720
|
177 " call Dret("s:NFH_pnm 0")
|
555
|
178 return 0
|
|
179 endif
|
|
180
|
720
|
181 " call Dret("s:NFH_pnm 1")
|
555
|
182 return 1
|
|
183 endfun
|
|
184
|
|
185 " ---------------------------------------------------------------------
|
720
|
186 " s:NFH_bmp: visualize bmp files {{{1
|
|
187 fun! s:NFH_bmp(bmpfile)
|
|
188 " call Dfunc("s:NFH_bmp(bmpfile<".a:bmpfile.">)")
|
555
|
189
|
|
190 if executable("gimp")
|
|
191 exe "silent! !gimp -s ".a:bmpfile
|
|
192 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
|
1125
|
193 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:bmpfile.g:netrw_shq
|
555
|
194 else
|
720
|
195 " call Dret("s:NFH_bmp 0")
|
555
|
196 return 0
|
|
197 endif
|
|
198
|
720
|
199 " call Dret("s:NFH_bmp 1")
|
555
|
200 return 1
|
|
201 endfun
|
|
202
|
|
203 " ---------------------------------------------------------------------
|
720
|
204 " s:NFH_pdf: visualize pdf files {{{1
|
|
205 fun! s:NFH_pdf(pdf)
|
|
206 " call Dfunc("s:NFH_pdf(pdf<".a:pdf.">)")
|
555
|
207 if executable("gs")
|
1125
|
208 exe 'silent! !gs '.g:netrw_shq.a:pdf.g:netrw_shq
|
|
209 elseif executable("pdftotext")
|
|
210 exe 'silent! pdftotext -nopgbrk '.g:netrw_shq.a:pdf.g:netrw_shq
|
555
|
211 else
|
720
|
212 " call Dret("s:NFH_pdf 0")
|
555
|
213 return 0
|
|
214 endif
|
|
215
|
720
|
216 " call Dret("s:NFH_pdf 1")
|
555
|
217 return 1
|
|
218 endfun
|
|
219
|
|
220 " ---------------------------------------------------------------------
|
720
|
221 " s:NFH_doc: visualize doc files {{{1
|
|
222 fun! s:NFH_doc(doc)
|
|
223 " call Dfunc("s:NFH_doc(doc<".a:doc.">)")
|
555
|
224
|
|
225 if executable("oowriter")
|
1125
|
226 exe 'silent! !oowriter '.g:netrw_shq.a:doc.g:netrw_shq
|
555
|
227 redraw!
|
|
228 else
|
720
|
229 " call Dret("s:NFH_doc 0")
|
555
|
230 return 0
|
|
231 endif
|
|
232
|
720
|
233 " call Dret("s:NFH_doc 1")
|
555
|
234 return 1
|
|
235 endfun
|
|
236
|
|
237 " ---------------------------------------------------------------------
|
720
|
238 " s:NFH_sxw: visualize sxw files {{{1
|
|
239 fun! s:NFH_sxw(sxw)
|
|
240 " call Dfunc("s:NFH_sxw(sxw<".a:sxw.">)")
|
555
|
241
|
|
242 if executable("oowriter")
|
1125
|
243 exe 'silent! !oowriter '.g:netrw_shq.a:sxw.g:netrw_shq
|
555
|
244 redraw!
|
|
245 else
|
720
|
246 " call Dret("s:NFH_sxw 0")
|
555
|
247 return 0
|
|
248 endif
|
|
249
|
720
|
250 " call Dret("s:NFH_sxw 1")
|
555
|
251 return 1
|
|
252 endfun
|
|
253
|
|
254 " ---------------------------------------------------------------------
|
720
|
255 " s:NFH_xls: visualize xls files {{{1
|
|
256 fun! s:NFH_xls(xls)
|
|
257 " call Dfunc("s:NFH_xls(xls<".a:xls.">)")
|
555
|
258
|
|
259 if executable("oocalc")
|
1125
|
260 exe 'silent! !oocalc '.g:netrw_shq.a:xls.g:netrw_shq
|
555
|
261 redraw!
|
|
262 else
|
720
|
263 " call Dret("s:NFH_xls 0")
|
555
|
264 return 0
|
|
265 endif
|
|
266
|
720
|
267 " call Dret("s:NFH_xls 1")
|
555
|
268 return 1
|
|
269 endfun
|
|
270
|
|
271 " ---------------------------------------------------------------------
|
720
|
272 " s:NFH_ps: handles PostScript files {{{1
|
|
273 fun! s:NFH_ps(ps)
|
|
274 " call Dfunc("s:NFH_ps(ps<".a:ps.">)")
|
555
|
275 if executable("gs")
|
720
|
276 " call Decho("exe silent! !gs ".a:ps)
|
1125
|
277 exe "silent! !gs ".g:netrw_shq.a:ps.g:netrw_shq
|
555
|
278 redraw!
|
|
279 elseif executable("ghostscript")
|
720
|
280 " call Decho("exe silent! !ghostscript ".a:ps)
|
1125
|
281 exe "silent! !ghostscript ".g:netrw_shq.a:ps.g:netrw_shq
|
555
|
282 redraw!
|
|
283 elseif executable("gswin32")
|
1125
|
284 " call Decho("exe silent! !gswin32 ".g:netrw_shq.a:ps.g:netrw_shq)
|
|
285 exe "silent! !gswin32 ".g:netrw_shq.a:ps.g:netrw_shq
|
555
|
286 redraw!
|
|
287 else
|
720
|
288 " call Dret("s:NFH_ps 0")
|
555
|
289 return 0
|
|
290 endif
|
|
291
|
720
|
292 " call Dret("s:NFH_ps 1")
|
555
|
293 return 1
|
|
294 endfun
|
|
295
|
|
296 " ---------------------------------------------------------------------
|
720
|
297 " s:NFH_eps: handles encapsulated PostScript files {{{1
|
|
298 fun! s:NFH_eps(eps)
|
|
299 " call Dfunc("s:NFH_eps()")
|
555
|
300 if executable("gs")
|
1125
|
301 exe "silent! !gs ".g:netrw_shq.a:eps.g:netrw_shq
|
555
|
302 redraw!
|
|
303 elseif executable("ghostscript")
|
1125
|
304 exe "silent! !ghostscript ".g:netrw_shq.a:eps.g:netrw_shq
|
555
|
305 redraw!
|
|
306 elseif executable("ghostscript")
|
1125
|
307 exe "silent! !ghostscript ".g:netrw_shq.a:eps.g:netrw_shq
|
555
|
308 redraw!
|
|
309 elseif executable("gswin32")
|
1125
|
310 exe "silent! !gswin32 ".g:netrw_shq.a:eps.g:netrw_shq
|
555
|
311 redraw!
|
|
312 else
|
720
|
313 " call Dret("s:NFH_eps 0")
|
555
|
314 return 0
|
|
315 endif
|
720
|
316 " call Dret("s:NFH_eps 0")
|
|
317 return 1
|
555
|
318 endfun
|
|
319
|
|
320 " ---------------------------------------------------------------------
|
720
|
321 " s:NFH_fig: handles xfig files {{{1
|
|
322 fun! s:NFH_fig(fig)
|
|
323 " call Dfunc("s:NFH_fig()")
|
555
|
324 if executable("xfig")
|
|
325 exe "silent! !xfig ".a:fig
|
|
326 redraw!
|
|
327 else
|
720
|
328 " call Dret("s:NFH_fig 0")
|
555
|
329 return 0
|
|
330 endif
|
|
331
|
720
|
332 " call Dret("s:NFH_fig 1")
|
555
|
333 return 1
|
|
334 endfun
|
|
335
|
|
336 " ---------------------------------------------------------------------
|
720
|
337 " s:NFH_obj: handles tgif's obj files {{{1
|
|
338 fun! s:NFH_obj(obj)
|
|
339 " call Dfunc("s:NFH_obj()")
|
555
|
340 if has("unix") && executable("tgif")
|
|
341 exe "silent! !tgif ".a:obj
|
|
342 redraw!
|
|
343 else
|
720
|
344 " call Dret("s:NFH_obj 0")
|
555
|
345 return 0
|
|
346 endif
|
|
347
|
720
|
348 " call Dret("s:NFH_obj 1")
|
555
|
349 return 1
|
|
350 endfun
|
|
351
|
|
352 let &cpo= s:keepcpo
|
|
353 " ---------------------------------------------------------------------
|
|
354 " Modelines: {{{1
|
1125
|
355 " vim: fdm=marker
|