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