c3d9d92
To: vim-dev@vim.org
c3d9d92
Subject: Patch 7.2.274
c3d9d92
Fcc: outbox
c3d9d92
From: Bram Moolenaar <Bram@moolenaar.net>
c3d9d92
Mime-Version: 1.0
c3d9d92
Content-Type: text/plain; charset=UTF-8
c3d9d92
Content-Transfer-Encoding: 8bit
c3d9d92
------------
c3d9d92
c3d9d92
Patch 7.2.274
c3d9d92
Problem:    Syntax folding doesn't work properly when adding a comment.
c3d9d92
Solution:   Fix it and add a test. (Lech Lorens)
c3d9d92
Files:	    src/fold.c, src/testdir/test45.in, src/testdir/test45.ok
c3d9d92
c3d9d92
c3d9d92
*** ../vim-7.2.273/src/fold.c	2009-09-18 15:16:37.000000000 +0200
c3d9d92
--- src/fold.c	2009-11-03 12:36:37.000000000 +0100
c3d9d92
***************
c3d9d92
*** 2256,2261 ****
c3d9d92
--- 2256,2295 ----
c3d9d92
  	}
c3d9d92
      }
c3d9d92
  
c3d9d92
+     /*
c3d9d92
+      * If folding is defined by the syntax, it is possible that a change in
c3d9d92
+      * one line will cause all sub-folds of the current fold to change (e.g.,
c3d9d92
+      * closing a C-style comment can cause folds in the subsequent lines to
c3d9d92
+      * appear). To take that into account we should adjust the value of "bot"
c3d9d92
+      * to point to the end of the current fold:
c3d9d92
+      */
c3d9d92
+     if (foldlevelSyntax == getlevel)
c3d9d92
+     {
c3d9d92
+ 	garray_T *gap = &wp->w_folds;
c3d9d92
+ 	fold_T	 *fp = NULL;
c3d9d92
+ 	int	  current_fdl = 0;
c3d9d92
+ 	linenr_T  fold_start_lnum = 0;
c3d9d92
+ 	linenr_T  lnum_rel = fline.lnum;
c3d9d92
+ 
c3d9d92
+ 	while (current_fdl < fline.lvl)
c3d9d92
+ 	{
c3d9d92
+ 	    if (!foldFind(gap, lnum_rel, &fp))
c3d9d92
+ 		break;
c3d9d92
+ 	    ++current_fdl;
c3d9d92
+ 
c3d9d92
+ 	    fold_start_lnum += fp->fd_top;
c3d9d92
+ 	    gap = &fp->fd_nested;
c3d9d92
+ 	    lnum_rel -= fp->fd_top;
c3d9d92
+ 	}
c3d9d92
+ 	if (fp != NULL && current_fdl == fline.lvl)
c3d9d92
+ 	{
c3d9d92
+ 	    linenr_T fold_end_lnum = fold_start_lnum + fp->fd_len;
c3d9d92
+ 
c3d9d92
+ 	    if (fold_end_lnum > bot)
c3d9d92
+ 		bot = fold_end_lnum;
c3d9d92
+ 	}
c3d9d92
+     }
c3d9d92
+ 
c3d9d92
      start = fline.lnum;
c3d9d92
      end = bot;
c3d9d92
      /* Do at least one line. */
c3d9d92
*** ../vim-7.2.273/src/testdir/test45.in	2007-09-25 17:58:43.000000000 +0200
c3d9d92
--- src/testdir/test45.in	2009-11-03 12:22:38.000000000 +0100
c3d9d92
***************
c3d9d92
*** 28,36 ****
c3d9d92
  k:call append("$", foldlevel("."))
c3d9d92
  :" test syntax folding
c3d9d92
  :set fdm=syntax fdl=0
c3d9d92
! :syn region Hup start="dd" end="hh" fold
c3d9d92
  Gzk:call append("$", "folding " . getline("."))
c3d9d92
  k:call append("$", getline("."))
c3d9d92
  :" test expression folding
c3d9d92
  :fun Flvl()
c3d9d92
    let l = getline(v:lnum)
c3d9d92
--- 28,41 ----
c3d9d92
  k:call append("$", foldlevel("."))
c3d9d92
  :" test syntax folding
c3d9d92
  :set fdm=syntax fdl=0
c3d9d92
! :syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3
c3d9d92
! :syn region Fd1 start="ee" end="ff" fold contained
c3d9d92
! :syn region Fd2 start="gg" end="hh" fold contained
c3d9d92
! :syn region Fd3 start="commentstart" end="commentend" fold contained
c3d9d92
  Gzk:call append("$", "folding " . getline("."))
c3d9d92
  k:call append("$", getline("."))
c3d9d92
+ jAcommentstart  ?Acommentend?:set fdl=1
c3d9d92
+ 3j:call append("$", getline("."))
c3d9d92
  :" test expression folding
c3d9d92
  :fun Flvl()
c3d9d92
    let l = getline(v:lnum)
c3d9d92
*** ../vim-7.2.273/src/testdir/test45.ok	2004-06-13 17:47:37.000000000 +0200
c3d9d92
--- src/testdir/test45.ok	2009-11-03 12:22:50.000000000 +0100
c3d9d92
***************
c3d9d92
*** 8,15 ****
c3d9d92
  0
c3d9d92
  indent 2
c3d9d92
  1
c3d9d92
! folding 8 hh
c3d9d92
      3 cc
c3d9d92
  expr 2
c3d9d92
  1
c3d9d92
  2
c3d9d92
--- 8,16 ----
c3d9d92
  0
c3d9d92
  indent 2
c3d9d92
  1
c3d9d92
! folding 9 ii
c3d9d92
      3 cc
c3d9d92
+ 7 gg
c3d9d92
  expr 2
c3d9d92
  1
c3d9d92
  2
c3d9d92
*** ../vim-7.2.273/src/version.c	2009-11-03 14:26:29.000000000 +0100
c3d9d92
--- src/version.c	2009-11-03 14:44:21.000000000 +0100
c3d9d92
***************
c3d9d92
*** 678,679 ****
c3d9d92
--- 678,681 ----
c3d9d92
  {   /* Add new patch number below this line */
c3d9d92
+ /**/
c3d9d92
+     274,
c3d9d92
  /**/
c3d9d92
c3d9d92
-- 
c3d9d92
BRIDGEKEEPER: What is your favorite colour?
c3d9d92
LAUNCELOT:    Blue.
c3d9d92
BRIDGEKEEPER: Right.  Off you go.
c3d9d92
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
c3d9d92
c3d9d92
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
c3d9d92
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
c3d9d92
\\\        download, build and distribute -- http://www.A-A-P.org        ///
c3d9d92
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///