> Patch 7.4.700
> Problem:    Fold can't be opened after ":move". (Ein Brown)
> Solution:   Delete the folding information and update it afterwards.
>             (Christian Brabandt)
> Files:      src/ex_cmds.c, src/fold.c, src/testdir/test45.in,
>             src/testdir/test45.ok

Recently I have been looking into this issue again. Reason is, I don't 
like the folds being changed after doing :move.

Turns out, do_move() does finally call mark_adjust with a negative 
amount (ex_cmds.c:859)

mark_adjust() calls foldMarkAdjust() which will then call 
foldMarkAdjustRecurse() which does finally:

1561    if (last <= line2)
1562    {
1563        /* 2. fold contains line1, line2 is below fold */
1564        if (amount == MAXLNUM)
1565            fp->fd_len = line1 - fp->fd_top;
1566        else
1567            fp->fd_len += amount;
1568    }

Note, that it unconditionally adds amount to fd_len, which in this 
particular case means, fp->fd_len becomes negative and I believe this is 
wrong. So how about just checking, that the sum cannot be negative?

That is what the attached patch does it and also does not fail test45

On a related note, what test45 does is calling :1m1 which basically is a 
no op. We might want to return early in that case from do_move. Also 
calling mark_adjust with line1==line2 and a negative amount looks 
certainly wrong to me.

Best,
Christian
-- 
Ich bin körperlich und physisch topfit.
                -- Thomas Häßler

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
From a8ae14ecb7fbcd11916b7737e87ff6d2a4dd5668 Mon Sep 17 00:00:00 2001
From: Christian Brabandt <[email protected]>
Date: Tue, 31 Jan 2017 21:48:59 +0100
Subject: [PATCH] Revert "patch 7.4.700"

This reverts commit d5f6933d5c57ea6f79bbdeab6c426cf66a393f33.

Do not reset fold information on :move

Make sure fp->fd_len won't be negative
---
 src/ex_cmds.c | 16 ----------------
 src/fold.c    |  2 +-
 2 files changed, 1 insertion(+), 17 deletions(-)

diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 58a018612..fb8bc685a 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -798,16 +798,6 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
     linenr_T	extra;	    /* Num lines added before line1 */
     linenr_T	num_lines;  /* Num lines moved */
     linenr_T	last_line;  /* Last line in file after adding new text */
-#ifdef FEAT_FOLDING
-    int		isFolded;
-
-    /* Moving lines seems to corrupt the folds, delete folding info now
-     * and recreate it when finished.  Don't do this for manual folding, it
-     * would delete all folds. */
-    isFolded = hasAnyFolding(curwin) && !foldmethodIsManual(curwin);
-    if (isFolded)
-	deleteFoldRecurse(&curwin->w_folds);
-#endif
 
     if (dest >= line1 && dest < line2)
     {
@@ -906,12 +896,6 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
     else
 	changed_lines(dest + 1, 0, line1 + num_lines, 0L);
 
-#ifdef FEAT_FOLDING
-	/* recreate folds */
-	if (isFolded)
-	    foldUpdateAll(curwin);
-#endif
-
     return OK;
 }
 
diff --git a/src/fold.c b/src/fold.c
index d3635a6d7..86c4c93f6 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -1563,7 +1563,7 @@ foldMarkAdjustRecurse(
 			/* 2. fold contains line1, line2 is below fold */
 			if (amount == MAXLNUM)
 			    fp->fd_len = line1 - fp->fd_top;
-			else
+			else if (fp->fd_len > -amount)
 			    fp->fd_len += amount;
 		    }
 		    else
-- 
2.11.0

Raspunde prin e-mail lui