Karsten Hopp b1eb23
To: vim_dev@googlegroups.com
Karsten Hopp b1eb23
Subject: Patch 7.3.462
Karsten Hopp b1eb23
Fcc: outbox
Karsten Hopp b1eb23
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp b1eb23
Mime-Version: 1.0
Karsten Hopp b1eb23
Content-Type: text/plain; charset=UTF-8
Karsten Hopp b1eb23
Content-Transfer-Encoding: 8bit
Karsten Hopp b1eb23
------------
Karsten Hopp b1eb23
Karsten Hopp b1eb23
Patch 7.3.462
Karsten Hopp b1eb23
Problem:    When using ":loadview" folds may be closed unexpectedly.
Karsten Hopp b1eb23
Solution:   Take into account foldlevel. (Xavier de Gaye)
Karsten Hopp b1eb23
Files:	    src/fold.c
Karsten Hopp b1eb23
Karsten Hopp b1eb23
Karsten Hopp b1eb23
*** ../vim-7.3.461/src/fold.c	2012-01-10 22:26:12.000000000 +0100
Karsten Hopp b1eb23
--- src/fold.c	2012-02-29 19:18:07.000000000 +0100
Karsten Hopp b1eb23
***************
Karsten Hopp b1eb23
*** 3292,3298 ****
Karsten Hopp b1eb23
  /* put_folds() {{{2 */
Karsten Hopp b1eb23
  #if defined(FEAT_SESSION) || defined(PROTO)
Karsten Hopp b1eb23
  static int put_folds_recurse __ARGS((FILE *fd, garray_T *gap, linenr_T off));
Karsten Hopp b1eb23
! static int put_foldopen_recurse __ARGS((FILE *fd, garray_T *gap, linenr_T off));
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
  /*
Karsten Hopp b1eb23
   * Write commands to "fd" to restore the manual folds in window "wp".
Karsten Hopp b1eb23
--- 3292,3299 ----
Karsten Hopp b1eb23
  /* put_folds() {{{2 */
Karsten Hopp b1eb23
  #if defined(FEAT_SESSION) || defined(PROTO)
Karsten Hopp b1eb23
  static int put_folds_recurse __ARGS((FILE *fd, garray_T *gap, linenr_T off));
Karsten Hopp b1eb23
! static int put_foldopen_recurse __ARGS((FILE *fd, win_T *wp, garray_T *gap, linenr_T off));
Karsten Hopp b1eb23
! static int put_fold_open_close __ARGS((FILE *fd, fold_T *fp, linenr_T off));
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
  /*
Karsten Hopp b1eb23
   * Write commands to "fd" to restore the manual folds in window "wp".
Karsten Hopp b1eb23
***************
Karsten Hopp b1eb23
*** 3312,3318 ****
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
      /* If some folds are manually opened/closed, need to restore that. */
Karsten Hopp b1eb23
      if (wp->w_fold_manual)
Karsten Hopp b1eb23
! 	return put_foldopen_recurse(fd, &wp->w_folds, (linenr_T)0);
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
      return OK;
Karsten Hopp b1eb23
  }
Karsten Hopp b1eb23
--- 3313,3319 ----
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
      /* If some folds are manually opened/closed, need to restore that. */
Karsten Hopp b1eb23
      if (wp->w_fold_manual)
Karsten Hopp b1eb23
! 	return put_foldopen_recurse(fd, wp, &wp->w_folds, (linenr_T)0);
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
      return OK;
Karsten Hopp b1eb23
  }
Karsten Hopp b1eb23
***************
Karsten Hopp b1eb23
*** 3352,3363 ****
Karsten Hopp b1eb23
   * Returns FAIL when writing failed.
Karsten Hopp b1eb23
   */
Karsten Hopp b1eb23
      static int
Karsten Hopp b1eb23
! put_foldopen_recurse(fd, gap, off)
Karsten Hopp b1eb23
      FILE	*fd;
Karsten Hopp b1eb23
      garray_T	*gap;
Karsten Hopp b1eb23
      linenr_T	off;
