--- a/plugin/threesome.py Sun Jun 12 23:33:31 2011 -0400
+++ b/plugin/threesome.py Mon Jun 13 00:25:16 2011 -0400
@@ -17,8 +17,6 @@
init.init()
threesome = init
-def ThreesomeDiff():
- threesome.modes.current_mode.key_diff()
def ThreesomeOriginal():
threesome.modes.current_mode.key_original()
@@ -32,8 +30,17 @@
def ThreesomeResult():
threesome.modes.current_mode.key_result()
+
def ThreesomeGrid():
threesome.modes.key_grid()
def ThreesomeLoupe():
threesome.modes.key_loupe()
+
+def ThreesomeCompare():
+ threesome.modes.key_compare()
+
+
+def ThreesomeDiff():
+ threesome.modes.current_mode.key_diff()
+
--- a/plugin/threesome.vim Sun Jun 12 23:33:31 2011 -0400
+++ b/plugin/threesome.vim Mon Jun 13 00:25:16 2011 -0400
@@ -75,6 +75,9 @@
function! s:ThreesomeLoupe()"{{{
python ThreesomeLoupe()
endfunction"}}}
+function! s:ThreesomeCompare()"{{{
+ python ThreesomeCompare()
+endfunction"}}}
function! s:ThreesomeOriginal()"{{{
python ThreesomeOriginal()
@@ -101,6 +104,7 @@
command! -nargs=0 ThreesomeGrid call s:ThreesomeGrid()
command! -nargs=0 ThreesomeLoupe call s:ThreesomeLoupe()
+command! -nargs=0 ThreesomeCompare call s:ThreesomeCompare()
command! -nargs=0 ThreesomeOriginal call s:ThreesomeOriginal()
command! -nargs=0 ThreesomeOne call s:ThreesomeOne()
--- a/plugin/threesomelib/init.py Sun Jun 12 23:33:31 2011 -0400
+++ b/plugin/threesomelib/init.py Mon Jun 13 00:25:16 2011 -0400
@@ -31,6 +31,7 @@
def bind_global_keys():
keys.bind('g', ':ThreesomeGrid<cr>')
keys.bind('l', ':ThreesomeLoupe<cr>')
+ keys.bind('c', ':ThreesomeCompare<cr>')
keys.bind('o', ':ThreesomeOriginal<cr>')
keys.bind('1', ':ThreesomeOne<cr>')
--- a/plugin/threesomelib/modes.py Sun Jun 12 23:33:31 2011 -0400
+++ b/plugin/threesomelib/modes.py Mon Jun 13 00:25:16 2011 -0400
@@ -150,9 +150,127 @@
windows.focus(1)
buffers.result.open()
+class CompareMode(Mode):
+ def __init__(self):
+ self._number_of_diff_modes = 2
+ return super(CompareMode, self).__init__()
+
+
+ def _init_layout(self):
+ # Open the layout
+ windows.close_all()
+ windows.vsplit()
+
+ # Put the buffers in the appropriate windows
+ windows.focus(1)
+ buffers.original.open()
+
+ windows.focus(2)
+ buffers.result.open()
+
+
+ def _diff_0(self):
+ vim.command('diffoff!')
+ self._current_diff_mode = 0
+
+ def _diff_1(self):
+ vim.command('diffoff!')
+ self._current_diff_mode = 1
+
+ for i in range(1, 3):
+ windows.focus(i)
+ vim.command('diffthis')
+
+
+ def activate(self):
+ self._init_layout()
+ super(CompareMode, self).activate()
+
+
+ def key_original(self):
+ windows.focus(1)
+ buffers.original.open()
+ self.diff(self._current_diff_mode)
+
+ def key_one(self):
+ def open_one(winnr):
+ windows.focus(winnr)
+ buffers.one.open()
+ self.diff(self._current_diff_mode)
+
+ curwindow = windows.currentnr()
+
+ # If file one is showing, go to it.
+ windows.focus(1)
+ if buffers.current.name == buffers.one.name:
+ return
+
+ windows.focus(2)
+ if buffers.current.name == buffers.one.name:
+ return
+
+ # If both the original and result are showing, open file one in the
+ # current window.
+ windows.focus(1)
+ if buffers.current.name == buffers.original.name:
+ windows.focus(2)
+ if buffers.current.name == buffers.result.name:
+ open_one(curwindow)
+ return
+
+ # If file two is in window 1, then we open file one in window 1.
+ windows.focus(1)
+ if buffers.current.name == buffers.two.name:
+ open_one(1)
+ return
+
+ # Otherwise, open file one in window 1.
+ open_one(1)
+
+ def key_two(self):
+ def open_two(winnr):
+ windows.focus(winnr)
+ buffers.two.open()
+ self.diff(self._current_diff_mode)
+
+ curwindow = windows.currentnr()
+
+ # If file two is showing, go to it.
+ windows.focus(1)
+ if buffers.current.name == buffers.two.name:
+ return
+
+ windows.focus(2)
+ if buffers.current.name == buffers.two.name:
+ return
+
+ # If both the original and result are showing, open file two in the
+ # current window.
+ windows.focus(1)
+ if buffers.current.name == buffers.original.name:
+ windows.focus(2)
+ if buffers.current.name == buffers.result.name:
+ open_two(curwindow)
+ return
+
+ # If file one is in window 2, then we open file two in window 2.
+ windows.focus(2)
+ if buffers.current.name == buffers.two.name:
+ open_two(2)
+ return
+
+ # Otherwise, open file two in window 2.
+ open_two(2)
+
+ def key_result(self):
+ windows.focus(2)
+ buffers.result.open()
+ self.diff(self._current_diff_mode)
+
grid = GridMode()
loupe = LoupeMode()
+compare = CompareMode()
def key_grid():
@@ -164,3 +282,7 @@
global current_mode
current_mode = loupe
loupe.activate()
+def key_compare():
+ global current_mode
+ current_mode = compare
+ compare.activate()
--- a/plugin/threesomelib/util/bufferlib.py Sun Jun 12 23:33:31 2011 -0400
+++ b/plugin/threesomelib/util/bufferlib.py Mon Jun 13 00:25:16 2011 -0400
@@ -1,5 +1,7 @@
+import os
import vim
+ap = os.path.abspath
class Buffer(object):
def __init__(self, i):
@@ -36,4 +38,19 @@
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()
--- a/plugin/threesomelib/util/windows.py Sun Jun 12 23:33:31 2011 -0400
+++ b/plugin/threesomelib/util/windows.py Mon Jun 13 00:25:16 2011 -0400
@@ -1,5 +1,4 @@
import vim
-from io import error
def focus(winnr):
@@ -18,3 +17,7 @@
def vsplit():
vim.command('wincmd v')
+
+def currentnr():
+ return int(vim.eval('winnr()'))
+