diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2024-11-25 19:15:05 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2024-11-25 19:27:38 +0000 |
commit | c5d770d311841ea5230426cc4c868e8db27300a8 (patch) | |
tree | dd21f70127b4b8b5f109baefc8ecc5016f507c91 /src/nvim/cmdexpand.c | |
parent | 9be89f131f87608f224f0ee06d199fcd09d32176 (diff) | |
parent | 081beb3659bd6d8efc3e977a160b1e72becbd8a2 (diff) | |
download | rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.gz rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.tar.bz2 rneovim-c5d770d311841ea5230426cc4c868e8db27300a8.zip |
Merge remote-tracking branch 'upstream/master' into mix_20240309
Diffstat (limited to 'src/nvim/cmdexpand.c')
-rw-r--r-- | src/nvim/cmdexpand.c | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 402a891099..700d554821 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -109,6 +109,7 @@ static bool cmdline_fuzzy_completion_supported(const expand_T *const xp) && xp->xp_context != EXPAND_FILES && xp->xp_context != EXPAND_FILES_IN_PATH && xp->xp_context != EXPAND_FILETYPE + && xp->xp_context != EXPAND_FINDFUNC && xp->xp_context != EXPAND_HELP && xp->xp_context != EXPAND_KEYMAP && xp->xp_context != EXPAND_LUA @@ -119,6 +120,7 @@ static bool cmdline_fuzzy_completion_supported(const expand_T *const xp) && xp->xp_context != EXPAND_PACKADD && xp->xp_context != EXPAND_RUNTIME && xp->xp_context != EXPAND_SHELLCMD + && xp->xp_context != EXPAND_SHELLCMDLINE && xp->xp_context != EXPAND_TAGS && xp->xp_context != EXPAND_TAGS_LISTFILES && xp->xp_context != EXPAND_USER_LIST @@ -356,7 +358,8 @@ static int cmdline_pum_create(CmdlineInfo *ccline, expand_T *xp, char **matches, .pum_info = NULL, .pum_extra = NULL, .pum_kind = NULL, - .pum_user_hlattr = -1, + .pum_user_abbr_hlattr = -1, + .pum_user_kind_hlattr = -1, }; } @@ -976,20 +979,19 @@ void ExpandCleanup(expand_T *xp) /// @param linenr line number of matches to display /// @param maxlen maximum number of characters in each line /// @param showtail display only the tail of the full path of a file name -/// @param dir_attr highlight attribute to use for directory names static void showmatches_oneline(expand_T *xp, char **matches, int numMatches, int lines, int linenr, - int maxlen, bool showtail, int dir_attr) + int maxlen, bool showtail) { char *p; int lastlen = 999; for (int j = linenr; j < numMatches; j += lines) { if (xp->xp_context == EXPAND_TAGS_LISTFILES) { - msg_outtrans(matches[j], HL_ATTR(HLF_D)); + msg_outtrans(matches[j], HLF_D, false); p = matches[j] + strlen(matches[j]) + 1; msg_advance(maxlen + 1); msg_puts(p); msg_advance(maxlen + 3); - msg_outtrans_long(p + 2, HL_ATTR(HLF_D)); + msg_outtrans_long(p + 2, HLF_D); break; } for (int i = maxlen - lastlen; --i >= 0;) { @@ -1026,7 +1028,7 @@ static void showmatches_oneline(expand_T *xp, char **matches, int numMatches, in isdir = false; p = SHOW_MATCH(j); } - lastlen = msg_outtrans(p, isdir ? dir_attr : 0); + lastlen = msg_outtrans(p, isdir ? HLF_D : 0, false); } if (msg_col > 0) { // when not wrapped around msg_clr_eos(); @@ -1116,18 +1118,16 @@ int showmatches(expand_T *xp, bool wildmenu) lines = (numMatches + columns - 1) / columns; } - int attr = HL_ATTR(HLF_D); // find out highlighting for directories - if (xp->xp_context == EXPAND_TAGS_LISTFILES) { - msg_puts_attr(_("tagname"), HL_ATTR(HLF_T)); + msg_puts_hl(_("tagname"), HLF_T, false); msg_clr_eos(); msg_advance(maxlen - 3); - msg_puts_attr(_(" kind file\n"), HL_ATTR(HLF_T)); + msg_puts_hl(_(" kind file\n"), HLF_T, false); } // list the files line by line for (int i = 0; i < lines; i++) { - showmatches_oneline(xp, matches, numMatches, lines, i, maxlen, showtail, attr); + showmatches_oneline(xp, matches, numMatches, lines, i, maxlen, showtail); if (got_int) { got_int = false; break; @@ -1226,7 +1226,8 @@ char *addstar(char *fname, size_t len, int context) // For help tags the translation is done in find_help_tags(). // For a tag pattern starting with "/" no translation is needed. - if (context == EXPAND_HELP + if (context == EXPAND_FINDFUNC + || context == EXPAND_HELP || context == EXPAND_COLORS || context == EXPAND_COMPILER || context == EXPAND_OWNSYNTAX @@ -1348,7 +1349,7 @@ char *addstar(char *fname, size_t len, int context) /// it. /// EXPAND_BUFFERS Complete file names for :buf and :sbuf commands. /// EXPAND_FILES After command with EX_XFILE set, or after setting -/// with P_EXPAND set. eg :e ^I, :w>>^I +/// with kOptFlagExpand set. eg :e ^I, :w>>^I /// EXPAND_DIRECTORIES In some cases this is used instead of the latter /// when we know only directories are of interest. /// E.g. :set dir=^I and :cd ^I @@ -1527,7 +1528,9 @@ static void set_context_for_wildcard_arg(exarg_T *eap, const char *arg, bool use xp->xp_context = EXPAND_FILES; // For a shell command more chars need to be escaped. - if (usefilter || eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal) { + if (usefilter + || (eap != NULL && (eap->cmdidx == CMD_bang || eap->cmdidx == CMD_terminal)) + || *complp == EXPAND_SHELLCMDLINE) { #ifndef BACKSLASH_IN_FILENAME xp->xp_shell = true; #endif @@ -1823,7 +1826,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa case CMD_sfind: case CMD_tabfind: if (xp->xp_context == EXPAND_FILES) { - xp->xp_context = EXPAND_FILES_IN_PATH; + xp->xp_context = *get_findfunc() != NUL ? EXPAND_FINDFUNC : EXPAND_FILES_IN_PATH; } break; case CMD_cd: @@ -2493,21 +2496,25 @@ static int expand_files_and_dirs(expand_T *xp, char *pat, char ***matches, int * } } - if (xp->xp_context == EXPAND_FILES) { - flags |= EW_FILE; - } else if (xp->xp_context == EXPAND_FILES_IN_PATH) { - flags |= (EW_FILE | EW_PATH); - } else if (xp->xp_context == EXPAND_DIRS_IN_CDPATH) { - flags = (flags | EW_DIR | EW_CDPATH) & ~EW_FILE; + int ret = FAIL; + if (xp->xp_context == EXPAND_FINDFUNC) { + ret = expand_findfunc(pat, matches, numMatches); } else { - flags = (flags | EW_DIR) & ~EW_FILE; - } - if (options & WILD_ICASE) { - flags |= EW_ICASE; + if (xp->xp_context == EXPAND_FILES) { + flags |= EW_FILE; + } else if (xp->xp_context == EXPAND_FILES_IN_PATH) { + flags |= (EW_FILE | EW_PATH); + } else if (xp->xp_context == EXPAND_DIRS_IN_CDPATH) { + flags = (flags | EW_DIR | EW_CDPATH) & ~EW_FILE; + } else { + flags = (flags | EW_DIR) & ~EW_FILE; + } + if (options & WILD_ICASE) { + flags |= EW_ICASE; + } + // Expand wildcards, supporting %:h and the like. + ret = expand_wildcards_eval(&pat, numMatches, matches, flags); } - - // Expand wildcards, supporting %:h and the like. - int ret = expand_wildcards_eval(&pat, numMatches, matches, flags); if (free_pat) { xfree(pat); } @@ -2712,6 +2719,7 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM if (xp->xp_context == EXPAND_FILES || xp->xp_context == EXPAND_DIRECTORIES || xp->xp_context == EXPAND_FILES_IN_PATH + || xp->xp_context == EXPAND_FINDFUNC || xp->xp_context == EXPAND_DIRS_IN_CDPATH) { return expand_files_and_dirs(xp, pat, matches, numMatches, flags, options); } @@ -3601,6 +3609,11 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) set_context_in_runtime_cmd(&xpc, xpc.xp_pattern); xpc.xp_pattern_len = strlen(xpc.xp_pattern); } + if (xpc.xp_context == EXPAND_SHELLCMDLINE) { + int context = EXPAND_SHELLCMDLINE; + set_context_for_wildcard_arg(NULL, xpc.xp_pattern, false, &xpc, &context); + xpc.xp_pattern_len = strlen(xpc.xp_pattern); + } theend: if (xpc.xp_context == EXPAND_LUA) { |