c716ddab8449

Configurable scrollbinding!
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Mon, 13 Jun 2011 17:24:49 -0400
parents 94dd97c75c52
children b9e75c5a9f2c
branches/tags (none)
files README.markdown doc/threesome.txt plugin/threesome.py plugin/threesome.vim plugin/threesomelib/init.py plugin/threesomelib/modes.py plugin/threesomelib/util/io.py

Changes

--- a/README.markdown	Mon Jun 13 16:48:58 2011 -0400
+++ b/README.markdown	Mon Jun 13 17:24:49 2011 -0400
@@ -77,8 +77,7 @@
 TODO for v1.0.0
 ===============
 
+* Add a help/status bar at the top.
 * Add hunk-pulling functionality.
-* Add scroll-locking functionality.
-* Add a help/status bar at the top.
 * Add a basic test suite.
 * Remove the eat-your-data warnings in the docs.
--- a/doc/threesome.txt	Mon Jun 13 16:48:58 2011 -0400
+++ b/doc/threesome.txt	Mon Jun 13 17:24:49 2011 -0400
@@ -25,38 +25,42 @@
 ==============================================================================
 CONTENTS                                                  *Threesome-contents*
 
-    1. Version Control Integration ............ |ThreesomeVCS|
-        1.1 Mercurial ......................... |ThreesomeVCS-hg|
-        1.2 Git ............................... |ThreesomeVCS-git|
-    2. Basic Usage ............................ |ThreesomeUsage|
-        2.1 Files ............................. |ThreesomeUsage-files|
-        2.2 Modes ............................. |ThreesomeUsage-modes|
-    3. Key Bindings ........................... |ThreesomeKeys|
-        3.1 Mode Selection Keys ............... |ThreesomeKeys-mode|
-        3.2 File Selection Keys ............... |ThreesomeKeys-file|
-        3.3 Other Keys ........................ |ThreesomeKeys-other|
-    4. Modes .................................. |ThreesomeModes|
-        4.1 Grid .............................. |ThreesomeModes-grid|
-        4.2 Loupe ............................. |ThreesomeModes-loupe|
-        4.3 Compare ........................... |ThreesomeModes-compare|
-        4.4 Path .............................. |ThreesomeModes-path|
-    5. Configuration .......................... |ThreesomeConfig|
-        5.1 threesome_debug ................... |ThreesomeConfig-debug|
-        5.2 threesome_disable ................. |ThreesomeConfig-disable|
-        5.3 threesome_initial_diff_grid ....... |ThreesomeConfig-id_grid|
-        5.4 threesome_initial_diff_loupe ...... |ThreesomeConfig-id_loupe|
-        5.5 threesome_initial_diff_compare .... |ThreesomeConfig-id_compare|
-        5.6 threesome_initial_diff_path ....... |ThreesomeConfig-id_path|
-        5.7 threesome_initial_layout_grid ..... |ThreesomeConfig-il_grid|
-        5.8 threesome_initial_layout_loupe .... |ThreesomeConfig-il_loupe|
-        5.9 threesome_initial_layout_compare .. |ThreesomeConfig-il_compare|
-        5.10 threesome_initial_layout_path .... |ThreesomeConfig-il_path|
-        5.11 threesome_initial_mode ........... |ThreesomeConfig-initial_mode|
-    6. License ................................ |ThreesomeLicense|
-    7. Bugs ................................... |ThreesomeBugs|
-    8. Contributing ........................... |ThreesomeContributing|
-    9. Changelog .............................. |ThreesomeChangelog|
-   10. Credits ................................ |ThreesomeCredits|
+    1. Version Control Integration ................. |ThreesomeVCS|
+        1.1 Mercurial .............................. |ThreesomeVCS-hg|
+        1.2 Git .................................... |ThreesomeVCS-git|
+    2. Basic Usage ................................. |ThreesomeUsage|
+        2.1 Files .................................. |ThreesomeUsage-files|
+        2.2 Modes .................................. |ThreesomeUsage-modes|
+    3. Key Bindings ................................ |ThreesomeKeys|
+        3.1 Mode Selection Keys .................... |ThreesomeKeys-mode|
+        3.2 File Selection Keys .................... |ThreesomeKeys-file|
+        3.3 Other Keys ............................. |ThreesomeKeys-other|
+    4. Modes ....................................... |ThreesomeModes|
+        4.1 Grid ................................... |ThreesomeModes-grid|
+        4.2 Loupe .................................. |ThreesomeModes-loupe|
+        4.3 Compare ................................ |ThreesomeModes-compare|
+        4.4 Path ................................... |ThreesomeModes-path|
+    5. Configuration ............................... |ThreesomeConfig|
+        5.1 threesome_debug ........................ |ThreesomeConfig-debug|
+        5.2 threesome_disable ...................... |ThreesomeConfig-disable|
+        5.3 threesome_initial_diff_grid ............ |ThreesomeConfig-id_grid|
+        5.4 threesome_initial_diff_loupe ........... |ThreesomeConfig-id_loupe|
+        5.5 threesome_initial_diff_compare ......... |ThreesomeConfig-id_compare|
+        5.6 threesome_initial_diff_path ............ |ThreesomeConfig-id_path|
+        5.7 threesome_initial_layout_grid .......... |ThreesomeConfig-il_grid|
+        5.8 threesome_initial_layout_loupe ......... |ThreesomeConfig-il_loupe|
+        5.9 threesome_initial_layout_compare ....... |ThreesomeConfig-il_compare|
+        5.10 threesome_initial_layout_path ......... |ThreesomeConfig-il_path|
+        5.11 threesome_initial_scrollbind_grid ..... |ThreesomeConfig-is_grid|
+        5.12 threesome_initial_scrollbind_loupe .... |ThreesomeConfig-is_loupe|
+        5.13 threesome_initial_scrollbind_compare .. |ThreesomeConfig-is_compare|
+        5.14 threesome_initial_scrollbind_path ..... |ThreesomeConfig-is_path|
+        5.15 threesome_initial_mode ................ |ThreesomeConfig-im|
+    6. License ..................................... |ThreesomeLicense|
+    7. Bugs ........................................ |ThreesomeBugs|
+    8. Contributing ................................ |ThreesomeContributing|
+    9. Changelog ................................... |ThreesomeChangelog|
+   10. Credits ..................................... |ThreesomeCredits|
 
 
 ==============================================================================
