forked from aniani/vim
updated for version 7.0117
This commit is contained in:
6
runtime/autoload/README.txt
Normal file
6
runtime/autoload/README.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
The autoload directory is for standard Vim autoload scripts.
|
||||
|
||||
These are functions used by plugins and for general use. They will be loaded
|
||||
automatically when the function is invoked. See ":help autoload".
|
||||
|
||||
gzip.vim for editing compressed files
|
173
runtime/autoload/gzip.vim
Normal file
173
runtime/autoload/gzip.vim
Normal file
@@ -0,0 +1,173 @@
|
||||
" Vim autoload file for editing compressed files.
|
||||
" Maintainer: Bram Moolenaar <Bram@vim.org>
|
||||
" Last Change: 2005 Jul 26
|
||||
|
||||
" These functions are used by the gzip plugin.
|
||||
|
||||
" Function to check that executing "cmd [-f]" works.
|
||||
" The result is cached in s:have_"cmd" for speed.
|
||||
fun s:check(cmd)
|
||||
let name = substitute(a:cmd, '\(\S*\).*', '\1', '')
|
||||
if !exists("s:have_" . name)
|
||||
let e = executable(name)
|
||||
if e < 0
|
||||
let r = system(name . " --version")
|
||||
let e = (r !~ "not found" && r != "")
|
||||
endif
|
||||
exe "let s:have_" . name . "=" . e
|
||||
endif
|
||||
exe "return s:have_" . name
|
||||
endfun
|
||||
|
||||
" Set b:gzip_comp_arg to the gzip argument to be used for compression, based on
|
||||
" the flags in the compressed file.
|
||||
" The only compression methods that can be detected are max speed (-1) and max
|
||||
" compression (-9).
|
||||
fun s:set_compression(line)
|
||||
" get the Compression Method
|
||||
let l:cm = char2nr(a:line[2])
|
||||
" if it's 8 (DEFLATE), we can check for the compression level
|
||||
if l:cm == 8
|
||||
" get the eXtra FLags
|
||||
let l:xfl = char2nr(a:line[8])
|
||||
" max compression
|
||||
if l:xfl == 2
|
||||
let b:gzip_comp_arg = "-9"
|
||||
" min compression
|
||||
elseif l:xfl == 4
|
||||
let b:gzip_comp_arg = "-1"
|
||||
endif
|
||||
endif
|
||||
endfun
|
||||
|
||||
|
||||
" After reading compressed file: Uncompress text in buffer with "cmd"
|
||||
fun gzip#read(cmd)
|
||||
" don't do anything if the cmd is not supported
|
||||
if !s:check(a:cmd)
|
||||
return
|
||||
endif
|
||||
|
||||
" for gzip check current compression level and set b:gzip_comp_arg.
|
||||
silent! unlet b:gzip_comp_arg
|
||||
if a:cmd[0] == 'g'
|
||||
call s:set_compression(getline(1))
|
||||
endif
|
||||
|
||||
" make 'patchmode' empty, we don't want a copy of the written file
|
||||
let pm_save = &pm
|
||||
set pm=
|
||||
" remove 'a' and 'A' from 'cpo' to avoid the alternate file changes
|
||||
let cpo_save = &cpo
|
||||
set cpo-=a cpo-=A
|
||||
" set 'modifiable'
|
||||
let ma_save = &ma
|
||||
setlocal ma
|
||||
" when filtering the whole buffer, it will become empty
|
||||
let empty = line("'[") == 1 && line("']") == line("$")
|
||||
let tmp = tempname()
|
||||
let tmpe = tmp . "." . expand("<afile>:e")
|
||||
" write the just read lines to a temp file "'[,']w tmp.gz"
|
||||
execute "silent '[,']w " . tmpe
|
||||
" uncompress the temp file: call system("gzip -dn tmp.gz")
|
||||
call system(a:cmd . " " . tmpe)
|
||||
if !filereadable(tmp)
|
||||
" uncompress didn't work! Keep the compressed file then.
|
||||
echoerr "Error: Could not read uncompressed file"
|
||||
return
|
||||
endif
|
||||
" delete the compressed lines; remember the line number
|
||||
let l = line("'[") - 1
|
||||
if exists(":lockmarks")
|
||||
lockmarks '[,']d _
|
||||
else
|
||||
'[,']d _
|
||||
endif
|
||||
" read in the uncompressed lines "'[-1r tmp"
|
||||
setlocal nobin
|
||||
if exists(":lockmarks")
|
||||
execute "silent lockmarks " . l . "r " . tmp
|
||||
else
|
||||
execute "silent " . l . "r " . tmp
|
||||
endif
|
||||
|
||||
" if buffer became empty, delete trailing blank line
|
||||
if empty
|
||||
silent $delete _
|
||||
1
|
||||
endif
|
||||
" delete the temp file and the used buffers
|
||||
call delete(tmp)
|
||||
silent! exe "bwipe " . tmp
|
||||
silent! exe "bwipe " . tmpe
|
||||
let &pm = pm_save
|
||||
let &cpo = cpo_save
|
||||
let &l:ma = ma_save
|
||||
" When uncompressed the whole buffer, do autocommands
|
||||
if empty
|
||||
if &verbose >= 8
|
||||
execute "doau BufReadPost " . expand("%:r")
|
||||
else
|
||||
execute "silent! doau BufReadPost " . expand("%:r")
|
||||
endif
|
||||
endif
|
||||
endfun
|
||||
|
||||
" After writing compressed file: Compress written file with "cmd"
|
||||
fun gzip#write(cmd)
|
||||
" don't do anything if the cmd is not supported
|
||||
if s:check(a:cmd)
|
||||
" Rename the file before compressing it.
|
||||
let nm = resolve(expand("<afile>"))
|
||||
let nmt = s:tempname(nm)
|
||||
if rename(nm, nmt) == 0
|
||||
if exists("b:gzip_comp_arg")
|
||||
call system(a:cmd . " " . b:gzip_comp_arg . " " . nmt)
|
||||
else
|
||||
call system(a:cmd . " " . nmt)
|
||||
endif
|
||||
call rename(nmt . "." . expand("<afile>:e"), nm)
|
||||
endif
|
||||
endif
|
||||
endfun
|
||||
|
||||
" Before appending to compressed file: Uncompress file with "cmd"
|
||||
fun gzip#appre(cmd)
|
||||
" don't do anything if the cmd is not supported
|
||||
if s:check(a:cmd)
|
||||
let nm = expand("<afile>")
|
||||
|
||||
" for gzip check current compression level and set b:gzip_comp_arg.
|
||||
silent! unlet b:gzip_comp_arg
|
||||
if a:cmd[0] == 'g'
|
||||
call s:set_compression(readfile(nm, "b", 1)[0])
|
||||
endif
|
||||
|
||||
" Rename to a weird name to avoid the risk of overwriting another file
|
||||
let nmt = expand("<afile>:p:h") . "/X~=@l9q5"
|
||||
let nmte = nmt . "." . expand("<afile>:e")
|
||||
if rename(nm, nmte) == 0
|
||||
if &patchmode != "" && getfsize(nm . &patchmode) == -1
|
||||
" Create patchmode file by creating the decompressed file new
|
||||
call system(a:cmd . " -c " . nmte . " > " . nmt)
|
||||
call rename(nmte, nm . &patchmode)
|
||||
else
|
||||
call system(a:cmd . " " . nmte)
|
||||
endif
|
||||
call rename(nmt, nm)
|
||||
endif
|
||||
endif
|
||||
endfun
|
||||
|
||||
" find a file name for the file to be compressed. Use "name" without an
|
||||
" extension if possible. Otherwise use a weird name to avoid overwriting an
|
||||
" existing file.
|
||||
fun s:tempname(name)
|
||||
let fn = fnamemodify(a:name, ":r")
|
||||
if !filereadable(fn) && !isdirectory(fn)
|
||||
return fn
|
||||
endif
|
||||
return fnamemodify(a:name, ":p:h") . "/X~=@l9q5"
|
||||
endfun
|
||||
|
||||
" vim: set sw=2 :
|
130
runtime/autoload/tar.vim
Normal file
130
runtime/autoload/tar.vim
Normal file
@@ -0,0 +1,130 @@
|
||||
" vim:set ts=8 sts=4 sw=4:
|
||||
"
|
||||
" tar.vim -- a Vim plugin for browsing tarfiles
|
||||
" Copyright (c) 2002, Michael C. Toren <mct@toren.net>
|
||||
" Distributed under the GNU General Public License.
|
||||
"
|
||||
" Version: 1.01
|
||||
" Last Change: 2005 Jul 26
|
||||
"
|
||||
" Updates are available from <http://michael.toren.net/code/>. If you
|
||||
" find this script useful, or have suggestions for improvements, please
|
||||
" let me know.
|
||||
" Also look there for further comments and documentation.
|
||||
"
|
||||
" This part defines the functions. The autocommands are in plugin/tar.vim.
|
||||
|
||||
let s:version = "1.01"
|
||||
|
||||
function! tar#Write(argument)
|
||||
echo "ERROR: Sorry, no write support for tarfiles yet"
|
||||
endfunction
|
||||
|
||||
function! tar#Read(argument, cleanup)
|
||||
let l:argument = a:argument
|
||||
let l:argument = substitute(l:argument, '^tarfile:', '', '')
|
||||
let l:argument = substitute(l:argument, '^\~', $HOME, '')
|
||||
|
||||
let l:tarfile = l:argument
|
||||
while 1
|
||||
if (l:tarfile == "" || l:tarfile == "/")
|
||||
echo "ERROR: Could not find a readable tarfile in path:" l:argument
|
||||
return
|
||||
endif
|
||||
|
||||
if filereadable(l:tarfile) " found it!
|
||||
break
|
||||
endif
|
||||
|
||||
let l:tarfile = fnamemodify(l:tarfile, ":h")
|
||||
endwhile
|
||||
|
||||
let l:toextract = strpart(l:argument, strlen(l:tarfile) + 1)
|
||||
|
||||
if (l:toextract == "")
|
||||
return
|
||||
endif
|
||||
|
||||
let l:cat = s:TarCatCommand(l:tarfile)
|
||||
execute "r !" . l:cat . " < '" . l:tarfile . "'"
|
||||
\ " | tar OPxf - '" . l:toextract . "'"
|
||||
|
||||
if (a:cleanup)
|
||||
0d "blank line
|
||||
execute "doautocmd BufReadPost " . expand("%")
|
||||
setlocal readonly
|
||||
silent preserve
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! tar#Browse(tarfile)
|
||||
setlocal noswapfile
|
||||
setlocal buftype=nofile
|
||||
setlocal bufhidden=hide
|
||||
setlocal filetype=
|
||||
setlocal nobuflisted
|
||||
setlocal buftype=nofile
|
||||
setlocal wrap
|
||||
setlocal syntax=tar
|
||||
|
||||
let l:tarfile = a:tarfile
|
||||
let b:tarfile = l:tarfile
|
||||
let l:cat = s:TarCatCommand(l:tarfile)
|
||||
|
||||
if ! filereadable(l:tarfile)
|
||||
let l:tarfile = substitute(l:tarfile, '^tarfile:', '', '')
|
||||
endif
|
||||
|
||||
if ! filereadable(l:tarfile)
|
||||
echo "ERROR: File not readable:" l:tarfile
|
||||
return
|
||||
endif
|
||||
|
||||
call s:Say("\" tar.vim version " . s:version)
|
||||
call s:Say("\" Browsing tarfile " . l:tarfile)
|
||||
call s:Say("\" Hit ENTER to view a file in a new window")
|
||||
call s:Say("")
|
||||
|
||||
silent execute "r!" . l:cat . "<'" . l:tarfile . "'| tar Ptf - "
|
||||
0d "blank line
|
||||
/^$/1
|
||||
|
||||
setlocal readonly
|
||||
setlocal nomodifiable
|
||||
noremap <silent> <buffer> <cr> :call <SID>TarBrowseSelect()<cr>
|
||||
endfunction
|
||||
|
||||
function! s:TarBrowseSelect()
|
||||
let l:line = getline(".")
|
||||
|
||||
if (l:line =~ '^" ')
|
||||
return
|
||||
endif
|
||||
|
||||
if (l:line =~ '/$')
|
||||
echo "Please specify a file, not a directory"
|
||||
return
|
||||
endif
|
||||
|
||||
let l:selection = "tarfile:" . b:tarfile . "/" . l:line
|
||||
new
|
||||
wincmd _
|
||||
execute "e " . l:selection
|
||||
endfunction
|
||||
|
||||
" kludge to deal with compressed archives
|
||||
function! s:TarCatCommand(tarfile)
|
||||
if a:tarfile =~# '\.\(gz\|tgz\|Z\)$'
|
||||
let l:cat = "gzip -d -c"
|
||||
elseif a:tarfile =~# '\.bz2$'
|
||||
let l:cat = "bzip2 -d -c"
|
||||
else
|
||||
let l:cat = "cat"
|
||||
endif
|
||||
return l:cat
|
||||
endfunction
|
||||
|
||||
function! s:Say(string)
|
||||
let @" = a:string
|
||||
$ put
|
||||
endfunction
|
Reference in New Issue
Block a user