Karsten Hopp 9c3490
To: vim-dev@vim.org
Karsten Hopp 9c3490
Subject: Patch 7.1.240
Karsten Hopp 9c3490
Fcc: outbox
Karsten Hopp 9c3490
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 9c3490
Mime-Version: 1.0
Karsten Hopp 9c3490
Content-Type: text/plain; charset=ISO-8859-1
Karsten Hopp 9c3490
Content-Transfer-Encoding: 8bit
Karsten Hopp 9c3490
------------
Karsten Hopp 9c3490
Karsten Hopp 9c3490
Patch 7.1.240
Karsten Hopp 9c3490
Problem:    When "gUe" turns a German sharp s into SS the operation stops
Karsten Hopp 9c3490
            before the end of the word.  Latin2 has the same sharp s but it's
Karsten Hopp 9c3490
            not changed to SS there.
Karsten Hopp 9c3490
Solution:   Make sure all the characters are operated upon.  Detect the sharp
Karsten Hopp 9c3490
            s in latin2.  Also fixes that changing case of a multi-byte
Karsten Hopp 9c3490
            character that changes the byte cound doesn't always work.
Karsten Hopp 9c3490
Files:      src/ops.c
Karsten Hopp 9c3490
Karsten Hopp 9c3490
Karsten Hopp 9c3490
*** ../vim-7.1.239/src/ops.c	Wed Jan 16 20:01:14 2008
Karsten Hopp 9c3490
--- src/ops.c	Tue Jan 22 16:00:07 2008
Karsten Hopp 9c3490
***************
Karsten Hopp 9c3490
*** 2184,2189 ****
Karsten Hopp 9c3490
--- 2184,2191 ----
Karsten Hopp 9c3490
  }
Karsten Hopp 9c3490
  #endif
Karsten Hopp 9c3490
  
Karsten Hopp 9c3490
+ static int swapchars __ARGS((int op_type, pos_T *pos, int length));
Karsten Hopp 9c3490
+ 
Karsten Hopp 9c3490
  /*
Karsten Hopp 9c3490
   * Handle the (non-standard vi) tilde operator.  Also for "gu", "gU" and "g?".
Karsten Hopp 9c3490
   */
Karsten Hopp 9c3490
***************
Karsten Hopp 9c3490
*** 2194,2202 ****
Karsten Hopp 9c3490
      pos_T		pos;
Karsten Hopp 9c3490
  #ifdef FEAT_VISUAL
Karsten Hopp 9c3490
      struct block_def	bd;
Karsten Hopp 9c3490
-     int			todo;
Karsten Hopp 9c3490
  #endif
Karsten Hopp 9c3490
!     int			did_change = 0;
Karsten Hopp 9c3490
  
Karsten Hopp 9c3490
      if (u_save((linenr_T)(oap->start.lnum - 1),
Karsten Hopp 9c3490
  				       (linenr_T)(oap->end.lnum + 1)) == FAIL)
Karsten Hopp 9c3490
--- 2196,2203 ----
Karsten Hopp 9c3490
      pos_T		pos;
Karsten Hopp 9c3490
  #ifdef FEAT_VISUAL
Karsten Hopp 9c3490
      struct block_def	bd;
Karsten Hopp 9c3490
  #endif
Karsten Hopp 9c3490
!     int			did_change;
Karsten Hopp 9c3490
  
Karsten Hopp 9c3490
      if (u_save((linenr_T)(oap->start.lnum - 1),
Karsten Hopp 9c3490
  				       (linenr_T)(oap->end.lnum + 1)) == FAIL)
