Karsten Hopp b55325
To: vim-dev@vim.org
Karsten Hopp b55325
Subject: Patch 7.0.022
Karsten Hopp b55325
Fcc: outbox
Karsten Hopp b55325
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp b55325
Mime-Version: 1.0
Karsten Hopp b55325
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp b55325
Content-Transfer-Encoding: 8bit
Karsten Hopp b55325
------------
Karsten Hopp b55325
Karsten Hopp b55325
Patch 7.0.022
Karsten Hopp b55325
Problem:    Using buffer.append() in Ruby may append the line to the wrong
Karsten Hopp b55325
	    buffer. (Alex Norman)
Karsten Hopp b55325
Solution:   Properly switch to the buffer to do the appending.  Also for
Karsten Hopp b55325
	    buffer.delete() and setting a buffer line.
Karsten Hopp b55325
Files:	    src/if_ruby.c
Karsten Hopp b55325
Karsten Hopp b55325
Karsten Hopp b55325
*** ../vim-7.0.021/src/if_ruby.c	Sun Apr 30 20:25:42 2006
Karsten Hopp b55325
--- src/if_ruby.c	Tue Jun 20 21:01:23 2006
Karsten Hopp b55325
***************
Karsten Hopp b55325
*** 643,653 ****
Karsten Hopp b55325
  
Karsten Hopp b55325
  static VALUE set_buffer_line(buf_T *buf, linenr_T n, VALUE str)
