Sunday, March 7, 2010

Re: what is the advantage to use the vimball to get plugins?

On Mar 7, 9:31 am, mmarko <marko.mah...@gmail.com> wrote:
> Since Vim supports Python on multiple platforms, it could be used
> to add support for multiple archive types. The functions below can
> pack/unpack gz, bz2 and zip (files can only be added "incrementally").
> The code is just a proof of concept and may be the starting point
> for a real vim-packer.
>
> Marko

Below is an untested piece of code that implements a file interface
that could be used to unpack files directly into vim buffers:

Marko

import vim

class VimBufferStream:
def __init__(self, bufnr, mode):
self.vimbuf = vim.buffers[bufnr]
self.lastline = None
if mode == 'w': del self.vimbuf[:]
elif mode == 'a': pass
else: pass # unknown mode, raise error

def __del__(self):
self.close()

def close(self):
if self.lastline != None:
self.vimbuf.append(self.lastline)

def write(self, data):
if len(data) < 1: return
EOL = "\n" #TODO: system dependant
lines = data.split(EOL)
if self.lastline != None:
lines[0] = self.lastline + lines[0]
self.lastline = None
if not data.endswith(EOL):
self.lastline = lines[-1]
lines = lines[:-1]
for line in lines: self.vimbuf.append(line + EOL)

To use:

def gzip_expand_to_buffer(fname, bufnr):
fin = gzip.GzipFile(fname, 'rb')
fout = VimBufferStream(bufnr, 'w')
copyfile(fin, fout)
fin.close()
fout.close()

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: