dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

netrwFileHandlers.vim (10143B)


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