0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00
vim/runtime/plugin/NetrwFileHandlers.vim

313 lines
8.8 KiB
VimL
Raw Normal View History

2004-06-30 16:16:41 +00:00
" NetrwFileHandlers: contains various extension-based file handlers for
2004-07-29 08:43:53 +00:00
" netrw's browsers' x command ("eXecute launcher")
2005-08-01 21:54:37 +00:00
" Author: Charles E. Campbell, Jr.
2005-08-16 23:01:50 +00:00
" Date: Aug 15, 2005
" Version: 6
" Copyright: Copyright (C) 1999-2005 Charles E. Campbell, Jr. {{{1
2005-08-11 19:59:29 +00:00
" Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright
" notice is copied with it. Like anything else that's free,
2005-08-16 23:01:50 +00:00
" NetrwFileHandlers.vim is provided *as is* and comes with no
2005-08-11 19:59:29 +00:00
" warranty of any kind, either expressed or implied. In no
" event will the copyright holder be liable for any damages
" resulting from the use of this software.
2005-08-16 23:01:50 +00:00
"
" Rom 6:23 (WEB) For the wages of sin is death, but the free gift of God {{{1
" is eternal life in Christ Jesus our Lord.
2004-09-02 19:12:26 +00:00
2004-06-30 16:16:41 +00:00
" ---------------------------------------------------------------------
2005-08-01 21:54:37 +00:00
" Load Once: {{{1
2005-08-16 23:01:50 +00:00
if exists("g:loaded_NetrwFileHandlers") || &cp
2005-08-01 21:54:37 +00:00
finish
2004-09-02 19:12:26 +00:00
endif
2005-08-01 21:54:37 +00:00
let s:keepcpo= &cpo
set cpo&vim
2005-08-16 23:01:50 +00:00
let g:loaded_NetrwFileHandlers= "v6"
2004-06-30 16:16:41 +00:00
2004-09-02 19:12:26 +00:00
" ---------------------------------------------------------------------
" NetrwFileHandler_html: handles html when the user hits "x" when the {{{1
2004-07-02 15:38:35 +00:00
" cursor is atop a *.html file
2004-07-10 09:47:34 +00:00
fun! NetrwFileHandler_html(pagefile)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_html(".a:pagefile.")")
let page= substitute(a:pagefile,'^','file://','')
2004-06-30 16:16:41 +00:00
2004-07-10 09:47:34 +00:00
if executable("mozilla")
2005-08-01 21:54:37 +00:00
" call Decho("executing !mozilla ".page)
exe "!mozilla \"".page.'"'
2004-07-10 09:47:34 +00:00
elseif executable("netscape")
2005-08-01 21:54:37 +00:00
" call Decho("executing !netscape ".page)
exe "!netscape \"".page.'"'
2004-06-30 16:16:41 +00:00
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_html 0")
return 0
2004-06-30 16:16:41 +00:00
endif
2004-07-02 15:38:35 +00:00
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_html 1")
2004-07-10 09:47:34 +00:00
return 1
endfun
" ---------------------------------------------------------------------
2004-09-02 19:12:26 +00:00
" NetrwFileHandler_htm: handles html when the user hits "x" when the {{{1
2004-07-10 09:47:34 +00:00
" cursor is atop a *.htm file
fun! NetrwFileHandler_htm(pagefile)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_htm(".a:pagefile.")")
let page= substitute(a:pagefile,'^','file://','')
2004-07-10 09:47:34 +00:00
2004-07-02 15:38:35 +00:00
if executable("mozilla")
2005-08-01 21:54:37 +00:00
" call Decho("executing !mozilla ".page)
exe "!mozilla \"".page.'"'
2004-07-02 15:38:35 +00:00
elseif executable("netscape")
2005-08-01 21:54:37 +00:00
" call Decho("executing !netscape ".page)
exe "!netscape \"".page.'"'
2004-07-10 09:47:34 +00:00
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_htm 0")
return 0
2004-07-10 09:47:34 +00:00
endif
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_htm 1")
2004-07-10 09:47:34 +00:00
return 1
endfun
" ---------------------------------------------------------------------
2004-09-02 19:12:26 +00:00
" NetrwFileHandler_jpg: {{{1
2004-07-10 09:47:34 +00:00
fun! NetrwFileHandler_jpg(jpgfile)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_jpg(jpgfile<".a:jpgfile.">)")
2004-07-10 09:47:34 +00:00
if executable("gimp")
2005-08-01 21:54:37 +00:00
exe "silent! !gimp -s ".a:jpgfile
2004-07-10 09:47:34 +00:00
elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
2005-08-01 21:54:37 +00:00
" call Decho("silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT ".escape(a:jpgfile," []|'"))
exe "!".expand("$SystemRoot")."/SYSTEM32/MSPAINT \"".a:jpgfile.'"'
2004-07-10 09:47:34 +00:00
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_jpg 0")
return 0
2004-07-10 09:47:34 +00:00
endif
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_jpg 1")
2004-07-10 09:47:34 +00:00
return 1
endfun
" ---------------------------------------------------------------------
2004-09-02 19:12:26 +00:00
" NetrwFileHandler_gif: {{{1
2004-07-10 09:47:34 +00:00
fun! NetrwFileHandler_gif(giffile)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_gif(giffile<".a:giffile.">)")
2004-07-10 09:47:34 +00:00
if executable("gimp")
2005-08-01 21:54:37 +00:00
exe "silent! !gimp -s ".a:giffile
elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT \"".a:giffile.'"'
2004-07-10 09:47:34 +00:00
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_gif 0")
2004-07-10 09:47:34 +00:00
return 0
endif
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_gif 1")
2004-07-10 09:47:34 +00:00
return 1
endfun
" ---------------------------------------------------------------------
2004-09-02 19:12:26 +00:00
" NetrwFileHandler_png: {{{1
fun! NetrwFileHandler_png(pngfile)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_png(pngfile<".a:pngfile.">)")
2004-09-02 19:12:26 +00:00
if executable("gimp")
2005-08-01 21:54:37 +00:00
exe "silent! !gimp -s ".a:pngfile
elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT \"".a:pngfile.'"'
2004-09-02 19:12:26 +00:00
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_png 0")
2004-09-02 19:12:26 +00:00
return 0
endif
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_png 1")
2004-09-02 19:12:26 +00:00
return 1
endfun
" ---------------------------------------------------------------------
" NetrwFileHandler_pnm: {{{1
2004-07-10 09:47:34 +00:00
fun! NetrwFileHandler_pnm(pnmfile)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_pnm(pnmfile<".a:pnmfile.">)")
2004-07-10 09:47:34 +00:00
if executable("gimp")
2005-08-01 21:54:37 +00:00
exe "silent! !gimp -s ".a:pnmfile
elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT \"".a:pnmfile.'"'
2004-07-10 09:47:34 +00:00
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_pnm 0")
2004-07-10 09:47:34 +00:00
return 0
endif
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_pnm 1")
2004-07-10 09:47:34 +00:00
return 1
endfun
" ---------------------------------------------------------------------
2004-09-02 19:12:26 +00:00
" NetrwFileHandler_bmp: visualize bmp files {{{1
2004-07-10 09:47:34 +00:00
fun! NetrwFileHandler_bmp(bmpfile)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_bmp(bmpfile<".a:bmpfile.">)")
2004-07-10 09:47:34 +00:00
if executable("gimp")
2005-08-01 21:54:37 +00:00
exe "silent! !gimp -s ".a:bmpfile
2004-07-10 09:47:34 +00:00
elseif executable(expand("$SystemRoot")."/SYSTEM32/MSPAINT.EXE")
2005-08-01 21:54:37 +00:00
exe "silent! !".expand("$SystemRoot")."/SYSTEM32/MSPAINT \"".a:bmpfile.'"'
2004-07-10 09:47:34 +00:00
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_bmp 0")
2004-07-10 09:47:34 +00:00
return 0
2004-07-02 15:38:35 +00:00
endif
2004-06-30 16:16:41 +00:00
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_bmp 1")
2004-07-10 09:47:34 +00:00
return 1
2004-06-30 16:16:41 +00:00
endfun
" ---------------------------------------------------------------------
2004-09-02 19:12:26 +00:00
" NetrwFileHandler_pdf: visualize pdf files {{{1
2004-07-29 08:43:53 +00:00
fun! NetrwFileHandler_pdf(pdf)
2005-08-01 21:54:37 +00:00
" " call Dfunc("NetrwFileHandler_pdf(pdf<".a:pdf.">)")
if executable("gs")
exe 'silent! !gs "'.a:pdf.'"'
2004-07-29 08:43:53 +00:00
else
2005-08-01 21:54:37 +00:00
" " call Dret("NetrwFileHandler_pdf 0")
2004-07-29 08:43:53 +00:00
return 0
endif
2005-08-01 21:54:37 +00:00
" " call Dret("NetrwFileHandler_pdf 1")
2004-07-29 08:43:53 +00:00
return 1
endfun
" ---------------------------------------------------------------------
2004-09-02 19:12:26 +00:00
" NetrwFileHandler_doc: visualize doc files {{{1
2004-07-29 08:43:53 +00:00
fun! NetrwFileHandler_doc(doc)
2005-08-01 21:54:37 +00:00
" " call Dfunc("NetrwFileHandler_doc(doc<".a:doc.">)")
2004-07-29 08:43:53 +00:00
if executable("oowriter")
2005-08-01 21:54:37 +00:00
exe 'silent! !oowriter "'.a:doc.'"'
2004-07-29 08:43:53 +00:00
redraw!
else
2005-08-01 21:54:37 +00:00
" " call Dret("NetrwFileHandler_doc 0")
2004-07-29 08:43:53 +00:00
return 0
endif
2005-08-01 21:54:37 +00:00
" " call Dret("NetrwFileHandler_doc 1")
2004-07-29 08:43:53 +00:00
return 1
endfun
" ---------------------------------------------------------------------
2004-09-02 19:12:26 +00:00
" NetrwFileHandler_sxw: visualize sxw files {{{1
2004-07-29 08:43:53 +00:00
fun! NetrwFileHandler_sxw(sxw)
2005-08-01 21:54:37 +00:00
" " call Dfunc("NetrwFileHandler_sxw(sxw<".a:sxw.">)")
2004-07-29 08:43:53 +00:00
if executable("oowriter")
2005-08-01 21:54:37 +00:00
exe 'silent! !oowriter "'.a:sxw.'"'
2004-07-29 08:43:53 +00:00
redraw!
else
2005-08-01 21:54:37 +00:00
" " call Dret("NetrwFileHandler_sxw 0")
2004-07-29 08:43:53 +00:00
return 0
endif
2005-08-01 21:54:37 +00:00
" " call Dret("NetrwFileHandler_sxw 1")
2004-07-29 08:43:53 +00:00
return 1
endfun
" ---------------------------------------------------------------------
2004-09-02 19:12:26 +00:00
" NetrwFileHandler_xls: visualize xls files {{{1
2004-07-29 08:43:53 +00:00
fun! NetrwFileHandler_xls(xls)
2005-08-01 21:54:37 +00:00
" " call Dfunc("NetrwFileHandler_xls(xls<".a:xls.">)")
2004-07-29 08:43:53 +00:00
if executable("oocalc")
2005-08-01 21:54:37 +00:00
exe 'silent! !oocalc "'.a:xls.'"'
2004-07-29 08:43:53 +00:00
redraw!
else
2005-08-01 21:54:37 +00:00
" " call Dret("NetrwFileHandler_xls 0")
2004-09-02 19:12:26 +00:00
return 0
endif
2005-08-01 21:54:37 +00:00
" " call Dret("NetrwFileHandler_xls 1")
2004-09-02 19:12:26 +00:00
return 1
endfun
" ---------------------------------------------------------------------
" NetrwFileHandler_ps: handles PostScript files {{{1
fun! NetrwFileHandler_ps(ps)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_ps()")
2004-09-02 19:12:26 +00:00
if executable("gs")
2005-08-01 21:54:37 +00:00
exe "silent! !gs ".a:ps
2004-09-02 19:12:26 +00:00
redraw!
elseif executable("ghostscript")
2005-08-01 21:54:37 +00:00
exe "silent! !ghostscript ".a:ps
2004-09-02 19:12:26 +00:00
redraw!
elseif executable("ghostscript")
2005-08-01 21:54:37 +00:00
exe "silent! !ghostscript ".a:ps
2004-09-02 19:12:26 +00:00
redraw!
elseif executable("gswin32")
2005-08-01 21:54:37 +00:00
exe "silent! !gswin32 \"".a:ps.'"'
2004-09-02 19:12:26 +00:00
redraw!
2004-09-13 20:26:32 +00:00
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_ps 0")
2004-07-29 08:43:53 +00:00
return 0
endif
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_ps 1")
2004-07-29 08:43:53 +00:00
return 1
endfun
2004-09-13 20:26:32 +00:00
" ---------------------------------------------------------------------
" NetrwFileHandler_eps: handles encapsulated PostScript files {{{1
fun! NetrwFileHandler_eps(eps)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_ps()")
2004-09-13 20:26:32 +00:00
if executable("gs")
2005-08-01 21:54:37 +00:00
exe "silent! !gs ".a:eps
2004-09-13 20:26:32 +00:00
redraw!
elseif executable("ghostscript")
2005-08-01 21:54:37 +00:00
exe "silent! !ghostscript ".a:eps
2004-09-13 20:26:32 +00:00
redraw!
elseif executable("ghostscript")
2005-08-01 21:54:37 +00:00
exe "silent! !ghostscript ".a:eps
2004-09-13 20:26:32 +00:00
redraw!
elseif executable("gswin32")
2005-08-01 21:54:37 +00:00
exe "silent! !gswin32 \"".a:eps.'"'
2004-09-13 20:26:32 +00:00
redraw!
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_ps 0")
2004-09-13 20:26:32 +00:00
return 0
endif
endfun
" ---------------------------------------------------------------------
" NetrwFileHandler_fig: handles xfig files {{{1
fun! NetrwFileHandler_fig(fig)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_fig()")
2004-09-13 20:26:32 +00:00
if executable("xfig")
2005-08-01 21:54:37 +00:00
exe "silent! !xfig ".a:fig
2004-09-13 20:26:32 +00:00
redraw!
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_fig 0")
2004-09-13 20:26:32 +00:00
return 0
endif
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_fig 1")
2004-09-13 20:26:32 +00:00
return 1
endfun
" ---------------------------------------------------------------------
" NetrwFileHandler_obj: handles tgif's obj files {{{1
fun! NetrwFileHandler_obj(obj)
2005-08-01 21:54:37 +00:00
" call Dfunc("NetrwFileHandler_obj()")
2004-09-13 20:26:32 +00:00
if has("unix") && executable("tgif")
2005-08-01 21:54:37 +00:00
exe "silent! !tgif ".a:obj
2004-09-13 20:26:32 +00:00
redraw!
else
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_obj 0")
2004-09-13 20:26:32 +00:00
return 0
endif
2005-08-01 21:54:37 +00:00
" call Dret("NetrwFileHandler_obj 1")
2004-09-13 20:26:32 +00:00
return 1
endfun
2005-08-01 21:54:37 +00:00
let &cpo= s:keepcpo
2004-07-29 08:43:53 +00:00
" ---------------------------------------------------------------------
2005-08-01 21:54:37 +00:00
" Modelines: {{{1
" vim: ts=4 fdm=marker