Karsten Hopp 20f839
To: vim_dev@googlegroups.com
Karsten Hopp 20f839
Subject: Patch 7.3.319
Karsten Hopp 20f839
Fcc: outbox
Karsten Hopp 20f839
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 20f839
Mime-Version: 1.0
Karsten Hopp 20f839
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 20f839
Content-Transfer-Encoding: 8bit
Karsten Hopp 20f839
------------
Karsten Hopp 20f839
Karsten Hopp 20f839
Patch 7.3.319 (after 7.3.311)
Karsten Hopp 20f839
Problem:    Redobuff doesn't always include changes of the completion leader.
Karsten Hopp 20f839
Solution:   Insert backspaces as needed. (idea by Taro Muraoka)
Karsten Hopp 20f839
Files:	    src/edit.c
Karsten Hopp 20f839
Karsten Hopp 20f839
Karsten Hopp 20f839
*** ../vim-7.3.318/src/edit.c	2011-09-14 16:52:02.000000000 +0200
Karsten Hopp 20f839
--- src/edit.c	2011-09-21 17:59:10.000000000 +0200
Karsten Hopp 20f839
***************
Karsten Hopp 20f839
*** 163,168 ****
Karsten Hopp 20f839
--- 163,169 ----
Karsten Hopp 20f839
  static void ins_compl_set_original_text __ARGS((char_u *str));
Karsten Hopp 20f839
  static void ins_compl_addfrommatch __ARGS((void));
Karsten Hopp 20f839
  static int  ins_compl_prep __ARGS((int c));
Karsten Hopp 20f839
+ static void ins_compl_fixRedoBufForLeader __ARGS((char_u *ptr_arg));
Karsten Hopp 20f839
  static buf_T *ins_compl_next_buf __ARGS((buf_T *buf, int flag));
Karsten Hopp 20f839
  #if defined(FEAT_COMPL_FUNC) || defined(FEAT_EVAL)
Karsten Hopp 20f839
  static void ins_compl_add_list __ARGS((list_T *list));
Karsten Hopp 20f839
***************
Karsten Hopp 20f839
*** 3713,3721 ****
Karsten Hopp 20f839
  	     * memory that was used, and make sure we can redo the insert. */
Karsten Hopp 20f839
  	    if (compl_curr_match != NULL || compl_leader != NULL || c == Ctrl_E)
Karsten Hopp 20f839
  	    {
Karsten Hopp 20f839
- 		char_u	*p;
Karsten Hopp 20f839
- 		int	temp = 0;
Karsten Hopp 20f839
- 
Karsten Hopp 20f839
  		/*
Karsten Hopp 20f839
  		 * If any of the original typed text has been changed, eg when
Karsten Hopp 20f839
  		 * ignorecase is set, we must add back-spaces to the redo
Karsten Hopp 20f839
--- 3714,3719 ----
Karsten Hopp 20f839
***************
Karsten Hopp 20f839
*** 3726,3750 ****
Karsten Hopp 20f839
  		 */
Karsten Hopp 20f839
  		if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E)
Karsten Hopp 20f839
  		    ptr = compl_curr_match->cp_str;
Karsten Hopp 20f839
- 		else if (compl_leader != NULL)
Karsten Hopp 20f839
- 		    ptr = compl_leader;
Karsten Hopp 20f839
  		else
Karsten Hopp 20f839
! 		    ptr = compl_orig_text;
Karsten Hopp 20f839
! 		if (compl_orig_text != NULL)
Karsten Hopp 20f839
! 		{
Karsten Hopp 20f839
! 		    p = compl_orig_text;
Karsten Hopp 20f839
! 		    for (temp = 0; p[temp] != NUL && p[temp] == ptr[temp];
Karsten Hopp 20f839
! 								       ++temp)
Karsten Hopp 20f839
! 			;
Karsten Hopp 20f839
! #ifdef FEAT_MBYTE
Karsten Hopp 20f839
! 		    if (temp > 0)
Karsten Hopp 20f839
! 			temp -= (*mb_head_off)(compl_orig_text, p + temp);
Karsten Hopp 20f839
! #endif
Karsten Hopp 20f839
! 		    for (p += temp; *p != NUL; mb_ptr_adv(p))
Karsten Hopp 20f839
! 			AppendCharToRedobuff(K_BS);
Karsten Hopp 20f839
! 		}
Karsten Hopp 20f839
! 		if (ptr != NULL)
Karsten Hopp 20f839
! 		    AppendToRedobuffLit(ptr + temp, -1);
Karsten Hopp 20f839
  	    }
Karsten Hopp 20f839
  
Karsten Hopp 20f839
  #ifdef FEAT_CINDENT
Karsten Hopp 20f839
--- 3724,3732 ----
Karsten Hopp 20f839
  		 */
Karsten Hopp 20f839
  		if (compl_curr_match != NULL && compl_used_match && c != Ctrl_E)
Karsten Hopp 20f839
  		    ptr = compl_curr_match->cp_str;
Karsten Hopp 20f839
  		else
Karsten Hopp 20f839
! 		    ptr = NULL;
Karsten Hopp 20f839
! 		ins_compl_fixRedoBufForLeader(ptr);
Karsten Hopp 20f839
  	    }
