933ae90
To: vim-dev@vim.org
933ae90
Subject: patch 7.1.067
933ae90
Fcc: outbox
933ae90
From: Bram Moolenaar <Bram@moolenaar.net>
933ae90
Mime-Version: 1.0
933ae90
Content-Type: text/plain; charset=ISO-8859-1
933ae90
Content-Transfer-Encoding: 8bit
933ae90
------------
933ae90
933ae90
Patch 7.1.067
933ae90
Problem:    'thesaurus' doesn't work when 'infercase' is set. (Mohsin)
933ae90
Solution:   Don't copy the characters being completed but check the case and
933ae90
	    apply it to the suggested word.  Also fix that the first word in
933ae90
	    the thesaurus line is not used.  (Martin Toft)
933ae90
Files:	    src/edit.c
933ae90
933ae90
933ae90
*** ../vim-7.1.066/src/edit.c	Sun Jul 29 15:02:34 2007
933ae90
--- src/edit.c	Sat Aug 11 17:16:51 2007
933ae90
***************
933ae90
*** 2057,2063 ****
933ae90
   * case of the originally typed text is used, and the case of the completed
933ae90
   * text is inferred, ie this tries to work out what case you probably wanted
933ae90
   * the rest of the word to be in -- webb
933ae90
-  * TODO: make this work for multi-byte characters.
933ae90
   */
933ae90
      int
933ae90
  ins_compl_add_infercase(str, len, icase, fname, dir, flags)
933ae90
--- 2057,2062 ----
933ae90
***************
933ae90
*** 2068,2121 ****
933ae90
      int		dir;
933ae90
      int		flags;
