bug with using :move on folds?

86 views
Skip to first unread message

Ein Brown

unread,
May 24, 2013, 2:54:34 PM5/24/13
to vim...@googlegroups.com
Hi, I have encountered a bug where my folds become 'corrupted' and unrecognized by vim. I looks like this is caused by using :move on a closed fold under the right circumstances.

The SO question has more details:
http://stackoverflow.com/questions/16592654/in-vim-why-is-move-randomly-corrupting-my-folds

at the bottom of the SO question (under 'edit') I explain ways to run into the bug without the Alt-Up / Alt-Down mapping.

Best,
Ein

Christian Brabandt

unread,
May 24, 2013, 4:20:37 PM5/24/13
to vim...@googlegroups.com
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
--

Christian Brabandt

unread,
May 24, 2013, 4:48:57 PM5/24/13
to vim...@googlegroups.com

On Fr, 24 Mai 2013, Christian Brabandt wrote:

> On Fr, 24 Mai 2013, Ein Brown wrote:
>
> > The SO question has more details:
> > http://stackoverflow.com/questions/16592654/in-vim-why-is-move-randomly-corrupting-my-folds
> >
> > at the bottom of the SO question (under 'edit') I explain ways to run into the bug without the Alt-Up / Alt-Down mapping.
>
> I just saw the problem yesterday. Here is an simpler example of the bug:
>
> I think this patch fixes it.
[...]

No, it doesn't fix it completely. I'll look into it some more.

regards,
Christian
--
Der Glaube versetzt Berge, der Zweifel erklettert sie.
-- Karl Heinrich Waggerl

Bram Moolenaar

unread,
May 25, 2013, 7:13:09 AM5/25/13
to Christian Brabandt, vim...@googlegroups.com
[...]

Thanks.

> BTW: I think, there is also an error in fold.c:

[...]

Yep.


--
I once paid $12 to peer at the box that held King Tutankhamen's little
bandage-covered midget corpse at the De Young Museum in San Francisco. I
remember thinking how pleased he'd be about the way things turned out in his
afterlife.
(Scott Adams - The Dilbert principle)

/// Bram Moolenaar -- Br...@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 ///

Bram Moolenaar

unread,
May 29, 2013, 7:33:13 AM5/29/13
to Christian Brabandt, vim...@googlegroups.com

Christian Brabandt wrote:

> On Fr, 24 Mai 2013, Christian Brabandt wrote:
>
> > On Fr, 24 Mai 2013, Ein Brown wrote:
> >
> > > The SO question has more details:
> > > http://stackoverflow.com/questions/16592654/in-vim-why-is-move-randomly-corrupting-my-folds
> > >
> > > at the bottom of the SO question (under 'edit') I explain ways to run into the bug without the Alt-Up / Alt-Down mapping.
> >
> > I just saw the problem yesterday. Here is an simpler example of the bug:
> >
> > I think this patch fixes it.
> [...]
>
> No, it doesn't fix it completely. I'll look into it some more.

Any progress? What still fails?

--
hundred-and-one symptoms of being an internet addict:
10. And even your night dreams are in HTML.

Christian Brabandt

unread,
May 29, 2013, 8:06:44 AM5/29/13
to vim...@googlegroups.com
On Wed, May 29, 2013 13:33, Bram Moolenaar wrote:
>
> Christian Brabandt wrote:
>
>> On Fr, 24 Mai 2013, Christian Brabandt wrote:
>>
>> > On Fr, 24 Mai 2013, Ein Brown wrote:
>> >
>> > > The SO question has more details:
>> > > http://stackoverflow.com/questions/16592654/in-vim-why-is-move-randomly-corrupting-my-folds
>> > >
>> > > at the bottom of the SO question (under 'edit') I explain ways to
>> run into the bug without the Alt-Up / Alt-Down mapping.
>> >
>> > I just saw the problem yesterday. Here is an simpler example of the
>> bug:
>> >
>> > I think this patch fixes it.
>> [...]
>>
>> No, it doesn't fix it completely. I'll look into it some more.
>
> Any progress? What still fails?
>

No, I can't figure out why curwin->w_folds gets out of order and
also sometimes many more folds.
I haven't really figured out the complete foldUpdate process yet.

regards,
Christian

Bram Moolenaar

unread,
May 30, 2013, 5:43:53 AM5/30/13
to Christian Brabandt, vim...@googlegroups.com

Christian Brabandt wrote:

> On Fr, 24 Mai 2013, Christian Brabandt wrote:
>
> > On Fr, 24 Mai 2013, Ein Brown wrote:
> >
> > > The SO question has more details:
> > > http://stackoverflow.com/questions/16592654/in-vim-why-is-move-randomly-corrupting-my-folds
> > >
> > > at the bottom of the SO question (under 'edit') I explain ways to run into the bug without the Alt-Up / Alt-Down mapping.
> >
> > I just saw the problem yesterday. Here is an simpler example of the bug:
> >
> > I think this patch fixes it.
> [...]
>
> No, it doesn't fix it completely. I'll look into it some more.

I accidentally included some of this in patch 7.3.1042.
I hope it doesn't cause any problems...

--
Far back in the mists of ancient time, in the great and glorious days of the
former Galactic Empire, life was wild, rich and largely tax free.
Mighty starships plied their way between exotic suns, seeking adventure and
reward among the furthest reaches of Galactic space. In those days, spirits
were brave, the stakes were high, men were real men, women were real women
and small furry creatures from Alpha Centauri were real small furry creatures
from Alpha Centauri. And all dared to brave unknown terrors, to do mighty
deeds, to boldly split infinitives that no man had split before -- and thus
was the Empire forged.
-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

Christian Brabandt

unread,
May 30, 2013, 7:42:01 AM5/30/13
to vim...@googlegroups.com
Hi Bram!

On Do, 30 Mai 2013, Bram Moolenaar wrote:

> Christian Brabandt wrote:
>
> > On Fr, 24 Mai 2013, Christian Brabandt wrote:
> >
> > > On Fr, 24 Mai 2013, Ein Brown wrote:
> > >
> > > > The SO question has more details:
> > > > http://stackoverflow.com/questions/16592654/in-vim-why-is-move-randomly-corrupting-my-folds
> > > >
> > > > at the bottom of the SO question (under 'edit') I explain ways to run into the bug without the Alt-Up / Alt-Down mapping.
> > >
> > > I just saw the problem yesterday. Here is an simpler example of the bug:
> > >
> > > I think this patch fixes it.
> > [...]
> >
> > No, it doesn't fix it completely. I'll look into it some more.
>
> I accidentally included some of this in patch 7.3.1042.
> I hope it doesn't cause any problems...

Opps, well it fixes a particular problem, but is not a complete
solution.

regards,
Christian
--
Steine sind stumme Lehrer, sie machen den Beobachter stumm, und
das Beste, was man von ihnen lernt, ist nicht mitzuteilen.
-- Goethe, Maximen und Reflektionen, Nr. 853

Christian Brabandt

unread,
May 30, 2013, 8:34:11 AM5/30/13
to vim...@googlegroups.com
Well here is a patch, that deletes the foldinfo and recreates it after
moving is finished. Admittedly, this doesn't solve the problem, but I
think it is actually simpler to delete and recreate the fold info, then
to update the curwin->w_folds several times for a single :move command.

This patch is against 7.3.1006, so does not include the changes
introduced by 7.3.1042.

regards,
Christian
move_folding_bug.diff
Reply all
Reply to author
Forward
0 new messages