*** src/proto/.svn/text-base/normal.pro.svn-base	2009-01-11 02:46:04.000000000 +1030
--- src/proto/normal.pro	2009-01-11 04:04:08.000000000 +1030
***************
*** 14,20 ****
--- 14,22 ----
  void add_to_showcmd_c __ARGS((int c));
  void push_showcmd __ARGS((void));
  void pop_showcmd __ARGS((void));
+ void do_check_scrollbind_win __ARGS((int check, win_T *wp));
  void do_check_scrollbind __ARGS((int check));
+ void check_scrollbind_win __ARGS((linenr_T topline_diff, long leftcol_diff, win_T *wp));
  void check_scrollbind __ARGS((linenr_T topline_diff, long leftcol_diff));
  int find_decl __ARGS((char_u *ptr, int len, int locally, int thisblock, int searchflags));
  void scroll_redraw __ARGS((int up, long count));
*** src/.svn/text-base/gui.c.svn-base	2009-01-11 02:46:05.000000000 +1030
--- src/gui.c	2009-01-11 04:04:08.000000000 +1030
***************
*** 3674,3688 ****
  {
  #ifdef FEAT_WINDOWS
      win_T	*wp;
  #endif
      int		sb_num;
  #ifdef USE_ON_FLY_SCROLL
      colnr_T	old_leftcol = curwin->w_leftcol;
  # ifdef FEAT_SCROLLBIND
!     linenr_T	old_topline = curwin->w_topline;
  # endif
  # ifdef FEAT_DIFF
!     int		old_topfill = curwin->w_topfill;
  # endif
  #else
      char_u	bytes[sizeof(long_u)];
--- 3674,3689 ----
  {
  #ifdef FEAT_WINDOWS
      win_T	*wp;
+     win_T	*scrolledwin = (sb->wp == NULL) ? curwin : sb->wp;
  #endif
      int		sb_num;
  #ifdef USE_ON_FLY_SCROLL
      colnr_T	old_leftcol = curwin->w_leftcol;
  # ifdef FEAT_SCROLLBIND
!     linenr_T	old_topline = scrolledwin->w_topline;
  # endif
  # ifdef FEAT_DIFF
!     int		old_topfill = scrolledwin->w_topfill;
  # endif
  #else
      char_u	bytes[sizeof(long_u)];
***************
*** 3854,3868 ****
      /*
       * synchronize other windows, as necessary according to 'scrollbind'
       */
!     if (curwin->w_p_scb
! 	    && ((sb->wp == NULL && curwin->w_leftcol != old_leftcol)
! 		|| (sb->wp == curwin && (curwin->w_topline != old_topline
  #  ifdef FEAT_DIFF
! 					   || curwin->w_topfill != old_topfill
  #  endif
! 			))))
      {
! 	do_check_scrollbind(TRUE);
  	/* need to update the window right here */
  	for (wp = firstwin; wp != NULL; wp = wp->w_next)
  	    if (wp->w_redr_type > 0)
--- 3855,3869 ----
      /*
       * synchronize other windows, as necessary according to 'scrollbind'
       */
!     if ((curwin->w_p_scb && (sb->wp == NULL && curwin->w_leftcol != old_leftcol))
! 	    || ((sb->wp != NULL) && scrolledwin->w_p_scb
! 		&& (scrolledwin->w_topline != old_topline
  #  ifdef FEAT_DIFF
! 		   || scrolledwin->w_topfill != old_topfill
  #  endif
! 		)))
      {
! 	do_check_scrollbind_win(TRUE, scrolledwin);
  	/* need to update the window right here */
  	for (wp = firstwin; wp != NULL; wp = wp->w_next)
  	    if (wp->w_redr_type > 0)
***************
*** 4202,4208 ****
  	if (old_cursor.lnum != wp->w_cursor.lnum)
  	    coladvance(wp->w_curswant);
  #ifdef FEAT_SCROLLBIND
! 	wp->w_scbind_pos = wp->w_topline;
  #endif
      }
  
--- 4203,4209 ----
  	if (old_cursor.lnum != wp->w_cursor.lnum)
  	    coladvance(wp->w_curswant);
  #ifdef FEAT_SCROLLBIND
! 	do_check_scrollbind_win(TRUE, wp);
  #endif
      }
  
*** src/.svn/text-base/edit.c.svn-base	2009-01-11 02:46:16.000000000 +1030
--- src/edit.c	2009-01-11 04:04:08.000000000 +1030
***************
*** 8731,8736 ****
--- 8731,8739 ----
  # ifdef FEAT_INS_EXPAND
  	did_scroll = TRUE;
  # endif
+ #ifdef FEAT_SCROLLBIND
+ 	do_check_scrollbind(TRUE);
+ #endif
      }
  
  # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
*** src/.svn/text-base/normal.c.svn-base	2009-01-11 02:46:19.000000000 +1030
--- src/normal.c	2009-01-11 04:04:08.000000000 +1030
***************
*** 3921,3930 ****
   * scrolled.  Called from normal_cmd() and edit().
   */
      void
! do_check_scrollbind(check)
      int		check;
  {
!     static win_T	*old_curwin = NULL;
      static linenr_T	old_topline = 0;
  #ifdef FEAT_DIFF
      static int		old_topfill = 0;
--- 3921,3931 ----
   * scrolled.  Called from normal_cmd() and edit().
   */
      void
! do_check_scrollbind_win(check, wp)
      int		check;
+     win_T	*wp;
  {
!     static win_T	*old_wp = NULL;
      static linenr_T	old_topline = 0;
  #ifdef FEAT_DIFF
      static int		old_topfill = 0;
***************
*** 3932,3963 ****
      static buf_T	*old_buf = NULL;
      static colnr_T	old_leftcol = 0;
  
!     if (check && curwin->w_p_scb)
      {
  	/* If a ":syncbind" command was just used, don't scroll, only reset
  	 * the values. */
  	if (did_syncbind)
  	    did_syncbind = FALSE;
! 	else if (curwin == old_curwin)
  	{
  	    /*
  	     * Synchronize other windows, as necessary according to
  	     * 'scrollbind'.  Don't do this after an ":edit" command, except
  	     * when 'diff' is set.
  	     */
! 	    if ((curwin->w_buffer == old_buf
  #ifdef FEAT_DIFF
! 			|| curwin->w_p_diff
  #endif
  		)
! 		&& (curwin->w_topline != old_topline
  #ifdef FEAT_DIFF
! 			|| curwin->w_topfill != old_topfill
  #endif
! 			|| curwin->w_leftcol != old_leftcol))
  	    {
! 		check_scrollbind(curwin->w_topline - old_topline,
! 			(long)(curwin->w_leftcol - old_leftcol));
  	    }
  	}
  	else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */
--- 3933,3964 ----
      static buf_T	*old_buf = NULL;
      static colnr_T	old_leftcol = 0;
  
!     if (check && wp->w_p_scb)
      {
  	/* If a ":syncbind" command was just used, don't scroll, only reset
  	 * the values. */
  	if (did_syncbind)
  	    did_syncbind = FALSE;
! 	else if (wp == old_wp)
  	{
  	    /*
  	     * Synchronize other windows, as necessary according to
  	     * 'scrollbind'.  Don't do this after an ":edit" command, except
  	     * when 'diff' is set.
  	     */
! 	    if ((wp->w_buffer == old_buf
  #ifdef FEAT_DIFF
! 			|| wp->w_p_diff
  #endif
  		)
! 		&& (wp->w_topline != old_topline
  #ifdef FEAT_DIFF
! 			|| wp->w_topfill != old_topfill
  #endif
! 			|| wp->w_leftcol != old_leftcol))
  	    {
! 		check_scrollbind_win(wp->w_topline - old_topline,
! 			(long)(wp->w_leftcol - old_leftcol), wp);
  	    }
  	}
  	else if (vim_strchr(p_sbo, 'j')) /* jump flag set in 'scrollopt' */
***************
*** 3972,3989 ****
  	     * need to jump so that the current window's relative position is
  	     * visible on-screen.
  	     */
! 	    check_scrollbind(curwin->w_topline - curwin->w_scbind_pos, 0L);
  	}
! 	curwin->w_scbind_pos = curwin->w_topline;
      }
  
!     old_curwin = curwin;
!     old_topline = curwin->w_topline;
  #ifdef FEAT_DIFF
!     old_topfill = curwin->w_topfill;
  #endif
!     old_buf = curwin->w_buffer;
!     old_leftcol = curwin->w_leftcol;
  }
  
  /*
--- 3973,3997 ----
  	     * need to jump so that the current window's relative position is
  	     * visible on-screen.
  	     */
! 	    check_scrollbind_win(wp->w_topline - wp->w_scbind_pos, 0L, wp);
  	}
! 	wp->w_scbind_pos = wp->w_topline;
      }
  
