2014-07-10 21:05:51 -07:00
|
|
|
" zip.vim: Handles browsing zipfiles
|
2024-07-25 00:25:56 -07:00
|
|
|
" AUTOLOAD PORTION
|
2024-08-21 14:58:22 -07:00
|
|
|
" Date: 2024 Aug 21
|
2024-08-06 16:10:41 -07:00
|
|
|
" Version: 34
|
2024-02-20 15:30:18 -07:00
|
|
|
" Maintainer: This runtime file is looking for a new maintainer.
|
|
|
|
" Former Maintainer: Charles E Campbell
|
2024-06-15 14:51:30 -07:00
|
|
|
" Last Change:
|
2024-07-25 00:25:56 -07:00
|
|
|
" 2024 Jun 16 by Vim Project: handle whitespace on Windows properly (#14998)
|
|
|
|
" 2024 Jul 23 by Vim Project: fix 'x' command
|
|
|
|
" 2024 Jul 24 by Vim Project: use delete() function
|
2024-08-05 15:47:38 -07:00
|
|
|
" 2024 Jul 30 by Vim Project: fix opening remote zipfile
|
2024-08-04 09:59:34 -07:00
|
|
|
" 2024 Aug 04 by Vim Project: escape '[' in name of file to be extracted
|
2024-08-05 15:47:38 -07:00
|
|
|
" 2024 Aug 05 by Vim Project: workaround for the FreeBSD's unzip
|
2024-08-06 16:05:58 -07:00
|
|
|
" 2024 Aug 05 by Vim Project: clean-up and make it work with shellslash on Windows
|
2024-08-20 16:35:27 -07:00
|
|
|
" 2024 Aug 18 by Vim Project: correctly handle special globbing chars
|
2024-08-21 14:58:22 -07:00
|
|
|
" 2024 Aug 21 by Vim Project: simplify condition to detect MS-Windows
|
2014-07-10 21:05:51 -07:00
|
|
|
" License: Vim License (see vim's :help license)
|
2024-06-15 14:51:30 -07:00
|
|
|
" Copyright: Copyright (C) 2005-2019 Charles E. Campbell {{{1
|
|
|
|
" 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,
|
|
|
|
" 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
|
|
|
|
" holder be liable for any damages resulting from the use
|
|
|
|
" of this software.
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" Load Once: {{{1
|
|
|
|
if &cp || exists("g:loaded_zip")
|
|
|
|
finish
|
|
|
|
endif
|
2024-08-06 16:10:41 -07:00
|
|
|
let g:loaded_zip= "v34"
|
2014-07-10 21:05:51 -07:00
|
|
|
let s:keepcpo= &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
let s:zipfile_escape = ' ?&;\'
|
|
|
|
let s:ERROR = 2
|
|
|
|
let s:WARNING = 1
|
|
|
|
let s:NOTE = 0
|
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" Global Values: {{{1
|
|
|
|
if !exists("g:zip_shq")
|
|
|
|
if &shq != ""
|
|
|
|
let g:zip_shq= &shq
|
|
|
|
elseif has("unix")
|
|
|
|
let g:zip_shq= "'"
|
|
|
|
else
|
|
|
|
let g:zip_shq= '"'
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
if !exists("g:zip_zipcmd")
|
|
|
|
let g:zip_zipcmd= "zip"
|
|
|
|
endif
|
|
|
|
if !exists("g:zip_unzipcmd")
|
|
|
|
let g:zip_unzipcmd= "unzip"
|
|
|
|
endif
|
2017-04-28 13:47:40 -07:00
|
|
|
if !exists("g:zip_extractcmd")
|
|
|
|
let g:zip_extractcmd= g:zip_unzipcmd
|
|
|
|
endif
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2024-08-06 16:11:11 -07:00
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" required early
|
|
|
|
" s:Mess: {{{2
|
|
|
|
fun! s:Mess(group, msg)
|
|
|
|
redraw!
|
|
|
|
exe "echohl " . a:group
|
|
|
|
echomsg a:msg
|
|
|
|
echohl Normal
|
|
|
|
endfun
|
|
|
|
|
|
|
|
if v:version < 702
|
|
|
|
call s:Mess('WarningMsg', "***warning*** this version of zip needs vim 7.2 or later")
|
|
|
|
finish
|
|
|
|
endif
|
2024-08-20 16:35:27 -07:00
|
|
|
" sanity checks
|
|
|
|
if !executable(g:zip_unzipcmd)
|
|
|
|
call s:Mess('Error', "***error*** (zip#Browse) unzip not available on your system")
|
|
|
|
finish
|
|
|
|
endif
|
2023-11-04 03:37:42 -07:00
|
|
|
if !dist#vim#IsSafeExecutable('zip', g:zip_unzipcmd)
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "Warning: NOT executing " .. g:zip_unzipcmd .. " from current directory!")
|
2023-08-31 20:38:31 -07:00
|
|
|
finish
|
|
|
|
endif
|
2023-09-06 14:49:58 -07:00
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
" ----------------
|
|
|
|
" Functions: {{{1
|
|
|
|
" ----------------
|
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" zip#Browse: {{{2
|
|
|
|
fun! zip#Browse(zipfile)
|
2024-07-30 10:18:41 -07:00
|
|
|
" sanity check: ensure that the zipfile has "PK" as its first two letters
|
|
|
|
" (zip files have a leading PK as a "magic cookie")
|
|
|
|
if filereadable(a:zipfile) && readblob(a:zipfile, 0, 2) != 0z50.4B
|
|
|
|
exe "noswapfile noautocmd e " .. fnameescape(a:zipfile)
|
2014-07-10 21:05:51 -07:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2024-08-06 16:07:29 -07:00
|
|
|
let dict = s:SetSaneOpts()
|
2024-08-06 16:15:59 -07:00
|
|
|
defer s:RestoreOpts(dict)
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
" sanity checks
|
|
|
|
if !executable(g:zip_unzipcmd)
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "***error*** (zip#Browse) unzip not available on your system")
|
2014-07-10 21:05:51 -07:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
if !filereadable(a:zipfile)
|
|
|
|
if a:zipfile !~# '^\a\+://'
|
2021-04-25 08:56:17 -07:00
|
|
|
" if it's an url, don't complain, let url-handlers such as vim do its thing
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "***error*** (zip#Browse) File not readable <".a:zipfile.">")
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
if &ma != 1
|
|
|
|
set ma
|
|
|
|
endif
|
|
|
|
let b:zipfile= a:zipfile
|
|
|
|
|
|
|
|
setlocal noswapfile
|
|
|
|
setlocal buftype=nofile
|
|
|
|
setlocal bufhidden=hide
|
|
|
|
setlocal nobuflisted
|
|
|
|
setlocal nowrap
|
2021-11-17 02:02:59 -07:00
|
|
|
|
|
|
|
" Oct 12, 2021: need to re-use Bram's syntax/tar.vim.
|
|
|
|
" Setting the filetype to zip doesn't do anything (currently),
|
|
|
|
" but it is perhaps less confusing to curious perusers who do
|
|
|
|
" a :echo &ft
|
|
|
|
setf zip
|
|
|
|
run! syntax/tar.vim
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
" give header
|
|
|
|
call append(0, ['" zip.vim version '.g:loaded_zip,
|
|
|
|
\ '" Browsing zipfile '.a:zipfile,
|
|
|
|
\ '" Select a file with cursor and press ENTER'])
|
|
|
|
keepj $
|
|
|
|
|
2024-08-05 15:47:38 -07:00
|
|
|
exe $"keepj sil r! {g:zip_unzipcmd} -Z1 -- {s:Escape(a:zipfile, 1)}"
|
2014-07-10 21:05:51 -07:00
|
|
|
if v:shell_error != 0
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('WarningMsg', "***warning*** (zip#Browse) ".fnameescape(a:zipfile)." is not a zip file")
|
2014-07-10 21:05:51 -07:00
|
|
|
keepj sil! %d
|
|
|
|
let eikeep= &ei
|
|
|
|
set ei=BufReadCmd,FileReadCmd
|
|
|
|
exe "keepj r ".fnameescape(a:zipfile)
|
|
|
|
let &ei= eikeep
|
|
|
|
keepj 1d
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2017-04-28 13:47:40 -07:00
|
|
|
" Maps associated with zip plugin
|
2014-07-10 21:05:51 -07:00
|
|
|
setlocal noma nomod ro
|
2021-04-25 08:34:48 -07: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
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
endfun
|
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" ZipBrowseSelect: {{{2
|
|
|
|
fun! s:ZipBrowseSelect()
|
2024-08-06 16:07:29 -07:00
|
|
|
let dict = s:SetSaneOpts()
|
2024-08-06 16:15:59 -07:00
|
|
|
defer s:RestoreOpts(dict)
|
2014-07-10 21:05:51 -07:00
|
|
|
let fname= getline(".")
|
2023-04-23 06:22:55 -07:00
|
|
|
if !exists("b:zipfile")
|
|
|
|
return
|
|
|
|
endif
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
" sanity check
|
|
|
|
if fname =~ '^"'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
if fname =~ '/$'
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "***error*** (zip#Browse) Please specify a file, not a directory")
|
2014-07-10 21:05:51 -07:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" get zipfile to the new-window
|
|
|
|
let zipfile = b:zipfile
|
2021-04-25 08:34:48 -07:00
|
|
|
let curfile = expand("%")
|
2014-07-10 21:05:51 -07:00
|
|
|
|
2021-04-25 08:34:48 -07:00
|
|
|
noswapfile new
|
2014-07-10 21:05:51 -07:00
|
|
|
if !exists("g:zip_nomax") || g:zip_nomax == 0
|
|
|
|
wincmd _
|
|
|
|
endif
|
|
|
|
let s:zipfile_{winnr()}= curfile
|
2021-11-17 02:02:59 -07:00
|
|
|
exe "noswapfile e ".fnameescape("zipfile://".zipfile.'::'.fname)
|
2014-07-10 21:05:51 -07:00
|
|
|
filetype detect
|
|
|
|
|
|
|
|
endfun
|
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" zip#Read: {{{2
|
|
|
|
fun! zip#Read(fname,mode)
|
2024-08-06 16:07:29 -07:00
|
|
|
let dict = s:SetSaneOpts()
|
2024-08-06 16:15:59 -07:00
|
|
|
defer s:RestoreOpts(dict)
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
if has("unix")
|
2021-11-17 02:02:59 -07:00
|
|
|
let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','')
|
|
|
|
let fname = substitute(a:fname,'zipfile://.\{-}::\([^\\].*\)$','\1','')
|
2014-07-10 21:05:51 -07:00
|
|
|
else
|
2021-11-17 02:02:59 -07:00
|
|
|
let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\\].*$','\1','')
|
|
|
|
let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\\].*\)$','\1','')
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
2024-08-20 16:35:27 -07:00
|
|
|
let fname = fname->substitute('[', '[[]', 'g')->escape('?*\\')
|
2017-04-28 13:47:40 -07:00
|
|
|
" sanity check
|
|
|
|
if !executable(substitute(g:zip_unzipcmd,'\s\+.*$','',''))
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "***error*** (zip#Read) sorry, your system doesn't appear to have the ".g:zip_unzipcmd." program")
|
2017-04-28 13:47:40 -07:00
|
|
|
return
|
|
|
|
endif
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
" the following code does much the same thing as
|
2024-08-04 09:59:34 -07:00
|
|
|
" exe "keepj sil! r! ".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fname,1)
|
2021-11-17 02:02:59 -07:00
|
|
|
" but allows zipfile://... entries in quickfix lists
|
2014-07-10 21:05:51 -07:00
|
|
|
let temp = tempname()
|
|
|
|
let fn = expand('%:p')
|
2024-08-05 15:47:38 -07:00
|
|
|
exe "sil !".g:zip_unzipcmd." -p -- ".s:Escape(zipfile,1)." ".s:Escape(fname,1).' > '.temp
|
2014-07-10 21:05:51 -07:00
|
|
|
sil exe 'keepalt file '.temp
|
|
|
|
sil keepj e!
|
|
|
|
sil exe 'keepalt file '.fnameescape(fn)
|
|
|
|
call delete(temp)
|
|
|
|
|
|
|
|
filetype detect
|
|
|
|
|
|
|
|
" cleanup
|
|
|
|
set nomod
|
|
|
|
|
|
|
|
endfun
|
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" zip#Write: {{{2
|
|
|
|
fun! zip#Write(fname)
|
2024-08-06 16:07:29 -07:00
|
|
|
let dict = s:SetSaneOpts()
|
2024-08-06 16:15:59 -07:00
|
|
|
defer s:RestoreOpts(dict)
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
" sanity checks
|
2017-04-28 13:47:40 -07:00
|
|
|
if !executable(substitute(g:zip_zipcmd,'\s\+.*$','',''))
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "***error*** (zip#Write) sorry, your system doesn't appear to have the ".g:zip_zipcmd." program")
|
2014-07-10 21:05:51 -07:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
if !exists("*mkdir")
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "***error*** (zip#Write) sorry, mkdir() doesn't work on your system")
|
2014-07-10 21:05:51 -07:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
let curdir= getcwd()
|
|
|
|
let tmpdir= tempname()
|
|
|
|
if tmpdir =~ '\.'
|
|
|
|
let tmpdir= substitute(tmpdir,'\.[^.]*$','','e')
|
|
|
|
endif
|
|
|
|
call mkdir(tmpdir,"p")
|
|
|
|
|
|
|
|
" attempt to change to the indicated directory
|
|
|
|
if s:ChgDir(tmpdir,s:ERROR,"(zip#Write) cannot cd to temporary directory")
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
|
|
|
" place temporary files under .../_ZIPVIM_/
|
|
|
|
if isdirectory("_ZIPVIM_")
|
2024-07-25 00:25:56 -07:00
|
|
|
call delete("_ZIPVIM_", "rf")
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
|
|
|
call mkdir("_ZIPVIM_")
|
|
|
|
cd _ZIPVIM_
|
|
|
|
|
|
|
|
if has("unix")
|
2021-11-17 02:02:59 -07:00
|
|
|
let zipfile = substitute(a:fname,'zipfile://\(.\{-}\)::[^\\].*$','\1','')
|
|
|
|
let fname = substitute(a:fname,'zipfile://.\{-}::\([^\\].*\)$','\1','')
|
2014-07-10 21:05:51 -07:00
|
|
|
else
|
2021-11-17 02:02:59 -07:00
|
|
|
let zipfile = substitute(a:fname,'^.\{-}zipfile://\(.\{-}\)::[^\\].*$','\1','')
|
|
|
|
let fname = substitute(a:fname,'^.\{-}zipfile://.\{-}::\([^\\].*\)$','\1','')
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
|
|
|
|
|
|
|
if fname =~ '/'
|
|
|
|
let dirpath = substitute(fname,'/[^/]\+$','','e')
|
|
|
|
if has("win32unix") && executable("cygpath")
|
|
|
|
let dirpath = substitute(system("cygpath ".s:Escape(dirpath,0)),'\n','','e')
|
|
|
|
endif
|
|
|
|
call mkdir(dirpath,"p")
|
|
|
|
endif
|
|
|
|
if zipfile !~ '/'
|
|
|
|
let zipfile= curdir.'/'.zipfile
|
|
|
|
endif
|
|
|
|
|
|
|
|
exe "w! ".fnameescape(fname)
|
|
|
|
if has("win32unix") && executable("cygpath")
|
|
|
|
let zipfile = substitute(system("cygpath ".s:Escape(zipfile,0)),'\n','','e')
|
|
|
|
endif
|
|
|
|
|
|
|
|
if (has("win32") || has("win95") || has("win64") || has("win16")) && &shell !~? 'sh$'
|
|
|
|
let fname = substitute(fname, '[', '[[]', 'g')
|
|
|
|
endif
|
|
|
|
|
|
|
|
call system(g:zip_zipcmd." -u ".s:Escape(fnamemodify(zipfile,":p"),0)." ".s:Escape(fname,0))
|
|
|
|
if v:shell_error != 0
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "***error*** (zip#Write) sorry, unable to update ".zipfile." with ".fname)
|
2014-07-10 21:05:51 -07:00
|
|
|
|
|
|
|
elseif s:zipfile_{winnr()} =~ '^\a\+://'
|
|
|
|
" support writing zipfiles across a network
|
|
|
|
let netzipfile= s:zipfile_{winnr()}
|
|
|
|
1split|enew
|
|
|
|
let binkeep= &binary
|
|
|
|
let eikeep = &ei
|
|
|
|
set binary ei=all
|
2021-04-25 08:34:48 -07:00
|
|
|
exe "noswapfile e! ".fnameescape(zipfile)
|
2014-07-10 21:05:51 -07:00
|
|
|
call netrw#NetWrite(netzipfile)
|
|
|
|
let &ei = eikeep
|
|
|
|
let &binary = binkeep
|
|
|
|
q!
|
|
|
|
unlet s:zipfile_{winnr()}
|
|
|
|
endif
|
2024-07-25 00:25:56 -07:00
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
" cleanup and restore current directory
|
|
|
|
cd ..
|
2024-07-25 00:25:56 -07:00
|
|
|
call delete("_ZIPVIM_", "rf")
|
2014-07-10 21:05:51 -07:00
|
|
|
call s:ChgDir(curdir,s:WARNING,"(zip#Write) unable to return to ".curdir."!")
|
2024-07-25 00:25:56 -07:00
|
|
|
call delete(tmpdir, "rf")
|
2014-07-10 21:05:51 -07:00
|
|
|
setlocal nomod
|
|
|
|
|
|
|
|
endfun
|
|
|
|
|
2017-04-28 13:47:40 -07:00
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" zip#Extract: extract a file from a zip archive {{{2
|
|
|
|
fun! zip#Extract()
|
|
|
|
|
2024-08-06 16:07:29 -07:00
|
|
|
let dict = s:SetSaneOpts()
|
2024-08-06 16:15:59 -07:00
|
|
|
defer s:RestoreOpts(dict)
|
2017-04-28 13:47:40 -07:00
|
|
|
let fname= getline(".")
|
|
|
|
|
|
|
|
" sanity check
|
|
|
|
if fname =~ '^"'
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
if fname =~ '/$'
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "***error*** (zip#Extract) Please specify a file, not a directory")
|
2017-04-28 13:47:40 -07:00
|
|
|
return
|
|
|
|
endif
|
2024-08-20 16:35:27 -07:00
|
|
|
if filereadable(fname)
|
|
|
|
call s:Mess('Error', "***error*** (zip#Extract) <" .. fname .."> already exists in directory, not overwriting!")
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
let target = fname->substitute('\[', '[[]', 'g')
|
2024-08-21 14:58:22 -07:00
|
|
|
if &shell =~ 'cmd' && has("win32")
|
2024-08-20 16:35:27 -07:00
|
|
|
let target = target
|
|
|
|
\ ->substitute('[?*]', '[&]', 'g')
|
|
|
|
\ ->substitute('[\\]', '?', 'g')
|
|
|
|
\ ->shellescape()
|
|
|
|
" there cannot be a file name with '\' in its name, unzip replaces it by _
|
|
|
|
let fname = fname->substitute('[\\?*]', '_', 'g')
|
|
|
|
else
|
|
|
|
let target = target->escape('*?\\')->shellescape()
|
|
|
|
endif
|
2017-04-28 13:47:40 -07:00
|
|
|
|
|
|
|
" extract the file mentioned under the cursor
|
2024-08-20 16:35:27 -07:00
|
|
|
call system($"{g:zip_extractcmd} -o {shellescape(b:zipfile)} {target}")
|
2017-04-28 13:47:40 -07:00
|
|
|
if v:shell_error != 0
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "***error*** ".g:zip_extractcmd." ".b:zipfile." ".fname.": failed!")
|
2017-04-28 13:47:40 -07:00
|
|
|
elseif !filereadable(fname)
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess('Error', "***error*** attempted to extract ".fname." but it doesn't appear to be present!")
|
2017-04-28 13:47:40 -07:00
|
|
|
else
|
2024-08-06 16:06:27 -07:00
|
|
|
echomsg "***note*** successfully extracted ".fname
|
2017-04-28 13:47:40 -07:00
|
|
|
endif
|
|
|
|
|
|
|
|
endfun
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" s:Escape: {{{2
|
|
|
|
fun! s:Escape(fname,isfilt)
|
|
|
|
if exists("*shellescape")
|
|
|
|
if a:isfilt
|
|
|
|
let qnameq= shellescape(a:fname,1)
|
|
|
|
else
|
|
|
|
let qnameq= shellescape(a:fname)
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
let qnameq= g:zip_shq.escape(a:fname,g:zip_shq).g:zip_shq
|
|
|
|
endif
|
|
|
|
return qnameq
|
|
|
|
endfun
|
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
2024-08-06 16:07:29 -07:00
|
|
|
" s:ChgDir: {{{2
|
2014-07-10 21:05:51 -07:00
|
|
|
fun! s:ChgDir(newdir,errlvl,errmsg)
|
|
|
|
try
|
|
|
|
exe "cd ".fnameescape(a:newdir)
|
|
|
|
catch /^Vim\%((\a\+)\)\=:E344/
|
|
|
|
redraw!
|
|
|
|
if a:errlvl == s:NOTE
|
2024-08-06 16:06:27 -07:00
|
|
|
echomsg "***note*** ".a:errmsg
|
2014-07-10 21:05:51 -07:00
|
|
|
elseif a:errlvl == s:WARNING
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess("WarningMsg", "***warning*** ".a:errmsg)
|
2014-07-10 21:05:51 -07:00
|
|
|
elseif a:errlvl == s:ERROR
|
2024-08-06 16:11:11 -07:00
|
|
|
call s:Mess("Error", "***error*** ".a:errmsg)
|
2014-07-10 21:05:51 -07:00
|
|
|
endif
|
|
|
|
return 1
|
|
|
|
endtry
|
|
|
|
|
|
|
|
return 0
|
|
|
|
endfun
|
|
|
|
|
2024-08-06 16:07:29 -07:00
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" s:SetSaneOpts: {{{2
|
|
|
|
fun! s:SetSaneOpts()
|
|
|
|
let dict = {}
|
|
|
|
let dict.report = &report
|
|
|
|
let dict.shellslash = &shellslash
|
|
|
|
|
|
|
|
let &report = 10
|
2024-11-04 06:00:12 -07:00
|
|
|
if exists('+shellslash')
|
|
|
|
let &shellslash = 0
|
|
|
|
endif
|
2024-08-06 16:07:29 -07:00
|
|
|
|
|
|
|
return dict
|
|
|
|
endfun
|
|
|
|
|
|
|
|
" ---------------------------------------------------------------------
|
|
|
|
" s:RestoreOpts: {{{2
|
|
|
|
fun! s:RestoreOpts(dict)
|
|
|
|
for [key, val] in items(a:dict)
|
|
|
|
exe $"let &{key} = {val}"
|
|
|
|
endfor
|
|
|
|
endfun
|
|
|
|
|
2014-07-10 21:05:51 -07:00
|
|
|
" ------------------------------------------------------------------------
|
|
|
|
" Modelines And Restoration: {{{1
|
|
|
|
let &cpo= s:keepcpo
|
|
|
|
unlet s:keepcpo
|
|
|
|
" vim:ts=8 fdm=marker
|