81c2858
To: vim-dev@vim.org
81c2858
Subject: Patch 7.2.226
81c2858
Fcc: outbox
81c2858
From: Bram Moolenaar <Bram@moolenaar.net>
81c2858
Mime-Version: 1.0
81c2858
Content-Type: text/plain; charset=UTF-8
81c2858
Content-Transfer-Encoding: 8bit
81c2858
------------
81c2858
81c2858
Patch 7.2.226
81c2858
Problem:    ml_get error after deleting the last line. (Xavier de Gaye)
81c2858
Solution:   When adjusting marks a callback may be invoked.  Adjust the cursor
81c2858
	    position before invoking deleted_lines_mark().
81c2858
Files:	    src/ex_cmds.c, src/ex_docmd.c, src/if_mzsch.c, src/if_python.c,
81c2858
	    src/if_perl.xs, src/misc1.c
81c2858
81c2858
81c2858
*** ../vim-7.2.225/src/ex_cmds.c	2009-05-17 13:30:58.000000000 +0200
81c2858
--- src/ex_cmds.c	2009-07-09 12:56:51.000000000 +0200
81c2858
***************
81c2858
*** 4013,4018 ****
81c2858
--- 4013,4021 ----
81c2858
  	    break;
81c2858
  	ml_delete(eap->line1, FALSE);
81c2858
      }
81c2858
+ 
81c2858
+     /* make sure the cursor is not beyond the end of the file now */
81c2858
+     check_cursor_lnum();
81c2858
      deleted_lines_mark(eap->line1, (long)(eap->line2 - lnum));
81c2858
  
81c2858
      /* ":append" on the line above the deleted lines. */
81c2858
*** ../vim-7.2.225/src/ex_docmd.c	2009-07-09 15:55:34.000000000 +0200
81c2858
--- src/ex_docmd.c	2009-07-09 15:24:03.000000000 +0200
81c2858
***************
81c2858
*** 7845,7854 ****
81c2858
  		if (*ml_get(lnum) == NUL && u_savedel(lnum, 1L) == OK)
81c2858
  		{
81c2858
  		    ml_delete(lnum, FALSE);
81c2858
- 		    deleted_lines_mark(lnum, 1L);
81c2858
  		    if (curwin->w_cursor.lnum > 1
81c2858
  					     && curwin->w_cursor.lnum >= lnum)
81c2858
  			--curwin->w_cursor.lnum;
81c2858
  		}
81c2858
  	    }
81c2858
  	    redraw_curbuf_later(VALID);
81c2858
--- 7845,7854 ----
81c2858
  		if (*ml_get(lnum) == NUL && u_savedel(lnum, 1L) == OK)
81c2858
  		{
81c2858
  		    ml_delete(lnum, FALSE);
81c2858
  		    if (curwin->w_cursor.lnum > 1
81c2858
  					     && curwin->w_cursor.lnum >= lnum)
81c2858
  			--curwin->w_cursor.lnum;
81c2858
+ 		    deleted_lines_mark(lnum, 1L);
81c2858
  		}
81c2858
  	    }
81c2858
  	    redraw_curbuf_later(VALID);
81c2858
*** ../vim-7.2.225/src/if_mzsch.c	2009-06-24 17:51:01.000000000 +0200
81c2858
--- src/if_mzsch.c	2009-07-09 12:59:17.000000000 +0200
81c2858
***************
81c2858
*** 2169,2177 ****
81c2858
  	    curbuf = savebuf;
81c2858
  	    raise_vim_exn(_("cannot delete line"));
81c2858
  	}
81c2858
- 	deleted_lines_mark((linenr_T)n, 1L);
81c2858
  	if (buf->buf == curwin->w_buffer)
81c2858
  	    mz_fix_cursor(n, n + 1, -1);
81c2858
  
81c2858
  	curbuf = savebuf;
81c2858
  
81c2858
--- 2169,2177 ----
81c2858
  	    curbuf = savebuf;
81c2858
  	    raise_vim_exn(_("cannot delete line"));
81c2858
  	}
81c2858
  	if (buf->buf == curwin->w_buffer)
81c2858
  	    mz_fix_cursor(n, n + 1, -1);
81c2858
+ 	deleted_lines_mark((linenr_T)n, 1L);
81c2858
  
81c2858
  	curbuf = savebuf;