Karsten Hopp b1eb23
  {
Karsten Hopp b1eb23
      int		i;
Karsten Hopp b1eb23
      fold_T	*fp;
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
      fp = (fold_T *)gap->ga_data;
Karsten Hopp b1eb23
--- 3353,3366 ----
Karsten Hopp b1eb23
   * Returns FAIL when writing failed.
Karsten Hopp b1eb23
   */
Karsten Hopp b1eb23
      static int
Karsten Hopp b1eb23
! put_foldopen_recurse(fd, wp, gap, off)
Karsten Hopp b1eb23
      FILE	*fd;
Karsten Hopp b1eb23
+     win_T	*wp;
Karsten Hopp b1eb23
      garray_T	*gap;
Karsten Hopp b1eb23
      linenr_T	off;
Karsten Hopp b1eb23
  {
Karsten Hopp b1eb23
      int		i;
Karsten Hopp b1eb23
+     int		level;
Karsten Hopp b1eb23
      fold_T	*fp;
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
      fp = (fold_T *)gap->ga_data;
Karsten Hopp b1eb23
***************
Karsten Hopp b1eb23
*** 3367,3393 ****
Karsten Hopp b1eb23
  	{
Karsten Hopp b1eb23
  	    if (fp->fd_nested.ga_len > 0)
Karsten Hopp b1eb23
  	    {
Karsten Hopp b1eb23
! 		/* open/close nested folds while this fold is open */
Karsten Hopp b1eb23
  		if (fprintf(fd, "%ld", fp->fd_top + off) < 0
Karsten Hopp b1eb23
  			|| put_eol(fd) == FAIL
Karsten Hopp b1eb23
  			|| put_line(fd, "normal zo") == FAIL)
Karsten Hopp b1eb23
  		    return FAIL;
Karsten Hopp b1eb23
! 		if (put_foldopen_recurse(fd, &fp->fd_nested, off + fp->fd_top)
Karsten Hopp b1eb23
  			== FAIL)
Karsten Hopp b1eb23
  		    return FAIL;
Karsten Hopp b1eb23
  	    }
Karsten Hopp b1eb23
- 	    if (fprintf(fd, "%ld", fp->fd_top + off) < 0
Karsten Hopp b1eb23
- 		    || put_eol(fd) == FAIL
Karsten Hopp b1eb23
- 		    || fprintf(fd, "normal z%c",
Karsten Hopp b1eb23
- 				    fp->fd_flags == FD_CLOSED ? 'c' : 'o') < 0
Karsten Hopp b1eb23
- 		    || put_eol(fd) == FAIL)
Karsten Hopp b1eb23
- 		return FAIL;
Karsten Hopp b1eb23
  	}
Karsten Hopp b1eb23
  	++fp;
Karsten Hopp b1eb23
      }
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
      return OK;
Karsten Hopp b1eb23
  }
Karsten Hopp b1eb23
  #endif /* FEAT_SESSION */
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
  /* }}}1 */
