e688175
To: vim-dev@vim.org
e688175
Subject: Patch 7.2.042
e688175
Fcc: outbox
e688175
From: Bram Moolenaar <Bram@moolenaar.net>
e688175
Mime-Version: 1.0
e688175
Content-Type: text/plain; charset=ISO-8859-1
e688175
Content-Transfer-Encoding: 8bit
e688175
------------
e688175
e688175
Patch 7.2.042
e688175
Problem:    When using winrestview() in a BufWinEnter autocommand the window
e688175
	    is scrolled anyway. (Matt Zyzik)
e688175
Solution:   Don't recompute topline when above 'scrolloff' from the bottom.
e688175
	    Don't always put the cursor halfway when entering a buffer.  Add
e688175
	    "w_topline_was_set".
e688175
Files:	    src/buffer.c, src/move.c, src/structs.h
e688175
e688175
e688175
*** ../vim-7.2.041/src/buffer.c	Sat Nov 15 14:10:23 2008
e688175
--- src/buffer.c	Sat Nov 15 14:58:52 2008
e688175
***************
e688175
*** 1401,1406 ****
e688175
--- 1401,1409 ----
e688175
      curwin->w_cursor.coladd = 0;
e688175
  #endif
e688175
      curwin->w_set_curswant = TRUE;
e688175
+ #ifdef FEAT_AUTOCMD
e688175
+     curwin->w_topline_was_set = FALSE;
e688175
+ #endif
e688175
  
e688175
      /* Make sure the buffer is loaded. */
e688175
      if (curbuf->b_ml.ml_mfp == NULL)	/* need to load the file */
e688175
***************
e688175
*** 1440,1446 ****
e688175
      maketitle();
e688175
  #endif
e688175
  #ifdef FEAT_AUTOCMD
e688175
!     if (curwin->w_topline == 1)		/* when autocmds didn't change it */
e688175
  #endif
e688175
  	scroll_cursor_halfway(FALSE);	/* redisplay at correct position */
e688175
  
e688175
--- 1443,1450 ----
e688175
      maketitle();
e688175
  #endif
e688175
  #ifdef FEAT_AUTOCMD
e688175
! 	/* when autocmds didn't change it */
e688175
!     if (curwin->w_topline == 1 && !curwin->w_topline_was_set)
e688175
  #endif
e688175
  	scroll_cursor_halfway(FALSE);	/* redisplay at correct position */
e688175
  
e688175
*** ../vim-7.2.041/src/move.c	Sun Jul 13 19:25:23 2008
e688175
--- src/move.c	Sat Nov 15 14:56:47 2008
e688175
***************
e688175
*** 280,297 ****
e688175
  
e688175
  	if (curwin->w_botline <= curbuf->b_ml.ml_line_count)
e688175
  	{
e688175
! 	    if (curwin->w_cursor.lnum < curwin->w_botline
e688175
! 		    && ((long)curwin->w_cursor.lnum
e688175
  					     >= (long)curwin->w_botline - p_so
e688175
  #ifdef FEAT_FOLDING
e688175
  			|| hasAnyFolding(curwin)
e688175
  #endif
e688175
  			))
e688175
! 	    {
e688175
  		lineoff_T	loff;
e688175
  
e688175
! 		/* Cursor is above botline, check if there are 'scrolloff'
e688175
! 		 * window lines below the cursor.  If not, need to scroll. */
e688175
  		n = curwin->w_empty_rows;
e688175
  		loff.lnum = curwin->w_cursor.lnum;
e688175
  #ifdef FEAT_FOLDING
e688175
--- 280,299 ----
e688175
  
e688175
  	if (curwin->w_botline <= curbuf->b_ml.ml_line_count)
e688175
  	{
e688175
! 	    if (curwin->w_cursor.lnum < curwin->w_botline)
e688175
! 	    {
e688175
! 	      if (((long)curwin->w_cursor.lnum
e688175
  					     >= (long)curwin->w_botline - p_so
e688175
  #ifdef FEAT_FOLDING
e688175
  			|| hasAnyFolding(curwin)
e688175
  #endif
e688175
  			))
e688175
! 	      {
e688175
  		lineoff_T	loff;
e688175
  
e688175
! 		/* Cursor is (a few lines) above botline, check if there are
e688175
! 		 * 'scrolloff' window lines below the cursor.  If not, need to
e688175
! 		 * scroll. */
e688175
  		n = curwin->w_empty_rows;
e688175
  		loff.lnum = curwin->w_cursor.lnum;
e688175
  #ifdef FEAT_FOLDING
e688175
***************
e688175
*** 317,322 ****
e688175
--- 319,328 ----
e688175
  		if (n >= p_so)
e688175
  		    /* sufficient context, no need to scroll */
e688175
  		    check_botline = FALSE;
e688175
+ 	      }
e688175
+ 	      else
e688175
+ 		  /* sufficient context, no need to scroll */
e688175
+ 		  check_botline = FALSE;
e688175
  	    }
e688175
  	    if (check_botline)
e688175
  	    {
e688175
***************
e688175
*** 509,514 ****
e688175
--- 515,523 ----
e688175
      /* Approximate the value of w_botline */
e688175
      wp->w_botline += lnum - wp->w_topline;
e688175
      wp->w_topline = lnum;
e688175
+ #ifdef FEAT_AUTOCMD
e688175
+     wp->w_topline_was_set = TRUE;
e688175
+ #endif
e688175
  #ifdef FEAT_DIFF
e688175
      wp->w_topfill = 0;
e688175
  #endif
e688175
*** ../vim-7.2.041/src/structs.h	Sun Nov  9 13:43:25 2008
e688175
--- src/structs.h	Sat Nov 15 14:56:42 2008
e688175
***************
e688175
*** 1784,1793 ****
e688175
  #endif
e688175
  
e688175
      /*
e688175
!      * The next three specify the offsets for displaying the buffer:
e688175
       */
e688175
      linenr_T	w_topline;	    /* buffer line number of the line at the
e688175
  				       top of the window */
e688175
  #ifdef FEAT_DIFF
e688175
      int		w_topfill;	    /* number of filler lines above w_topline */
e688175
      int		w_old_topfill;	    /* w_topfill at last redraw */
e688175
--- 1784,1798 ----
e688175
  #endif
e688175
  
e688175
      /*
e688175
!      * "w_topline", "w_leftcol" and "w_skipcol" specify the offsets for
e688175
!      * displaying the buffer.
e688175
       */
e688175
      linenr_T	w_topline;	    /* buffer line number of the line at the
e688175
  				       top of the window */
e688175
+ #ifdef FEAT_AUTOCMD
e688175
+     char	w_topline_was_set;  /* flag set to TRUE when topline is set,
e688175
+ 				       e.g. by winrestview() */
e688175
+ #endif
e688175
  #ifdef FEAT_DIFF
e688175
      int		w_topfill;	    /* number of filler lines above w_topline */
e688175
      int		w_old_topfill;	    /* w_topfill at last redraw */
e688175
*** ../vim-7.2.041/src/version.c	Sat Nov 15 14:10:23 2008
e688175
--- src/version.c	Sat Nov 15 16:01:29 2008
e688175
***************
e688175
*** 678,679 ****
e688175
--- 678,681 ----
e688175
  {   /* Add new patch number below this line */
e688175
+ /**/
e688175
+     42,
e688175
  /**/
e688175
e688175
-- 
e688175
hundred-and-one symptoms of being an internet addict:
e688175
261. You find diskettes in your pockets when doing laundry.
e688175
e688175
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
e688175
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
e688175
\\\        download, build and distribute -- http://www.A-A-P.org        ///
e688175
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///