!     old_wp = wp;
!     old_topline = wp->w_topline;
  #ifdef FEAT_DIFF
!     old_topfill = wp->w_topfill;
  #endif
!     old_buf = wp->w_buffer;
!     old_leftcol = wp->w_leftcol;
! }
! 
!     void
! do_check_scrollbind(check)
!     int		check;
! {
!     do_check_scrollbind_win(check, curwin);
  }
  
  /*
***************
*** 3992,4000 ****
   * (1998-11-02 16:21:01  R. Edward Ralston <eralston@computer.org>)
   */
      void
! check_scrollbind(topline_diff, leftcol_diff)
      linenr_T	topline_diff;
      long	leftcol_diff;
  {
      int		want_ver;
      int		want_hor;
--- 4000,4009 ----
   * (1998-11-02 16:21:01  R. Edward Ralston <eralston@computer.org>)
   */
      void
! check_scrollbind_win(topline_diff, leftcol_diff, wp)
      linenr_T	topline_diff;
      long	leftcol_diff;
+     win_T	*wp;
  {
      int		want_ver;
      int		want_hor;
***************
*** 4013,4019 ****
       */
      want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0);
  #ifdef FEAT_DIFF
!     want_ver |= old_curwin->w_p_diff;
  #endif
      want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0));
  
