Bram et al.,

I noticed that ":move" always sets 'modified'... even when lines aren't moved
within the buffer.  This patch fixes this problem.

Also, ":move" is not tested, so I added a test function to cover this command.

Just clearing out some stuff I had laying around today...

Best,
Jason Franklin

-- 
-- 
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 f3ee3a79220881278505a139ba99c797a44d67df Mon Sep 17 00:00:00 2001
From: Jason Franklin <[email protected]>
Date: Sat, 10 Nov 2018 10:45:07 -0500
Subject: [PATCH 1/2] Add a failing test for the ":move" command

This test examines the behavior of the ":move" command for accuracy.
It also checks that 'modified' is set by ":move" only when lines are
actually moved away from their original location.
---
 src/Make_all.mak          |  1 +
 src/testdir/test_alot.vim |  1 +
 src/testdir/test_move.vim | 40 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+)
 create mode 100644 src/testdir/test_move.vim

diff --git a/src/Make_all.mak b/src/Make_all.mak
index f5f0552b9..da3a62ca8 100644
--- a/src/Make_all.mak
+++ b/src/Make_all.mak
@@ -123,6 +123,7 @@ NEW_TESTS = \
 	test_mksession \
 	test_mksession_utf8 \
 	test_modeline \
+	test_move \
 	test_nested_function \
 	test_netbeans \
 	test_normal \
diff --git a/src/testdir/test_alot.vim b/src/testdir/test_alot.vim
index 3a0c6e042..be665120b 100644
--- a/src/testdir/test_alot.vim
+++ b/src/testdir/test_alot.vim
@@ -41,6 +41,7 @@ source test_match.vim
 source test_menu.vim
 source test_messages.vim
 source test_modeline.vim
+source test_move.vim
 source test_partial.vim
 source test_popup.vim
 source test_put.vim
diff --git a/src/testdir/test_move.vim b/src/testdir/test_move.vim
new file mode 100644
index 000000000..b737c216e
--- /dev/null
+++ b/src/testdir/test_move.vim
@@ -0,0 +1,40 @@
+" Test the ":move" command.
+
+function! Test_move()
+  enew!
+  call append(0, ['line 1', 'line 2', 'line 3'])
+  g /^$/ delete _
+  set nomodified
+
+  move .
+  call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
+  call assert_false(&modified)
+
+  1,2move 0
+  call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
+  call assert_false(&modified)
+
+  1,3move 3
+  call assert_equal(['line 1', 'line 2', 'line 3'], getline(1, 3))
+  call assert_false(&modified)
+
+  1move 2
+  call assert_equal(['line 2', 'line 1', 'line 3'], getline(1, 3))
+  call assert_true(&modified)
+  set nomodified
+
+  3move 0
+  call assert_equal(['line 3', 'line 2', 'line 1'], getline(1, 3))
+  call assert_true(&modified)
+  set nomodified
+
+  2,3move 0
+  call assert_equal(['line 2', 'line 1', 'line 3'], getline(1, 3))
+  call assert_true(&modified)
+  set nomodified
+
+  call assert_fails('1,2move 1', 'E134')
+  call assert_fails('2,3move 2', 'E134')
+
+  %bwipeout!
+endfunction
-- 
2.17.1


>From 1a141a05496251cc36983b30125ead50c78f5064 Mon Sep 17 00:00:00 2001
From: Jason Franklin <[email protected]>
Date: Sat, 10 Nov 2018 11:10:49 -0500
Subject: [PATCH 2/2] Make the ":move" command set 'modified' correctly

Currently, ":move" always sets 'modified' when invoked.  This commit
changes the command's behavior to avoid setting 'modified' unless
lines are actually being moved within the buffer.

We also are sure to move the cursor accurately so that the ending
cursor position is consistent regardless of whether lines are moved
or not.
---
 src/ex_cmds.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 7512785c9..6109e2ee3 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -909,10 +909,25 @@ do_move(linenr_T line1, linenr_T line2, linenr_T dest)
 
     if (dest >= line1 && dest < line2)
     {
-	EMSG(_("E134: Move lines into themselves"));
+	EMSG(_("E134: Cannot move a block into itself"));
 	return FAIL;
     }
 
+    // Do nothing if we are not actually moving any lines.  This will prevent
+    // the 'modified' flag from being set without cause.
+    if (dest == line1 - 1 || dest == line2)
+    {
+
+	// Move the cursor as if lines were moved (see below).  A consistent
+	// ending cursor position could prevent mappings from breaking.
+	if (dest >= line1)
+	    curwin->w_cursor.lnum = dest;
+	else
+	    curwin->w_cursor.lnum = dest + (line2 - line1) + 1;
+
+	return OK;
+    }
+
     num_lines = line2 - line1 + 1;
 
     /*
-- 
2.17.1

Raspunde prin e-mail lui