933ae90
  {
933ae90
      int		has_lower = FALSE;
933ae90
      int		was_letter = FALSE;
933ae90
-     int		idx;
933ae90
  
933ae90
!     if (p_ic && curbuf->b_p_inf && len < IOSIZE)
933ae90
      {
933ae90
! 	/* Infer case of completed part -- webb */
933ae90
! 	/* Use IObuff, str would change text in buffer! */
933ae90
! 	vim_strncpy(IObuff, str, len);
933ae90
  
933ae90
! 	/* Rule 1: Were any chars converted to lower? */
933ae90
! 	for (idx = 0; idx < compl_length; ++idx)
933ae90
  	{
933ae90
! 	    if (islower(compl_orig_text[idx]))
933ae90
  	    {
933ae90
! 		has_lower = TRUE;
933ae90
! 		if (isupper(IObuff[idx]))
933ae90
! 		{
933ae90
! 		    /* Rule 1 is satisfied */
933ae90
! 		    for (idx = compl_length; idx < len; ++idx)
933ae90
! 			IObuff[idx] = TOLOWER_LOC(IObuff[idx]);
933ae90
! 		    break;
933ae90
! 		}
933ae90
  	    }
933ae90
  	}
933ae90
  
933ae90
! 	/*
933ae90
! 	 * Rule 2: No lower case, 2nd consecutive letter converted to
933ae90
! 	 * upper case.
933ae90
! 	 */
933ae90
! 	if (!has_lower)
933ae90
  	{
933ae90
! 	    for (idx = 0; idx < compl_length; ++idx)
933ae90
  	    {
933ae90
! 		if (was_letter && isupper(compl_orig_text[idx])
933ae90
! 						      && islower(IObuff[idx]))
933ae90
  		{
933ae90
! 		    /* Rule 2 is satisfied */
933ae90
! 		    for (idx = compl_length; idx < len; ++idx)
933ae90
! 			IObuff[idx] = TOUPPER_LOC(IObuff[idx]);
933ae90
! 		    break;
933ae90
  		}
933ae90
- 		was_letter = isalpha(compl_orig_text[idx]);
933ae90
  	    }
933ae90
- 	}
933ae90
  
933ae90
! 	/* Copy the original case of the part we typed */
933ae90
! 	STRNCPY(IObuff, compl_orig_text, compl_length);
933ae90
  
933ae90
  	return ins_compl_add(IObuff, len, icase, fname, NULL, dir,
933ae90
  								flags, FALSE);
933ae90
--- 2067,2213 ----
933ae90
      int		dir;
933ae90
      int		flags;
933ae90
  {
933ae90
+     char_u	*p;
933ae90
+     int		i, c;
933ae90
+     int		actual_len;		/* Take multi-byte characters */
933ae90
+     int		actual_compl_length;	/* into account. */
933ae90
+     int		*wca;		        /* Wide character array. */
933ae90
      int		has_lower = FALSE;
933ae90
      int		was_letter = FALSE;
933ae90
  
933ae90
!     if (p_ic && curbuf->b_p_inf)
933ae90
      {
933ae90
! 	/* Infer case of completed part. */
933ae90
  
933ae90
! 	/* Find actual length of completion. */
933ae90
! #ifdef FEAT_MBYTE
933ae90
! 	if (has_mbyte)
933ae90
  	{
933ae90
! 	    p = str;
933ae90
! 	    actual_len = 0;
933ae90
! 	    while (*p != NUL)
933ae90
  	    {
933ae90
! 		mb_ptr_adv(p);
933ae90
! 		++actual_len;
933ae90
  	    }
933ae90
  	}
933ae90
+ 	else
933ae90
+ #endif
933ae90
+ 	    actual_len = len;
933ae90
  
933ae90
! 	/* Find actual length of original text. */
933ae90
! #ifdef FEAT_MBYTE
933ae90
! 	if (has_mbyte)
933ae90
  	{
933ae90
! 	    p = compl_orig_text;
933ae90
! 	    actual_compl_length = 0;
933ae90
! 	    while (*p != NUL)
933ae90
  	    {
933ae90
! 		mb_ptr_adv(p);
933ae90
! 		++actual_compl_length;
933ae90
! 	    }
933ae90
! 	}
933ae90
! 	else
933ae90
! #endif
933ae90
! 	    actual_compl_length = compl_length;
933ae90
! 
933ae90
! 	/* Allocate wide character array for the completion and fill it. */
933ae90
! 	wca = (int *)alloc(actual_len * sizeof(int));
933ae90
! 	if (wca != NULL)
933ae90
! 	{
933ae90
! 	    p = str;
933ae90
! 	    for (i = 0; i < actual_len; ++i)
933ae90
! #ifdef FEAT_MBYTE
933ae90
! 		if (has_mbyte)
933ae90
! 		    wca[i] = mb_ptr2char_adv(&p);
933ae90
! 		else
933ae90
! #endif
933ae90
! 		    wca[i] = *(p++);
933ae90
! 
933ae90
! 	    /* Rule 1: Were any chars converted to lower? */
933ae90
! 	    p = compl_orig_text;
933ae90
! 	    for (i = 0; i < actual_compl_length; ++i)
933ae90
! 	    {
933ae90
! #ifdef FEAT_MBYTE
933ae90
! 		if (has_mbyte)
933ae90
! 		    c = mb_ptr2char_adv(&p);
933ae90
! 		else
933ae90
! #endif
933ae90
! 		    c = *(p++);
933ae90
! 		if (MB_ISLOWER(c))
933ae90
  		{
933ae90
! 		    has_lower = TRUE;
933ae90
! 		    if (MB_ISUPPER(wca[i]))
933ae90
! 		    {
933ae90
! 			/* Rule 1 is satisfied. */
933ae90
! 			for (i = actual_compl_length; i < actual_len; ++i)
933ae90
! 			    wca[i] = MB_TOLOWER(wca[i]);
933ae90
! 			break;
933ae90
! 		    }
933ae90
  		}
933ae90
  	    }
933ae90
  
933ae90
! 	    /*
933ae90
! 	     * Rule 2: No lower case, 2nd consecutive letter converted to
933ae90
! 	     * upper case.
933ae90
! 	     */
933ae90
! 	    if (!has_lower)
933ae90
! 	    {
933ae90
! 		p = compl_orig_text;
933ae90
! 		for (i = 0; i < actual_compl_length; ++i)
933ae90
! 		{
933ae90
! #ifdef FEAT_MBYTE
933ae90
! 		    if (has_mbyte)
933ae90
! 			c = mb_ptr2char_adv(&p);
933ae90
! 		    else
933ae90
! #endif
933ae90
! 			c = *(p++);
933ae90
! 		    if (was_letter && MB_ISUPPER(c) && MB_ISLOWER(wca[i]))
933ae90
! 		    {
933ae90
! 			/* Rule 2 is satisfied. */
933ae90
! 			for (i = actual_compl_length; i < actual_len; ++i)
933ae90
! 			    wca[i] = MB_TOUPPER(wca[i]);
933ae90
! 			break;
933ae90
! 		    }
933ae90
! 		    was_letter = MB_ISLOWER(c) || MB_ISUPPER(c);
933ae90
! 		}
933ae90
! 	    }
933ae90
! 
933ae90
! 	    /* Copy the original case of the part we typed. */
933ae90
! 	    p = compl_orig_text;
933ae90
! 	    for (i = 0; i < actual_compl_length; ++i)
933ae90
! 	    {
933ae90
! #ifdef FEAT_MBYTE
933ae90
! 		if (has_mbyte)
933ae90
! 		    c = mb_ptr2char_adv(&p);
933ae90
! 		else
933ae90
! #endif
933ae90
! 		    c = *(p++);
933ae90
! 		if (MB_ISLOWER(c))
933ae90
! 		    wca[i] = MB_TOLOWER(wca[i]);
933ae90
! 		else if (MB_ISUPPER(c))
933ae90
! 		    wca[i] = MB_TOUPPER(wca[i]);
933ae90
! 	    }
933ae90
! 
933ae90
! 	    /* 
933ae90
! 	     * Generate encoding specific output from wide character array.
933ae90
! 	     * Multi-byte characters can occupy up to five bytes more than
933ae90
! 	     * ASCII characters, and we also need one byte for NUL, so stay
933ae90
! 	     * six bytes away from the edge of IObuff.
933ae90
! 	     */
933ae90
! 	    p = IObuff;
933ae90
! 	    i = 0;
933ae90
! 	    while (i < actual_len && (p - IObuff + 6) < IOSIZE)
933ae90
! #ifdef FEAT_MBYTE
933ae90
! 		if (has_mbyte)
933ae90
! 		    p += mb_char2bytes(wca[i++], p);
933ae90
! 		else
933ae90
! #endif
933ae90
! 		    *(p++) = wca[i++];
933ae90
! 	    *p = NUL;
933ae90
! 
933ae90
! 	    vim_free(wca);
933ae90
! 	}
933ae90
  
933ae90
  	return ins_compl_add(IObuff, len, icase, fname, NULL, dir,
933ae90
  								flags, FALSE);
933ae90
***************
933ae90
*** 2842,2847 ****
933ae90
--- 2934,2940 ----
933ae90
  			/*
933ae90
  			 * Add the other matches on the line
933ae90
  			 */
933ae90
+ 			ptr = buf;
933ae90
  			while (!got_int)
933ae90
  			{
933ae90
  			    /* Find start of the next word.  Skip white
933ae90
***************
933ae90
*** 2851,2857 ****
933ae90
  				break;
933ae90
  			    wstart = ptr;
933ae90
  
933ae90
! 			    /* Find end of the word and add it. */
933ae90
  #ifdef FEAT_MBYTE
933ae90
  			    if (has_mbyte)
933ae90
  				/* Japanese words may have characters in
933ae90
--- 2944,2950 ----
933ae90
  				break;
933ae90
  			    wstart = ptr;
933ae90
  
933ae90
! 			    /* Find end of the word. */
933ae90
  #ifdef FEAT_MBYTE
933ae90
  			    if (has_mbyte)
933ae90
  				/* Japanese words may have characters in
933ae90
***************
933ae90
*** 2868,2876 ****
933ae90
  			    else
933ae90
  #endif
933ae90
  				ptr = find_word_end(ptr);
933ae90
! 			    add_r = ins_compl_add_infercase(wstart,
933ae90
! 				    (int)(ptr - wstart),
933ae90
! 				    p_ic, files[i], *dir, 0);
933ae90
  			}
933ae90
  		    }
933ae90
  		    if (add_r == OK)
933ae90
--- 2961,2972 ----
933ae90
  			    else
933ae90
  #endif
933ae90
  				ptr = find_word_end(ptr);
933ae90
! 
933ae90
! 			    /* Add the word. Skip the regexp match. */
933ae90
! 			    if (wstart != regmatch->startp[0])
933ae90
! 				add_r = ins_compl_add_infercase(wstart,
933ae90
! 					(int)(ptr - wstart),
933ae90
! 					p_ic, files[i], *dir, 0);
933ae90
  			}
933ae90
  		    }
933ae90
  		    if (add_r == OK)
933ae90
*** ../vim-7.1.066/src/version.c	Sun Aug 12 15:50:26 2007
933ae90
--- src/version.c	Sun Aug 12 16:36:34 2007
933ae90
***************
933ae90
*** 668,669 ****
933ae90
--- 668,671 ----
933ae90
  {   /* Add new patch number below this line */
933ae90
+ /**/
933ae90
+     67,
933ae90
  /**/
933ae90
933ae90
-- 
933ae90
hundred-and-one symptoms of being an internet addict:
933ae90
128. You can access the Net -- via your portable and cellular phone.
933ae90
933ae90
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
933ae90
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
933ae90
\\\        download, build and distribute -- http://www.A-A-P.org        ///
933ae90
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///