# HG changeset patch # User Steve Losh # Date 1307992735 14400 # Node ID 2358d83d38306c0a1f4253cc1bbd4f91adcca081 # Parent 124cbd25b6a9dc111374fc82823a76b6b12dbc0c And now we have layouts. diff -r 124cbd25b6a9 -r 2358d83d3830 doc/threesome.txt --- a/doc/threesome.txt Mon Jun 13 14:43:41 2011 -0400 +++ b/doc/threesome.txt Mon Jun 13 15:18:55 2011 -0400 @@ -215,6 +215,9 @@ d *Diff* Cycle through various diff combinations. +D *DiffOff* + Turn off all diffs. + u *UseHunk* Place a hunk from file one or two into the result file. diff -r 124cbd25b6a9 -r 2358d83d3830 plugin/threesome.py --- a/plugin/threesome.py Mon Jun 13 14:43:41 2011 -0400 +++ b/plugin/threesome.py Mon Jun 13 15:18:55 2011 -0400 @@ -51,6 +51,9 @@ def ThreesomeDiffoff(): threesome.modes.current_mode.key_diffoff() +def ThreesomeLayout(): + threesome.modes.current_mode.key_layout() + def ThreesomeNext(): threesome.modes.current_mode.key_next() diff -r 124cbd25b6a9 -r 2358d83d3830 plugin/threesome.vim --- a/plugin/threesome.vim Mon Jun 13 14:43:41 2011 -0400 +++ b/plugin/threesome.vim Mon Jun 13 15:18:55 2011 -0400 @@ -101,6 +101,9 @@ function! s:ThreesomeDiffoff()"{{{ python ThreesomeDiffoff() endfunction"}}} +function! s:ThreesomeLayout()"{{{ + python ThreesomeLayout() +endfunction"}}} function! s:ThreesomeNext()"{{{ python ThreesomeNext() endfunction"}}} @@ -126,6 +129,7 @@ command! -nargs=0 ThreesomeDiff call s:ThreesomeDiff() command! -nargs=0 ThreesomeDiffoff call s:ThreesomeDiffoff() +command! -nargs=0 ThreesomeLayout call s:ThreesomeLayout() command! -nargs=0 ThreesomeNext call s:ThreesomeNext() command! -nargs=0 ThreesomePrev call s:ThreesomePrev() diff -r 124cbd25b6a9 -r 2358d83d3830 plugin/threesomelib/init.py --- a/plugin/threesomelib/init.py Mon Jun 13 14:43:41 2011 -0400 +++ b/plugin/threesomelib/init.py Mon Jun 13 15:18:55 2011 -0400 @@ -44,23 +44,21 @@ keys.bind('D', ':ThreesomeDiffoff') keys.bind('n', ':ThreesomeNext') keys.bind('N', ':ThreesomePrev') + keys.bind('', ':ThreesomeLayout') keys.bind('q', ':wa:qa') keys.bind('CC', ':cq') def setlocal_buffers(): buffers.original.open() - vim.command('setlocal buftype=nofile') vim.command('setlocal noswapfile') vim.command('setlocal nomodifiable') buffers.one.open() - vim.command('setlocal buftype=nofile') vim.command('setlocal noswapfile') vim.command('setlocal nomodifiable') buffers.two.open() - vim.command('setlocal buftype=nofile') vim.command('setlocal noswapfile') vim.command('setlocal nomodifiable') diff -r 124cbd25b6a9 -r 2358d83d3830 plugin/threesomelib/modes.py --- a/plugin/threesomelib/modes.py Mon Jun 13 14:43:41 2011 -0400 +++ b/plugin/threesomelib/modes.py Mon Jun 13 15:18:55 2011 -0400 @@ -7,6 +7,7 @@ class Mode(object): def __init__(self): self._current_diff_mode = 0 + self._current_layout = 0 return super(Mode, self).__init__() @@ -15,6 +16,13 @@ getattr(self, '_diff_%d' % diffmode)() windows.focus(curwindow) + def key_diff(self, diffmode=None): + 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 diffoff(self): curwindow = windows.currentnr() @@ -30,16 +38,21 @@ windows.focus(curwindow) - def key_diff(self, diffmode=None): - 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_diffoff(self): self.diff(0) + def layout(self, layoutnr): + getattr(self, '_layout_%d' % layoutnr)() + self.diff(self._current_diff_mode) + + def key_layout(self, diffmode=None): + next_layout = self._current_layout + 1 + if next_layout >= self._number_of_layouts: + next_layout = 0 + self.layout(next_layout) + + def key_original(self): pass @@ -54,6 +67,7 @@ def activate(self): + self.layout(self._current_layout) self._diff_0() @@ -68,26 +82,30 @@ class GridMode(Mode): """ - Layout 1 Layout 2 - +-------------------+ +--------------------------+ - | Original | | One | Result | Two | - |1 | | | | | - +-------------------+ | | | | - | One | Two | | | | | - |2 |3 | | | | | - +-------------------+ | | | | - | Result | | | | | - |4 | |1 |2 |3 | - +-------------------+ +--------------------------+ + Layout 0 Layout 1 Layout 2 + +-------------------+ +--------------------------+ +---------------+ + | Original | | One | Result | Two | | One | + |1 | | | | | |1 | + +-------------------+ | | | | +---------------+ + | One | Two | | | | | | Result | + |2 |3 | | | | | |2 | + +-------------------+ | | | | +---------------+ + | Result | | | | | | Two | + |4 | |1 |2 |3 | |3 | + +-------------------+ +--------------------------+ +---------------+ """ def __init__(self): self._number_of_diff_modes = 2 - self._number_of_windows = 4 + self._number_of_layouts = 3 + return super(GridMode, self).__init__() - def _init_layout(self): + def _layout_0(self): + self._number_of_windows = 4 + self._current_layout = 0 + # Open the layout windows.close_all() windows.split() @@ -108,106 +126,44 @@ windows.focus(4) buffers.result.open() - - def _diff_0(self): - self.diffoff() - self._current_diff_mode = 0 - - def _diff_1(self): - self.diffoff() - self._current_diff_mode = 1 - - for i in range(1, 5): - windows.focus(i) - vim.command('diffthis') - - - def activate(self): - self._init_layout() - super(GridMode, self).activate() - - - def key_original(self): - windows.focus(1) + def _layout_1(self): + self._number_of_windows = 3 + self._current_layout = 1 - def key_one(self): - windows.focus(2) - - def key_two(self): - windows.focus(3) - - def key_result(self): - windows.focus(4) - - - def goto_result(self): - windows.focus(4) - -class LoupeMode(Mode): - def __init__(self): - self._number_of_diff_modes = 1 - self._number_of_windows = 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): - self.diffoff() - self._current_diff_mode = 0 - - - def activate(self): - self._init_layout() - super(LoupeMode, self).activate() - - - 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() - - - def goto_result(self): - self.key_result() - -class CompareMode(Mode): - def __init__(self): - self._number_of_diff_modes = 2 - self._number_of_windows = 2 - return super(CompareMode, self).__init__() - - - def _init_layout(self): - # Open the layout - windows.close_all() + windows.vsplit() windows.vsplit() # Put the buffers in the appropriate windows windows.focus(1) - buffers.original.open() + buffers.one.open() windows.focus(2) buffers.result.open() + windows.focus(3) + buffers.two.open() + + def _layout_2(self): + self._number_of_windows = 4 + self._current_layout = 2 + + # Open the layout + windows.close_all() + windows.split() + windows.split() + + # Put the buffers in the appropriate windows + windows.focus(1) + buffers.one.open() + + windows.focus(2) + buffers.result.open() + + windows.focus(3) + buffers.two.open() + def _diff_0(self): self.diffoff() @@ -217,24 +173,173 @@ self.diffoff() self._current_diff_mode = 1 - for i in range(1, 3): + for i in range(1, self._number_of_windows + 1): windows.focus(i) vim.command('diffthis') - def activate(self): - self._init_layout() - super(CompareMode, self).activate() + def key_original(self): + if self._current_layout == 0: + windows.focus(1) + elif self._current_layout == 1: + return + elif self._current_layout == 2: + return + + def key_one(self): + if self._current_layout == 0: + windows.focus(2) + elif self._current_layout == 1: + windows.focus(1) + elif self._current_layout == 2: + windows.focus(1) + + def key_two(self): + if self._current_layout == 0: + windows.focus(3) + elif self._current_layout == 1: + windows.focus(3) + elif self._current_layout == 2: + windows.focus(3) + + def key_result(self): + if self._current_layout == 0: + windows.focus(4) + elif self._current_layout == 1: + windows.focus(2) + elif self._current_layout == 2: + windows.focus(2) + + + def goto_result(self): + if self._current_layout == 0: + windows.focus(4) + elif self._current_layout == 1: + windows.focus(2) + elif self._current_layout == 2: + windows.focus(2) + +class LoupeMode(Mode): + def __init__(self): + self._number_of_diff_modes = 1 + self._number_of_layouts = 1 + + self._current_buffer = buffers.result + + return super(LoupeMode, self).__init__() + + + def _diff_0(self): + self.diffoff() + self._current_diff_mode = 0 + + + def _layout_0(self): + self._number_of_windows = 1 + self._current_layout = 0 + + # Open the layout + windows.close_all() + + # Put the buffers in the appropriate windows + windows.focus(1) + self._current_buffer.open() def key_original(self): windows.focus(1) buffers.original.open() + self._current_buffer = buffers.original + + def key_one(self): + windows.focus(1) + buffers.one.open() + self._current_buffer = buffers.one + + def key_two(self): + windows.focus(1) + buffers.two.open() + self._current_buffer = buffers.two + + def key_result(self): + windows.focus(1) + buffers.result.open() + self._current_buffer = buffers.result + + + def goto_result(self): + self.key_result() + +class CompareMode(Mode): + def __init__(self): + self._number_of_diff_modes = 2 + self._number_of_layouts = 2 + + self._current_buffer_first = buffers.original + self._current_buffer_second = buffers.result + + return super(CompareMode, self).__init__() + + + def _diff_0(self): + self.diffoff() + self._current_diff_mode = 0 + + def _diff_1(self): + self.diffoff() + self._current_diff_mode = 1 + + windows.focus(1) + vim.command('diffthis') + + windows.focus(2) + vim.command('diffthis') + + + def _layout_0(self): + self._number_of_windows = 2 + self._current_layout = 0 + + # Open the layout + windows.close_all() + windows.vsplit() + + # Put the buffers in the appropriate windows + windows.focus(1) + self._current_buffer_first.open() + + windows.focus(2) + self._current_buffer_second.open() + + def _layout_1(self): + self._number_of_windows = 2 + self._current_layout = 1 + + # Open the layout + windows.close_all() + windows.split() + + # Put the buffers in the appropriate windows + windows.focus(1) + self._current_buffer_first.open() + + windows.focus(2) + self._current_buffer_second.open() + + + def key_original(self): + windows.focus(1) + buffers.original.open() + self._current_buffer_first = buffers.original self.diff(self._current_diff_mode) def key_one(self): def open_one(winnr): buffers.one.open(winnr) + if winnr == 1: + self._current_buffer_first = buffers.one + else: + self._current_buffer_second = buffers.one self.diff(self._current_diff_mode) curwindow = windows.currentnr() @@ -269,6 +374,10 @@ def key_two(self): def open_two(winnr): buffers.two.open(winnr) + if winnr == 1: + self._current_buffer_first = buffers.two + else: + self._current_buffer_second = buffers.two self.diff(self._current_diff_mode) curwindow = windows.currentnr() @@ -303,6 +412,7 @@ def key_result(self): windows.focus(2) buffers.result.open() + self._current_buffer_second = buffers.result self.diff(self._current_diff_mode) @@ -311,26 +421,12 @@ class PathMode(Mode): def __init__(self): - self._number_of_diff_modes = 4 - self._number_of_windows = 3 - return super(PathMode, self).__init__() - + self._number_of_diff_modes = 5 + self._number_of_layouts = 2 - def _init_layout(self): - # Open the layout - windows.close_all() - windows.vsplit() - windows.vsplit() + self._current_mid_buffer = buffers.one - # Put the buffers in the appropriate windows - windows.focus(1) - buffers.original.open() - - windows.focus(2) - buffers.one.open() - - windows.focus(3) - buffers.result.open() + return super(PathMode, self).__init__() def _diff_0(self): @@ -367,10 +463,57 @@ windows.focus(3) vim.command('diffthis') + def _diff_4(self): + self.diffoff() + self._current_diff_mode = 4 - def activate(self): - self._init_layout() - super(PathMode, self).activate() + windows.focus(1) + vim.command('diffthis') + + windows.focus(2) + vim.command('diffthis') + + windows.focus(3) + vim.command('diffthis') + + + def _layout_0(self): + self._number_of_windows = 3 + self._current_layout = 0 + + # Open the layout + windows.close_all() + windows.vsplit() + windows.vsplit() + + # Put the buffers in the appropriate windows + windows.focus(1) + buffers.original.open() + + windows.focus(2) + self._current_mid_buffer.open() + + windows.focus(3) + buffers.result.open() + + def _layout_1(self): + self._number_of_windows = 3 + self._current_layout = 1 + + # Open the layout + windows.close_all() + windows.split() + windows.split() + + # Put the buffers in the appropriate windows + windows.focus(1) + buffers.original.open() + + windows.focus(2) + self._current_mid_buffer.open() + + windows.focus(3) + buffers.result.open() def key_original(self): @@ -379,12 +522,14 @@ def key_one(self): windows.focus(2) buffers.one.open() + self._current_mid_buffer = buffers.one self.diff(self._current_diff_mode) windows.focus(2) def key_two(self): windows.focus(2) buffers.two.open() + self._current_mid_buffer = buffers.two self.diff(self._current_diff_mode) windows.focus(2) @@ -411,10 +556,12 @@ global current_mode current_mode = loupe loupe.activate() + def key_compare(): global current_mode current_mode = compare compare.activate() + def key_path(): global current_mode current_mode = path