summaryrefslogtreecommitdiffstats
path: root/source/ap/vim/patches/7.3.462
blob: df03724211b3e770f89b159c84ea49060044528c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
To: vim_dev@googlegroups.com
Subject: Patch 7.3.462
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.3.462
Problem:    When using ":loadview" folds may be closed unexpectedly.
Solution:   Take into account foldlevel. (Xavier de Gaye)
Files:	    src/fold.c


*** ../vim-7.3.461/src/fold.c	2012-01-10 22:26:12.000000000 +0100
--- src/fold.c	2012-02-29 19:18:07.000000000 +0100
***************
*** 3292,3298 ****
  /* put_folds() {{{2 */
  #if defined(FEAT_SESSION) || defined(PROTO)
  static int put_folds_recurse __ARGS((FILE *fd, garray_T *gap, linenr_T off));
! static int put_foldopen_recurse __ARGS((FILE *fd, garray_T *gap, linenr_T off));
  
  /*
   * Write commands to "fd" to restore the manual folds in window "wp".
--- 3292,3299 ----
  /* put_folds() {{{2 */
  #if defined(FEAT_SESSION) || defined(PROTO)
  static int put_folds_recurse __ARGS((FILE *fd, garray_T *gap, linenr_T off));
! static int put_foldopen_recurse __ARGS((FILE *fd, win_T *wp, garray_T *gap, linenr_T off));
! static int put_fold_open_close __ARGS((FILE *fd, fold_T *fp, linenr_T off));
  
  /*
   * Write commands to "fd" to restore the manual folds in window "wp".
***************
*** 3312,3318 ****
  
      /* If some folds are manually opened/closed, need to restore that. */
      if (wp->w_fold_manual)
! 	return put_foldopen_recurse(fd, &wp->w_folds, (linenr_T)0);
  
      return OK;
  }
--- 3313,3319 ----
  
      /* If some folds are manually opened/closed, need to restore that. */
      if (wp->w_fold_manual)
! 	return put_foldopen_recurse(fd, wp, &wp->w_folds, (linenr_T)0);
  
      return OK;
  }
***************
*** 3352,3363 ****
   * Returns FAIL when writing failed.
   */
      static int
! put_foldopen_recurse(fd, gap, off)
      FILE	*fd;
      garray_T	*gap;
      linenr_T	off;
  {
      int		i;
      fold_T	*fp;
  
      fp = (fold_T *)gap->ga_data;
--- 3353,3366 ----
   * Returns FAIL when writing failed.
   */
      static int
! put_foldopen_recurse(fd, wp, gap, off)
      FILE	*fd;
+     win_T	*wp;
      garray_T	*gap;
      linenr_T	off;
  {
      int		i;
+     int		level;
      fold_T	*fp;
  
      fp = (fold_T *)gap->ga_data;
***************
*** 3367,3393 ****
  	{
  	    if (fp->fd_nested.ga_len > 0)
  	    {
! 		/* open/close nested folds while this fold is open */
  		if (fprintf(fd, "%ld", fp->fd_top + off) < 0
  			|| put_eol(fd) == FAIL
  			|| put_line(fd, "normal zo") == FAIL)
  		    return FAIL;
! 		if (put_foldopen_recurse(fd, &fp->fd_nested, off + fp->fd_top)
  			== FAIL)
  		    return FAIL;
  	    }
- 	    if (fprintf(fd, "%ld", fp->fd_top + off) < 0
- 		    || put_eol(fd) == FAIL
- 		    || fprintf(fd, "normal z%c",
- 				    fp->fd_flags == FD_CLOSED ? 'c' : 'o') < 0
- 		    || put_eol(fd) == FAIL)
- 		return FAIL;
  	}
  	++fp;
      }
  
      return OK;
  }
  #endif /* FEAT_SESSION */
  
  /* }}}1 */
--- 3370,3429 ----
  	{
  	    if (fp->fd_nested.ga_len > 0)
  	    {
! 		/* open nested folds while this fold is open */
  		if (fprintf(fd, "%ld", fp->fd_top + off) < 0
  			|| put_eol(fd) == FAIL
  			|| put_line(fd, "normal zo") == FAIL)
  		    return FAIL;
! 		if (put_foldopen_recurse(fd, wp, &fp->fd_nested,
! 							     off + fp->fd_top)
  			== FAIL)
  		    return FAIL;
+ 		/* close the parent when needed */
+ 		if (fp->fd_flags == FD_CLOSED)
+ 		{
+ 		    if (put_fold_open_close(fd, fp, off) == FAIL)
+ 			return FAIL;
+ 		}
+ 	    }
+ 	    else
+ 	    {
+ 		/* Open or close the leaf according to the window foldlevel.
+ 		 * Do not close a leaf that is already closed, as it will close
+ 		 * the parent. */
+ 		level = foldLevelWin(wp, off + fp->fd_top);
+ 		if ((fp->fd_flags == FD_CLOSED && wp->w_p_fdl >= level)
+ 			|| (fp->fd_flags != FD_CLOSED && wp->w_p_fdl < level))
+ 		if (put_fold_open_close(fd, fp, off) == FAIL)
+ 		    return FAIL;
  	    }
  	}
  	++fp;
      }
  
      return OK;
  }
+ 
+ /* put_fold_open_close() {{{2 */
+ /*
+  * Write the open or close command to "fd".
+  * Returns FAIL when writing failed.
+  */
+     static int
+ put_fold_open_close(fd, fp, off)
+     FILE	*fd;
+     fold_T	*fp;
+     linenr_T	off;
+ {
+     if (fprintf(fd, "%ld", fp->fd_top + off) < 0
+ 	    || put_eol(fd) == FAIL
+ 	    || fprintf(fd, "normal z%c",
+ 			   fp->fd_flags == FD_CLOSED ? 'c' : 'o') < 0
+ 	    || put_eol(fd) == FAIL)
+ 	return FAIL;
+ 
+     return OK;
+ }
  #endif /* FEAT_SESSION */
  
  /* }}}1 */
*** ../vim-7.3.461/src/version.c	2012-02-29 18:22:03.000000000 +0100
--- src/version.c	2012-02-29 18:40:43.000000000 +0100
***************
*** 716,717 ****
--- 716,719 ----
  {   /* Add new patch number below this line */
+ /**/
+     462,
  /**/

-- 
~
~
~
".signature" 4 lines, 50 characters written

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///