Mercurial > vim
comparison src/cmdexpand.c @ 20745:49673325ca13 v8.2.0925
patch 8.2.0925: getcompletion() does not return command line arguments
Commit: https://github.com/vim/vim/commit/1f1fd44ef796dd909ff5f3e5288b3fd79294dc71
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 7 18:45:14 2020 +0200
patch 8.2.0925: getcompletion() does not return command line arguments
Problem: Getcompletion() does not return command line arguments.
Solution: Add the "cmdline" option. (Shougo, closes https://github.com/vim/vim/issues/1140)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 07 Jun 2020 19:00:03 +0200 |
parents | 5feb426d2ea1 |
children | d9a2e5dcfd9f |
comparison
equal
deleted
inserted
replaced
20744:e4fd0c87abd0 | 20745:49673325ca13 |
---|---|
2673 */ | 2673 */ |
2674 void | 2674 void |
2675 f_getcompletion(typval_T *argvars, typval_T *rettv) | 2675 f_getcompletion(typval_T *argvars, typval_T *rettv) |
2676 { | 2676 { |
2677 char_u *pat; | 2677 char_u *pat; |
2678 char_u *type; | |
2678 expand_T xpc; | 2679 expand_T xpc; |
2679 int filtered = FALSE; | 2680 int filtered = FALSE; |
2680 int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH | 2681 int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH |
2681 | WILD_NO_BEEP; | 2682 | WILD_NO_BEEP; |
2683 | |
2684 if (argvars[1].v_type != VAR_STRING) | |
2685 { | |
2686 semsg(_(e_invarg2), "type must be a string"); | |
2687 return; | |
2688 } | |
2689 type = tv_get_string(&argvars[1]); | |
2682 | 2690 |
2683 if (argvars[2].v_type != VAR_UNKNOWN) | 2691 if (argvars[2].v_type != VAR_UNKNOWN) |
2684 filtered = tv_get_number_chk(&argvars[2], NULL); | 2692 filtered = tv_get_number_chk(&argvars[2], NULL); |
2685 | 2693 |
2686 if (p_wic) | 2694 if (p_wic) |
2689 // For filtered results, 'wildignore' is used | 2697 // For filtered results, 'wildignore' is used |
2690 if (!filtered) | 2698 if (!filtered) |
2691 options |= WILD_KEEP_ALL; | 2699 options |= WILD_KEEP_ALL; |
2692 | 2700 |
2693 ExpandInit(&xpc); | 2701 ExpandInit(&xpc); |
2694 xpc.xp_pattern = tv_get_string(&argvars[0]); | 2702 if (STRCMP(type, "cmdline") == 0) |
2695 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern); | 2703 { |
2696 xpc.xp_context = cmdcomplete_str_to_type(tv_get_string(&argvars[1])); | 2704 set_one_cmd_context(&xpc, tv_get_string(&argvars[0])); |
2697 if (xpc.xp_context == EXPAND_NOTHING) | 2705 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern); |
2698 { | 2706 } |
2699 if (argvars[1].v_type == VAR_STRING) | 2707 else |
2700 semsg(_(e_invarg2), argvars[1].vval.v_string); | 2708 { |
2701 else | 2709 xpc.xp_pattern = tv_get_string(&argvars[0]); |
2702 emsg(_(e_invarg)); | 2710 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern); |
2703 return; | 2711 |
2704 } | 2712 xpc.xp_context = cmdcomplete_str_to_type(type); |
2713 if (xpc.xp_context == EXPAND_NOTHING) | |
2714 { | |
2715 semsg(_(e_invarg2), type); | |
2716 return; | |
2717 } | |
2705 | 2718 |
2706 # if defined(FEAT_MENU) | 2719 # if defined(FEAT_MENU) |
2707 if (xpc.xp_context == EXPAND_MENUS) | 2720 if (xpc.xp_context == EXPAND_MENUS) |
2708 { | 2721 { |
2709 set_context_in_menu_cmd(&xpc, (char_u *)"menu", xpc.xp_pattern, FALSE); | 2722 set_context_in_menu_cmd(&xpc, (char_u *)"menu", xpc.xp_pattern, FALSE); |
2710 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern); | 2723 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern); |
2711 } | 2724 } |
2712 # endif | 2725 # endif |
2713 # ifdef FEAT_CSCOPE | 2726 # ifdef FEAT_CSCOPE |
2714 if (xpc.xp_context == EXPAND_CSCOPE) | 2727 if (xpc.xp_context == EXPAND_CSCOPE) |
2715 { | 2728 { |
2716 set_context_in_cscope_cmd(&xpc, xpc.xp_pattern, CMD_cscope); | 2729 set_context_in_cscope_cmd(&xpc, xpc.xp_pattern, CMD_cscope); |
2717 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern); | 2730 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern); |
2718 } | 2731 } |
2719 # endif | 2732 # endif |
2720 # ifdef FEAT_SIGNS | 2733 # ifdef FEAT_SIGNS |
2721 if (xpc.xp_context == EXPAND_SIGN) | 2734 if (xpc.xp_context == EXPAND_SIGN) |
2722 { | 2735 { |
2723 set_context_in_sign_cmd(&xpc, xpc.xp_pattern); | 2736 set_context_in_sign_cmd(&xpc, xpc.xp_pattern); |
2724 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern); | 2737 xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern); |
2725 } | 2738 } |
2726 # endif | 2739 # endif |
2740 } | |
2727 | 2741 |
2728 pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context); | 2742 pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context); |
2729 if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL)) | 2743 if ((rettv_list_alloc(rettv) != FAIL) && (pat != NULL)) |
2730 { | 2744 { |
2731 int i; | 2745 int i; |