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