890a1d687c33

Diffoff and some cleanup.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 13 Jun 2011 01:03:56 -0400
parents 0e3a284792b2
children c353930abfc4
branches/tags (none)
files plugin/threesome.py plugin/threesome.vim plugin/threesomelib/init.py plugin/threesomelib/modes.py plugin/threesomelib/util/bufferlib.py

Changes

--- a/plugin/threesome.py	Mon Jun 13 00:50:43 2011 -0400
+++ b/plugin/threesome.py	Mon Jun 13 01:03:56 2011 -0400
@@ -47,6 +47,9 @@
 def ThreesomeDiff():
     threesome.modes.current_mode.key_diff()
 
+def ThreesomeDiffoff():
+    threesome.modes.current_mode.key_diffoff()
+
 def ThreesomeNext():
     threesome.modes.current_mode.key_next()
 
--- a/plugin/threesome.vim	Mon Jun 13 00:50:43 2011 -0400
+++ b/plugin/threesome.vim	Mon Jun 13 01:03:56 2011 -0400
@@ -98,6 +98,9 @@
 function! s:ThreesomeDiff()"{{{
     python ThreesomeDiff()
 endfunction"}}}
+function! s:ThreesomeDiffoff()"{{{
+    python ThreesomeDiffoff()
+endfunction"}}}
 function! s:ThreesomeNext()"{{{
     python ThreesomeNext()
 endfunction"}}}
@@ -122,6 +125,7 @@
 command! -nargs=0 ThreesomeResult call s:ThreesomeResult()
 
 command! -nargs=0 ThreesomeDiff call s:ThreesomeDiff()
+command! -nargs=0 ThreesomeDiffoff call s:ThreesomeDiffoff()
 command! -nargs=0 ThreesomeNext call s:ThreesomeNext()
 command! -nargs=0 ThreesomePrev call s:ThreesomePrev()
 
--- a/plugin/threesomelib/init.py	Mon Jun 13 00:50:43 2011 -0400
+++ b/plugin/threesomelib/init.py	Mon Jun 13 01:03:56 2011 -0400
@@ -1,3 +1,4 @@
+import vim
 import modes
 from util import buffers, keys, windows
 
@@ -40,11 +41,30 @@
     keys.bind('r', ':ThreesomeResult<cr>')
 
     keys.bind('d', ':ThreesomeDiff<cr>')
+    keys.bind('D', ':ThreesomeDiffoff<cr>')
     keys.bind('n', ':ThreesomeNext<cr>')
     keys.bind('N', ':ThreesomePrev<cr>')
 
+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')
+
+
 def init():
     process_result()
+    setlocal_buffers()
     bind_global_keys()
     modes.current_mode = modes.grid
     modes.current_mode.activate()
--- a/plugin/threesomelib/modes.py	Mon Jun 13 00:50:43 2011 -0400
+++ b/plugin/threesomelib/modes.py	Mon Jun 13 01:03:56 2011 -0400
@@ -11,7 +11,9 @@
 
 
     def diff(self, diffmode):
+        curwindow = windows.currentnr()
         getattr(self, '_diff_%d' % diffmode)()
+        windows.focus(curwindow)
 
     def key_diff(self, diffmode=None):
         next_diff_mode = self._current_diff_mode + 1
@@ -19,6 +21,9 @@
             next_diff_mode = 0
         self.diff(next_diff_mode)
 
+    def key_diffoff(self):
+        self.diff(0)
+
 
     def key_original(self):
         pass
@@ -211,8 +216,7 @@
 
     def key_one(self):
         def open_one(winnr):
-            windows.focus(winnr)
-            buffers.one.open()
+            buffers.one.open(winnr)
             self.diff(self._current_diff_mode)
 
         curwindow = windows.currentnr()
@@ -246,8 +250,7 @@
 
     def key_two(self):
         def open_two(winnr):
-            windows.focus(winnr)
-            buffers.two.open()
+            buffers.two.open(winnr)
             self.diff(self._current_diff_mode)
 
         curwindow = windows.currentnr()
@@ -358,11 +361,13 @@
         windows.focus(2)
         buffers.one.open()
         self.diff(self._current_diff_mode)
+        windows.focus(2)
 
     def key_two(self):
         windows.focus(2)
         buffers.two.open()
         self.diff(self._current_diff_mode)
+        windows.focus(2)
 
     def key_result(self):
         windows.focus(3)
--- a/plugin/threesomelib/util/bufferlib.py	Mon Jun 13 00:50:43 2011 -0400
+++ b/plugin/threesomelib/util/bufferlib.py	Mon Jun 13 01:03:56 2011 -0400
@@ -1,5 +1,6 @@
 import os
 import vim
+import windows
 
 ap = os.path.abspath
 
@@ -9,7 +10,9 @@
         self._buffer = vim.buffers[i]
         self.name = self._buffer.name
 
-    def open(self):
+    def open(self, winnr=None):
+        if winnr is not None:
+            windows.focus(winnr)
         vim.command('%dbuffer' % self.number)
 
     def set_lines(self, lines):