--- 4022,4028 ----
       */
      want_ver = (vim_strchr(p_sbo, 'v') && topline_diff != 0);
  #ifdef FEAT_DIFF
!     want_ver |= wp->w_p_diff;
  #endif
      want_hor = (vim_strchr(p_sbo, 'h') && (leftcol_diff || topline_diff != 0));
  
***************
*** 4027,4033 ****
      {
  	curbuf = curwin->w_buffer;
  	/* skip original window  and windows with 'noscrollbind' */
! 	if (curwin != old_curwin && curwin->w_p_scb)
  	{
  	    /*
  	     * do the vertical scroll
--- 4036,4042 ----
      {
  	curbuf = curwin->w_buffer;
  	/* skip original window  and windows with 'noscrollbind' */
! 	if (curwin != wp && curwin->w_p_scb)
  	{
  	    /*
  	     * do the vertical scroll
***************
*** 4035,4043 ****
  	    if (want_ver)
  	    {
  #ifdef FEAT_DIFF
! 		if (old_curwin->w_p_diff && curwin->w_p_diff)
  		{
! 		    diff_set_topline(old_curwin, curwin);
  		}
  		else
  #endif
--- 4044,4052 ----
  	    if (want_ver)
  	    {
  #ifdef FEAT_DIFF
! 		if (wp->w_p_diff && curwin->w_p_diff)
  		{
! 		    diff_set_topline(wp, curwin);
  		}
  		else
  #endif
***************
*** 4084,4089 ****
--- 4093,4106 ----
      curwin = old_curwin;
      curbuf = old_curbuf;
  }
+ 
+ void
+ check_scrollbind(topline_diff, leftcol_diff)
+     linenr_T	topline_diff;
+     long	leftcol_diff;
+ {
+     check_scrollbind_win(topline_diff, leftcol_diff, curwin);
+ }
  #endif /* #ifdef FEAT_SCROLLBIND */
  
  /*
***************
*** 4506,4511 ****
--- 4523,4532 ----
  	nv_scroll_line(cap);
      }
  
+ #ifdef FEAT_SCROLLBIND
+     do_check_scrollbind(TRUE);
+ #endif
+ 
  # if defined(FEAT_GUI) && defined(FEAT_WINDOWS)
      curwin->w_redr_status = TRUE;
  
