Wednesday, November 23, 2016

Fold-related bug and pointer to fix

I had the following problem and I think it is a bug in some fold-related code:

I was trying to use the NarrowRegion plugin to do diffs between two functions in the same file by creating narrowed buffers for each function and calling :diffthis on them.  When I tried to do this using folds, i.e. :.,+2NarrowRegion to create a buffer for a folded-up function which looked like this:

int FuncName() {
.....folded........
}

I got everything but the final brace in the narrowed buffer.  Eventually I discovered that this has nothing to do with NarrowRegion, but just a yank such as:

:.,+2y

over a fold gives only the folded lines but not the line after the fold.

A normal command of y2j works just fine and gets the line after the fold.  Similarly, in a file where multiple folds are right after one another (a nice example is in fold.c of the vim code), a normal command of y2j yanks two folds, but :.,+2y yanks only one.

A little debugging led me to believe that the problem is in this code in ex_docmd.c, lines 2548-2549 in the latest git code:

    /* Put the first line at the start of a closed fold, put the last line
     * at the end of a closed fold. */
    (void)hasFolding(ea.line1, &ea.line1, NULL);
    (void)hasFolding(ea.line2, NULL, &ea.line2);

This seems to use the side effect of the hasFolding call to set the value of ea.line2 which is passed to the actual yank command.

I hope this will be helpful to fix the bug.

Ephraim

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: