home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.3 / 7.3.462 < prev    next >
Encoding:
Internet Message Format  |  2012-11-20  |  5.0 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.3.462
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.3.462
  11. Problem:    When using ":loadview" folds may be closed unexpectedly.
  12. Solution:   Take into account foldlevel. (Xavier de Gaye)
  13. Files:        src/fold.c
  14.  
  15.  
  16. *** ../vim-7.3.461/src/fold.c    2012-01-10 22:26:12.000000000 +0100
  17. --- src/fold.c    2012-02-29 19:18:07.000000000 +0100
  18. ***************
  19. *** 3292,3298 ****
  20.   /* put_folds() {{{2 */
  21.   #if defined(FEAT_SESSION) || defined(PROTO)
  22.   static int put_folds_recurse __ARGS((FILE *fd, garray_T *gap, linenr_T off));
  23. ! static int put_foldopen_recurse __ARGS((FILE *fd, garray_T *gap, linenr_T off));
  24.   
  25.   /*
  26.    * Write commands to "fd" to restore the manual folds in window "wp".
  27. --- 3292,3299 ----
  28.   /* put_folds() {{{2 */
  29.   #if defined(FEAT_SESSION) || defined(PROTO)
  30.   static int put_folds_recurse __ARGS((FILE *fd, garray_T *gap, linenr_T off));
  31. ! static int put_foldopen_recurse __ARGS((FILE *fd, win_T *wp, garray_T *gap, linenr_T off));
  32. ! static int put_fold_open_close __ARGS((FILE *fd, fold_T *fp, linenr_T off));
  33.   
  34.   /*
  35.    * Write commands to "fd" to restore the manual folds in window "wp".
  36. ***************
  37. *** 3312,3318 ****
  38.   
  39.       /* If some folds are manually opened/closed, need to restore that. */
  40.       if (wp->w_fold_manual)
  41. !     return put_foldopen_recurse(fd, &wp->w_folds, (linenr_T)0);
  42.   
  43.       return OK;
  44.   }
  45. --- 3313,3319 ----
  46.   
  47.       /* If some folds are manually opened/closed, need to restore that. */
  48.       if (wp->w_fold_manual)
  49. !     return put_foldopen_recurse(fd, wp, &wp->w_folds, (linenr_T)0);
  50.   
  51.       return OK;
  52.   }
  53. ***************
  54. *** 3352,3363 ****
  55.    * Returns FAIL when writing failed.
  56.    */
  57.       static int
  58. ! put_foldopen_recurse(fd, gap, off)
  59.       FILE    *fd;
  60.       garray_T    *gap;
  61.       linenr_T    off;
  62.   {
  63.       int        i;
  64.       fold_T    *fp;
  65.   
  66.       fp = (fold_T *)gap->ga_data;
  67. --- 3353,3366 ----
  68.    * Returns FAIL when writing failed.
  69.    */
  70.       static int
  71. ! put_foldopen_recurse(fd, wp, gap, off)
  72.       FILE    *fd;
  73. +     win_T    *wp;
  74.       garray_T    *gap;
  75.       linenr_T    off;
  76.   {
  77.       int        i;
  78. +     int        level;
  79.       fold_T    *fp;
  80.   
  81.       fp = (fold_T *)gap->ga_data;
  82. ***************
  83. *** 3367,3393 ****
  84.       {
  85.           if (fp->fd_nested.ga_len > 0)
  86.           {
  87. !         /* open/close nested folds while this fold is open */
  88.           if (fprintf(fd, "%ld", fp->fd_top + off) < 0
  89.               || put_eol(fd) == FAIL
  90.               || put_line(fd, "normal zo") == FAIL)
  91.               return FAIL;
  92. !         if (put_foldopen_recurse(fd, &fp->fd_nested, off + fp->fd_top)
  93.               == FAIL)
  94.               return FAIL;
  95.           }
  96. -         if (fprintf(fd, "%ld", fp->fd_top + off) < 0
  97. -             || put_eol(fd) == FAIL
  98. -             || fprintf(fd, "normal z%c",
  99. -                     fp->fd_flags == FD_CLOSED ? 'c' : 'o') < 0
  100. -             || put_eol(fd) == FAIL)
  101. -         return FAIL;
  102.       }
  103.       ++fp;
  104.       }
  105.   
  106.       return OK;
  107.   }
  108.   #endif /* FEAT_SESSION */
  109.   
  110.   /* }}}1 */
  111. --- 3370,3429 ----
  112.       {
  113.           if (fp->fd_nested.ga_len > 0)
  114.           {
  115. !         /* open nested folds while this fold is open */
  116.           if (fprintf(fd, "%ld", fp->fd_top + off) < 0
  117.               || put_eol(fd) == FAIL
  118.               || put_line(fd, "normal zo") == FAIL)
  119.               return FAIL;
  120. !         if (put_foldopen_recurse(fd, wp, &fp->fd_nested,
  121. !                                  off + fp->fd_top)
  122.               == FAIL)
  123.               return FAIL;
  124. +         /* close the parent when needed */
  125. +         if (fp->fd_flags == FD_CLOSED)
  126. +         {
  127. +             if (put_fold_open_close(fd, fp, off) == FAIL)
  128. +             return FAIL;
  129. +         }
  130. +         }
  131. +         else
  132. +         {
  133. +         /* Open or close the leaf according to the window foldlevel.
  134. +          * Do not close a leaf that is already closed, as it will close
  135. +          * the parent. */
  136. +         level = foldLevelWin(wp, off + fp->fd_top);
  137. +         if ((fp->fd_flags == FD_CLOSED && wp->w_p_fdl >= level)
  138. +             || (fp->fd_flags != FD_CLOSED && wp->w_p_fdl < level))
  139. +         if (put_fold_open_close(fd, fp, off) == FAIL)
  140. +             return FAIL;
  141.           }
  142.       }
  143.       ++fp;
  144.       }
  145.   
  146.       return OK;
  147.   }
  148. + /* put_fold_open_close() {{{2 */
  149. + /*
  150. +  * Write the open or close command to "fd".
  151. +  * Returns FAIL when writing failed.
  152. +  */
  153. +     static int
  154. + put_fold_open_close(fd, fp, off)
  155. +     FILE    *fd;
  156. +     fold_T    *fp;
  157. +     linenr_T    off;
  158. + {
  159. +     if (fprintf(fd, "%ld", fp->fd_top + off) < 0
  160. +         || put_eol(fd) == FAIL
  161. +         || fprintf(fd, "normal z%c",
  162. +                fp->fd_flags == FD_CLOSED ? 'c' : 'o') < 0
  163. +         || put_eol(fd) == FAIL)
  164. +     return FAIL;
  165. +     return OK;
  166. + }
  167.   #endif /* FEAT_SESSION */
  168.   
  169.   /* }}}1 */
  170. *** ../vim-7.3.461/src/version.c    2012-02-29 18:22:03.000000000 +0100
  171. --- src/version.c    2012-02-29 18:40:43.000000000 +0100
  172. ***************
  173. *** 716,717 ****
  174. --- 716,719 ----
  175.   {   /* Add new patch number below this line */
  176. + /**/
  177. +     462,
  178.   /**/
  179.  
  180. -- 
  181. ~
  182. ~
  183. ~
  184. ".signature" 4 lines, 50 characters written
  185.  
  186.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  187. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  188. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  189.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  190.