Re: v_p at last line causes error "E315: ml_get: invalid lnum"

2015-05-22 Fir de Conversatie Bram Moolenaar

Yukihiro Nakadaira wrote:

> v_p at last line causes error "E315: ml_get: invalid lnum"
> 
> Steps to reproduce:
> 
>   $ vim -u NONE
>   oxylv$p
>   E315: ml_get: invalid lnum: 2
>   E322: line number out of range: 1 past the end
> 
> This behavior was introduced by 7.4.034.
> 
> There is related another problem.
> 
>   $ vim -u NONE
>   ixyv$d
>   :echo getline(1, '$')
>   ["x"]
> 
>   Expected: ["x", ""]
> 
> This behavior was introduce by 7.3.251.  "v$d" delete line.  I think this
> is not
> expected behavior at last line.
> 
> v_p execute 'd' and 'p'.
> 
> normal.c:nv_put()
> 9411 /* Now delete the selected text. */
> 9412 cap->cmdchar = 'd';
> 9413 cap->nchar = NUL;
> 9414 cap->oap->regname = NUL;
> 9415 nv_operator(cap);
> 9416 do_pending_operator(cap, 0, FALSE);
> 9417 empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
> ...
> 9450 do_put(cap->oap->regname, dir, cap->count1, flags);
> 
> For the above behavior 'd' delete last line.  And 'p' put register to the
> line
> already deleted.  Then it causes error.
> 
> I wrote patch for this problem.  Please check the attached patch.  It revert
> 7.3.251 and add the following line.  It passes test.  But I'm not sure it
> doesn't cause another problem.

Thanks!  I'll await others to try it out.

-- 
The future isn't what it used to be.

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

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


v_p at last line causes error "E315: ml_get: invalid lnum"

2015-05-22 Fir de Conversatie Yukihiro Nakadaira
v_p at last line causes error "E315: ml_get: invalid lnum"

Steps to reproduce:

  $ vim -u NONE
  oxylv$p
  E315: ml_get: invalid lnum: 2
  E322: line number out of range: 1 past the end

This behavior was introduced by 7.4.034.

There is related another problem.

  $ vim -u NONE
  ixyv$d
  :echo getline(1, '$')
  ["x"]

  Expected: ["x", ""]

This behavior was introduce by 7.3.251.  "v$d" delete line.  I think this
is not
expected behavior at last line.

v_p execute 'd' and 'p'.

normal.c:nv_put()
9411 /* Now delete the selected text. */
9412 cap->cmdchar = 'd';
9413 cap->nchar = NUL;
9414 cap->oap->regname = NUL;
9415 nv_operator(cap);
9416 do_pending_operator(cap, 0, FALSE);
9417 empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
...
9450 do_put(cap->oap->regname, dir, cap->count1, flags);

For the above behavior 'd' delete last line.  And 'p' put register to the
line
already deleted.  Then it causes error.

I wrote patch for this problem.  Please check the attached patch.  It revert
7.3.251 and add the following line.  It passes test.  But I'm not sure it
doesn't cause another problem.

diff -r 18d84ed365a5 src/normal.c
--- a/src/normal.c Wed Apr 22 22:18:22 2015 +0200
+++ b/src/normal.c Fri May 22 14:26:03 2015 +0900
@@ -1547,8 +1547,10 @@
 }

 /* In Select mode, a linewise selection is operated upon like a
- * characterwise selection. */
-if (VIsual_select && VIsual_mode == 'V')
+ * characterwise selection.
+ * Special case: gH deletes the last line. */
+if (VIsual_select && VIsual_mode == 'V'
+&& cap->oap->op_type != OP_DELETE)
 {
  if (lt(VIsual, curwin->w_cursor))
  {

-- 
Yukihiro Nakadaira - yukihiro.nakada...@gmail.com

-- 
-- 
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 vim_dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
diff -r 18d84ed365a5 src/normal.c
--- a/src/normal.c  Wed Apr 22 22:18:22 2015 +0200
+++ b/src/normal.c  Fri May 22 14:26:03 2015 +0900
@@ -1547,8 +1547,10 @@
}
 
/* In Select mode, a linewise selection is operated upon like a
-* characterwise selection. */
-   if (VIsual_select && VIsual_mode == 'V')
+* characterwise selection.
+* Special case: gH deletes the last line. */
+   if (VIsual_select && VIsual_mode == 'V'
+   && cap->oap->op_type != OP_DELETE)
{
if (lt(VIsual, curwin->w_cursor))
{
@@ -1770,24 +1772,16 @@
oap->inclusive = FALSE;
/* Try to include the newline, unless it's an operator
 * that works on lines only. */
-   if (*p_sel != 'o' && !op_on_lines(oap->op_type))
+   if (*p_sel != 'o'
+   && !op_on_lines(oap->op_type)
+   && oap->end.lnum < curbuf->b_ml.ml_line_count)
{
-   if (oap->end.lnum < curbuf->b_ml.ml_line_count)
-   {
-   ++oap->end.lnum;
-   oap->end.col = 0;
+   ++oap->end.lnum;
+   oap->end.col = 0;
 #ifdef FEAT_VIRTUALEDIT
-   oap->end.coladd = 0;
-#endif
-   ++oap->line_count;
-   }
-   else
-   {
-   /* Cannot move below the last line, make the op
-* inclusive to tell the operation to include the
-* line break. */
-   oap->inclusive = TRUE;
-   }
+   oap->end.coladd = 0;
+#endif
+   ++oap->line_count;
}
}
}
diff -r 18d84ed365a5 src/ops.c
--- a/src/ops.c Wed Apr 22 22:18:22 2015 +0200
+++ b/src/ops.c Fri May 22 14:26:03 2015 +0900
@@ -1959,60 +1959,31 @@
curwin->w_cursor.coladd = 0;
}
 #endif
-   if (oap->op_type == OP_DELETE
-   && oap->inclusive
-