comparison src/usercmd.c @ 27744:515ce8e07bf2 v8.2.4398

patch 8.2.4398: some command completion functions are too long Commit: https://github.com/vim/vim/commit/b31aec3b9387ed12677dca09069c3ae98c6c7447 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Wed Feb 16 12:44:29 2022 +0000 patch 8.2.4398: some command completion functions are too long Problem: Some command completion functions are too long. Solution: Refactor code into separate functions. Add a few more tests. (Yegappan Lakshmanan, closes #9785)
author Bram Moolenaar <Bram@vim.org>
date Wed, 16 Feb 2022 13:45:04 +0100
parents 80f2c282ef9c
children 858002fef4b7
comparison
equal deleted inserted replaced
27743:629769fd1ff1 27744:515ce8e07bf2
229 if (found || possible) 229 if (found || possible)
230 return p + (matchlen - len); 230 return p + (matchlen - len);
231 return p; 231 return p;
232 } 232 }
233 233
234 /*
235 * Set completion context for :command
236 */
234 char_u * 237 char_u *
235 set_context_in_user_cmd(expand_T *xp, char_u *arg_in) 238 set_context_in_user_cmd(expand_T *xp, char_u *arg_in)
236 { 239 {
237 char_u *arg = arg_in; 240 char_u *arg = arg_in;
238 char_u *p; 241 char_u *p;
288 return NULL; 291 return NULL;
289 } 292 }
290 293
291 // And finally comes a normal command 294 // And finally comes a normal command
292 return skipwhite(p); 295 return skipwhite(p);
296 }
297
298 /*
299 * Set the completion context for the argument of a user defined command.
300 */
301 char_u *
302 set_context_in_user_cmdarg(
303 char_u *cmd UNUSED,
304 char_u *arg,
305 long argt,
306 int compl,
307 expand_T *xp,
308 int forceit)
309 {
310 char_u *p;
311
312 if (compl == EXPAND_NOTHING)
313 return NULL;
314
315 if (argt & EX_XFILE)
316 {
317 // EX_XFILE: file names are handled before this call
318 xp->xp_context = compl;
319 return NULL;
320 }
321
322 #ifdef FEAT_MENU
323 if (compl == EXPAND_MENUS)
324 return set_context_in_menu_cmd(xp, cmd, arg, forceit);
325 #endif
326 if (compl == EXPAND_COMMANDS)
327 return arg;
328 if (compl == EXPAND_MAPPINGS)
329 return set_context_in_map_cmd(xp, (char_u *)"map", arg, forceit, FALSE,
330 FALSE, CMD_map);
331 // Find start of last argument.
332 p = arg;
333 while (*p)
334 {
335 if (*p == ' ')
336 // argument starts after a space
337 arg = p + 1;
338 else if (*p == '\\' && *(p + 1) != NUL)
339 ++p; // skip over escaped character
340 MB_PTR_ADV(p);
341 }
342 xp->xp_pattern = arg;
343 xp->xp_context = compl;
344
345 return NULL;
293 } 346 }
294 347
295 char_u * 348 char_u *
296 expand_user_command_name(int idx) 349 expand_user_command_name(int idx)
297 { 350 {