Karsten Hopp b55325
  {
Karsten Hopp b55325
!     buf_T *savebuf = curbuf;
Karsten Hopp b55325
!     char *line = STR2CSTR(str);
Karsten Hopp b55325
  
Karsten Hopp b55325
!     if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL) {
Karsten Hopp b55325
  	curbuf = buf;
Karsten Hopp b55325
  	if (u_savesub(n) == OK) {
Karsten Hopp b55325
  	    ml_replace(n, (char_u *)line, TRUE);
Karsten Hopp b55325
  	    changed();
Karsten Hopp b55325
--- 643,665 ----
Karsten Hopp b55325
  
Karsten Hopp b55325
  static VALUE set_buffer_line(buf_T *buf, linenr_T n, VALUE str)
Karsten Hopp b55325
  {
Karsten Hopp b55325
!     char	*line = STR2CSTR(str);
Karsten Hopp b55325
! #ifdef FEAT_AUTOCMD
Karsten Hopp b55325
!     aco_save_T	aco;
Karsten Hopp b55325
! #else
Karsten Hopp b55325
!     buf_T	*save_curbuf = curbuf;
Karsten Hopp b55325
! #endif
Karsten Hopp b55325
  
Karsten Hopp b55325
!     if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL)
Karsten Hopp b55325
!     {
Karsten Hopp b55325
! #ifdef FEAT_AUTOCMD
Karsten Hopp b55325
! 	/* set curwin/curbuf for "buf" and save some things */
Karsten Hopp b55325
! 	aucmd_prepbuf(&aco, buf);
Karsten Hopp b55325
! #else
Karsten Hopp b55325
  	curbuf = buf;
Karsten Hopp b55325
+ 	curwin->w_buffer = buf;
Karsten Hopp b55325
+ #endif
Karsten Hopp b55325
+ 
Karsten Hopp b55325
  	if (u_savesub(n) == OK) {
Karsten Hopp b55325
  	    ml_replace(n, (char_u *)line, TRUE);
Karsten Hopp b55325
  	    changed();
Karsten Hopp b55325
***************
Karsten Hopp b55325
*** 655,664 ****
Karsten Hopp b55325
  	    syn_changed(n); /* recompute syntax hl. for this line */
Karsten Hopp b55325
  #endif
Karsten Hopp b55325
  	}
Karsten Hopp b55325
! 	curbuf = savebuf;
Karsten Hopp b55325
  	update_curbuf(NOT_VALID);
Karsten Hopp b55325
      }
Karsten Hopp b55325
!     else {
Karsten Hopp b55325
  	rb_raise(rb_eIndexError, "index %d out of buffer", n);
Karsten Hopp b55325
  	return Qnil; /* For stop warning */
Karsten Hopp b55325
      }
Karsten Hopp b55325
--- 667,685 ----
Karsten Hopp b55325
  	    syn_changed(n); /* recompute syntax hl. for this line */
Karsten Hopp b55325
  #endif
Karsten Hopp b55325
  	}
Karsten Hopp b55325
! 
Karsten Hopp b55325
! #ifdef FEAT_AUTOCMD
Karsten Hopp b55325
! 	/* restore curwin/curbuf and a few other things */
Karsten Hopp b55325
! 	aucmd_restbuf(&aco;;
Karsten Hopp b55325
! 	/* Careful: autocommands may have made "buf" invalid! */
Karsten Hopp b55325
! #else
Karsten Hopp b55325
! 	curwin->w_buffer = save_curbuf;
Karsten Hopp b55325
! 	curbuf = save_curbuf;
Karsten Hopp b55325
! #endif
Karsten Hopp b55325
  	update_curbuf(NOT_VALID);
Karsten Hopp b55325
      }
Karsten Hopp b55325
!     else
Karsten Hopp b55325
!     {
Karsten Hopp b55325
  	rb_raise(rb_eIndexError, "index %d out of buffer", n);
Karsten Hopp b55325
  	return Qnil; /* For stop warning */
Karsten Hopp b55325
      }
Karsten Hopp b55325
***************
Karsten Hopp b55325
*** 676,687 ****
Karsten Hopp b55325
  
Karsten Hopp b55325
  static VALUE buffer_delete(VALUE self, VALUE num)
Karsten Hopp b55325
  {
Karsten Hopp b55325
!     buf_T *buf = get_buf(self);
Karsten Hopp b55325
!     buf_T *savebuf = curbuf;
Karsten Hopp b55325
!     long n = NUM2LONG(num);
Karsten Hopp b55325
  
Karsten Hopp b55325
!     if (n > 0 && n <= buf->b_ml.ml_line_count) {
Karsten Hopp b55325
  	curbuf = buf;
Karsten Hopp b55325
  	if (u_savedel(n, 1) == OK) {
Karsten Hopp b55325
  	    ml_delete(n, 0);
Karsten Hopp b55325
  
Karsten Hopp b55325
--- 697,720 ----
Karsten Hopp b55325
  
Karsten Hopp b55325
  static VALUE buffer_delete(VALUE self, VALUE num)
Karsten Hopp b55325
  {
Karsten Hopp b55325
!     buf_T	*buf = get_buf(self);
Karsten Hopp b55325
!     long	n = NUM2LONG(num);
Karsten Hopp b55325
! #ifdef FEAT_AUTOCMD
Karsten Hopp b55325
!     aco_save_T	aco;
Karsten Hopp b55325
! #else
Karsten Hopp b55325
!     buf_T	*save_curbuf = curbuf;
Karsten Hopp b55325
! #endif
Karsten Hopp b55325
  
Karsten Hopp b55325
!     if (n > 0 && n <= buf->b_ml.ml_line_count)
Karsten Hopp b55325
!     {
Karsten Hopp b55325
! #ifdef FEAT_AUTOCMD
Karsten Hopp b55325
! 	/* set curwin/curbuf for "buf" and save some things */
Karsten Hopp b55325
! 	aucmd_prepbuf(&aco, buf);
Karsten Hopp b55325
! #else
Karsten Hopp b55325
  	curbuf = buf;
Karsten Hopp b55325
+ 	curwin->w_buffer = buf;
Karsten Hopp b55325
+ #endif
Karsten Hopp b55325
+ 
Karsten Hopp b55325
  	if (u_savedel(n, 1) == OK) {
Karsten Hopp b55325
  	    ml_delete(n, 0);
Karsten Hopp b55325
  
Karsten Hopp b55325
***************
Karsten Hopp b55325
*** 691,700 ****
Karsten Hopp b55325
  
Karsten Hopp b55325
  	    changed();
Karsten Hopp b55325
  	}
Karsten Hopp b55325
! 	curbuf = savebuf;
Karsten Hopp b55325
  	update_curbuf(NOT_VALID);
Karsten Hopp b55325
      }
Karsten Hopp b55325
!     else {
Karsten Hopp b55325
  	rb_raise(rb_eIndexError, "index %d out of buffer", n);
Karsten Hopp b55325
      }
Karsten Hopp b55325
      return Qnil;
Karsten Hopp b55325
--- 724,742 ----
Karsten Hopp b55325
  
Karsten Hopp b55325
  	    changed();
Karsten Hopp b55325
  	}
Karsten Hopp b55325
! 
Karsten Hopp b55325
! #ifdef FEAT_AUTOCMD
Karsten Hopp b55325
! 	/* restore curwin/curbuf and a few other things */
Karsten Hopp b55325
! 	aucmd_restbuf(&aco;;
Karsten Hopp b55325
! 	/* Careful: autocommands may have made "buf" invalid! */
Karsten Hopp b55325
! #else
Karsten Hopp b55325
! 	curwin->w_buffer = save_curbuf;
Karsten Hopp b55325
! 	curbuf = save_curbuf;
Karsten Hopp b55325
! #endif
Karsten Hopp b55325
  	update_curbuf(NOT_VALID);
Karsten Hopp b55325
      }
Karsten Hopp b55325
!     else
Karsten Hopp b55325
!     {
Karsten Hopp b55325
  	rb_raise(rb_eIndexError, "index %d out of buffer", n);
Karsten Hopp b55325
      }
Karsten Hopp b55325
      return Qnil;
Karsten Hopp b55325
***************
Karsten Hopp b55325
*** 702,714 ****
Karsten Hopp b55325
  
Karsten Hopp b55325
  static VALUE buffer_append(VALUE self, VALUE num, VALUE str)
Karsten Hopp b55325
  {
Karsten Hopp b55325
!     buf_T *buf = get_buf(self);
Karsten Hopp b55325
!     buf_T *savebuf = curbuf;
Karsten Hopp b55325
!     char *line = STR2CSTR(str);
Karsten Hopp b55325
!     long n = NUM2LONG(num);
Karsten Hopp b55325
  
Karsten Hopp b55325
!     if (n >= 0 && n <= buf->b_ml.ml_line_count && line != NULL) {
Karsten Hopp b55325
  	curbuf = buf;
Karsten Hopp b55325
  	if (u_inssub(n + 1) == OK) {
Karsten Hopp b55325
  	    ml_append(n, (char_u *) line, (colnr_T) 0, FALSE);
Karsten Hopp b55325
  
Karsten Hopp b55325
--- 744,768 ----
Karsten Hopp b55325
  
Karsten Hopp b55325
  static VALUE buffer_append(VALUE self, VALUE num, VALUE str)
Karsten Hopp b55325
  {
Karsten Hopp b55325
!     buf_T	*buf = get_buf(self);
Karsten Hopp b55325
!     char	*line = STR2CSTR(str);
Karsten Hopp b55325
!     long	n = NUM2LONG(num);
Karsten Hopp b55325
! #ifdef FEAT_AUTOCMD
Karsten Hopp b55325
!     aco_save_T	aco;
Karsten Hopp b55325
! #else
Karsten Hopp b55325
!     buf_T	*save_curbuf = curbuf;
Karsten Hopp b55325
! #endif
Karsten Hopp b55325
  
Karsten Hopp b55325
!     if (n >= 0 && n <= buf->b_ml.ml_line_count && line != NULL)
Karsten Hopp b55325
!     {
Karsten Hopp b55325
! #ifdef FEAT_AUTOCMD
Karsten Hopp b55325
! 	/* set curwin/curbuf for "buf" and save some things */
Karsten Hopp b55325
! 	aucmd_prepbuf(&aco, buf);
Karsten Hopp b55325
! #else
Karsten Hopp b55325
  	curbuf = buf;
Karsten Hopp b55325
+ 	curwin->w_buffer = buf;
Karsten Hopp b55325
+ #endif
Karsten Hopp b55325
+ 
Karsten Hopp b55325
  	if (u_inssub(n + 1) == OK) {
Karsten Hopp b55325
  	    ml_append(n, (char_u *) line, (colnr_T) 0, FALSE);
Karsten Hopp b55325
  
Karsten Hopp b55325
***************
Karsten Hopp b55325
*** 718,724 ****
Karsten Hopp b55325
  
Karsten Hopp b55325
  	    changed();
Karsten Hopp b55325
  	}
Karsten Hopp b55325
! 	curbuf = savebuf;
Karsten Hopp b55325
  	update_curbuf(NOT_VALID);
Karsten Hopp b55325
      }
Karsten Hopp b55325
      else {
Karsten Hopp b55325
--- 772,786 ----
Karsten Hopp b55325
  
Karsten Hopp b55325
  	    changed();
Karsten Hopp b55325
  	}
Karsten Hopp b55325
! 
Karsten Hopp b55325
! #ifdef FEAT_AUTOCMD
Karsten Hopp b55325
! 	/* restore curwin/curbuf and a few other things */
Karsten Hopp b55325
! 	aucmd_restbuf(&aco;;
Karsten Hopp b55325
! 	/* Careful: autocommands may have made "buf" invalid! */
Karsten Hopp b55325
! #else
Karsten Hopp b55325
! 	curwin->w_buffer = save_curbuf;
Karsten Hopp b55325
! 	curbuf = save_curbuf;
Karsten Hopp b55325
! #endif
Karsten Hopp b55325
  	update_curbuf(NOT_VALID);
Karsten Hopp b55325
      }
Karsten Hopp b55325
      else {
Karsten Hopp b55325
*** ../vim-7.0.021/src/version.c	Tue Jun 20 20:49:42 2006
Karsten Hopp b55325
--- src/version.c	Tue Jun 20 18:42:35 2006
Karsten Hopp b55325
***************
Karsten Hopp b55325
*** 668,669 ****
Karsten Hopp b55325
--- 668,671 ----
Karsten Hopp b55325
  {   /* Add new patch number below this line */
Karsten Hopp b55325
+ /**/
Karsten Hopp b55325
+     22,
Karsten Hopp b55325
  /**/