Hi Ein!
I just saw the problem yesterday. Here is an simpler example of the bug:
#v+
chrisbra@R500 % cat foldmarker_bug.txt
vim: fdm=marker
fold A {{{
some
text
here
}}}
fold B {{{
some
text
here
}}}
fold C {{{
some
text
here
}}}
fold D {{{
some
text
here
}}}
chrisbra@R500 vim -u NONE -N foldmarker_bug.txt
:10
:4m
#v-
Note, that the fold B stays open and it is not possible to close
it. Debugging it with gdb, you'll find, that wp->w_folds get invalid
(e.g. is out of order).
I think this patch fixes it.
iff --git a/src/ex_cmds.c b/src/ex_cmds.c
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -784,6 +784,7 @@
*/
last_line = curbuf->b_ml.ml_line_count;
mark_adjust(line1, line2, last_line - line2, 0L);
+ changed_lines(last_line - num_lines + 1, 0, last_line + 1, num_lines);
if (dest >= line2)
{
mark_adjust(line2 + 1, dest, -num_lines, 0L);
@@ -800,6 +801,7 @@
mark_adjust(last_line - num_lines + 1, last_line,
-(last_line - dest - extra), 0L);
+ changed_lines(last_line - num_lines + 1, 0, last_line + 1, -extra);
/*
* Now we delete the original text -- webb
*/
BTW: I think, there is also an error in fold.c:
diff --git a/src/fold.c b/src/fold.c
--- a/src/fold.c
+++ b/src/fold.c
@@ -849,8 +849,8 @@
fold_T *fp;
/* Mark all folds from top to bot as maybe-small. */
- (void)foldFind(&curwin->w_folds, top, &fp);
- while (fp < (fold_T *)curwin->w_folds.ga_data + curwin->w_folds.ga_len
+ (void)foldFind(&wp->w_folds, top, &fp);
+ while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
&& fp->fd_top < bot)
{
fp->fd_small = MAYBE;
regards,
Christian
--