diff options
author | Bram Moolenaar <Bram@vim.org> | 2005-05-18 22:24:46 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2005-05-18 22:24:46 +0000 |
commit | 34cdc3e32917a3812a8ec4369c64ef3e35243cfd (patch) | |
tree | a192d6da2ccb602a9b265519be64d4c170e2d8e3 /runtime/plugin | |
parent | a7fc0101b2c5feb7fc70eb79e5b02c61c7de545f (diff) | |
download | vim-git-34cdc3e32917a3812a8ec4369c64ef3e35243cfd.tar.gz |
updated for version 7.0072v7.0072
Diffstat (limited to 'runtime/plugin')
-rw-r--r-- | runtime/plugin/gzip.vim | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/runtime/plugin/gzip.vim b/runtime/plugin/gzip.vim index 0e9d0f5b8..0eebc5cb3 100644 --- a/runtime/plugin/gzip.vim +++ b/runtime/plugin/gzip.vim @@ -1,6 +1,6 @@ " Vim plugin for editing compressed files. " Maintainer: Bram Moolenaar <Bram@vim.org> -" Last Change: 2005 Mar 24 +" Last Change: 2005 May 18 " Exit quickly when: " - this plugin was already loaded @@ -48,12 +48,41 @@ fun s:check(cmd) 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 s: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= @@ -121,7 +150,11 @@ fun s:write(cmd) let nm = resolve(expand("<afile>")) let nmt = s:tempname(nm) if rename(nm, nmt) == 0 - call system(a:cmd . " " . nmt) + 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 @@ -131,8 +164,15 @@ endfun fun s:appre(cmd) " don't do anything if the cmd is not supported if s:check(a:cmd) - " Rename to a weird name to avoid the risk of overwriting another file 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 |