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