0255569
To: vim-dev@vim.org
0255569
Subject: Patch 7.2.262
0255569
Fcc: outbox
0255569
From: Bram Moolenaar <Bram@moolenaar.net>
0255569
Mime-Version: 1.0
0255569
Content-Type: text/plain; charset=UTF-8
0255569
Content-Transfer-Encoding: 8bit
0255569
------------
0255569
0255569
Patch 7.2.262
0255569
Problem:    When using custom completion for a user command the pattern string
0255569
	    goes beyond the cursor position. (Hari Krishna Dara)
0255569
Solution:   Truncate the string at the cursor position.
0255569
Files:	    src/ex_getln.c, src/structs.h
0255569
0255569
0255569
*** ../vim-7.2.261/src/ex_getln.c	2009-06-24 17:04:40.000000000 +0200
0255569
--- src/ex_getln.c	2009-09-18 16:58:16.000000000 +0200
0255569
***************
0255569
*** 3266,3272 ****
0255569
      int		i, j;
0255569
      char_u	*p1;
0255569
      char_u	*p2;
0255569
-     int		oldlen;
0255569
      int		difflen;
0255569
      int		v;
0255569
  
0255569
--- 3266,3271 ----
0255569
***************
0255569
*** 3291,3297 ****
0255569
      out_flush();
0255569
  
0255569
      i = (int)(xp->xp_pattern - ccline.cmdbuff);
0255569
!     oldlen = ccline.cmdpos - i;
0255569
  
0255569
      if (type == WILD_NEXT || type == WILD_PREV)