81c2858
  
81c2858
***************
81c2858
*** 2299,2307 ****
81c2858
  		    curbuf = savebuf;
81c2858
  		    raise_vim_exn(_("cannot delete line"));
81c2858
  		}
81c2858
- 	    deleted_lines_mark((linenr_T)lo, (long)old_len);
81c2858
  	    if (buf->buf == curwin->w_buffer)
81c2858
  		mz_fix_cursor(lo, hi, -old_len);
81c2858
  	}
81c2858
  
81c2858
  	curbuf = savebuf;
81c2858
--- 2299,2307 ----
81c2858
  		    curbuf = savebuf;
81c2858
  		    raise_vim_exn(_("cannot delete line"));
81c2858
  		}
81c2858
  	    if (buf->buf == curwin->w_buffer)
81c2858
  		mz_fix_cursor(lo, hi, -old_len);
81c2858
+ 	    deleted_lines_mark((linenr_T)lo, (long)old_len);
81c2858
  	}
81c2858
  
81c2858
  	curbuf = savebuf;
81c2858
*** ../vim-7.2.225/src/if_python.c	2009-05-21 23:25:38.000000000 +0200
81c2858
--- src/if_python.c	2009-07-09 12:59:45.000000000 +0200
81c2858
***************
81c2858
*** 2497,2505 ****
81c2858
  	    PyErr_SetVim(_("cannot delete line"));
81c2858
  	else
81c2858
  	{
81c2858
- 	    deleted_lines_mark((linenr_T)n, 1L);
81c2858
  	    if (buf == curwin->w_buffer)
81c2858
  		py_fix_cursor((linenr_T)n, (linenr_T)n + 1, (linenr_T)-1);
81c2858
  	}
81c2858
  
81c2858
  	curbuf = savebuf;
81c2858
--- 2497,2505 ----
81c2858
  	    PyErr_SetVim(_("cannot delete line"));
81c2858
  	else
81c2858
  	{
81c2858
  	    if (buf == curwin->w_buffer)
81c2858
  		py_fix_cursor((linenr_T)n, (linenr_T)n + 1, (linenr_T)-1);
81c2858
+ 	    deleted_lines_mark((linenr_T)n, 1L);
81c2858
  	}
81c2858
  
81c2858
  	curbuf = savebuf;
81c2858
***************
81c2858
*** 2596,2605 ****
81c2858
  		    break;
81c2858
  		}
81c2858
  	    }
81c2858
- 	    deleted_lines_mark((linenr_T)lo, (long)i);
81c2858
- 
81c2858
  	    if (buf == curwin->w_buffer)
81c2858
  		py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n);
81c2858
  	}
81c2858
  
81c2858
  	curbuf = savebuf;
81c2858
--- 2596,2604 ----
81c2858
  		    break;
81c2858
  		}
81c2858
  	    }
81c2858
  	    if (buf == curwin->w_buffer)
81c2858
  		py_fix_cursor((linenr_T)lo, (linenr_T)hi, (linenr_T)-n);
81c2858
+ 	    deleted_lines_mark((linenr_T)lo, (long)i);
81c2858
  	}
81c2858
  
81c2858
  	curbuf = savebuf;
81c2858
*** ../vim-7.2.225/src/if_perl.xs	2009-06-16 16:01:34.000000000 +0200
81c2858
--- src/if_perl.xs	2009-07-09 13:02:16.000000000 +0200
81c2858
***************
81c2858
*** 1233,1241 ****
81c2858
  		    if (u_savedel(lnum, 1) == OK)
81c2858
  		    {
81c2858
  			ml_delete(lnum, 0);
81c2858
  			deleted_lines_mark(lnum, 1L);
81c2858
- 			if (aco.save_curbuf == curbuf)
81c2858
- 			    check_cursor();
81c2858
  		    }
81c2858
  
81c2858
  		    /* restore curwin/curbuf and a few other things */
81c2858
--- 1235,1242 ----
81c2858
  		    if (u_savedel(lnum, 1) == OK)
81c2858
  		    {
81c2858
  			ml_delete(lnum, 0);
81c2858
+ 			check_cursor();
81c2858
  			deleted_lines_mark(lnum, 1L);
81c2858
  		    }
81c2858
  
81c2858
  		    /* restore curwin/curbuf and a few other things */