Karsten Hopp 20f839
  
Karsten Hopp 20f839
  #ifdef FEAT_CINDENT
Karsten Hopp 20f839
***************
Karsten Hopp 20f839
*** 3834,3839 ****
Karsten Hopp 20f839
--- 3816,3859 ----
Karsten Hopp 20f839
  }
Karsten Hopp 20f839
  
Karsten Hopp 20f839
  /*
Karsten Hopp 20f839
+  * Fix the redo buffer for the completion leader replacing some of the typed
Karsten Hopp 20f839
+  * text.  This inserts backspaces and appends the changed text.
Karsten Hopp 20f839
+  * "ptr" is the known leader text or NUL.
Karsten Hopp 20f839
+  */
Karsten Hopp 20f839
+     static void
Karsten Hopp 20f839
+ ins_compl_fixRedoBufForLeader(ptr_arg)
Karsten Hopp 20f839
+     char_u *ptr_arg;
Karsten Hopp 20f839
+ {
Karsten Hopp 20f839
+     int	    len;
Karsten Hopp 20f839
+     char_u  *p;
Karsten Hopp 20f839
+     char_u  *ptr = ptr_arg;
Karsten Hopp 20f839
+ 
Karsten Hopp 20f839
+     if (ptr == NULL)
Karsten Hopp 20f839
+     {
Karsten Hopp 20f839
+ 	if (compl_leader != NULL)
Karsten Hopp 20f839
+ 	    ptr = compl_leader;
Karsten Hopp 20f839
+ 	else
Karsten Hopp 20f839
+ 	    return;  /* nothing to do */
Karsten Hopp 20f839
+     }
Karsten Hopp 20f839
+     if (compl_orig_text != NULL)
Karsten Hopp 20f839
+     {
Karsten Hopp 20f839
+ 	p = compl_orig_text;
Karsten Hopp 20f839
+ 	for (len = 0; p[len] != NUL && p[len] == ptr[len]; ++len)
Karsten Hopp 20f839
+ 	    ;
Karsten Hopp 20f839
+ #ifdef FEAT_MBYTE
Karsten Hopp 20f839
+ 	if (len > 0)
Karsten Hopp 20f839
+ 	    len -= (*mb_head_off)(p, p + len);
Karsten Hopp 20f839
+ #endif
Karsten Hopp 20f839
+ 	for (p += len; *p != NUL; mb_ptr_adv(p))
Karsten Hopp 20f839
+ 	    AppendCharToRedobuff(K_BS);
Karsten Hopp 20f839
+     }
Karsten Hopp 20f839
+     else
Karsten Hopp 20f839
+ 	len = 0;
Karsten Hopp 20f839
+     if (ptr != NULL)
Karsten Hopp 20f839
+ 	AppendToRedobuffLit(ptr + len, -1);
Karsten Hopp 20f839
+ }
Karsten Hopp 20f839
+ 
Karsten Hopp 20f839
+ /*
Karsten Hopp 20f839
   * Loops through the list of windows, loaded-buffers or non-loaded-buffers
Karsten Hopp 20f839
   * (depending on flag) starting from buf and looking for a non-scanned
Karsten Hopp 20f839
   * buffer (other than curbuf).	curbuf is special, if it is called with
Karsten Hopp 20f839
***************
Karsten Hopp 20f839
*** 5241,5246 ****
Karsten Hopp 20f839
--- 5261,5270 ----
Karsten Hopp 20f839
  	else
Karsten Hopp 20f839
  	    edit_submode = (char_u *)_(CTRL_X_MSG(ctrl_x_mode));
Karsten Hopp 20f839
  
Karsten Hopp 20f839
+ 	/* If any of the original typed text has been changed we need to fix
Karsten Hopp 20f839
+ 	 * the redo buffer. */
Karsten Hopp 20f839
+ 	ins_compl_fixRedoBufForLeader(NULL);
Karsten Hopp 20f839
+ 
Karsten Hopp 20f839
  	/* Always add completion for the original text. */
Karsten Hopp 20f839
  	vim_free(compl_orig_text);
Karsten Hopp 20f839
  	compl_orig_text = vim_strnsave(line + compl_col, compl_length);
Karsten Hopp 20f839
*** ../vim-7.3.318/src/version.c	2011-09-21 17:33:49.000000000 +0200
Karsten Hopp 20f839
--- src/version.c	2011-09-21 18:21:07.000000000 +0200
Karsten Hopp 20f839
***************
Karsten Hopp 20f839
*** 711,712 ****
Karsten Hopp 20f839
--- 711,714 ----
Karsten Hopp 20f839
  {   /* Add new patch number below this line */
Karsten Hopp 20f839
+ /**/
Karsten Hopp 20f839
+     319,
Karsten Hopp 20f839
  /**/
Karsten Hopp 20f839
Karsten Hopp 20f839
-- 
Karsten Hopp 20f839
hundred-and-one symptoms of being an internet addict:
Karsten Hopp 20f839
27. You refer to your age as 3.x.
Karsten Hopp 20f839
Karsten Hopp 20f839
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 20f839
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 20f839
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 20f839
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///