@@ -516,10 +520,44 @@
 Default: 0
 
 ------------------------------------------------------------------------------
-5.11 g:threesome_initial_mode                   *ThreesomeConfig-initial_mode*
+5.11 g:threesome_initial_scrollbind_grid             *ThreesomeConfig-is_grid*
+
+Set this to 1 to enable |scrollbind| by default in grid mode.
+
+Options: 0 or 1
+Default: 0
+
+------------------------------------------------------------------------------
+5.12 g:threesome_initial_scrollbind_loupe           *ThreesomeConfig-is_loupe*
+
+Set this to 1 to enable |scrollbind| by default in loupe mode.
+
+Options: 0 or 1
+Default: 0
+
+------------------------------------------------------------------------------
+5.13 g:threesome_initial_scrollbind_compare       *ThreesomeConfig-is_compare*
+
+Set this to 1 to enable |scrollbind| by default in compare mode.
+
+Options: 0 or 1
+Default: 0
+
+------------------------------------------------------------------------------
+5.14 g:threesome_initial_scrollbind_path             *ThreesomeConfig-is_path*
+
+Set this to 1 to enable |scrollbind| by default in path mode.
+
+Options: 0 or 1
+Default: 0
+
+------------------------------------------------------------------------------
+5.15 g:threesome_initial_mode                             *ThreesomeConfig-im*
 
 Set this to change the mode Threesome initially starts up in.
 
+See |ThreesomeModes| for a description of each mode.
+
 Options: "grid", "loupe", "compare", or "path"
 Default: "grid"
 
@@ -550,6 +588,8 @@
 ==============================================================================
 9. Changelog                                              *ThreesomeChangelog*
 
+v0.0.5
+    * Configurable scrollbinding.
 v0.0.4
     * Basic configuration settings.
 v0.0.3
--- a/plugin/threesome.py	Mon Jun 13 16:48:58 2011 -0400
+++ b/plugin/threesome.py	Mon Jun 13 17:24:49 2011 -0400
@@ -51,6 +51,9 @@
 def ThreesomeDiffoff():
     threesome.modes.current_mode.key_diffoff()
 
+def ThreesomeScroll():
+    threesome.modes.current_mode.key_scrollbind()
+
 def ThreesomeLayout():
     threesome.modes.current_mode.key_layout()
 
--- a/plugin/threesome.vim	Mon Jun 13 16:48:58 2011 -0400
+++ b/plugin/threesome.vim	Mon Jun 13 17:24:49 2011 -0400
@@ -83,6 +83,18 @@
 if !exists('g:threesome_initial_diff_path') " {{{
     let g:threesome_initial_diff_path = 0
 endif " }}}
+if !exists('g:threesome_initial_scrollbind_grid') " {{{
+    let g:threesome_initial_scrollbind_grid = 0
+endif " }}}
+if !exists('g:threesome_initial_scrollbind_loupe') " {{{
+    let g:threesome_initial_scrollbind_loupe = 0
+endif " }}}
+if !exists('g:threesome_initial_scrollbind_compare') " {{{
+    let g:threesome_initial_scrollbind_compare = 0
+endif " }}}
+if !exists('g:threesome_initial_scrollbind_path') " {{{
+    let g:threesome_initial_scrollbind_path = 0
+endif " }}}
 
 "}}}
 
@@ -128,6 +140,9 @@
 function! s:ThreesomeDiffoff()"{{{
     python ThreesomeDiffoff()
 endfunction"}}}
+function! s:ThreesomeScroll()"{{{
+    python ThreesomeScroll()
+endfunction"}}}
 function! s:ThreesomeLayout()"{{{
     python ThreesomeLayout()
 endfunction"}}}
