Mercurial > vim
comparison src/ex_docmd.c @ 33555:46d449fd4fe4 v9.0.2025
patch 9.0.2025: no cmdline completion for ++opt args
Commit: https://github.com/vim/vim/commit/989426be6e9ae23d2413943890206cbe15d9df38
Author: Yee Cheng Chin <ychin.git@gmail.com>
Date: Sat Oct 14 11:46:51 2023 +0200
patch 9.0.2025: no cmdline completion for ++opt args
Problem: no cmdline completion for ++opt args
Solution: Add cmdline completion for :e ++opt=arg and :terminal
[++options]
closes: #13319
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 15 Oct 2023 09:11:10 +0200 |
parents | 256febd1cbf0 |
children | e628d7f03758 |
comparison
equal
deleted
inserted
replaced
33554:8498422688a9 | 33555:46d449fd4fe4 |
---|---|
5406 return FAIL; | 5406 return FAIL; |
5407 return OK; | 5407 return OK; |
5408 } | 5408 } |
5409 | 5409 |
5410 /* | 5410 /* |
5411 * Function given to ExpandGeneric() to obtain the list of bad= names. | |
5412 */ | |
5413 static char_u * | |
5414 get_bad_name(expand_T *xp UNUSED, int idx) | |
5415 { | |
5416 // Note: Keep this in sync with getargopt. | |
5417 static char *(p_bad_values[]) = | |
5418 { | |
5419 "?", | |
5420 "keep", | |
5421 "drop", | |
5422 }; | |
5423 | |
5424 if (idx < (int)ARRAY_LENGTH(p_bad_values)) | |
5425 return (char_u*)p_bad_values[idx]; | |
5426 return NULL; | |
5427 } | |
5428 | |
5429 /* | |
5411 * Get "++opt=arg" argument. | 5430 * Get "++opt=arg" argument. |
5412 * Return FAIL or OK. | 5431 * Return FAIL or OK. |
5413 */ | 5432 */ |
5414 static int | 5433 static int |
5415 getargopt(exarg_T *eap) | 5434 getargopt(exarg_T *eap) |
5416 { | 5435 { |
5417 char_u *arg = eap->arg + 2; | 5436 char_u *arg = eap->arg + 2; |
5418 int *pp = NULL; | 5437 int *pp = NULL; |
5419 int bad_char_idx; | 5438 int bad_char_idx; |
5420 char_u *p; | 5439 char_u *p; |
5440 | |
5441 // Note: Keep this in sync with get_argopt_name. | |
5421 | 5442 |
5422 // ":edit ++[no]bin[ary] file" | 5443 // ":edit ++[no]bin[ary] file" |
5423 if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0) | 5444 if (STRNCMP(arg, "bin", 3) == 0 || STRNCMP(arg, "nobin", 5) == 0) |
5424 { | 5445 { |
5425 if (*arg == 'n') | 5446 if (*arg == 'n') |
5495 if (get_bad_opt(eap->cmd + bad_char_idx, eap) == FAIL) | 5516 if (get_bad_opt(eap->cmd + bad_char_idx, eap) == FAIL) |
5496 return FAIL; | 5517 return FAIL; |
5497 } | 5518 } |
5498 | 5519 |
5499 return OK; | 5520 return OK; |
5521 } | |
5522 | |
5523 /* | |
5524 * Function given to ExpandGeneric() to obtain the list of ++opt names. | |
5525 */ | |
5526 static char_u * | |
5527 get_argopt_name(expand_T *xp UNUSED, int idx) | |
5528 { | |
5529 // Note: Keep this in sync with getargopt. | |
5530 static char *(p_opt_values[]) = | |
5531 { | |
5532 "fileformat=", | |
5533 "encoding=", | |
5534 "binary", | |
5535 "nobinary", | |
5536 "bad=", | |
5537 "edit", | |
5538 }; | |
5539 | |
5540 if (idx < (int)ARRAY_LENGTH(p_opt_values)) | |
5541 return (char_u*)p_opt_values[idx]; | |
5542 return NULL; | |
5543 } | |
5544 | |
5545 /* | |
5546 * Command-line expansion for ++opt=name. | |
5547 */ | |
5548 int | |
5549 expand_argopt( | |
5550 char_u *pat, | |
5551 expand_T *xp, | |
5552 regmatch_T *rmp, | |
5553 char_u ***matches, | |
5554 int *numMatches) | |
5555 { | |
5556 if (xp->xp_pattern > xp->xp_line && *(xp->xp_pattern-1) == '=') | |
5557 { | |
5558 char_u *(*cb)(expand_T *, int) = NULL; | |
5559 | |
5560 char_u *name_end = xp->xp_pattern - 1; | |
5561 if (name_end - xp->xp_line >= 2 | |
5562 && STRNCMP(name_end - 2, "ff", 2) == 0) | |
5563 cb = get_fileformat_name; | |
5564 else if (name_end - xp->xp_line >= 10 | |
5565 && STRNCMP(name_end - 10, "fileformat", 10) == 0) | |
5566 cb = get_fileformat_name; | |
5567 else if (name_end - xp->xp_line >= 3 | |
5568 && STRNCMP(name_end - 3, "enc", 3) == 0) | |
5569 cb = get_encoding_name; | |
5570 else if (name_end - xp->xp_line >= 8 | |
5571 && STRNCMP(name_end - 8, "encoding", 8) == 0) | |
5572 cb = get_encoding_name; | |
5573 else if (name_end - xp->xp_line >= 3 | |
5574 && STRNCMP(name_end - 3, "bad", 3) == 0) | |
5575 cb = get_bad_name; | |
5576 | |
5577 if (cb != NULL) | |
5578 { | |
5579 return ExpandGeneric( | |
5580 pat, | |
5581 xp, | |
5582 rmp, | |
5583 matches, | |
5584 numMatches, | |
5585 cb, | |
5586 FALSE); | |
5587 } | |
5588 return FAIL; | |
5589 } | |
5590 | |
5591 // Special handling of "ff" which acts as a short form of | |
5592 // "fileformat", as "ff" is not a substring of it. | |
5593 if (STRCMP(xp->xp_pattern, "ff") == 0) | |
5594 { | |
5595 *matches = ALLOC_MULT(char_u *, 1); | |
5596 if (*matches == NULL) | |
5597 return FAIL; | |
5598 *numMatches = 1; | |
5599 (*matches)[0] = vim_strsave((char_u*)"fileformat="); | |
5600 return OK; | |
5601 } | |
5602 | |
5603 return ExpandGeneric( | |
5604 pat, | |
5605 xp, | |
5606 rmp, | |
5607 matches, | |
5608 numMatches, | |
5609 get_argopt_name, | |
5610 FALSE); | |
5500 } | 5611 } |
5501 | 5612 |
5502 static void | 5613 static void |
5503 ex_autocmd(exarg_T *eap) | 5614 ex_autocmd(exarg_T *eap) |
5504 { | 5615 { |