Karsten Hopp b1eb23
--- 3370,3429 ----
Karsten Hopp b1eb23
  	{
Karsten Hopp b1eb23
  	    if (fp->fd_nested.ga_len > 0)
Karsten Hopp b1eb23
  	    {
Karsten Hopp b1eb23
! 		/* open nested folds while this fold is open */
Karsten Hopp b1eb23
  		if (fprintf(fd, "%ld", fp->fd_top + off) < 0
Karsten Hopp b1eb23
  			|| put_eol(fd) == FAIL
Karsten Hopp b1eb23
  			|| put_line(fd, "normal zo") == FAIL)
Karsten Hopp b1eb23
  		    return FAIL;
Karsten Hopp b1eb23
! 		if (put_foldopen_recurse(fd, wp, &fp->fd_nested,
Karsten Hopp b1eb23
! 							     off + fp->fd_top)
Karsten Hopp b1eb23
  			== FAIL)
Karsten Hopp b1eb23
  		    return FAIL;
Karsten Hopp b1eb23
+ 		/* close the parent when needed */
Karsten Hopp b1eb23
+ 		if (fp->fd_flags == FD_CLOSED)
Karsten Hopp b1eb23
+ 		{
Karsten Hopp b1eb23
+ 		    if (put_fold_open_close(fd, fp, off) == FAIL)
Karsten Hopp b1eb23
+ 			return FAIL;
Karsten Hopp b1eb23
+ 		}
Karsten Hopp b1eb23
+ 	    }
Karsten Hopp b1eb23
+ 	    else
Karsten Hopp b1eb23
+ 	    {
Karsten Hopp b1eb23
+ 		/* Open or close the leaf according to the window foldlevel.
Karsten Hopp b1eb23
+ 		 * Do not close a leaf that is already closed, as it will close
Karsten Hopp b1eb23
+ 		 * the parent. */
Karsten Hopp b1eb23
+ 		level = foldLevelWin(wp, off + fp->fd_top);
Karsten Hopp b1eb23
+ 		if ((fp->fd_flags == FD_CLOSED && wp->w_p_fdl >= level)
Karsten Hopp b1eb23
+ 			|| (fp->fd_flags != FD_CLOSED && wp->w_p_fdl < level))
Karsten Hopp b1eb23
+ 		if (put_fold_open_close(fd, fp, off) == FAIL)
Karsten Hopp b1eb23
+ 		    return FAIL;
Karsten Hopp b1eb23
  	    }
Karsten Hopp b1eb23
  	}
Karsten Hopp b1eb23
  	++fp;
Karsten Hopp b1eb23
      }
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
      return OK;
Karsten Hopp b1eb23
  }
Karsten Hopp b1eb23
+ 
Karsten Hopp b1eb23
+ /* put_fold_open_close() {{{2 */
Karsten Hopp b1eb23
+ /*
Karsten Hopp b1eb23
+  * Write the open or close command to "fd".
Karsten Hopp b1eb23
+  * Returns FAIL when writing failed.
Karsten Hopp b1eb23
+  */
Karsten Hopp b1eb23
+     static int
Karsten Hopp b1eb23
+ put_fold_open_close(fd, fp, off)
Karsten Hopp b1eb23
+     FILE	*fd;
Karsten Hopp b1eb23
+     fold_T	*fp;
Karsten Hopp b1eb23
+     linenr_T	off;
Karsten Hopp b1eb23
+ {
Karsten Hopp b1eb23
+     if (fprintf(fd, "%ld", fp->fd_top + off) < 0
Karsten Hopp b1eb23
+ 	    || put_eol(fd) == FAIL
Karsten Hopp b1eb23
+ 	    || fprintf(fd, "normal z%c",
Karsten Hopp b1eb23
+ 			   fp->fd_flags == FD_CLOSED ? 'c' : 'o') < 0
Karsten Hopp b1eb23
+ 	    || put_eol(fd) == FAIL)
Karsten Hopp b1eb23
+ 	return FAIL;
Karsten Hopp b1eb23
+ 
Karsten Hopp b1eb23
+     return OK;
Karsten Hopp b1eb23
+ }
Karsten Hopp b1eb23
  #endif /* FEAT_SESSION */
Karsten Hopp b1eb23
  
Karsten Hopp b1eb23
  /* }}}1 */
Karsten Hopp b1eb23
*** ../vim-7.3.461/src/version.c	2012-02-29 18:22:03.000000000 +0100
Karsten Hopp b1eb23
--- src/version.c	2012-02-29 18:40:43.000000000 +0100
Karsten Hopp b1eb23
***************
Karsten Hopp b1eb23
*** 716,717 ****
Karsten Hopp b1eb23
--- 716,719 ----
Karsten Hopp b1eb23
  {   /* Add new patch number below this line */
Karsten Hopp b1eb23
+ /**/
Karsten Hopp b1eb23
+     462,
Karsten Hopp b1eb23
  /**/
Karsten Hopp b1eb23
Karsten Hopp b1eb23
-- 
Karsten Hopp b1eb23
~
Karsten Hopp b1eb23
~
Karsten Hopp b1eb23
~
Karsten Hopp b1eb23
".signature" 4 lines, 50 characters written
Karsten Hopp b1eb23
Karsten Hopp b1eb23
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp b1eb23
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp b1eb23
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp b1eb23
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///