@@ -156,6 +171,7 @@
 
 command! -nargs=0 ThreesomeDiff call s:ThreesomeDiff()
 command! -nargs=0 ThreesomeDiffoff call s:ThreesomeDiffoff()
+command! -nargs=0 ThreesomeScroll call s:ThreesomeScroll()
 command! -nargs=0 ThreesomeLayout call s:ThreesomeLayout()
 command! -nargs=0 ThreesomeNext call s:ThreesomeNext()
 command! -nargs=0 ThreesomePrev call s:ThreesomePrev()
--- a/plugin/threesomelib/init.py	Mon Jun 13 16:48:58 2011 -0400
+++ b/plugin/threesomelib/init.py	Mon Jun 13 17:24:49 2011 -0400
@@ -43,6 +43,7 @@
 
     keys.bind('d', ':ThreesomeDiff<cr>')
     keys.bind('D', ':ThreesomeDiffoff<cr>')
+    keys.bind('s', ':ThreesomeScroll<cr>')
     keys.bind('n', ':ThreesomeNext<cr>')
     keys.bind('N', ':ThreesomePrev<cr>')
     keys.bind('<space>', ':ThreesomeLayout<cr>')
--- a/plugin/threesomelib/modes.py	Mon Jun 13 16:48:58 2011 -0400
+++ b/plugin/threesomelib/modes.py	Mon Jun 13 17:24:49 2011 -0400
@@ -1,6 +1,7 @@
 import vim
 from util import buffers, windows
 from settings import setting
+from util.io import error
 
 
 current_mode = None
@@ -15,6 +16,10 @@
         getattr(self, '_diff_%d' % diffmode)()
         windows.focus(curwindow)
 
+        # Reset the scrollbind to whatever it was before we diffed.
+        if not diffmode:
+            self.scrollbind(self._current_scrollbind)
+
     def key_diff(self, diffmode=None):
         next_diff_mode = self._current_diff_mode + 1
         if next_diff_mode >= self._number_of_diff_modes:
@@ -41,6 +46,32 @@
         self.diff(0)
 
 
+    def scrollbind(self, enabled):
+        if self._current_diff_mode:
+            return
+
+        curwindow = windows.currentnr()
+        pos = vim.current.window.cursor
+        self._current_scrollbind = enabled
+
+        for winnr in range(1, 1 + self._number_of_windows):
+            windows.focus(winnr)
+
+            if enabled:
+                vim.command('set scrollbind')
+            else:
+                vim.command('set noscrollbind')
+
+        if enabled:
+            vim.command('syncbind')
+
+        windows.focus(curwindow)
+        vim.current.window.cursor = pos
+
+    def key_scrollbind(self):
+        self.scrollbind(not self._current_scrollbind)
+
+
     def layout(self, layoutnr):
         getattr(self, '_layout_%d' % layoutnr)()
         self.diff(self._current_diff_mode)
@@ -69,6 +100,8 @@
         self.layout(self._current_layout)
         self.diff(self._current_diff_mode)
 
+        self.scrollbind(self._current_scrollbind)
+
 
     def key_next(self):
         self.goto_result()
@@ -97,6 +130,7 @@
     def __init__(self):
         self._current_layout = int(setting('initial_layout_grid', 0))
         self._current_diff_mode = int(setting('initial_diff_grid', 0))
+        self._current_scrollbind = int(setting('initial_scrollbind_grid', 0)) and True or False
 
         self._number_of_diff_modes = 2
         self._number_of_layouts = 3
@@ -225,6 +259,7 @@
     def __init__(self):
         self._current_layout = int(setting('initial_layout_loupe', 0))
         self._current_diff_mode = int(setting('initial_diff_loupe', 0))
+        self._current_scrollbind = int(setting('initial_scrollbind_loupe', 0)) and True or False
 
         self._number_of_diff_modes = 1
         self._number_of_layouts = 1
@@ -279,6 +314,7 @@
     def __init__(self):
         self._current_layout = int(setting('initial_layout_compare', 0))
         self._current_diff_mode = int(setting('initial_diff_compare', 0))
+        self._current_scrollbind = int(setting('initial_scrollbind_compare', 0)) and True or False
 
         self._number_of_diff_modes = 2
         self._number_of_layouts = 2
@@ -431,6 +467,7 @@
     def __init__(self):
         self._current_layout = int(setting('initial_layout_path', 0))
         self._current_diff_mode = int(setting('initial_diff_path', 0))
+        self._current_scrollbind = int(setting('initial_scrollbind_path', 0)) and True or False
 
         self._number_of_diff_modes = 5
         self._number_of_layouts = 2
--- a/plugin/threesomelib/util/io.py	Mon Jun 13 16:48:58 2011 -0400
+++ b/plugin/threesomelib/util/io.py	Mon Jun 13 17:24:49 2011 -0400
@@ -2,4 +2,4 @@
 
 
 def error(m):
-    sys.stdout.write(m + '\n')
+    sys.stdout.write(str(m) + '\n')