Karsten Hopp 9c3490
***************
Karsten Hopp 9c3490
*** 2210,2225 ****
Karsten Hopp 9c3490
  	{
Karsten Hopp 9c3490
  	    block_prep(oap, &bd, pos.lnum, FALSE);
Karsten Hopp 9c3490
  	    pos.col = bd.textcol;
Karsten Hopp 9c3490
! 	    for (todo = bd.textlen; todo > 0; --todo)
Karsten Hopp 9c3490
! 	    {
Karsten Hopp 9c3490
! # ifdef FEAT_MBYTE
Karsten Hopp 9c3490
! 		if (has_mbyte)
Karsten Hopp 9c3490
! 		    todo -= (*mb_ptr2len)(ml_get_pos(&pos)) - 1;
Karsten Hopp 9c3490
! # endif
Karsten Hopp 9c3490
! 		did_change |= swapchar(oap->op_type, &pos;;
Karsten Hopp 9c3490
! 		if (inc(&pos) == -1)	    /* at end of file */
Karsten Hopp 9c3490
! 		    break;
Karsten Hopp 9c3490
! 	    }
Karsten Hopp 9c3490
  # ifdef FEAT_NETBEANS_INTG
Karsten Hopp 9c3490
  	    if (usingNetbeans && did_change)
Karsten Hopp 9c3490
  	    {
Karsten Hopp 9c3490
--- 2211,2218 ----
Karsten Hopp 9c3490
  	{
Karsten Hopp 9c3490
  	    block_prep(oap, &bd, pos.lnum, FALSE);
Karsten Hopp 9c3490
  	    pos.col = bd.textcol;
Karsten Hopp 9c3490
! 	    did_change = swapchars(oap->op_type, &pos, bd.textlen);
Karsten Hopp 9c3490
! 
Karsten Hopp 9c3490
  # ifdef FEAT_NETBEANS_INTG
Karsten Hopp 9c3490
  	    if (usingNetbeans && did_change)
Karsten Hopp 9c3490
  	    {
Karsten Hopp 9c3490
***************
Karsten Hopp 9c3490
*** 2249,2261 ****
Karsten Hopp 9c3490
  	else if (!oap->inclusive)
Karsten Hopp 9c3490
  	    dec(&(oap->end));
Karsten Hopp 9c3490
  
Karsten Hopp 9c3490
! 	while (ltoreq(pos, oap->end))
Karsten Hopp 9c3490
! 	{
Karsten Hopp 9c3490
! 	    did_change |= swapchar(oap->op_type, &pos;;
Karsten Hopp 9c3490
! 	    if (inc(&pos) == -1)    /* at end of file */
Karsten Hopp 9c3490
! 		break;
Karsten Hopp 9c3490
! 	}
Karsten Hopp 9c3490
! 
Karsten Hopp 9c3490
  	if (did_change)
Karsten Hopp 9c3490
  	{
Karsten Hopp 9c3490
  	    changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1,
Karsten Hopp 9c3490
--- 2242,2248 ----
Karsten Hopp 9c3490
  	else if (!oap->inclusive)
Karsten Hopp 9c3490
  	    dec(&(oap->end));
Karsten Hopp 9c3490
  
Karsten Hopp 9c3490
! 	did_change = swapchars(oap->op_type, &pos, oap->end.col - pos.col + 1);
Karsten Hopp 9c3490
  	if (did_change)
Karsten Hopp 9c3490
  	{
Karsten Hopp 9c3490
  	    changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1,
Karsten Hopp 9c3490
***************
Karsten Hopp 9c3490
*** 2309,2314 ****
Karsten Hopp 9c3490
--- 2296,2337 ----
Karsten Hopp 9c3490
  }
Karsten Hopp 9c3490
  
Karsten Hopp 9c3490
  /*
Karsten Hopp 9c3490
+  * Invoke swapchar() on "length" bytes at position "pos".
Karsten Hopp 9c3490
+  * "pos" is advanced to just after the changed characters.
Karsten Hopp 9c3490
+  * "length" is rounded up to include the whole last multi-byte character.
Karsten Hopp 9c3490
+  * Also works correctly when the number of bytes changes.
Karsten Hopp 9c3490
+  * Returns TRUE if some character was changed.
Karsten Hopp 9c3490
+  */
Karsten Hopp 9c3490
+     static int
Karsten Hopp 9c3490
+ swapchars(op_type, pos, length)
Karsten Hopp 9c3490
+     int		op_type;
Karsten Hopp 9c3490
+     pos_T	*pos;
Karsten Hopp 9c3490
+     int		length;
Karsten Hopp 9c3490
+ {
Karsten Hopp 9c3490
+     int todo;
Karsten Hopp 9c3490
+     int	did_change = 0;
Karsten Hopp 9c3490
+ 
Karsten Hopp 9c3490
+     for (todo = length; todo > 0; --todo)
Karsten Hopp 9c3490
+     {
Karsten Hopp 9c3490
+ # ifdef FEAT_MBYTE
Karsten Hopp 9c3490
+ 	int pos_col = pos->col;
Karsten Hopp 9c3490
+ 
Karsten Hopp 9c3490
+ 	if (has_mbyte)
Karsten Hopp 9c3490
+ 	    /* we're counting bytes, not characters */
Karsten Hopp 9c3490
+ 	    todo -= (*mb_ptr2len)(ml_get_pos(pos)) - 1;
Karsten Hopp 9c3490
+ # endif
Karsten Hopp 9c3490
+ 	did_change |= swapchar(op_type, pos);
Karsten Hopp 9c3490
+ # ifdef FEAT_MBYTE
Karsten Hopp 9c3490
+ 	/* Changing German sharp s to SS increases the column. */
Karsten Hopp 9c3490
+ 	todo += pos->col - pos_col;
Karsten Hopp 9c3490
+ # endif
Karsten Hopp 9c3490
+ 	if (inc(pos) == -1)    /* at end of file */
Karsten Hopp 9c3490
+ 	    break;
Karsten Hopp 9c3490
+     }
Karsten Hopp 9c3490
+     return did_change;
Karsten Hopp 9c3490
+ }
Karsten Hopp 9c3490
+ 
Karsten Hopp 9c3490
+ /*
Karsten Hopp 9c3490
   * If op_type == OP_UPPER: make uppercase,
Karsten Hopp 9c3490
   * if op_type == OP_LOWER: make lowercase,
Karsten Hopp 9c3490
   * if op_type == OP_ROT13: do rot13 encoding,
Karsten Hopp 9c3490
***************
Karsten Hopp 9c3490
*** 2330,2336 ****
Karsten Hopp 9c3490
  	return FALSE;
Karsten Hopp 9c3490
  
Karsten Hopp 9c3490
  #ifdef FEAT_MBYTE
Karsten Hopp 9c3490
!     if (op_type == OP_UPPER && enc_latin1like && c == 0xdf)
Karsten Hopp 9c3490
      {
Karsten Hopp 9c3490
  	pos_T   sp = curwin->w_cursor;
Karsten Hopp 9c3490
  
Karsten Hopp 9c3490
--- 2353,2360 ----
Karsten Hopp 9c3490
  	return FALSE;
Karsten Hopp 9c3490
  
Karsten Hopp 9c3490
  #ifdef FEAT_MBYTE
Karsten Hopp 9c3490
!     if (op_type == OP_UPPER && c == 0xdf
Karsten Hopp 9c3490
! 		      && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0))
Karsten Hopp 9c3490
      {
Karsten Hopp 9c3490
  	pos_T   sp = curwin->w_cursor;
Karsten Hopp 9c3490
  
Karsten Hopp 9c3490
*** ../vim-7.1.239/src/version.c	Tue Jan 22 12:44:03 2008
Karsten Hopp 9c3490
--- src/version.c	Tue Jan 22 15:36:36 2008
Karsten Hopp 9c3490
***************
Karsten Hopp 9c3490
*** 668,669 ****
Karsten Hopp 9c3490
--- 668,671 ----
Karsten Hopp 9c3490
  {   /* Add new patch number below this line */
Karsten Hopp 9c3490
+ /**/
Karsten Hopp 9c3490
+     240,
Karsten Hopp 9c3490
  /**/
Karsten Hopp 9c3490
Karsten Hopp 9c3490
-- 
Karsten Hopp 9c3490
ARTHUR: It is I, Arthur, son of Uther Pendragon, from the castle of Camelot.
Karsten Hopp 9c3490
        King of all Britons, defeator of the Saxons, sovereign of all England!
Karsten Hopp 9c3490
   [Pause]
Karsten Hopp 9c3490
SOLDIER: Get away!
Karsten Hopp 9c3490
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
Karsten Hopp 9c3490
Karsten Hopp 9c3490
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 9c3490
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 9c3490
\\\        download, build and distribute -- http://www.A-A-P.org        ///
Karsten Hopp 9c3490
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///