7a72225
To: vim-dev@vim.org
7a72225
Subject: Patch 7.1.185
7a72225
Fcc: outbox
7a72225
From: Bram Moolenaar <Bram@moolenaar.net>
7a72225
Mime-Version: 1.0
7a72225
Content-Type: text/plain; charset=ISO-8859-1
7a72225
Content-Transfer-Encoding: 8bit
7a72225
------------
7a72225
7a72225
Patch 7.1.185
7a72225
Problem:    Using "gR" with a multi-byte encoding and typing a CR pushes
7a72225
	    characters onto the replace stack incorrectly, resulting in BS
7a72225
	    putting back the wrong characters. (Paul B. Mahol)
7a72225
Solution:   Push multi-byte characters onto the replace stack in reverse byte
7a72225
	    order.  Add replace_push_mb().
7a72225
Files:	    src/edit.c, src/misc1.c, src/proto/edit.pro
7a72225
7a72225
7a72225
*** ../vim-7.1.184/src/edit.c	Sun Dec  9 20:25:59 2007
7a72225
--- src/edit.c	Tue Jan  1 17:28:07 2008
7a72225
***************
7a72225
*** 6939,6944 ****
7a72225
--- 6939,6963 ----
7a72225
      ++replace_stack_nr;
7a72225
  }
7a72225
  
7a72225
+ #if defined(FEAT_MBYTE) || defined(PROTO)
7a72225
+ /*
7a72225
+  * Push a character onto the replace stack.  Handles a multi-byte character in
7a72225
+  * reverse byte order, so that the first byte is popped off first.
7a72225
+  * Return the number of bytes done (includes composing characters).
7a72225
+  */
7a72225
+     int
7a72225
+ replace_push_mb(p)
7a72225
+     char_u *p;
7a72225
+ {
7a72225
+     int l = (*mb_ptr2len)(p);
7a72225
+     int j;
7a72225
+ 
7a72225
+     for (j = l - 1; j >= 0; --j)
7a72225
+ 	replace_push(p[j]);
7a72225
+     return l;
7a72225
+ }
7a72225
+ #endif
7a72225
+ 
7a72225
  #if 0
7a72225
  /*
7a72225
   * call replace_push(c) with replace_offset set to the first NUL.
7a72225
*** ../vim-7.1.184/src/misc1.c	Wed Sep 26 22:35:06 2007
7a72225
--- src/misc1.c	Wed Jan  2 17:48:00 2008
7a72225
***************
7a72225
*** 591,597 ****
7a72225
  	replace_push(NUL);
7a72225
  	p = saved_line + curwin->w_cursor.col;
7a72225
  	while (*p != NUL)
7a72225
! 	    replace_push(*p++);
7a72225
  	saved_line[curwin->w_cursor.col] = NUL;
7a72225
      }
7a72225
  #endif
7a72225
--- 592,605 ----
7a72225
  	replace_push(NUL);
7a72225
  	p = saved_line + curwin->w_cursor.col;
7a72225
  	while (*p != NUL)
7a72225
! 	{
7a72225
! #ifdef FEAT_MBYTE
7a72225
! 	    if (has_mbyte)
7a72225
! 		p += replace_push_mb(p);
7a72225
! 	    else
7a72225
! #endif
7a72225
! 		replace_push(*p++);
7a72225
! 	}
7a72225
  	saved_line[curwin->w_cursor.col] = NUL;
7a72225
      }
7a72225
  #endif
7a72225
***************
7a72225
*** 1914,1920 ****
7a72225
      int		charlen;
7a72225
  {
7a72225
      int		c = buf[0];
7a72225
-     int		l, j;
7a72225
  #endif
7a72225
      int		newlen;		/* nr of bytes inserted */
7a72225
      int		oldlen;		/* nr of bytes deleted (0 when not replacing) */
7a72225
--- 1922,1927 ----
7a72225
***************
7a72225
*** 2016,2028 ****
7a72225
  	for (i = 0; i < oldlen; ++i)
7a72225
  	{
7a72225
  #ifdef FEAT_MBYTE
7a72225
! 	    l = (*mb_ptr2len)(oldp + col + i) - 1;
7a72225
! 	    for (j = l; j >= 0; --j)
7a72225
! 		replace_push(oldp[col + i + j]);
7a72225
! 	    i += l;
7a72225
! #else
7a72225
! 	    replace_push(oldp[col + i]);
7a72225
  #endif
7a72225
  	}
7a72225
      }
7a72225
  
7a72225
--- 2023,2033 ----
7a72225
  	for (i = 0; i < oldlen; ++i)
7a72225
  	{
7a72225
  #ifdef FEAT_MBYTE
7a72225
! 	    if (has_mbyte)
7a72225
! 		i += replace_push_mb(oldp + col + i) - 1;
7a72225
! 	    else
7a72225
  #endif
7a72225
+ 		replace_push(oldp[col + i]);
7a72225
  	}
7a72225
      }
7a72225
  
7a72225
*** ../vim-7.1.184/src/proto/edit.pro	Sat May  5 20:21:34 2007
7a72225
--- src/proto/edit.pro	Tue Jan  1 17:21:24 2008
7a72225
***************
7a72225
*** 32,37 ****
7a72225
--- 32,38 ----
7a72225
  char_u *get_last_insert __ARGS((void));
7a72225
  char_u *get_last_insert_save __ARGS((void));
7a72225
  void replace_push __ARGS((int c));
7a72225
+ int replace_push_mb __ARGS((char_u *p));
7a72225
  void fixthisline __ARGS((int (*get_the_indent)(void)));
7a72225
  void fix_indent __ARGS((void));
7a72225
  int in_cinkeys __ARGS((int keytyped, int when, int line_is_empty));
7a72225
*** ../vim-7.1.184/src/version.c	Wed Jan  2 16:25:20 2008
7a72225
--- src/version.c	Wed Jan  2 17:45:10 2008
7a72225
***************
7a72225
*** 668,669 ****
7a72225
--- 668,671 ----
7a72225
  {   /* Add new patch number below this line */
7a72225
+ /**/
7a72225
+     185,
7a72225
  /**/
7a72225
7a72225
-- 
7a72225
Not too long ago, a keyboard was something to make music with...
7a72225
7a72225
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
7a72225
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
7a72225
\\\        download, build and distribute -- http://www.A-A-P.org        ///
7a72225
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///