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