--- a/plugin/threesome.py Sun Jun 12 21:44:55 2011 -0400
+++ b/plugin/threesome.py Sun Jun 12 23:33:31 2011 -0400
@@ -18,16 +18,22 @@
threesome = init
def ThreesomeDiff():
- threesome.current_mode.key_diff()
+ threesome.modes.current_mode.key_diff()
def ThreesomeOriginal():
- threesome.current_mode.key_original()
+ threesome.modes.current_mode.key_original()
def ThreesomeOne():
- threesome.current_mode.key_one()
+ threesome.modes.current_mode.key_one()
def ThreesomeTwo():
- threesome.current_mode.key_two()
+ threesome.modes.current_mode.key_two()
def ThreesomeResult():
- threesome.current_mode.key_result()
+ threesome.modes.current_mode.key_result()
+
+def ThreesomeGrid():
+ threesome.modes.key_grid()
+
+def ThreesomeLoupe():
+ threesome.modes.key_loupe()
--- a/plugin/threesome.vim Sun Jun 12 21:44:55 2011 -0400
+++ b/plugin/threesome.vim Sun Jun 12 23:33:31 2011 -0400
@@ -68,9 +68,14 @@
exe 'pyfile ' . python_module
python ThreesomeInit()
endfunction"}}}
-function! s:ThreesomeDiff()"{{{
- python ThreesomeDiff()
+
+function! s:ThreesomeGrid()"{{{
+ python ThreesomeGrid()
endfunction"}}}
+function! s:ThreesomeLoupe()"{{{
+ python ThreesomeLoupe()
+endfunction"}}}
+
function! s:ThreesomeOriginal()"{{{
python ThreesomeOriginal()
endfunction"}}}
@@ -84,17 +89,26 @@
python ThreesomeResult()
endfunction"}}}
+function! s:ThreesomeDiff()"{{{
+ python ThreesomeDiff()
+endfunction"}}}
+
"}}}
"{{{ Commands
command! -nargs=0 ThreesomeInit call s:ThreesomeInit()
-command! -nargs=0 ThreesomeDiff call s:ThreesomeDiff()
+
+command! -nargs=0 ThreesomeGrid call s:ThreesomeGrid()
+command! -nargs=0 ThreesomeLoupe call s:ThreesomeLoupe()
+
command! -nargs=0 ThreesomeOriginal call s:ThreesomeOriginal()
command! -nargs=0 ThreesomeOne call s:ThreesomeOne()
command! -nargs=0 ThreesomeTwo call s:ThreesomeTwo()
command! -nargs=0 ThreesomeResult call s:ThreesomeResult()
+command! -nargs=0 ThreesomeDiff call s:ThreesomeDiff()
+
"}}}
" vim:se fdm=marker:sw=4:
--- a/plugin/threesomelib/init.py Sun Jun 12 21:44:55 2011 -0400
+++ b/plugin/threesomelib/init.py Sun Jun 12 23:33:31 2011 -0400
@@ -1,15 +1,11 @@
-import vim
-from modes import Grid
-from util import windows
-from util.buffers import buffers
+import modes
+from util import buffers, keys, windows
CONFLICT_MARKER_START = '<<<<<<<'
CONFLICT_MARKER_MARK = '======='
CONFLICT_MARKER_END = '>>>>>>>'
-current_mode = Grid
-
def process_result():
windows.close_all()
buffers.result.open()
@@ -32,9 +28,21 @@
buffers.result.set_lines(lines)
+def bind_global_keys():
+ keys.bind('g', ':ThreesomeGrid<cr>')
+ keys.bind('l', ':ThreesomeLoupe<cr>')
+
+ keys.bind('o', ':ThreesomeOriginal<cr>')
+ keys.bind('1', ':ThreesomeOne<cr>')
+ keys.bind('2', ':ThreesomeTwo<cr>')
+ keys.bind('r', ':ThreesomeResult<cr>')
+
+ keys.bind('d', ':ThreesomeDiff<cr>')
def init():
process_result()
- current_mode.activate()
+ bind_global_keys()
+ modes.current_mode = modes.grid
+ modes.current_mode.activate()
--- a/plugin/threesomelib/modes.py Sun Jun 12 21:44:55 2011 -0400
+++ b/plugin/threesomelib/modes.py Sun Jun 12 23:33:31 2011 -0400
@@ -1,7 +1,8 @@
import vim
-from util import keys, windows
-from util.buffers import buffers
-from util.io import error
+from util import buffers, windows
+
+
+current_mode = None
class Mode(object):
def __init__(self):
@@ -9,14 +10,14 @@
return super(Mode, self).__init__()
+ def diff(self, diffmode):
+ getattr(self, '_diff_%d' % diffmode)()
+
def key_diff(self, diffmode=None):
- if diffmode is not None:
- getattr(self, '_diff_%d' % diffmode)()
- else:
- next_diff_mode = self._current_diff_mode + 1
- if next_diff_mode >= self._number_of_diff_modes:
- next_diff_mode = 0
- self.diff(next_diff_mode)
+ next_diff_mode = self._current_diff_mode + 1
+ if next_diff_mode >= self._number_of_diff_modes:
+ next_diff_mode = 0
+ self.diff(next_diff_mode)
def key_original(self):
@@ -32,6 +33,10 @@
pass
+ def activate(self):
+ self._diff_0()
+
+
class GridMode(Mode):
"""
Layout 1 Layout 2
@@ -62,7 +67,7 @@
# Put the buffers in the appropriate windows
windows.focus(1)
- buffers.base.open()
+ buffers.original.open()
windows.focus(2)
buffers.one.open()
@@ -73,13 +78,6 @@
windows.focus(4)
buffers.result.open()
- def _init_keys(self):
- keys.bind('d', ':ThreesomeDiff<cr>')
- keys.bind('o', ':ThreesomeOriginal<cr>')
- keys.bind('1', ':ThreesomeOne<cr>')
- keys.bind('2', ':ThreesomeTwo<cr>')
- keys.bind('r', ':ThreesomeResult<cr>')
-
def _diff_0(self):
vim.command('diffoff!')
@@ -96,7 +94,7 @@
def activate(self):
self._init_layout()
- self._init_keys()
+ super(GridMode, self).activate()
def key_original(self):
@@ -111,6 +109,58 @@
def key_result(self):
windows.focus(4)
+class LoupeMode(Mode):
+ def __init__(self):
+ self._number_of_diff_modes = 1
+ return super(LoupeMode, self).__init__()
+
+
+ def _init_layout(self):
+ # Open the layout
+ windows.close_all()
+
+ # Put the buffers in the appropriate windows
+ windows.focus(1)
+ buffers.original.open()
+
+
+ def _diff_0(self):
+ vim.command('diffoff!')
+ self._current_diff_mode = 0
+
+
+ def activate(self):
+ self._init_layout()
+ super(LoupeMode, self).activate()
-Grid = GridMode()
+ def key_original(self):
+ windows.focus(1)
+ buffers.original.open()
+
+ def key_one(self):
+ windows.focus(1)
+ buffers.one.open()
+
+ def key_two(self):
+ windows.focus(1)
+ buffers.two.open()
+
+ def key_result(self):
+ windows.focus(1)
+ buffers.result.open()
+
+
+grid = GridMode()
+loupe = LoupeMode()
+
+
+def key_grid():
+ global current_mode
+ current_mode = grid
+ grid.activate()
+
+def key_loupe():
+ global current_mode
+ current_mode = loupe
+ loupe.activate()
--- a/plugin/threesomelib/util/__init__.py Sun Jun 12 21:44:55 2011 -0400
+++ b/plugin/threesomelib/util/__init__.py Sun Jun 12 23:33:31 2011 -0400
@@ -1,1 +1,2 @@
-from misc import *
+# This is kind of a dirty hack. Feels bad, man.
+from bufferlib import buffers
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/threesomelib/util/bufferlib.py Sun Jun 12 23:33:31 2011 -0400
@@ -0,0 +1,39 @@
+import vim
+
+
+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)
+
+buffers = _BufferList()
--- a/plugin/threesomelib/util/buffers.py Sun Jun 12 21:44:55 2011 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-import vim
-
-
-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 base(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)
-
-buffers = _BufferList()