1" netrwFileHandlers: contains various extension-based file handlers for 2" netrw's browsers' x command ("eXecute launcher") 3" Author: Charles E. Campbell, Jr. 4" Date: Mar 22, 2006 5" Version: 8 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 20if exists("g:loaded_netrwFileHandlers") || &cp 21 finish 22endif 23let s:keepcpo= &cpo 24set cpo&vim 25let g:loaded_netrwFileHandlers= "v8" 26 27" --------------------------------------------------------------------- 28" netrwFileHandlers#Invoke: {{{2 29fun! netrwFileHandlers#Invoke(exten,fname) 30" call Dfunc("netrwFileHandlers#Invoke(exten<".a:exten."> fname<".a:fname.">)") 31 32 if a:exten != "" && exists("*s:NFH_".a:exten) 33" call Decho("let ret= netrwFileHandlers#NFH_".a:exten.'("'.a:fname.'")') 34 exe "let ret= s:NFH_".a:exten.'("'.a:fname.'")' 35 endif 36 37" call Dret("netrwFileHandlers#Invoke 0 : ret=".ret) 38 return 0 39endfun 40 41" --------------------------------------------------------------------- 42" s:NFH_html: handles html when the user hits "x" when the {{{1 43" cursor is atop a *.html file 44fun! s:NFH_html(pagefile) 45" call Dfunc("s:NFH_html(".a:pagefile.")") 46 47 let page= substitute(a:pagefile,'^','file://','') 48 49 if executable("mozilla") 50" call Decho("executing !mozilla ".page) 51 exe "!mozilla \"".page.'"' 52 elseif executable("netscape") 53" call Decho("executing !netscape ".page) 54 exe "!netscape \"".page.'"' 55 else 56" call Dret("s:NFH_html 0") 57 return 0 58 endif 59 60" call Dret("s:NFH_html 1") 61 return 1 62endfun 63 64" --------------------------------------------------------------------- 65" s:NFH_htm: handles html when the user hits "x" when the {{{1 66" cursor is atop a *.htm file 67fun! s:NFH_htm(pagefile) 68" call Dfunc("s:NFH_htm(".a:pagefile.")") 69 70 let page= substitute(a:pagefile,'^','file://','') 71 72 if executable("mozilla") 73" call Decho("executing !mozilla ".page) 74 exe "!mozilla \"".page.'"' 75 elseif executable("netscape") 76" call Decho("executing !netscape ".page) 77 exe "!netscape \"".page.'"' 78 else 79" call Dret("s:NFH_htm 0") 80 return 0 81 endif 82 83" call Dret("s:NFH_htm 1") 84 return 1 85endfun 86 87" --------------------------------------------------------------------- 88" s:NFH_jpg: {{{1 89fun! s:NFH_jpg(jpgfile) 90" call Dfunc("s:NFH_jpg(jpgfile<".a:jpgfile.">)") 91 92 if executable("gimp") 93 exe "silent! !gimp -s ".a:jpgfile 94 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") 95" call Decho("silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".escape(a:jpgfile," []|'")) 96 exe "!".expand("$SystemRoot")."/SYSTEM32/MSPAINT \"".a:jpgfile.'"' 97 else 98" call Dret("s:NFH_jpg 0") 99 return 0 100 endif 101 102" call Dret("s:NFH_jpg 1") 103 return 1 104endfun 105 106" --------------------------------------------------------------------- 107" s:NFH_gif: {{{1 108fun! s:NFH_gif(giffile) 109" call Dfunc("s:NFH_gif(giffile<".a:giffile.">)") 110 111 if executable("gimp") 112 exe "silent! !gimp -s ".a:giffile 113 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") 114 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT \"".a:giffile.'"' 115 else 116" call Dret("s:NFH_gif 0") 117 return 0 118 endif 119 120" call Dret("s:NFH_gif 1") 121 return 1 122endfun 123 124" --------------------------------------------------------------------- 125" s:NFH_png: {{{1 126fun! s:NFH_png(pngfile) 127" call Dfunc("s:NFH_png(pngfile<".a:pngfile.">)") 128 129 if executable("gimp") 130 exe "silent! !gimp -s ".a:pngfile 131 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") 132 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT \"".a:pngfile.'"' 133 else 134" call Dret("s:NFH_png 0") 135 return 0 136 endif 137 138" call Dret("s:NFH_png 1") 139 return 1 140endfun 141 142" --------------------------------------------------------------------- 143" s:NFH_pnm: {{{1 144fun! s:NFH_pnm(pnmfile) 145" call Dfunc("s:NFH_pnm(pnmfile<".a:pnmfile.">)") 146 147 if executable("gimp") 148 exe "silent! !gimp -s ".a:pnmfile 149 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") 150 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT \"".a:pnmfile.'"' 151 else 152" call Dret("s:NFH_pnm 0") 153 return 0 154 endif 155 156" call Dret("s:NFH_pnm 1") 157 return 1 158endfun 159 160" --------------------------------------------------------------------- 161" s:NFH_bmp: visualize bmp files {{{1 162fun! s:NFH_bmp(bmpfile) 163" call Dfunc("s:NFH_bmp(bmpfile<".a:bmpfile.">)") 164 165 if executable("gimp") 166 exe "silent! !gimp -s ".a:bmpfile 167 elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE") 168 exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT \"".a:bmpfile.'"' 169 else 170" call Dret("s:NFH_bmp 0") 171 return 0 172 endif 173 174" call Dret("s:NFH_bmp 1") 175 return 1 176endfun 177 178" --------------------------------------------------------------------- 179" s:NFH_pdf: visualize pdf files {{{1 180fun! s:NFH_pdf(pdf) 181" call Dfunc("s:NFH_pdf(pdf<".a:pdf.">)") 182 if executable("gs") 183 exe 'silent! !gs "'.a:pdf.'"' 184 else 185" call Dret("s:NFH_pdf 0") 186 return 0 187 endif 188 189" call Dret("s:NFH_pdf 1") 190 return 1 191endfun 192 193" --------------------------------------------------------------------- 194" s:NFH_doc: visualize doc files {{{1 195fun! s:NFH_doc(doc) 196" call Dfunc("s:NFH_doc(doc<".a:doc.">)") 197 198 if executable("oowriter") 199 exe 'silent! !oowriter "'.a:doc.'"' 200 redraw! 201 else 202" call Dret("s:NFH_doc 0") 203 return 0 204 endif 205 206" call Dret("s:NFH_doc 1") 207 return 1 208endfun 209 210" --------------------------------------------------------------------- 211" s:NFH_sxw: visualize sxw files {{{1 212fun! s:NFH_sxw(sxw) 213" call Dfunc("s:NFH_sxw(sxw<".a:sxw.">)") 214 215 if executable("oowriter") 216 exe 'silent! !oowriter "'.a:sxw.'"' 217 redraw! 218 else 219" call Dret("s:NFH_sxw 0") 220 return 0 221 endif 222 223" call Dret("s:NFH_sxw 1") 224 return 1 225endfun 226 227" --------------------------------------------------------------------- 228" s:NFH_xls: visualize xls files {{{1 229fun! s:NFH_xls(xls) 230" call Dfunc("s:NFH_xls(xls<".a:xls.">)") 231 232 if executable("oocalc") 233 exe 'silent! !oocalc "'.a:xls.'"' 234 redraw! 235 else 236" call Dret("s:NFH_xls 0") 237 return 0 238 endif 239 240" call Dret("s:NFH_xls 1") 241 return 1 242endfun 243 244" --------------------------------------------------------------------- 245" s:NFH_ps: handles PostScript files {{{1 246fun! s:NFH_ps(ps) 247" call Dfunc("s:NFH_ps(ps<".a:ps.">)") 248 if executable("gs") 249" call Decho("exe silent! !gs ".a:ps) 250 exe "silent! !gs ".a:ps 251 redraw! 252 elseif executable("ghostscript") 253" call Decho("exe silent! !ghostscript ".a:ps) 254 exe "silent! !ghostscript ".a:ps 255 redraw! 256 elseif executable("gswin32") 257" call Decho("exe silent! !gswin32 \"".a:ps.'"') 258 exe "silent! !gswin32 \"".a:ps.'"' 259 redraw! 260 else 261" call Dret("s:NFH_ps 0") 262 return 0 263 endif 264 265" call Dret("s:NFH_ps 1") 266 return 1 267endfun 268 269" --------------------------------------------------------------------- 270" s:NFH_eps: handles encapsulated PostScript files {{{1 271fun! s:NFH_eps(eps) 272" call Dfunc("s:NFH_eps()") 273 if executable("gs") 274 exe "silent! !gs ".a:eps 275 redraw! 276 elseif executable("ghostscript") 277 exe "silent! !ghostscript ".a:eps 278 redraw! 279 elseif executable("ghostscript") 280 exe "silent! !ghostscript ".a:eps 281 redraw! 282 elseif executable("gswin32") 283 exe "silent! !gswin32 \"".a:eps.'"' 284 redraw! 285 else 286" call Dret("s:NFH_eps 0") 287 return 0 288 endif 289" call Dret("s:NFH_eps 0") 290 return 1 291endfun 292 293" --------------------------------------------------------------------- 294" s:NFH_fig: handles xfig files {{{1 295fun! s:NFH_fig(fig) 296" call Dfunc("s:NFH_fig()") 297 if executable("xfig") 298 exe "silent! !xfig ".a:fig 299 redraw! 300 else 301" call Dret("s:NFH_fig 0") 302 return 0 303 endif 304 305" call Dret("s:NFH_fig 1") 306 return 1 307endfun 308 309" --------------------------------------------------------------------- 310" s:NFH_obj: handles tgif's obj files {{{1 311fun! s:NFH_obj(obj) 312" call Dfunc("s:NFH_obj()") 313 if has("unix") && executable("tgif") 314 exe "silent! !tgif ".a:obj 315 redraw! 316 else 317" call Dret("s:NFH_obj 0") 318 return 0 319 endif 320 321" call Dret("s:NFH_obj 1") 322 return 1 323endfun 324 325let &cpo= s:keepcpo 326" --------------------------------------------------------------------- 327" Modelines: {{{1 328" vim: ts=4 fdm=marker 329