1 " netrwFileHandlers: contains various extension-based file handlers for
2 " netrw's browsers' x command ("eXecute launcher")
3 " Author: Charles E. Campbell, Jr.
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.
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.
18 " ---------------------------------------------------------------------
20 if exists("g:loaded_netrwFileHandlers") || &cp
25 let g:loaded_netrwFileHandlers= "v9"
27 " ---------------------------------------------------------------------
28 " netrwFileHandlers#Invoke: {{{1
29 fun! netrwFileHandlers#Invoke(exten,fname)
30 " call Dfunc("netrwFileHandlers#Invoke(exten<".a:exten."> 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 =~ '[@:,$!=\-+%?;~]'
40 \ '!' : 'EXCLAMATION',
48 let fname= substitute(a:fname,'[@:,$!=\-+%?;~]','\=specials[submatch(0)]','ge')
49 " call Decho('fname<'.fname.'> done with dictionary')
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.'")'
62 " call Dret("netrwFileHandlers#Invoke 0 : ret=".ret)
66 " ---------------------------------------------------------------------
67 " s:NFH_html: handles html when the user hits "x" when the {{{1
68 " cursor is atop a *.html file
69 fun! s:NFH_html(pagefile)
70 " call Dfunc("s:NFH_html(".a:pagefile.")")
72 let page= substitute(a:pagefile,'^','file://','')
74 if executable("mozilla")
75 " call Decho("executing !mozilla ".page)
76 exe "!mozilla ".g:netrw_shq.page.g:netrw_shq
77 elseif executable("netscape")
78 " call Decho("executing !netscape ".page)
79 exe "!netscape ".g:netrw_shq..page.g:netrw_shq
81 " call Dret("s:NFH_html 0")
85 " call Dret("s:NFH_html 1")
89 " ---------------------------------------------------------------------
90 " s:NFH_htm: handles html when the user hits "x" when the {{{1
91 " cursor is atop a *.htm file
92 fun! s:NFH_htm(pagefile)
93 " call Dfunc("s:NFH_htm(".a:pagefile.")")
95 let page= substitute(a:pagefile,'^','file://','')
97 if executable("mozilla")
98 " call Decho("executing !mozilla ".page)
99 exe "!mozilla ".g:netrw_shq.page.g:netrw_shq
100 elseif executable("netscape")
101 " call Decho("executing !netscape ".page)
102 exe "!netscape ".g:netrw_shq.page.g:netrw_shq
104 " call Dret("s:NFH_htm 0")
108 " call Dret("s:NFH_htm 1")
112 " ---------------------------------------------------------------------
114 fun! s:NFH_jpg(jpgfile)
115 " call Dfunc("s:NFH_jpg(jpgfile<".a:jpgfile.">)")
117 if executable("gimp")
118 exe "silent! !gimp -s ".g:netrw_shq.a:jpgfile.g:netrw_shq
119 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
120 " call Decho("silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".escape(a:jpgfile," []|'"))
121 exe "!".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:jpgfile.g:netrw_shq
123 " call Dret("s:NFH_jpg 0")
127 " call Dret("s:NFH_jpg 1")
131 " ---------------------------------------------------------------------
133 fun! s:NFH_gif(giffile)
134 " call Dfunc("s:NFH_gif(giffile<".a:giffile.">)")
136 if executable("gimp")
137 exe "silent! !gimp -s ".g:netrw_shq.a:giffile.g:netrw_shq
138 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
139 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:giffile.g:netrw_shq
141 " call Dret("s:NFH_gif 0")
145 " call Dret("s:NFH_gif 1")
149 " ---------------------------------------------------------------------
151 fun! s:NFH_png(pngfile)
152 " call Dfunc("s:NFH_png(pngfile<".a:pngfile.">)")
154 if executable("gimp")
155 exe "silent! !gimp -s ".g:netrw_shq.a:pngfile.g:netrw_shq
156 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
157 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:pngfile.g:netrw_shq
159 " call Dret("s:NFH_png 0")
163 " call Dret("s:NFH_png 1")
167 " ---------------------------------------------------------------------
169 fun! s:NFH_pnm(pnmfile)
170 " call Dfunc("s:NFH_pnm(pnmfile<".a:pnmfile.">)")
172 if executable("gimp")
173 exe "silent! !gimp -s ".g:netrw_shq.a:pnmfile.g:netrw_shq
174 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
175 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:pnmfile.g:netrw_shq
177 " call Dret("s:NFH_pnm 0")
181 " call Dret("s:NFH_pnm 1")
185 " ---------------------------------------------------------------------
186 " s:NFH_bmp: visualize bmp files {{{1
187 fun! s:NFH_bmp(bmpfile)
188 " call Dfunc("s:NFH_bmp(bmpfile<".a:bmpfile.">)")
190 if executable("gimp")
191 exe "silent! !gimp -s ".a:bmpfile
192 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
193 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".g:netrw_shq.a:bmpfile.g:netrw_shq
195 " call Dret("s:NFH_bmp 0")
199 " call Dret("s:NFH_bmp 1")
203 " ---------------------------------------------------------------------
204 " s:NFH_pdf: visualize pdf files {{{1
206 " call Dfunc("s:NFH_pdf(pdf<".a:pdf.">)")
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
212 " call Dret("s:NFH_pdf 0")
216 " call Dret("s:NFH_pdf 1")
220 " ---------------------------------------------------------------------
221 " s:NFH_doc: visualize doc files {{{1
223 " call Dfunc("s:NFH_doc(doc<".a:doc.">)")
225 if executable("oowriter")
226 exe 'silent! !oowriter '.g:netrw_shq.a:doc.g:netrw_shq
229 " call Dret("s:NFH_doc 0")
233 " call Dret("s:NFH_doc 1")
237 " ---------------------------------------------------------------------
238 " s:NFH_sxw: visualize sxw files {{{1
240 " call Dfunc("s:NFH_sxw(sxw<".a:sxw.">)")
242 if executable("oowriter")
243 exe 'silent! !oowriter '.g:netrw_shq.a:sxw.g:netrw_shq
246 " call Dret("s:NFH_sxw 0")
250 " call Dret("s:NFH_sxw 1")
254 " ---------------------------------------------------------------------
255 " s:NFH_xls: visualize xls files {{{1
257 " call Dfunc("s:NFH_xls(xls<".a:xls.">)")
259 if executable("oocalc")
260 exe 'silent! !oocalc '.g:netrw_shq.a:xls.g:netrw_shq
263 " call Dret("s:NFH_xls 0")
267 " call Dret("s:NFH_xls 1")
271 " ---------------------------------------------------------------------
272 " s:NFH_ps: handles PostScript files {{{1
274 " call Dfunc("s:NFH_ps(ps<".a:ps.">)")
276 " call Decho("exe silent! !gs ".a:ps)
277 exe "silent! !gs ".g:netrw_shq.a:ps.g:netrw_shq
279 elseif executable("ghostscript")
280 " call Decho("exe silent! !ghostscript ".a:ps)
281 exe "silent! !ghostscript ".g:netrw_shq.a:ps.g:netrw_shq
283 elseif executable("gswin32")
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
288 " call Dret("s:NFH_ps 0")
292 " call Dret("s:NFH_ps 1")
296 " ---------------------------------------------------------------------
297 " s:NFH_eps: handles encapsulated PostScript files {{{1
299 " call Dfunc("s:NFH_eps()")
301 exe "silent! !gs ".g:netrw_shq.a:eps.g:netrw_shq
303 elseif executable("ghostscript")
304 exe "silent! !ghostscript ".g:netrw_shq.a:eps.g:netrw_shq
306 elseif executable("ghostscript")
307 exe "silent! !ghostscript ".g:netrw_shq.a:eps.g:netrw_shq
309 elseif executable("gswin32")
310 exe "silent! !gswin32 ".g:netrw_shq.a:eps.g:netrw_shq
313 " call Dret("s:NFH_eps 0")
316 " call Dret("s:NFH_eps 0")
320 " ---------------------------------------------------------------------
321 " s:NFH_fig: handles xfig files {{{1
323 " call Dfunc("s:NFH_fig()")
324 if executable("xfig")
325 exe "silent! !xfig ".a:fig
328 " call Dret("s:NFH_fig 0")
332 " call Dret("s:NFH_fig 1")
336 " ---------------------------------------------------------------------
337 " s:NFH_obj: handles tgif's obj files {{{1
339 " call Dfunc("s:NFH_obj()")
340 if has("unix") && executable("tgif")
341 exe "silent! !tgif ".a:obj
344 " call Dret("s:NFH_obj 0")
348 " call Dret("s:NFH_obj 1")
353 " ---------------------------------------------------------------------