81c2858
*** ../vim-7.2.225/src/misc1.c	2009-06-24 16:25:23.000000000 +0200
81c2858
--- src/misc1.c	2009-07-09 13:00:59.000000000 +0200
81c2858
***************
81c2858
*** 2345,2356 ****
81c2858
      int		undo;		/* if TRUE, prepare for undo */
81c2858
  {
81c2858
      long	n;
81c2858
  
81c2858
      if (nlines <= 0)
81c2858
  	return;
81c2858
  
81c2858
      /* save the deleted lines for undo */
81c2858
!     if (undo && u_savedel(curwin->w_cursor.lnum, nlines) == FAIL)
81c2858
  	return;
81c2858
  
81c2858
      for (n = 0; n < nlines; )
81c2858
--- 2345,2357 ----
81c2858
      int		undo;		/* if TRUE, prepare for undo */
81c2858
  {
81c2858
      long	n;
81c2858
+     linenr_T	first = curwin->w_cursor.lnum;
81c2858
  
81c2858
      if (nlines <= 0)
81c2858
  	return;
81c2858
  
81c2858
      /* save the deleted lines for undo */
81c2858
!     if (undo && u_savedel(first, nlines) == FAIL)
81c2858
  	return;
81c2858
  
81c2858
      for (n = 0; n < nlines; )
81c2858
***************
81c2858
*** 2358,2375 ****
81c2858
  	if (curbuf->b_ml.ml_flags & ML_EMPTY)	    /* nothing to delete */
81c2858
  	    break;
81c2858
  
81c2858
! 	ml_delete(curwin->w_cursor.lnum, TRUE);
81c2858
  	++n;
81c2858
  
81c2858
  	/* If we delete the last line in the file, stop */
81c2858
! 	if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
81c2858
  	    break;
81c2858
      }
81c2858
-     /* adjust marks, mark the buffer as changed and prepare for displaying */
81c2858
-     deleted_lines_mark(curwin->w_cursor.lnum, n);
81c2858
  
81c2858
      curwin->w_cursor.col = 0;
81c2858
      check_cursor_lnum();
81c2858
  }
81c2858
  
81c2858
      int
81c2858
--- 2359,2379 ----
81c2858
  	if (curbuf->b_ml.ml_flags & ML_EMPTY)	    /* nothing to delete */
81c2858
  	    break;
81c2858
  
81c2858
! 	ml_delete(first, TRUE);
81c2858
  	++n;
81c2858
  
81c2858
  	/* If we delete the last line in the file, stop */
81c2858
! 	if (first > curbuf->b_ml.ml_line_count)
81c2858
  	    break;
81c2858
      }
81c2858
  
81c2858
+     /* Correct the cursor position before calling deleted_lines_mark(), it may
81c2858
+      * trigger a callback to display the cursor. */
81c2858
      curwin->w_cursor.col = 0;
81c2858
      check_cursor_lnum();
81c2858
+ 
81c2858
+     /* adjust marks, mark the buffer as changed and prepare for displaying */
81c2858
+     deleted_lines_mark(first, n);
81c2858
  }
81c2858
  
81c2858
      int
81c2858
***************
81c2858
*** 2621,2626 ****
81c2858
--- 2625,2632 ----
81c2858
  
81c2858
  /*
81c2858
   * Like deleted_lines(), but adjust marks first.
81c2858
+  * Make sure the cursor is on a valid line before calling, a GUI callback may
81c2858
+  * be triggered to display the cursor.
81c2858
   */
81c2858
      void
81c2858
  deleted_lines_mark(lnum, count)
81c2858
*** ../vim-7.2.225/src/version.c	2009-07-09 18:24:24.000000000 +0200
81c2858
--- src/version.c	2009-07-09 20:01:16.000000000 +0200
81c2858
***************
81c2858
*** 678,679 ****
81c2858
--- 678,681 ----
81c2858
  {   /* Add new patch number below this line */
81c2858
+ /**/
81c2858
+     226,
81c2858
  /**/
81c2858
81c2858
-- 
81c2858
hundred-and-one symptoms of being an internet addict:
81c2858
80. At parties, you introduce your spouse as your "service provider."
81c2858
81c2858
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
81c2858
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
81c2858
\\\        download, build and distribute -- http://www.A-A-P.org        ///
81c2858
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///