4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: When using custom completion for a user command the pattern string
12 goes beyond the cursor position. (Hari Krishna Dara)
13 Solution: Truncate the string at the cursor position.
14 Files: src/ex_getln.c, src/structs.h
17 *** ../vim-7.2.261/src/ex_getln.c 2009-06-24 17:04:40.000000000 +0200
18 --- src/ex_getln.c 2009-09-18 16:58:16.000000000 +0200
33 i = (int)(xp->xp_pattern - ccline.cmdbuff);
34 ! oldlen = ccline.cmdpos - i;
36 if (type == WILD_NEXT || type == WILD_PREV)
41 i = (int)(xp->xp_pattern - ccline.cmdbuff);
42 ! xp->xp_pattern_len = ccline.cmdpos - i;
44 if (type == WILD_NEXT || type == WILD_PREV)
49 * Translate string into pattern and expand it.
51 ! if ((p1 = addstar(&ccline.cmdbuff[i], oldlen, xp->xp_context)) == NULL)
55 ! p2 = ExpandOne(xp, p1, vim_strnsave(&ccline.cmdbuff[i], oldlen),
56 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT|WILD_ESCAPE
59 /* longest match: make sure it is not shorter (happens with :help */
60 if (p2 != NULL && type == WILD_LONGEST)
62 ! for (j = 0; j < oldlen; ++j)
63 if (ccline.cmdbuff[i + j] == '*'
64 || ccline.cmdbuff[i + j] == '?')
68 * Translate string into pattern and expand it.
70 ! if ((p1 = addstar(xp->xp_pattern, xp->xp_pattern_len,
71 ! xp->xp_context)) == NULL)
75 ! p2 = ExpandOne(xp, p1,
76 ! vim_strnsave(&ccline.cmdbuff[i], xp->xp_pattern_len),
77 WILD_HOME_REPLACE|WILD_ADD_SLASH|WILD_SILENT|WILD_ESCAPE
80 /* longest match: make sure it is not shorter (happens with :help */
81 if (p2 != NULL && type == WILD_LONGEST)
83 ! for (j = 0; j < xp->xp_pattern_len; ++j)
84 if (ccline.cmdbuff[i + j] == '*'
85 || ccline.cmdbuff[i + j] == '?')
90 if (p2 != NULL && !got_int)
92 ! difflen = (int)STRLEN(p2) - oldlen;
93 if (ccline.cmdlen + difflen > ccline.cmdbufflen - 4)
95 v = realloc_cmdbuff(ccline.cmdlen + difflen);
98 if (p2 != NULL && !got_int)
100 ! difflen = (int)STRLEN(p2) - xp->xp_pattern_len;
101 if (ccline.cmdlen + difflen > ccline.cmdbufflen - 4)
103 v = realloc_cmdbuff(ccline.cmdlen + difflen);
109 xp->xp_pattern = NULL;
110 + xp->xp_pattern_len = 0;
111 xp->xp_backslash = XP_BS_NONE;
112 #ifndef BACKSLASH_IN_FILENAME
113 xp->xp_shell = FALSE;
118 /* add star to file name, or convert to regexp if not exp. files. */
119 ! file_str = addstar(xp->xp_pattern,
120 ! (int)(str + col - xp->xp_pattern), xp->xp_context);
121 if (file_str == NULL)
122 return EXPAND_UNSUCCESSFUL;
127 /* add star to file name, or convert to regexp if not exp. files. */
128 ! xp->xp_pattern_len = (int)(str + col - xp->xp_pattern);
129 ! file_str = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context);
130 if (file_str == NULL)
131 return EXPAND_UNSUCCESSFUL;
135 sprintf((char *)num, "%d", ccline.cmdpos);
136 args[1] = ccline.cmdbuff;
138 ! args[0] = xp->xp_pattern;
141 /* Save the cmdline, we don't know what the function may do. */
143 sprintf((char *)num, "%d", ccline.cmdpos);
144 args[1] = ccline.cmdbuff;
146 ! args[0] = vim_strnsave(xp->xp_pattern, xp->xp_pattern_len);
149 /* Save the cmdline, we don't know what the function may do. */
153 if (ccline.cmdbuff != NULL)
154 ccline.cmdbuff[ccline.cmdlen] = keep;
160 *** ../vim-7.2.261/src/structs.h 2009-07-29 12:09:49.000000000 +0200
161 --- src/structs.h 2009-09-18 15:33:15.000000000 +0200
166 int xp_context; /* type of expansion */
167 char_u *xp_pattern; /* start of item to expand */
168 + int xp_pattern_len; /* bytes in xp_pattern before cursor */
169 #if defined(FEAT_USR_CMDS) && defined(FEAT_EVAL) && defined(FEAT_CMDL_COMPL)
170 char_u *xp_arg; /* completion function */
171 int xp_scriptID; /* SID for completion function */
172 *** ../vim-7.2.261/src/version.c 2009-09-18 15:16:37.000000000 +0200
173 --- src/version.c 2009-09-18 17:23:20.000000000 +0200
177 { /* Add new patch number below this line */
183 hundred-and-one symptoms of being an internet addict:
184 252. You vote for foreign officials.
186 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
187 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
188 \\\ download, build and distribute -- http://www.A-A-P.org ///
189 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///