plugin/threesomelib/util/bufferlib.py @ bb3247356f22

Compare mode.
author Steve Losh <steve@stevelosh.com>
date Mon, 13 Jun 2011 00:25:16 -0400
parents 02506b7b8b92
children 890a1d687c33
import os
import vim

ap = os.path.abspath

class Buffer(object):
    def __init__(self, i):
        self.number = i + 1
        self._buffer = vim.buffers[i]
        self.name = self._buffer.name

    def open(self):
        vim.command('%dbuffer' % self.number)

    def set_lines(self, lines):
        self._buffer[:] = lines

    @property
    def lines(self):
        for line in self._buffer:
            yield line


class _BufferList(object):
    @property
    def original(self):
        return Buffer(0)

    @property
    def one(self):
        return Buffer(1)

    @property
    def two(self):
        return Buffer(2)

    @property
    def result(self):
        return Buffer(3)


    @property
    def current(self):
        bufname = ap(vim.eval('bufname("%")'))

        if bufname == ap(self.original.name):
            return self.original
        elif bufname == ap(self.one.name):
            return self.one
        elif bufname == ap(self.two.name):
            return self.two
        elif bufname == ap(self.result.name):
            return self.result


buffers = _BufferList()