0255569
      {
0255569
--- 3290,3296 ----
0255569
      out_flush();
0255569
  
0255569
      i = (int)(xp->xp_pattern - ccline.cmdbuff);
0255569
!     xp->xp_pattern_len = ccline.cmdpos - i;
0255569
  
0255569
      if (type == WILD_NEXT || type == WILD_PREV)
0255569
      {
0255569
***************
0255569
*** 3305,3322 ****
0255569
  	/*
0255569
  	 * Translate string into pattern and expand it.
0255569
  	 */
0255569
! 	if ((p1 = addstar(&ccline.cmdbuff[i], oldlen, xp->xp_context)) == NULL)
0255569
  	    p2 = NULL;
0255569
  	else
0255569
  	{
0255569
! 	    p2 = ExpandOne(xp, p1, vim_strnsave(&ccline.cmdbuff[i], oldlen),
0255569
  		    WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT|WILD_ESCAPE
0255569
  							      |options, type);
0255569
  	    vim_free(p1);
0255569
  	    /* longest match: make sure it is not shorter (happens with :help */
0255569
  	    if (p2 != NULL && type == WILD_LONGEST)
0255569
  	    {
0255569
! 		for (j = 0; j < oldlen; ++j)
0255569
  		     if (ccline.cmdbuff[i + j] == '*'
0255569
  			     || ccline.cmdbuff[i + j] == '?')
0255569
  			 break;
0255569
--- 3304,3323 ----
0255569
  	/*
0255569
  	 * Translate string into pattern and expand it.
0255569
  	 */
0255569
! 	if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len,
0255569
! 						     xp->xp_context)) == NULL)
0255569
  	    p2 = NULL;
0255569
  	else
0255569
  	{
0255569
! 	    p2 = ExpandOne(xp, p1,
0255569
! 			 vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len),
0255569
  		    WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT|WILD_ESCAPE
0255569
  							      |options, type);
0255569
  	    vim_free(p1);
0255569
  	    /* longest match: make sure it is not shorter (happens with :help */
0255569
  	    if (p2 != NULL && type == WILD_LONGEST)
0255569
  	    {
0255569
! 		for (j = 0; j < xp->xp_pattern_len; ++j)
0255569
  		     if (ccline.cmdbuff[i + j] == '*'
0255569
  			     || ccline.cmdbuff[i + j] == '?')
0255569
  			 break;
0255569
***************
0255569
*** 3331,3337 ****
0255569
  
0255569
      if (p2 != NULL && !got_int)
0255569
      {
0255569
! 	difflen = (int)STRLEN(p2) - oldlen;
0255569
  	if (ccline.cmdlen + difflen > ccline.cmdbufflen - 4)
0255569
  	{
0255569
  	    v = realloc_cmdbuff(ccline.cmdlen + difflen);
0255569
--- 3332,3338 ----
0255569
  
0255569
      if (p2 != NULL && !got_int)
0255569
      {
0255569
! 	difflen = (int)STRLEN(p2) - xp->xp_pattern_len;
0255569
  	if (ccline.cmdlen + difflen > ccline.cmdbufflen - 4)
0255569
  	{
0255569
  	    v = realloc_cmdbuff(ccline.cmdlen + difflen);
0255569
***************
0255569
*** 3620,3625 ****
0255569
--- 3621,3627 ----
0255569
      expand_T	*xp;
0255569
  {
0255569
      xp->xp_pattern = NULL;
0255569
+     xp->xp_pattern_len = 0;
0255569
      xp->xp_backslash = XP_BS_NONE;
0255569
  #ifndef BACKSLASH_IN_FILENAME
0255569
      xp->xp_shell = FALSE;
0255569
***************
0255569
*** 4311,4318 ****
0255569
      }
0255569
  
0255569
      /* add star to file name, or convert to regexp if not exp. files. */
0255569
!     file_str = addstar(xp->xp_pattern,
0255569
! 			   (int)(str + col - xp->xp_pattern), xp->xp_context);
0255569
      if (file_str == NULL)
0255569
  	return EXPAND_UNSUCCESSFUL;
0255569
  
0255569
--- 4313,4320 ----
0255569
      }
0255569
  
0255569
      /* add star to file name, or convert to regexp if not exp. files. */
0255569
!     xp->xp_pattern_len = (int)(str + col - xp->xp_pattern);
0255569
!     file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
0255569
      if (file_str == NULL)
0255569
  	return EXPAND_UNSUCCESSFUL;
0255569
  
0255569
***************
0255569
*** 4781,4787 ****
0255569
  	sprintf((char *)num, "%d", ccline.cmdpos);
0255569
  	args[1] = ccline.cmdbuff;
0255569
      }
0255569
!     args[0] = xp->xp_pattern;
0255569
      args[2] = num;
0255569
  
0255569
      /* Save the cmdline, we don't know what the function may do. */
0255569
--- 4783,4789 ----
0255569
  	sprintf((char *)num, "%d", ccline.cmdpos);
0255569
  	args[1] = ccline.cmdbuff;
0255569
      }
0255569
!     args[0] = vim_strnsave(xp->xp_pattern, xp->xp_pattern_len);
0255569
      args[2] = num;
0255569
  
0255569
      /* Save the cmdline, we don't know what the function may do. */
0255569
***************
0255569
*** 4797,4802 ****
0255569
--- 4799,4805 ----
0255569
      if (ccline.cmdbuff != NULL)
0255569
  	ccline.cmdbuff[ccline.cmdlen] = keep;
0255569
  
0255569
+     vim_free(args[0]);
0255569
      return ret;
0255569
  }
0255569
  
0255569
*** ../vim-7.2.261/src/structs.h	2009-07-29 12:09:49.000000000 +0200
0255569
--- src/structs.h	2009-09-18 15:33:15.000000000 +0200
0255569
***************
0255569
*** 432,437 ****
0255569
--- 432,438 ----
0255569
  {
0255569
      int		xp_context;		/* type of expansion */
0255569
      char_u	*xp_pattern;		/* start of item to expand */
0255569
+     int		xp_pattern_len;		/* bytes in xp_pattern before cursor */
0255569
  #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
0255569
      char_u	*xp_arg;		/* completion function */
0255569
      int		xp_scriptID;		/* SID for completion function */
0255569
*** ../vim-7.2.261/src/version.c	2009-09-18 15:16:37.000000000 +0200
0255569
--- src/version.c	2009-09-18 17:23:20.000000000 +0200
0255569
***************
0255569
*** 678,679 ****
0255569
--- 678,681 ----
0255569
  {   /* Add new patch number below this line */
0255569
+ /**/
0255569
+     262,
0255569
  /**/
0255569
0255569
-- 
0255569
hundred-and-one symptoms of being an internet addict:
0255569
252. You vote for foreign officials.
0255569
0255569
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
0255569
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
0255569
\\\        download, build and distribute -- http://www.A-A-P.org        ///
0255569
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///