| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | " zip.vim: Handles browsing zipfiles | 
					
						
							|  |  |  | "            AUTOLOAD PORTION | 
					
						
							| 
									
										
										
										
											2020-01-09 21:46:04 +01:00
										 |  |  | " Date:		Jan 07, 2020 | 
					
						
							|  |  |  | " Version:	30 | 
					
						
							|  |  |  | " Maintainer:	Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM> | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | " License:	Vim License  (see vim's :help license) | 
					
						
							| 
									
										
										
										
											2020-01-09 21:46:04 +01:00
										 |  |  | " Copyright:    Copyright (C) 2005-2019 Charles E. Campbell {{{1 | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +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, | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  | "               zip.vim and zipPlugin.vim are provided *as is* and comes with | 
					
						
							|  |  |  | "               no warranty of any kind, either expressed or implied. By using | 
					
						
							|  |  |  | "               this plugin, you agree that in no event will the copyright | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "               holder be liable for any damages resulting from the use | 
					
						
							|  |  |  | "               of this software. | 
					
						
							| 
									
										
										
										
											2013-07-04 22:50:40 +02:00
										 |  |  | "redraw!|call DechoSep()|call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " --------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | " Load Once: {{{1 | 
					
						
							| 
									
										
										
										
											2010-05-14 23:24:24 +02:00
										 |  |  | if &cp || exists("g:loaded_zip") | 
					
						
							|  |  |  |  finish | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2020-01-09 21:46:04 +01:00
										 |  |  | let g:loaded_zip= "v30" | 
					
						
							| 
									
										
										
										
											2010-05-14 23:24:24 +02:00
										 |  |  | if v:version < 702 | 
					
						
							|  |  |  |  echohl WarningMsg | 
					
						
							| 
									
										
										
										
											2016-09-16 20:02:31 +02:00
										 |  |  |  echo "***warning*** this version of zip needs vim 7.2 or later" | 
					
						
							| 
									
										
										
										
											2010-05-14 23:24:24 +02:00
										 |  |  |  echohl Normal | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |  finish | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2010-05-14 23:24:24 +02:00
										 |  |  | let s:keepcpo= &cpo | 
					
						
							|  |  |  | set cpo&vim | 
					
						
							| 
									
										
										
										
											2013-07-04 22:50:40 +02:00
										 |  |  | "DechoTabOn | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-23 22:59:57 +00:00
										 |  |  | let s:zipfile_escape = ' ?&;\' | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | let s:ERROR          = 2 | 
					
						
							|  |  |  | let s:WARNING        = 1 | 
					
						
							|  |  |  | let s:NOTE           = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " --------------------------------------------------------------------- | 
					
						
							|  |  |  | "  Global Values: {{{1 | 
					
						
							|  |  |  | if !exists("g:zip_shq") | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |  if &shq != "" | 
					
						
							|  |  |  |   let g:zip_shq= &shq | 
					
						
							|  |  |  |  elseif has("unix") | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   let g:zip_shq= "'" | 
					
						
							|  |  |  |  else | 
					
						
							|  |  |  |   let g:zip_shq= '"' | 
					
						
							|  |  |  |  endif | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2007-05-10 18:25:20 +00:00
										 |  |  | if !exists("g:zip_zipcmd") | 
					
						
							|  |  |  |  let g:zip_zipcmd= "zip" | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | if !exists("g:zip_unzipcmd") | 
					
						
							|  |  |  |  let g:zip_unzipcmd= "unzip" | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2016-09-16 20:02:31 +02:00
										 |  |  | if !exists("g:zip_extractcmd") | 
					
						
							|  |  |  |  let g:zip_extractcmd= g:zip_unzipcmd | 
					
						
							|  |  |  | endif | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " ---------------- | 
					
						
							|  |  |  | "  Functions: {{{1 | 
					
						
							|  |  |  | " ---------------- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " --------------------------------------------------------------------- | 
					
						
							|  |  |  | " zip#Browse: {{{2 | 
					
						
							|  |  |  | fun! zip#Browse(zipfile) | 
					
						
							|  |  |  | "  call Dfunc("zip#Browse(zipfile<".a:zipfile.">)") | 
					
						
							| 
									
										
										
										
											2020-01-14 19:29:13 +01:00
										 |  |  |   " sanity check: ensure that the zipfile has "PK" as its first two letters | 
					
						
							| 
									
										
										
										
											2013-07-04 22:50:40 +02:00
										 |  |  |   "               (zipped files have a leading PK as a "magic cookie") | 
					
						
							|  |  |  |   if !filereadable(a:zipfile) || readfile(a:zipfile, "", 1)[0] !~ '^PK' | 
					
						
							| 
									
										
										
										
											2020-01-09 21:46:04 +01:00
										 |  |  |    exe "noswapfile noautocmd noswapfile e ".fnameescape(a:zipfile) | 
					
						
							| 
									
										
										
										
											2013-07-04 22:50:40 +02:00
										 |  |  | "   call Dret("zip#Browse : not a zipfile<".a:zipfile.">") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  | "  else        " Decho | 
					
						
							| 
									
										
										
										
											2020-01-14 19:29:13 +01:00
										 |  |  | "   call Decho("zip#Browse: a:zipfile<".a:zipfile."> passed PK test - it's a zip file") | 
					
						
							| 
									
										
										
										
											2013-07-04 22:50:40 +02:00
										 |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |   let repkeep= &report | 
					
						
							|  |  |  |   set report=10 | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   " sanity checks | 
					
						
							| 
									
										
										
										
											2008-08-06 17:06:04 +00:00
										 |  |  |   if !exists("*fnameescape") | 
					
						
							|  |  |  |    if &verbose > 1 | 
					
						
							|  |  |  |     echoerr "the zip plugin is not available (your vim doens't support fnameescape())" | 
					
						
							|  |  |  |    endif | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2007-05-10 18:25:20 +00:00
										 |  |  |   if !executable(g:zip_unzipcmd) | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |    redraw! | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |    echohl Error | echo "***error*** (zip#Browse) unzip not available on your system" | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | "   call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |    let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "   call Dret("zip#Browse") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   if !filereadable(a:zipfile) | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |    if a:zipfile !~# '^\a\+://' | 
					
						
							| 
									
										
										
										
											2020-01-14 19:29:13 +01:00
										 |  |  |     " if it's an url, don't complain, let url-handlers such as vim do its thing | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |     redraw! | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |     echohl Error | echo "***error*** (zip#Browse) File not readable<".a:zipfile.">" | echohl None | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | "    call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |    endif | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |    let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  | "   call Dret("zip#Browse : file<".a:zipfile."> not readable") | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2006-03-23 22:59:57 +00:00
										 |  |  | "  call Decho("passed sanity checks") | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   if &ma != 1 | 
					
						
							|  |  |  |    set ma | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2007-05-10 18:25:20 +00:00
										 |  |  |   let b:zipfile= a:zipfile | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   setlocal noswapfile | 
					
						
							|  |  |  |   setlocal buftype=nofile | 
					
						
							|  |  |  |   setlocal bufhidden=hide | 
					
						
							|  |  |  |   setlocal nobuflisted | 
					
						
							|  |  |  |   setlocal nowrap | 
					
						
							|  |  |  |   set ft=tar | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " give header | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |   call append(0, ['" zip.vim version '.g:loaded_zip, | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  |  \                '" Browsing zipfile '.a:zipfile, | 
					
						
							|  |  |  |  \                '" Select a file with cursor and press ENTER']) | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |   keepj $ | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-06 17:06:04 +00:00
										 |  |  | "  call Decho("exe silent r! ".g:zip_unzipcmd." -l -- ".s:Escape(a:zipfile,1)) | 
					
						
							| 
									
										
										
										
											2012-01-20 21:08:56 +01:00
										 |  |  |   exe "keepj sil! r! ".g:zip_unzipcmd." -Z -1 -- ".s:Escape(a:zipfile,1) | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  |   if v:shell_error != 0 | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |    redraw! | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |    echohl WarningMsg | echo "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file" | echohl None | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | "   call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |    keepj sil! %d | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  |    let eikeep= &ei | 
					
						
							|  |  |  |    set ei=BufReadCmd,FileReadCmd | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |    exe "keepj r ".fnameescape(a:zipfile) | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  |    let &ei= eikeep | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |    keepj 1d | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  | "   call Dret("zip#Browse") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-16 20:02:31 +02:00
										 |  |  |   " Maps associated with zip plugin | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   setlocal noma nomod ro | 
					
						
							| 
									
										
										
										
											2020-01-09 21:46:04 +01:00
										 |  |  |   noremap <silent> <buffer>	<cr>		:call <SID>ZipBrowseSelect()<cr> | 
					
						
							|  |  |  |   noremap <silent> <buffer>	x		:call zip#Extract()<cr> | 
					
						
							|  |  |  |   if &mouse != "" | 
					
						
							|  |  |  |    noremap <silent> <buffer>	<leftmouse>	<leftmouse>:call <SID>ZipBrowseSelect()<cr> | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |   let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "  call Dret("zip#Browse") | 
					
						
							|  |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " --------------------------------------------------------------------- | 
					
						
							|  |  |  | " ZipBrowseSelect: {{{2 | 
					
						
							|  |  |  | fun! s:ZipBrowseSelect() | 
					
						
							| 
									
										
										
										
											2007-05-10 18:25:20 +00:00
										 |  |  | "  call Dfunc("ZipBrowseSelect() zipfile<".b:zipfile."> curfile<".expand("%").">") | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |   let repkeep= &report | 
					
						
							|  |  |  |   set report=10 | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   let fname= getline(".") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " sanity check | 
					
						
							|  |  |  |   if fname =~ '^"' | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |    let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "   call Dret("ZipBrowseSelect") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   if fname =~ '/$' | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |    redraw! | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |    echohl Error | echo "***error*** (zip#Browse) Please specify a file, not a directory" | echohl None | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | "   call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |    let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "   call Dret("ZipBrowseSelect") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "  call Decho("fname<".fname.">") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " get zipfile to the new-window | 
					
						
							| 
									
										
										
										
											2007-05-10 18:25:20 +00:00
										 |  |  |   let zipfile = b:zipfile | 
					
						
							| 
									
										
										
										
											2020-01-09 21:46:04 +01:00
										 |  |  |   let curfile = expand("%") | 
					
						
							| 
									
										
										
										
											2006-03-23 22:59:57 +00:00
										 |  |  | "  call Decho("zipfile<".zipfile.">") | 
					
						
							|  |  |  | "  call Decho("curfile<".curfile.">") | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-09 21:46:04 +01:00
										 |  |  |   noswapfile new | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |   if !exists("g:zip_nomax") || g:zip_nomax == 0 | 
					
						
							|  |  |  |    wincmd _ | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |   let s:zipfile_{winnr()}= curfile | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  | "  call Decho("exe e ".fnameescape("zipfile:".zipfile.'::'.fname)) | 
					
						
							| 
									
										
										
										
											2020-01-09 21:46:04 +01:00
										 |  |  |   exe "noswapfile e ".fnameescape("zipfile:".zipfile.'::'.fname) | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   filetype detect | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |   let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  | "  call Dret("ZipBrowseSelect : s:zipfile_".winnr()."<".s:zipfile_{winnr()}.">") | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " --------------------------------------------------------------------- | 
					
						
							|  |  |  | " zip#Read: {{{2 | 
					
						
							|  |  |  | fun! zip#Read(fname,mode) | 
					
						
							|  |  |  | "  call Dfunc("zip#Read(fname<".a:fname.">,mode=".a:mode.")") | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |   let repkeep= &report | 
					
						
							|  |  |  |   set report=10 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  |   if has("unix") | 
					
						
							|  |  |  |    let zipfile = substitute(a:fname,'zipfile:\(.\{-}\)::[^\\].*$','\1','') | 
					
						
							|  |  |  |    let fname   = substitute(a:fname,'zipfile:.\{-}::\([^\\].*\)$','\1','') | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |    let zipfile = substitute(a:fname,'^.\{-}zipfile:\(.\{-}\)::[^\\].*$','\1','') | 
					
						
							|  |  |  |    let fname   = substitute(a:fname,'^.\{-}zipfile:.\{-}::\([^\\].*\)$','\1','') | 
					
						
							| 
									
										
										
										
											2013-04-24 18:51:19 +02:00
										 |  |  |    let fname   = substitute(fname, '[', '[[]', 'g') | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  |   endif | 
					
						
							|  |  |  | "  call Decho("zipfile<".zipfile.">") | 
					
						
							|  |  |  | "  call Decho("fname  <".fname.">") | 
					
						
							| 
									
										
										
										
											2016-09-16 20:02:31 +02:00
										 |  |  |   " sanity check | 
					
						
							|  |  |  |   if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','','')) | 
					
						
							|  |  |  |    redraw! | 
					
						
							|  |  |  |    echohl Error | echo "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program" | echohl None | 
					
						
							|  |  |  | "   call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							|  |  |  |    let &report= repkeep | 
					
						
							|  |  |  | "   call Dret("zip#Write") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-24 18:51:19 +02:00
										 |  |  |   " the following code does much the same thing as | 
					
						
							|  |  |  |   "   exe "keepj sil! r! ".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1) | 
					
						
							|  |  |  |   " but allows zipfile:... entries in quickfix lists | 
					
						
							|  |  |  |   let temp = tempname() | 
					
						
							| 
									
										
										
										
											2013-07-04 22:50:40 +02:00
										 |  |  | "  call Decho("using temp file<".temp.">") | 
					
						
							| 
									
										
										
										
											2013-04-24 18:51:19 +02:00
										 |  |  |   let fn   = expand('%:p') | 
					
						
							|  |  |  |   exe "sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp | 
					
						
							|  |  |  | "  call Decho("exe sil! !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fnameescape(fname),1).' > '.temp) | 
					
						
							|  |  |  |   sil exe 'keepalt file '.temp | 
					
						
							|  |  |  |   sil keepj e! | 
					
						
							|  |  |  |   sil exe 'keepalt file '.fnameescape(fn) | 
					
						
							|  |  |  |   call delete(temp) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-19 05:09:16 +02:00
										 |  |  |   filetype detect | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   " cleanup | 
					
						
							| 
									
										
										
										
											2013-07-04 22:50:40 +02:00
										 |  |  |   "  keepj 0d   " used to be needed for the ...r! ... method | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   set nomod | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |   let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "  call Dret("zip#Read") | 
					
						
							|  |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " --------------------------------------------------------------------- | 
					
						
							|  |  |  | " zip#Write: {{{2 | 
					
						
							|  |  |  | fun! zip#Write(fname) | 
					
						
							| 
									
										
										
										
											2006-04-05 20:41:53 +00:00
										 |  |  | "  call Dfunc("zip#Write(fname<".a:fname.">) zipfile_".winnr()."<".s:zipfile_{winnr()}.">") | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |   let repkeep= &report | 
					
						
							|  |  |  |   set report=10 | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   " sanity checks | 
					
						
							| 
									
										
										
										
											2016-09-16 20:02:31 +02:00
										 |  |  |   if !executable(substitute(g:zip_zipcmd,'\s\+.*$','','')) | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |    redraw! | 
					
						
							| 
									
										
										
										
											2016-09-16 20:02:31 +02:00
										 |  |  |    echohl Error | echo "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program" | echohl None | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | "   call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |    let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "   call Dret("zip#Write") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   if !exists("*mkdir") | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |    redraw! | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |    echohl Error | echo "***error*** (zip#Write) sorry, mkdir() doesn't work on your system" | echohl None | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | "   call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |    let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "   call Dret("zip#Write") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let curdir= getcwd() | 
					
						
							|  |  |  |   let tmpdir= tempname() | 
					
						
							|  |  |  | "  call Decho("orig tempname<".tmpdir.">") | 
					
						
							|  |  |  |   if tmpdir =~ '\.' | 
					
						
							|  |  |  |    let tmpdir= substitute(tmpdir,'\.[^.]*$','','e') | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | "  call Decho("tmpdir<".tmpdir.">") | 
					
						
							|  |  |  |   call mkdir(tmpdir,"p") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " attempt to change to the indicated directory | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory") | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |    let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "   call Dret("zip#Write") | 
					
						
							|  |  |  |    return | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   endif | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "  call Decho("current directory now: ".getcwd()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " place temporary files under .../_ZIPVIM_/ | 
					
						
							|  |  |  |   if isdirectory("_ZIPVIM_") | 
					
						
							|  |  |  |    call s:Rmdir("_ZIPVIM_") | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   call mkdir("_ZIPVIM_") | 
					
						
							|  |  |  |   cd _ZIPVIM_ | 
					
						
							|  |  |  | "  call Decho("current directory now: ".getcwd()) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-02 22:08:30 +00:00
										 |  |  |   if has("unix") | 
					
						
							|  |  |  |    let zipfile = substitute(a:fname,'zipfile:\(.\{-}\)::[^\\].*$','\1','') | 
					
						
							|  |  |  |    let fname   = substitute(a:fname,'zipfile:.\{-}::\([^\\].*\)$','\1','') | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |    let zipfile = substitute(a:fname,'^.\{-}zipfile:\(.\{-}\)::[^\\].*$','\1','') | 
					
						
							|  |  |  |    let fname   = substitute(a:fname,'^.\{-}zipfile:.\{-}::\([^\\].*\)$','\1','') | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | "  call Decho("zipfile<".zipfile.">") | 
					
						
							|  |  |  | "  call Decho("fname  <".fname.">") | 
					
						
							| 
									
										
										
										
											2005-12-29 22:48:26 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if fname =~ '/' | 
					
						
							|  |  |  |    let dirpath = substitute(fname,'/[^/]\+$','','e') | 
					
						
							| 
									
										
										
										
											2013-04-24 18:51:19 +02:00
										 |  |  |    if has("win32unix") && executable("cygpath") | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |     let dirpath = substitute(system("cygpath ".s:Escape(dirpath,0)),'\n','','e') | 
					
						
							| 
									
										
										
										
											2005-12-29 22:48:26 +00:00
										 |  |  |    endif | 
					
						
							| 
									
										
										
										
											2006-04-05 20:41:53 +00:00
										 |  |  | "   call Decho("mkdir(dirpath<".dirpath.">,p)") | 
					
						
							| 
									
										
										
										
											2005-12-29 22:48:26 +00:00
										 |  |  |    call mkdir(dirpath,"p") | 
					
						
							|  |  |  |   endif | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   if zipfile !~ '/' | 
					
						
							|  |  |  |    let zipfile= curdir.'/'.zipfile | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | "  call Decho("zipfile<".zipfile."> fname<".fname.">") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |   exe "w! ".fnameescape(fname) | 
					
						
							| 
									
										
										
										
											2013-04-24 18:51:19 +02:00
										 |  |  |   if has("win32unix") && executable("cygpath") | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |    let zipfile = substitute(system("cygpath ".s:Escape(zipfile,0)),'\n','','e') | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$' | 
					
						
							|  |  |  |     let fname = substitute(fname, '[', '[[]', 'g') | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-06 17:06:04 +00:00
										 |  |  | "  call Decho(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) | 
					
						
							|  |  |  |   call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0)) | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   if v:shell_error != 0 | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |    redraw! | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |    echohl Error | echo "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname | echohl None | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | "   call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   elseif s:zipfile_{winnr()} =~ '^\a\+://' | 
					
						
							|  |  |  |    " support writing zipfiles across a network | 
					
						
							|  |  |  |    let netzipfile= s:zipfile_{winnr()} | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | "   call Decho("handle writing <".zipfile."> across network as <".netzipfile.">") | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |    1split|enew | 
					
						
							|  |  |  |    let binkeep= &binary | 
					
						
							|  |  |  |    let eikeep = &ei | 
					
						
							|  |  |  |    set binary ei=all | 
					
						
							| 
									
										
										
										
											2020-01-09 21:46:04 +01:00
										 |  |  |    exe "noswapfile e! ".fnameescape(zipfile) | 
					
						
							| 
									
										
										
										
											2005-11-23 21:25:05 +00:00
										 |  |  |    call netrw#NetWrite(netzipfile) | 
					
						
							|  |  |  |    let &ei     = eikeep | 
					
						
							|  |  |  |    let &binary = binkeep | 
					
						
							|  |  |  |    q! | 
					
						
							|  |  |  |    unlet s:zipfile_{winnr()} | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   endif | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   " cleanup and restore current directory | 
					
						
							|  |  |  |   cd .. | 
					
						
							|  |  |  |   call s:Rmdir("_ZIPVIM_") | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   call s:ChgDir(curdir,s:WARNING,"(zip#Write) unable to return to ".curdir."!") | 
					
						
							|  |  |  |   call s:Rmdir(tmpdir) | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   setlocal nomod | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-28 23:01:53 +00:00
										 |  |  |   let &report= repkeep | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | "  call Dret("zip#Write") | 
					
						
							|  |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-16 20:02:31 +02:00
										 |  |  | " --------------------------------------------------------------------- | 
					
						
							|  |  |  | " zip#Extract: extract a file from a zip archive {{{2 | 
					
						
							|  |  |  | fun! zip#Extract() | 
					
						
							|  |  |  | "  call Dfunc("zip#Extract()") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   let repkeep= &report | 
					
						
							|  |  |  |   set report=10 | 
					
						
							|  |  |  |   let fname= getline(".") | 
					
						
							|  |  |  | "  call Decho("fname<".fname.">") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " sanity check | 
					
						
							|  |  |  |   if fname =~ '^"' | 
					
						
							|  |  |  |    let &report= repkeep | 
					
						
							|  |  |  | "   call Dret("zip#Extract") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  |   if fname =~ '/$' | 
					
						
							|  |  |  |    redraw! | 
					
						
							|  |  |  |    echohl Error | echo "***error*** (zip#Extract) Please specify a file, not a directory" | echohl None | 
					
						
							|  |  |  |    let &report= repkeep | 
					
						
							|  |  |  | "   call Dret("zip#Extract") | 
					
						
							|  |  |  |    return | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " extract the file mentioned under the cursor | 
					
						
							|  |  |  | "  call Decho("system(".g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell).")") | 
					
						
							|  |  |  |   call system(g:zip_extractcmd." ".shellescape(b:zipfile)." ".shellescape(shell)) | 
					
						
							|  |  |  | "  call Decho("zipfile<".b:zipfile.">") | 
					
						
							|  |  |  |   if v:shell_error != 0 | 
					
						
							|  |  |  |    echohl Error | echo "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!" | echohl NONE | 
					
						
							|  |  |  |   elseif !filereadable(fname) | 
					
						
							|  |  |  |    echohl Error | echo "***error*** attempted to extract ".fname." but it doesn't appear to be present!" | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |    echo "***note*** successfully extracted ".fname | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   " restore option | 
					
						
							|  |  |  |   let &report= repkeep | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "  call Dret("zip#Extract") | 
					
						
							|  |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | " --------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  | " s:Escape: {{{2 | 
					
						
							|  |  |  | fun! s:Escape(fname,isfilt) | 
					
						
							|  |  |  | "  call Dfunc("QuoteFileDir(fname<".a:fname."> isfilt=".a:isfilt.")") | 
					
						
							|  |  |  |   if exists("*shellescape") | 
					
						
							|  |  |  |    if a:isfilt | 
					
						
							|  |  |  |     let qnameq= shellescape(a:fname,1) | 
					
						
							|  |  |  |    else | 
					
						
							|  |  |  |     let qnameq= shellescape(a:fname) | 
					
						
							|  |  |  |    endif | 
					
						
							| 
									
										
										
										
											2008-06-24 21:56:24 +00:00
										 |  |  |   else | 
					
						
							|  |  |  |    let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq | 
					
						
							|  |  |  |   endif | 
					
						
							|  |  |  | "  call Dret("QuoteFileDir <".qnameq.">") | 
					
						
							|  |  |  |   return qnameq | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " --------------------------------------------------------------------- | 
					
						
							|  |  |  | " ChgDir: {{{2 | 
					
						
							|  |  |  | fun! s:ChgDir(newdir,errlvl,errmsg) | 
					
						
							|  |  |  | "  call Dfunc("ChgDir(newdir<".a:newdir."> errlvl=".a:errlvl."  errmsg<".a:errmsg.">)") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   try | 
					
						
							| 
									
										
										
										
											2008-08-06 17:06:04 +00:00
										 |  |  |    exe "cd ".fnameescape(a:newdir) | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   catch /^Vim\%((\a\+)\)\=:E344/ | 
					
						
							|  |  |  |    redraw! | 
					
						
							|  |  |  |    if a:errlvl == s:NOTE | 
					
						
							|  |  |  |     echo "***note*** ".a:errmsg | 
					
						
							|  |  |  |    elseif a:errlvl == s:WARNING | 
					
						
							|  |  |  |     echohl WarningMsg | echo "***warning*** ".a:errmsg | echohl NONE | 
					
						
							|  |  |  |    elseif a:errlvl == s:ERROR | 
					
						
							|  |  |  |     echohl Error | echo "***error*** ".a:errmsg | echohl NONE | 
					
						
							|  |  |  |    endif | 
					
						
							|  |  |  | "   call inputsave()|call input("Press <cr> to continue")|call inputrestore() | 
					
						
							|  |  |  | "   call Dret("ChgDir 1") | 
					
						
							|  |  |  |    return 1 | 
					
						
							|  |  |  |   endtry | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "  call Dret("ChgDir 0") | 
					
						
							|  |  |  |   return 0 | 
					
						
							|  |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | " --------------------------------------------------------------------- | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  | " s:Rmdir: {{{2 | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  | fun! s:Rmdir(fname) | 
					
						
							|  |  |  | "  call Dfunc("Rmdir(fname<".a:fname.">)") | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$' | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |    call system("rmdir /S/Q ".s:Escape(a:fname,0)) | 
					
						
							| 
									
										
										
										
											2007-05-05 17:54:07 +00:00
										 |  |  |   else | 
					
						
							| 
									
										
										
										
											2008-07-13 17:41:49 +00:00
										 |  |  |    call system("/bin/rm -rf ".s:Escape(a:fname,0)) | 
					
						
							| 
									
										
										
										
											2005-09-16 21:55:43 +00:00
										 |  |  |   endif | 
					
						
							|  |  |  | "  call Dret("Rmdir") | 
					
						
							|  |  |  | endfun | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | " ------------------------------------------------------------------------ | 
					
						
							|  |  |  | " Modelines And Restoration: {{{1 | 
					
						
							|  |  |  | let &cpo= s:keepcpo | 
					
						
							|  |  |  | unlet s:keepcpo | 
					
						
							| 
									
										
										
										
											2007-05-10 18:25:20 +00:00
										 |  |  | " vim:ts=8 fdm=marker |