4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Syntax folding doesn't work properly when adding a comment.
12 Solution: Fix it and add a test. (Lech Lorens)
13 Files: src/fold.c, src/testdir/test45.in, src/testdir/test45.ok
16 *** ../vim-7.2.273/src/fold.c 2009-09-18 15:16:37.000000000 +0200
17 --- src/fold.c 2009-11-03 12:36:37.000000000 +0100
25 + * If folding is defined by the syntax, it is possible that a change in
26 + * one line will cause all sub-folds of the current fold to change (e.g.,
27 + * closing a C-style comment can cause folds in the subsequent lines to
28 + * appear). To take that into account we should adjust the value of "bot"
29 + * to point to the end of the current fold:
31 + if (foldlevelSyntax == getlevel)
33 + garray_T *gap = &wp->w_folds;
35 + int current_fdl = 0;
36 + linenr_T fold_start_lnum = 0;
37 + linenr_T lnum_rel = fline.lnum;
39 + while (current_fdl < fline.lvl)
41 + if (!foldFind(gap, lnum_rel, &fp))
45 + fold_start_lnum += fp->fd_top;
46 + gap = &fp->fd_nested;
47 + lnum_rel -= fp->fd_top;
49 + if (fp != NULL && current_fdl == fline.lvl)
51 + linenr_T fold_end_lnum = fold_start_lnum + fp->fd_len;
53 + if (fold_end_lnum > bot)
54 + bot = fold_end_lnum;
60 /* Do at least one line. */
61 *** ../vim-7.2.273/src/testdir/test45.in 2007-09-25 17:58:43.000000000 +0200
62 --- src/testdir/test45.in 2009-11-03 12:22:38.000000000 +0100
65 k:call append("$", foldlevel("."))
66 :" test syntax folding
68 ! :syn region Hup start="dd" end="hh" fold
69 Gzk:call append("$", "folding " . getline("."))
70 k:call append("$", getline("."))
71 :" test expression folding
73 let l = getline(v:lnum)
75 k:call append("$", foldlevel("."))
76 :" test syntax folding
78 ! :syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3
79 ! :syn region Fd1 start="ee" end="ff" fold contained
80 ! :syn region Fd2 start="gg" end="hh" fold contained
81 ! :syn region Fd3 start="commentstart" end="commentend" fold contained
82 Gzk:call append("$", "folding " . getline("."))
83 k:call append("$", getline("."))
84 + jAcommentstart
\eAcommentend
\e:set fdl=1
85 + 3j:call append("$", getline("."))
86 :" test expression folding
88 let l = getline(v:lnum)
89 *** ../vim-7.2.273/src/testdir/test45.ok 2004-06-13 17:47:37.000000000 +0200
90 --- src/testdir/test45.ok 2009-11-03 12:22:50.000000000 +0100
111 *** ../vim-7.2.273/src/version.c 2009-11-03 14:26:29.000000000 +0100
112 --- src/version.c 2009-11-03 14:44:21.000000000 +0100
116 { /* Add new patch number below this line */
122 BRIDGEKEEPER: What is your favorite colour?
124 BRIDGEKEEPER: Right. Off you go.
125 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
127 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
128 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
129 \\\ download, build and distribute -- http://www.A-A-P.org ///
130 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///