From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/cmdexpand.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 5e4b49db24..64e5664f1f 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2000,8 +2000,8 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa case CMD_snoremap: case CMD_xmap: case CMD_xnoremap: - return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, false, - false, cmdidx); + return set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, false, + false, cmdidx); case CMD_unmap: case CMD_nunmap: case CMD_vunmap: @@ -2011,8 +2011,8 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa case CMD_lunmap: case CMD_sunmap: case CMD_xunmap: - return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, false, - true, cmdidx); + return set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, false, + true, cmdidx); case CMD_mapclear: case CMD_nmapclear: case CMD_vmapclear: @@ -2032,13 +2032,13 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa case CMD_cnoreabbrev: case CMD_iabbrev: case CMD_inoreabbrev: - return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, true, - false, cmdidx); + return set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, true, + false, cmdidx); case CMD_unabbreviate: case CMD_cunabbrev: case CMD_iunabbrev: - return (const char *)set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, true, - true, cmdidx); + return set_context_in_map_cmd(xp, (char *)cmd, (char *)arg, forceit, true, + true, cmdidx); case CMD_menu: case CMD_noremenu: case CMD_unmenu: @@ -3238,7 +3238,7 @@ void globpath(char *path, char *file, garray_T *ga, int expand_options, bool dir ga_grow(ga, num_p); // take over the pointers and put them in "ga" for (int i = 0; i < num_p; i++) { - ((char_u **)ga->ga_data)[ga->ga_len] = (char_u *)p[i]; + ((char **)ga->ga_data)[ga->ga_len] = p[i]; ga->ga_len++; } xfree(p); -- cgit From 27177e581902967dcf4f2f426464da1b636ca420 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 14:14:24 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22211) --- src/nvim/cmdexpand.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 64e5664f1f..97feab2978 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -222,10 +222,8 @@ static void ExpandEscape(expand_T *xp, char *str, int numfiles, char **files, in int nextwild(expand_T *xp, int type, int options, bool escape) { CmdlineInfo *const ccline = get_cmdline_info(); - int i, j; - char *p1; + int i; char *p2; - int difflen; if (xp->xp_numfiles == -1) { set_expand_context(xp); @@ -258,6 +256,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) // Get next/previous match for a previous expanded pattern. p2 = ExpandOne(xp, NULL, NULL, 0, type); } else { + char *p1; if (cmdline_fuzzy_completion_supported(xp)) { // If fuzzy matching, don't modify the search string p1 = xstrdup(xp->xp_pattern); @@ -282,6 +281,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) // Longest match: make sure it is not shorter, happens with :help. if (p2 != NULL && type == WILD_LONGEST) { + int j; for (j = 0; (size_t)j < xp->xp_pattern_len; j++) { if (ccline->cmdbuff[i + j] == '*' || ccline->cmdbuff[i + j] == '?') { @@ -295,7 +295,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) } if (p2 != NULL && !got_int) { - difflen = (int)strlen(p2) - (int)(xp->xp_pattern_len); + int difflen = (int)strlen(p2) - (int)(xp->xp_pattern_len); if (ccline->cmdlen + difflen + 4 > ccline->cmdbufflen) { realloc_cmdbuff(ccline->cmdlen + difflen + 4); xp->xp_pattern = ccline->cmdbuff + i; @@ -454,8 +454,6 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m char *selend = NULL; static int first_match = 0; bool add_left = false; - char *s; - int emenu; int l; if (matches == NULL) { // interrupted completion? @@ -528,10 +526,9 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m selstart_col = clen; } - s = SHOW_MATCH(i); + char *s = SHOW_MATCH(i); // Check for menu separators - replace with '|' - emenu = (xp->xp_context == EXPAND_MENUS - || xp->xp_context == EXPAND_MENUNAMES); + int emenu = (xp->xp_context == EXPAND_MENUS || xp->xp_context == EXPAND_MENUNAMES); if (emenu && menu_is_separator(s)) { STRCPY(buf + len, transchar('|')); l = (int)strlen(buf + len); @@ -847,7 +844,6 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) static int findex; static char *orig_save = NULL; // kept value of orig int orig_saved = false; - int i; // first handle the case of using an old match if (mode == WILD_NEXT || mode == WILD_PREV @@ -900,12 +896,12 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) // TODO(philix): use xstpcpy instead of strcat in a loop (ExpandOne) if (mode == WILD_ALL && xp->xp_numfiles > 0 && !got_int) { size_t len = 0; - for (i = 0; i < xp->xp_numfiles; i++) { + for (int i = 0; i < xp->xp_numfiles; i++) { len += strlen(xp->xp_files[i]) + 1; } ss = xmalloc(len); *ss = NUL; - for (i = 0; i < xp->xp_numfiles; i++) { + for (int i = 0; i < xp->xp_numfiles; i++) { STRCAT(ss, xp->xp_files[i]); if (i != xp->xp_numfiles - 1) { STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); @@ -1375,7 +1371,6 @@ void set_expand_context(expand_T *xp) static const char *set_cmd_index(const char *cmd, exarg_T *eap, expand_T *xp, int *complp) { const char *p = NULL; - size_t len = 0; const bool fuzzy = cmdline_fuzzy_complete(cmd); // Isolate the command and search for it in the command table. @@ -1410,7 +1405,7 @@ static const char *set_cmd_index(const char *cmd, exarg_T *eap, expand_T *xp, in if (p == cmd && vim_strchr("@*!=><&~#", (uint8_t)(*p)) != NULL) { p++; } - len = (size_t)(p - cmd); + size_t len = (size_t)(p - cmd); if (len == 0) { xp->xp_context = EXPAND_UNSUCCESSFUL; @@ -2955,7 +2950,6 @@ static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int char *path = NULL; garray_T ga; char *buf = xmalloc(MAXPATHL); - size_t l; char *s, *e; int flags = flagsarg; bool did_curdir = false; @@ -3013,7 +3007,7 @@ static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int flags &= ~EW_DIR; } - l = (size_t)(e - s); + size_t l = (size_t)(e - s); if (l > MAXPATHL - 5) { break; } -- cgit From 0cbbe27e93e87a5336673e0529b011313c51a123 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Feb 2023 11:00:48 +0800 Subject: vim-patch:8.2.0154: reallocating the list of scripts is inefficient Problem: Reallocating the list of scripts is inefficient. Solution: Instead of using a growarray of scriptitem_T, store pointers and allocate each scriptitem_T separately. Also avoids that the growarray pointers change when sourcing a new script. https://github.com/vim/vim/commit/21b9e9773d64de40994f8762173bdd8befa6acf7 Co-authored-by: Bram Moolenaar --- src/nvim/cmdexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 97feab2978..fcd6a73b2d 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2524,7 +2524,7 @@ static char *get_scriptnames_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx) return NULL; } - scriptitem_T *si = &SCRIPT_ITEM(idx + 1); + scriptitem_T *si = SCRIPT_ITEM(idx + 1); home_replace(NULL, si->sn_name, NameBuff, MAXPATHL, true); return NameBuff; } -- cgit From 1b3c1f6c06d73e881bfc2a46e5ee3e0b24ba96d8 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 27 Feb 2023 19:37:43 +0100 Subject: refactor(build): graduate HAVE_LOCALE_H feature Merge locale.h into os/lang.h Having a source file with the same name as a system header we use is considered an anti-pattern. --- src/nvim/cmdexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index fcd6a73b2d..18d35e1e20 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -40,7 +40,6 @@ #include "nvim/highlight_defs.h" #include "nvim/highlight_group.h" #include "nvim/keycodes.h" -#include "nvim/locale.h" #include "nvim/log.h" #include "nvim/lua/executor.h" #include "nvim/macros.h" @@ -50,6 +49,7 @@ #include "nvim/menu.h" #include "nvim/message.h" #include "nvim/option.h" +#include "nvim/os/lang.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/popupmenu.h" -- cgit From 07f59467da5a80c7ce46fdc9efcc0e2c18633df1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Mar 2023 20:09:56 +0800 Subject: refactor(completion): don't add and remove '^' for Lua (#22702) --- src/nvim/cmdexpand.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 18d35e1e20..220cb4cf93 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1206,7 +1206,6 @@ 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 - || context == EXPAND_CHECKHEALTH || context == EXPAND_COLORS || context == EXPAND_COMPILER || context == EXPAND_OWNSYNTAX @@ -1214,7 +1213,9 @@ char *addstar(char *fname, size_t len, int context) || context == EXPAND_PACKADD || context == EXPAND_RUNTIME || ((context == EXPAND_TAGS_LISTFILES || context == EXPAND_TAGS) - && fname[0] == '/')) { + && fname[0] == '/') + || context == EXPAND_CHECKHEALTH + || context == EXPAND_LUA) { retval = xstrnsave(fname, len); } else { new_len = len + 2; // +2 for '^' at start, NUL at end -- cgit From a92b38934a2d00c13ee4d1969d994da15e0857ab Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 20 Mar 2023 21:11:10 +0100 Subject: feat(lua): allow `:=expr` as a shorter version of `:lua =expr` existing behavior of := and :[range]= are unchanged. `|` is still allowed with this usage. However, :=p and similar are changed in a way which could be construed as a breaking change. Allowing |ex-flags| for := in the first place was a mistake as any form of := DOES NOT MOVE THE CURSOR. So it would print one line number and then print a completely different line contents after that. --- src/nvim/cmdexpand.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 220cb4cf93..bce28fa449 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2141,6 +2141,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa return set_context_in_scriptnames_cmd(xp, arg); case CMD_lua: + case CMD_equal: xp->xp_context = EXPAND_LUA; break; -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/cmdexpand.c | 68 +++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index bce28fa449..774e16f73d 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -959,7 +959,7 @@ static void showmatches_oneline(expand_T *xp, char **matches, int numMatches, in msg_outtrans_attr(matches[j], HL_ATTR(HLF_D)); p = matches[j] + strlen(matches[j]) + 1; msg_advance(maxlen + 1); - msg_puts((const char *)p); + msg_puts(p); msg_advance(maxlen + 3); msg_outtrans_long_attr(p + 2, HL_ATTR(HLF_D)); break; @@ -1438,7 +1438,7 @@ static const char *set_cmd_index(const char *cmd, exarg_T *eap, expand_T *xp, in p = cmd + 1; } else if (cmd[0] >= 'A' && cmd[0] <= 'Z') { eap->cmd = (char *)cmd; - p = (const char *)find_ucmd(eap, (char *)p, NULL, xp, complp); + p = find_ucmd(eap, (char *)p, NULL, xp, complp); if (p == NULL) { eap->cmdidx = CMD_SIZE; // Ambiguous user command. } @@ -1464,7 +1464,7 @@ static void set_context_for_wildcard_arg(exarg_T *eap, const char *arg, bool use // Allow spaces within back-quotes to count as part of the argument // being expanded. xp->xp_pattern = skipwhite(arg); - const char *p = (const char *)xp->xp_pattern; + const char *p = xp->xp_pattern; while (*p != NUL) { int c = utf_ptr2char(p); if (c == '\\' && p[1] != NUL) { @@ -1517,7 +1517,7 @@ static void set_context_for_wildcard_arg(exarg_T *eap, const char *arg, bool use // Check for environment variable. if (*xp->xp_pattern == '$') { - for (p = (const char *)xp->xp_pattern + 1; *p != NUL; p++) { + for (p = xp->xp_pattern + 1; *p != NUL; p++) { if (!vim_isIDc((uint8_t)(*p))) { break; } @@ -1533,12 +1533,11 @@ static void set_context_for_wildcard_arg(exarg_T *eap, const char *arg, bool use } // Check for user names. if (*xp->xp_pattern == '~') { - for (p = (const char *)xp->xp_pattern + 1; *p != NUL && *p != '/'; p++) {} + for (p = xp->xp_pattern + 1; *p != NUL && *p != '/'; p++) {} // Complete ~user only if it partially matches a user name. // A full match ~user will be replaced by user's home // directory i.e. something like ~user -> /home/user/ - if (*p == NUL && p > (const char *)xp->xp_pattern + 1 - && match_user(xp->xp_pattern + 1) >= 1) { + if (*p == NUL && p > xp->xp_pattern + 1 && match_user(xp->xp_pattern + 1) >= 1) { xp->xp_context = EXPAND_USER; xp->xp_pattern++; } @@ -1550,13 +1549,13 @@ static void set_context_for_wildcard_arg(exarg_T *eap, const char *arg, bool use static const char *set_context_in_filter_cmd(expand_T *xp, const char *arg) { if (*arg != NUL) { - arg = (const char *)skip_vimgrep_pat((char *)arg, NULL, NULL); + arg = skip_vimgrep_pat((char *)arg, NULL, NULL); } if (arg == NULL || *arg == NUL) { xp->xp_context = EXPAND_NOTHING; return NULL; } - return (const char *)skipwhite(arg); + return skipwhite(arg); } /// Set the completion context for the :match command. Returns a pointer to the @@ -1566,13 +1565,13 @@ static const char *set_context_in_match_cmd(expand_T *xp, const char *arg) if (*arg == NUL || !ends_excmd(*arg)) { // also complete "None" set_context_in_echohl_cmd(xp, arg); - arg = (const char *)skipwhite(skiptowhite(arg)); + arg = skipwhite(skiptowhite(arg)); if (*arg != NUL) { xp->xp_context = EXPAND_NOTHING; - arg = (const char *)skip_regexp((char *)arg + 1, (uint8_t)(*arg), magic_isset()); + arg = skip_regexp((char *)arg + 1, (uint8_t)(*arg), magic_isset()); } } - return (const char *)find_nextcmd(arg); + return find_nextcmd(arg); } /// Returns a pointer to the next command after a :global or a :v command. @@ -1605,7 +1604,7 @@ static const char *find_cmd_after_substitute_cmd(const char *arg) if (delim) { // Skip "from" part. arg++; - arg = (const char *)skip_regexp((char *)arg, delim, magic_isset()); + arg = skip_regexp((char *)arg, delim, magic_isset()); if (arg[0] != NUL && arg[0] == delim) { // Skip "to" part. @@ -1637,7 +1636,7 @@ static const char *find_cmd_after_substitute_cmd(const char *arg) static const char *find_cmd_after_isearch_cmd(expand_T *xp, const char *arg) { // Skip count. - arg = (const char *)skipwhite(skipdigits(arg)); + arg = skipwhite(skipdigits(arg)); if (*arg != '/') { return NULL; } @@ -1649,7 +1648,7 @@ static const char *find_cmd_after_isearch_cmd(expand_T *xp, const char *arg) } } if (*arg) { - arg = (const char *)skipwhite(arg + 1); + arg = skipwhite(arg + 1); // Check for trailing illegal characters. if (*arg == NUL || strchr("|\"\n", *arg) == NULL) { @@ -1666,7 +1665,7 @@ static const char *find_cmd_after_isearch_cmd(expand_T *xp, const char *arg) static const char *set_context_in_unlet_cmd(expand_T *xp, const char *arg) { while ((xp->xp_pattern = strchr(arg, ' ')) != NULL) { - arg = (const char *)xp->xp_pattern + 1; + arg = xp->xp_pattern + 1; } xp->xp_context = EXPAND_USER_VARS; @@ -1683,7 +1682,7 @@ static const char *set_context_in_unlet_cmd(expand_T *xp, const char *arg) /// Set the completion context for the :language command. Always returns NULL. static const char *set_context_in_lang_cmd(expand_T *xp, const char *arg) { - const char *p = (const char *)skiptowhite(arg); + const char *p = skiptowhite(arg); if (*p == NUL) { xp->xp_context = EXPAND_LANGUAGE; xp->xp_pattern = (char *)arg; @@ -1876,11 +1875,11 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa case CMD_dsplit: return find_cmd_after_isearch_cmd(xp, arg); case CMD_autocmd: - return (const char *)set_context_in_autocmd(xp, (char *)arg, false); + return set_context_in_autocmd(xp, (char *)arg, false); case CMD_doautocmd: case CMD_doautoall: - return (const char *)set_context_in_autocmd(xp, (char *)arg, true); + return set_context_in_autocmd(xp, (char *)arg, true); case CMD_set: set_context_in_set_cmd(xp, (char *)arg, 0); break; @@ -1957,7 +1956,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa case CMD_bwipeout: case CMD_bunload: while ((xp->xp_pattern = strchr(arg, ' ')) != NULL) { - arg = (const char *)xp->xp_pattern + 1; + arg = xp->xp_pattern + 1; } FALLTHROUGH; case CMD_buffer: @@ -2063,7 +2062,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa case CMD_tunmenu: case CMD_popup: case CMD_emenu: - return (const char *)set_context_in_menu_cmd(xp, cmd, (char *)arg, forceit); + return set_context_in_menu_cmd(xp, cmd, (char *)arg, forceit); case CMD_colorscheme: xp->xp_context = EXPAND_COLORS; @@ -2126,7 +2125,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa case CMD_argdelete: while ((xp->xp_pattern = vim_strchr(arg, ' ')) != NULL) { - arg = (const char *)(xp->xp_pattern + 1); + arg = (xp->xp_pattern + 1); } xp->xp_context = EXPAND_ARGLIST; xp->xp_pattern = (char *)arg; @@ -2186,7 +2185,7 @@ static const char *set_one_cmd_context(expand_T *xp, const char *buff) } // 3. skip over a range specifier of the form: addr [,addr] [;addr] .. - cmd = (const char *)skip_range(cmd, &xp->xp_context); + cmd = skip_range(cmd, &xp->xp_context); xp->xp_pattern = (char *)cmd; if (*cmd == NUL) { return NULL; @@ -2218,7 +2217,7 @@ static const char *set_one_cmd_context(expand_T *xp, const char *buff) ea.argt = excmd_get_argt(ea.cmdidx); } - const char *arg = (const char *)skipwhite(p); + const char *arg = skipwhite(p); // Skip over ++argopt argument if ((ea.argt & EX_ARGOPT) && *arg != NUL && strncmp(arg, "++", 2) == 0) { @@ -2226,7 +2225,7 @@ static const char *set_one_cmd_context(expand_T *xp, const char *buff) while (*p && !ascii_isspace(*p)) { MB_PTR_ADV(p); } - arg = (const char *)skipwhite(p); + arg = skipwhite(p); } if (ea.cmdidx == CMD_write || ea.cmdidx == CMD_update) { @@ -2234,7 +2233,7 @@ static const char *set_one_cmd_context(expand_T *xp, const char *buff) if (*++arg == '>') { arg++; } - arg = (const char *)skipwhite(arg); + arg = skipwhite(arg); } else if (*arg == '!' && ea.cmdidx == CMD_write) { // :w !filter arg++; usefilter = true; @@ -2253,14 +2252,14 @@ static const char *set_one_cmd_context(expand_T *xp, const char *buff) while (*arg == *cmd) { // allow any number of '>' or '<' arg++; } - arg = (const char *)skipwhite(arg); + arg = skipwhite(arg); } // Does command allow "+command"? if ((ea.argt & EX_CMDARG) && !usefilter && *arg == '+') { // Check if we're in the +command p = arg + 1; - arg = (const char *)skip_cmd_arg((char *)arg, false); + arg = skip_cmd_arg((char *)arg, false); // Still touching the command after '+'? if (*arg == NUL) { @@ -2268,7 +2267,7 @@ static const char *set_one_cmd_context(expand_T *xp, const char *buff) } // Skip space(s) after +command to get to the real argument. - arg = (const char *)skipwhite(arg); + arg = skipwhite(arg); } // Check for '|' to separate commands and '"' to start comments. @@ -2344,7 +2343,7 @@ void set_cmd_context(expand_T *xp, char *str, int len, int col, int use_ccline) old_char = str[col]; } str[col] = NUL; - const char *nextcomm = (const char *)str; + const char *nextcomm = str; if (use_ccline && ccline->cmdfirstc == '=') { // pass CMD_SIZE because there is no real command @@ -2922,7 +2921,7 @@ static void expand_shellcmd_onedir(char *buf, char *s, size_t l, char *pat, char // Check if this name was already found. hash_T hash = hash_hash(name + l); hashitem_T *hi = - hash_lookup(ht, (const char *)(name + l), strlen(name + l), hash); + hash_lookup(ht, name + l, strlen(name + l), hash); if (HASHITEM_EMPTY(hi)) { // Remove the path that was prepended. STRMOVE(name, name + l); @@ -3166,7 +3165,7 @@ static int ExpandUserList(expand_T *xp, char ***matches, int *numMatches) continue; // Skip non-string items and empty strings. } - GA_APPEND(char *, &ga, xstrdup((const char *)TV_LIST_ITEM_TV(li)->vval.v_string)); + GA_APPEND(char *, &ga, xstrdup(TV_LIST_ITEM_TV(li)->vval.v_string)); }); tv_list_unref(retlist); @@ -3195,7 +3194,7 @@ static int ExpandUserLua(expand_T *xp, int *num_file, char ***file) continue; // Skip non-string items and empty strings. } - GA_APPEND(char *, &ga, xstrdup((const char *)TV_LIST_ITEM_TV(li)->vval.v_string)); + GA_APPEND(char *, &ga, xstrdup(TV_LIST_ITEM_TV(li)->vval.v_string)); }); tv_list_unref(retlist); @@ -3551,8 +3550,7 @@ theend: tv_list_alloc_ret(rettv, xpc.xp_numfiles); for (int i = 0; i < xpc.xp_numfiles; i++) { - tv_list_append_string(rettv->vval.v_list, (const char *)xpc.xp_files[i], - -1); + tv_list_append_string(rettv->vval.v_list, xpc.xp_files[i], -1); } xfree(pat); ExpandCleanup(&xpc); -- cgit From e4a136f713753e6ace97f419be562567f1ce535f Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 12 Apr 2023 22:22:37 +0200 Subject: feat(ex_cmds)!: remove :behave just use the individual options instead. set selection=exclusive set selectmode=mouse,key set mousemodel=popup set keymodel=startsel,stopsel --- src/nvim/cmdexpand.c | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 774e16f73d..f2776191b7 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2104,10 +2104,6 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa xp->xp_context = EXPAND_CHECKHEALTH; xp->xp_pattern = (char *)arg; break; - case CMD_behave: - xp->xp_context = EXPAND_BEHAVE; - xp->xp_pattern = (char *)arg; - break; case CMD_messages: xp->xp_context = EXPAND_MESSAGES; @@ -2478,19 +2474,6 @@ static int expand_files_and_dirs(expand_T *xp, char *pat, char ***matches, int * return ret; } -/// Function given to ExpandGeneric() to obtain the possible arguments of the -/// ":behave {mswin,xterm}" command. -static char *get_behave_arg(expand_T *xp FUNC_ATTR_UNUSED, int idx) -{ - if (idx == 0) { - return "mswin"; - } - if (idx == 1) { - return "xterm"; - } - return NULL; -} - /// Function given to ExpandGeneric() to obtain the possible arguments of the /// ":breakadd {expr, file, func, here}" command. /// ":breakdel {func, file, here}" command. @@ -2585,7 +2568,6 @@ static int ExpandOther(char *pat, expand_T *xp, regmatch_T *rmp, char ***matches int escaped; } tab[] = { { EXPAND_COMMANDS, get_command_name, false, true }, - { EXPAND_BEHAVE, get_behave_arg, true, true }, { EXPAND_MAPCLEAR, get_mapclear_arg, true, true }, { EXPAND_MESSAGES, get_messages_arg, true, true }, { EXPAND_HISTORY, get_history_arg, true, true }, -- cgit From 431b152726013ec6a5cece0285e7c103673bc511 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Apr 2023 08:12:44 +0800 Subject: vim-patch:9.0.1479: small source file problems; outdated list of distrib. files (#23272) Problem: Small source file problems; outdated list of distributed files. Solution: Small updates to source files and list of distributed files. https://github.com/vim/vim/commit/f39d9e9dca443e42920066be3a98fd9780e4ed33 Co-authored-by: Bram Moolenaar --- src/nvim/cmdexpand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index f2776191b7..a400be6039 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1328,8 +1328,8 @@ char *addstar(char *fname, size_t len, int context) /// EXPAND_FILES After command with EX_XFILE set, or after setting /// with P_EXPAND 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. eg -/// :set dir=^I +/// when we know only directories are of interest. +/// E.g. :set dir=^I and :cd ^I /// EXPAND_SHELLCMD After ":!cmd", ":r !cmd" or ":w !cmd". /// EXPAND_SETTINGS Complete variable names. eg :set d^I /// EXPAND_BOOL_SETTINGS Complete boolean variables only, eg :set no^I -- cgit From 7e0d66801297677ecbb6b35d0c9139e672920be4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 25 Apr 2023 23:39:15 +0800 Subject: vim-patch:partial:9.0.0359: error message for wrong argument type is not specific (#23315) Problem: Error message for wrong argument type is not specific. Solution: Include more information in the error. (Yegappan Lakshmanan, closes vim/vim#11037) https://github.com/vim/vim/commit/8deb2b30c77035bb682ccf80b781455ac1d6038b Skip reduce() and deepcopy() changes because of missing patches. Co-authored-by: Yegappan Lakshmanan --- src/nvim/cmdexpand.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index a400be6039..5f135ff7b0 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -3466,8 +3466,7 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH | WILD_NO_BEEP | WILD_HOME_REPLACE; - if (argvars[1].v_type != VAR_STRING) { - semsg(_(e_invarg2), "type must be a string"); + if (tv_check_for_string_arg(argvars, 1) == FAIL) { return; } const char *const type = tv_get_string(&argvars[1]); -- cgit From fa1baa9a47cdb3eed17d48b6011a164d4009d2ee Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:00:08 +0800 Subject: vim-patch:9.0.1520: completion for option name includes all bool options (#23518) Problem: Completion for option name includes all bool options. Solution: Do not recognize the "noinv" prefix. Prefix "no" or "inv" when appropriate. https://github.com/vim/vim/commit/048d9d25214049dfde04c468c14bd1708fb692b8 Co-authored-by: Bram Moolenaar --- src/nvim/cmdexpand.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 5f135ff7b0..bf0944a81d 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -897,12 +897,27 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) if (mode == WILD_ALL && xp->xp_numfiles > 0 && !got_int) { size_t len = 0; for (int i = 0; i < xp->xp_numfiles; i++) { + if (i > 0) { + if (xp->xp_prefix == XP_PREFIX_NO) { + len += 2; // prefix "no" + } else if (xp->xp_prefix == XP_PREFIX_INV) { + len += 3; // prefix "inv" + } + } len += strlen(xp->xp_files[i]) + 1; } ss = xmalloc(len); *ss = NUL; for (int i = 0; i < xp->xp_numfiles; i++) { + if (i > 0) { + if (xp->xp_prefix == XP_PREFIX_NO) { + STRCAT(ss, "no"); + } else if (xp->xp_prefix == XP_PREFIX_INV) { + STRCAT(ss, "inv"); + } + } STRCAT(ss, xp->xp_files[i]); + if (i != xp->xp_numfiles - 1) { STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); } @@ -927,6 +942,7 @@ void ExpandInit(expand_T *xp) { CLEAR_POINTER(xp); xp->xp_backslash = XP_BS_NONE; + xp->xp_prefix = XP_PREFIX_NONE; xp->xp_numfiles = -1; } -- cgit From ddba917efee26229d77f86d14a9f62dcfdc822b8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 16 Jun 2023 07:02:21 +0800 Subject: vim-patch:9.0.1636: expanding a pattern interferes with cmdline completion (#24034) Problem: Expanding a pattern interferes with command line completion. Solution: Set the file index only when appropriate. (closes vim/vim#12519) https://github.com/vim/vim/commit/094dd152fe1d47878ec6c0b3f54b03ffde7f4a2d --- src/nvim/cmdexpand.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index bf0944a81d..b2835cae0f 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -841,7 +841,7 @@ static char *find_longest_match(expand_T *xp, int options) char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) { char *ss = NULL; - static int findex; + static int findex; // TODO(vim): Move into expand_T static char *orig_save = NULL; // kept value of orig int orig_saved = false; @@ -871,7 +871,10 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) cmdline_pum_remove(); } } - findex = 0; + // TODO(vim): Remove condition if "findex" is part of expand_T ? + if (mode != WILD_EXPAND_FREE && mode != WILD_ALL && mode != WILD_ALL_KEEP) { + findex = 0; + } if (mode == WILD_FREE) { // only release file name return NULL; -- cgit From fcf3519c65a2d6736de437f686e788684a6c8564 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 17 Apr 2023 22:18:58 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/cmdexpand.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index b2835cae0f..47c69ed6f8 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -483,13 +483,13 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m clen += 2; } // jumping right, put match at the left - if ((long)clen > Columns) { + if (clen > Columns) { first_match = match; // if showing the last match, we can add some on the left clen = 2; for (i = match; i < num_matches; i++) { clen += wildmenu_match_len(xp, SHOW_MATCH(i)) + 2; - if ((long)clen >= Columns) { + if (clen >= Columns) { break; } } @@ -501,7 +501,7 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m if (add_left) { while (first_match > 0) { clen += wildmenu_match_len(xp, SHOW_MATCH(first_match - 1)) + 2; - if ((long)clen >= Columns) { + if (clen >= Columns) { break; } first_match--; -- cgit From 3cd5ef63fd17a4eb294856360039803f31a10a76 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 16 Aug 2023 06:07:01 +0800 Subject: vim-patch:9.0.1714: getcompletion() "cmdline" fails after :autocmd (#24727) Problem: getcompletion() "cmdline" fails after :autocmd Solution: Use set_cmd_context() instead of set_one_cmd_context(). closes: vim/vim#12804 https://github.com/vim/vim/commit/e4c79d36150431ffb97cb8952ec482af2e57f228 --- src/nvim/cmdexpand.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 47c69ed6f8..610f2c4e0b 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -3479,7 +3479,6 @@ void wildmenu_cleanup(CmdlineInfo *cclp) /// "getcompletion()" function void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - char *pat; expand_T xpc; bool filtered = false; int options = WILD_SILENT | WILD_USE_NL | WILD_ADD_SLASH @@ -3510,9 +3509,10 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const char *pattern = tv_get_string(&argvars[0]); if (strcmp(type, "cmdline") == 0) { - set_one_cmd_context(&xpc, pattern); + const int cmdline_len = (int)strlen(pattern); + set_cmd_context(&xpc, (char *)pattern, cmdline_len, cmdline_len, false); xpc.xp_pattern_len = strlen(xpc.xp_pattern); - xpc.xp_col = (int)strlen(pattern); + xpc.xp_col = cmdline_len; goto theend; } @@ -3539,6 +3539,8 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } theend: + ; + char *pat; if (cmdline_fuzzy_completion_supported(&xpc)) { // when fuzzy matching, don't modify the search string pat = xstrdup(xpc.xp_pattern); -- cgit From 1d6c4ad073ecff42a4421c7b30b42937809bd248 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 18 Aug 2023 07:23:43 +0800 Subject: vim-patch:9.0.1735: Rename completion specific findex var (#24769) Problem: Rename completion specific findex var Solution: Move "findex" static variable to xp_selected in expand_T closes: vim/vim#12548 https://github.com/vim/vim/commit/e9ef347c137aca6c2592beb19da45a8aece65e11 --- src/nvim/cmdexpand.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 610f2c4e0b..eb9394c8ff 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -616,14 +616,14 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m } /// Get the next or prev cmdline completion match. The index of the match is set -/// in "p_findex" -static char *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, char *orig_save) +/// in "xp->xp_selected" +static char *get_next_or_prev_match(int mode, expand_T *xp, char *orig_save) { if (xp->xp_numfiles <= 0) { return NULL; } - int findex = *p_findex; + int findex = xp->xp_selected; if (mode == WILD_PREV) { if (findex == -1) { @@ -696,7 +696,7 @@ static char *get_next_or_prev_match(int mode, expand_T *xp, int *p_findex, char } else if (p_wmnu) { redraw_wildmenu(xp, xp->xp_numfiles, xp->xp_files, findex, cmd_showtail); } - *p_findex = findex; + xp->xp_selected = findex; return xstrdup(findex == -1 ? orig_save : xp->xp_files[findex]); } @@ -841,7 +841,6 @@ static char *find_longest_match(expand_T *xp, int options) char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) { char *ss = NULL; - static int findex; // TODO(vim): Move into expand_T static char *orig_save = NULL; // kept value of orig int orig_saved = false; @@ -849,15 +848,15 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) if (mode == WILD_NEXT || mode == WILD_PREV || mode == WILD_PAGEUP || mode == WILD_PAGEDOWN || mode == WILD_PUM_WANT) { - return get_next_or_prev_match(mode, xp, &findex, orig_save); + return get_next_or_prev_match(mode, xp, orig_save); } if (mode == WILD_CANCEL) { ss = xstrdup(orig_save ? orig_save : ""); } else if (mode == WILD_APPLY) { - ss = xstrdup(findex == -1 + ss = xstrdup(xp->xp_selected == -1 ? (orig_save ? orig_save : "") - : xp->xp_files[findex]); + : xp->xp_files[xp->xp_selected]); } // free old names @@ -871,10 +870,7 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) cmdline_pum_remove(); } } - // TODO(vim): Remove condition if "findex" is part of expand_T ? - if (mode != WILD_EXPAND_FREE && mode != WILD_ALL && mode != WILD_ALL_KEEP) { - findex = 0; - } + xp->xp_selected = 0; if (mode == WILD_FREE) { // only release file name return NULL; @@ -891,7 +887,7 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) // Find longest common part if (mode == WILD_LONGEST && xp->xp_numfiles > 0) { ss = find_longest_match(xp, options); - findex = -1; // next p_wc gets first one + xp->xp_selected = -1; // next p_wc gets first one } // Concatenate all matching names. Unless interrupted, this can be slow -- cgit From 694814cdd54ac245d1f4d2c28dce7e9132fcb616 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 07:29:49 +0800 Subject: vim-patch:9.0.1774: no support for custom cmdline completion (#24808) Problem: no support for custom cmdline completion Solution: Add new vimscript functions Add the following two functions: - getcmdcompltype() returns custom and customlist functions - getcompletion() supports both custom and customlist closes: vim/vim#12228 https://github.com/vim/vim/commit/92997dda789ad8061841128cbc99b15ec0374411 Co-authored-by: Shougo Matsushita --- src/nvim/cmdexpand.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index eb9394c8ff..9470f77ab5 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -3515,12 +3515,34 @@ void f_getcompletion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) ExpandInit(&xpc); xpc.xp_pattern = (char *)pattern; xpc.xp_pattern_len = strlen(xpc.xp_pattern); + xpc.xp_line = (char *)pattern; + xpc.xp_context = cmdcomplete_str_to_type(type); if (xpc.xp_context == EXPAND_NOTHING) { semsg(_(e_invarg2), type); return; } + if (xpc.xp_context == EXPAND_USER_DEFINED) { + // Must be "custom,funcname" pattern + if (strncmp(type, "custom,", 7) != 0) { + semsg(_(e_invarg2), type); + return; + } + + xpc.xp_arg = (char *)(type + 7); + } + + if (xpc.xp_context == EXPAND_USER_LIST) { + // Must be "customlist,funcname" pattern + if (strncmp(type, "customlist,", 11) != 0) { + semsg(_(e_invarg2), type); + return; + } + + xpc.xp_arg = (char *)(type + 11); + } + if (xpc.xp_context == EXPAND_MENUS) { set_context_in_menu_cmd(&xpc, "menu", xpc.xp_pattern, false); xpc.xp_pattern_len = strlen(xpc.xp_pattern); -- cgit From 3a7cb72dcbe4aaaed47999ab5afaf3d1cb8d4df8 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 20 Sep 2023 13:42:37 +0200 Subject: refactor(grid): properly namespace and separate stateful grid functions This is a step in an ongoing refactor where the "grid_puts" and "grid_put_linebuf" code paths will share more of the implementation (in particular for delta calculation, doublewidth and 'arabicshape' handling). But it also makes sense by its own as a cleanup, and is thus committed separately. Before this change many of the low level grid functions grid_puts, grid_fill etc could both be used in a standalone fashion but also as part of a batched line update which would be finally transmitted as a single grid_line call (via ui_line() ). This was initially useful to quickly refactor pre-existing vim code to use batched logic safely. However, this pattern is not really helpful for maintainable and newly written code, where the "grid" and "row" arguments are just needlessly repeated. This simplifies these calls to just use grid and row as specified in the initial grid_line_start(grid, row) call. This also makes the intent clear whether any grid_puts() call is actually part of a batch or not, which is better in the long run when more things get refactored to use effective (properly batched) updates. --- src/nvim/cmdexpand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 9470f77ab5..1e088ec7fc 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -601,10 +601,10 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m ScreenGrid *grid = (wild_menu_showing == WM_SCROLLED) ? &msg_grid_adj : &default_grid; - grid_puts(grid, buf, row, 0, attr); + grid_puts(grid, buf, -1, row, 0, attr); if (selstart != NULL && highlight) { *selend = NUL; - grid_puts(grid, selstart, row, selstart_col, HL_ATTR(HLF_WM)); + grid_puts(grid, selstart, -1, row, selstart_col, HL_ATTR(HLF_WM)); } grid_fill(grid, row, row + 1, clen, Columns, -- cgit From 3689bcb7631dd6921a3f82ccf891ec70b9748454 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 26 Sep 2023 14:01:57 +0200 Subject: refactor(grid): use batched updates for horizontal wildmenu --- src/nvim/cmdexpand.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 1e088ec7fc..4da6c3c8ba 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -598,17 +598,17 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m // Tricky: wildmenu can be drawn either over a status line, or at empty // scrolled space in the message output - ScreenGrid *grid = (wild_menu_showing == WM_SCROLLED) - ? &msg_grid_adj : &default_grid; + grid_line_start((wild_menu_showing == WM_SCROLLED) ? &msg_grid_adj : &default_grid, row); - grid_puts(grid, buf, -1, row, 0, attr); + grid_line_puts(0, buf, -1, attr); if (selstart != NULL && highlight) { *selend = NUL; - grid_puts(grid, selstart, -1, row, selstart_col, HL_ATTR(HLF_WM)); + grid_line_puts(selstart_col, selstart, -1, HL_ATTR(HLF_WM)); } - grid_fill(grid, row, row + 1, clen, Columns, - fillchar, fillchar, attr); + grid_line_fill(clen, Columns, fillchar, attr); + + grid_line_flush(false); } win_redraw_last_status(topframe); -- cgit From f91cd31d7d9d70006e0000592637d5d997eab52c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 21:46:39 +0200 Subject: refactor(messages): fold msg_outtrans_attr into msg_outtrans problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/cmdexpand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 4da6c3c8ba..290cc336b8 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -971,7 +971,7 @@ static void showmatches_oneline(expand_T *xp, char **matches, int numMatches, in int lastlen = 999; for (int j = linenr; j < numMatches; j += lines) { if (xp->xp_context == EXPAND_TAGS_LISTFILES) { - msg_outtrans_attr(matches[j], HL_ATTR(HLF_D)); + msg_outtrans(matches[j], HL_ATTR(HLF_D)); p = matches[j] + strlen(matches[j]) + 1; msg_advance(maxlen + 1); msg_puts(p); @@ -1013,7 +1013,7 @@ static void showmatches_oneline(expand_T *xp, char **matches, int numMatches, in isdir = false; p = SHOW_MATCH(j); } - lastlen = msg_outtrans_attr(p, isdir ? dir_attr : 0); + lastlen = msg_outtrans(p, isdir ? dir_attr : 0); } if (msg_col > 0) { // when not wrapped around msg_clr_eos(); -- cgit From e33269578b5bea2528cc48afc5b009eb8d4ad1d6 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 20 Sep 2023 10:08:05 +0200 Subject: refactor(grid): unify the two put-text-on-the-screen code paths The screen grid refactors will continue until morale improves. Jokes aside, this is quite a central installment in the series. Before this refactor, there were two fundamentally distinct codepaths for getting some text on the screen: - the win_line() -> grid_put_linebuf() -> ui_line() call chain used for buffer text, with linebuf_char as a temporary scratch buffer - the grid_line_start/grid_line_puts/grid_line_flush() -> ui_line() path used for every thing else: statuslines, messages and the command line. Here the grid->chars[] array itself doubles as a scratch buffer. With this refactor, the later family of functions still exist, however they now as well render to linebuf_char just like win_line() did, and grid_put_linebuf() is called in the end to calculate delta changes. This means we don't need any duplicate logic for delta calculations anymore. Later down the line, it will be possible to share more logic operating on this scratch buffer, like doing 'rightleft' reversal and arabic shaping as a post-processing step. --- src/nvim/cmdexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 290cc336b8..e5a97e28bb 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -608,7 +608,7 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m grid_line_fill(clen, Columns, fillchar, attr); - grid_line_flush(false); + grid_line_flush(); } win_redraw_last_status(topframe); -- cgit From b07fd0e988581f6b9c620bcfc27a068ee61242c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 15:52:27 +0200 Subject: refactor(message): msg_outtrans_long_len_attr -> msg_outtrans_long --- src/nvim/cmdexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 290cc336b8..bcb893022a 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -976,7 +976,7 @@ static void showmatches_oneline(expand_T *xp, char **matches, int numMatches, in msg_advance(maxlen + 1); msg_puts(p); msg_advance(maxlen + 3); - msg_outtrans_long_attr(p + 2, HL_ATTR(HLF_D)); + msg_outtrans_long(p + 2, HL_ATTR(HLF_D)); break; } for (int i = maxlen - lastlen; --i >= 0;) { -- cgit From dbfdb52ea867ccd900575bd7dd52a71add7a7346 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 06:30:10 +0800 Subject: vim-patch:9.0.1956: Custom completion skips orig cmdline if it invokes glob() (#25427) Problem: Custom cmdline completion skips original cmdline when pressing Ctrl-P at first match if completion function invokes glob(). Solution: Move orig_save into struct expand_T. closes: vim/vim#13216 https://github.com/vim/vim/commit/28a23602e8f88937645b8506b7915ecea6e09b18 --- src/nvim/cmdexpand.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index ed693092a1..1fb8018304 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -617,7 +617,7 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m /// Get the next or prev cmdline completion match. The index of the match is set /// in "xp->xp_selected" -static char *get_next_or_prev_match(int mode, expand_T *xp, char *orig_save) +static char *get_next_or_prev_match(int mode, expand_T *xp) { if (xp->xp_numfiles <= 0) { return NULL; @@ -677,14 +677,14 @@ static char *get_next_or_prev_match(int mode, expand_T *xp, char *orig_save) // When wrapping around, return the original string, set findex to -1. if (findex < 0) { - if (orig_save == NULL) { + if (xp->xp_orig == NULL) { findex = xp->xp_numfiles - 1; } else { findex = -1; } } if (findex >= xp->xp_numfiles) { - if (orig_save == NULL) { + if (xp->xp_orig == NULL) { findex = 0; } else { findex = -1; @@ -698,7 +698,7 @@ static char *get_next_or_prev_match(int mode, expand_T *xp, char *orig_save) } xp->xp_selected = findex; - return xstrdup(findex == -1 ? orig_save : xp->xp_files[findex]); + return xstrdup(findex == -1 ? xp->xp_orig : xp->xp_files[findex]); } /// Start the command-line expansion and get the matches. @@ -805,8 +805,8 @@ static char *find_longest_match(expand_T *xp, int options) /// Return NULL for failure. /// /// "orig" is the originally expanded string, copied to allocated memory. It -/// should either be kept in orig_save or freed. When "mode" is WILD_NEXT or -/// WILD_PREV "orig" should be NULL. +/// should either be kept in "xp->xp_orig" or freed. When "mode" is WILD_NEXT +/// or WILD_PREV "orig" should be NULL. /// /// Results are cached in xp->xp_files and xp->xp_numfiles, except when "mode" /// is WILD_EXPAND_FREE or WILD_ALL. @@ -841,21 +841,20 @@ static char *find_longest_match(expand_T *xp, int options) char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) { char *ss = NULL; - static char *orig_save = NULL; // kept value of orig int orig_saved = false; // first handle the case of using an old match if (mode == WILD_NEXT || mode == WILD_PREV || mode == WILD_PAGEUP || mode == WILD_PAGEDOWN || mode == WILD_PUM_WANT) { - return get_next_or_prev_match(mode, xp, orig_save); + return get_next_or_prev_match(mode, xp); } if (mode == WILD_CANCEL) { - ss = xstrdup(orig_save ? orig_save : ""); + ss = xstrdup(xp->xp_orig ? xp->xp_orig : ""); } else if (mode == WILD_APPLY) { ss = xstrdup(xp->xp_selected == -1 - ? (orig_save ? orig_save : "") + ? (xp->xp_orig ? xp->xp_orig : "") : xp->xp_files[xp->xp_selected]); } @@ -863,7 +862,7 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) if (xp->xp_numfiles != -1 && mode != WILD_ALL && mode != WILD_LONGEST) { FreeWild(xp->xp_numfiles, xp->xp_files); xp->xp_numfiles = -1; - XFREE_CLEAR(orig_save); + XFREE_CLEAR(xp->xp_orig); // The entries from xp_files may be used in the PUM, remove it. if (compl_match_array != NULL) { @@ -877,8 +876,8 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) } if (xp->xp_numfiles == -1 && mode != WILD_APPLY && mode != WILD_CANCEL) { - xfree(orig_save); - orig_save = orig; + xfree(xp->xp_orig); + xp->xp_orig = orig; orig_saved = true; ss = ExpandOne_start(mode, xp, str, options); @@ -927,7 +926,7 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) ExpandCleanup(xp); } - // Free "orig" if it wasn't stored in "orig_save". + // Free "orig" if it wasn't stored in "xp->xp_orig". if (!orig_saved) { xfree(orig); } @@ -952,6 +951,7 @@ void ExpandCleanup(expand_T *xp) FreeWild(xp->xp_numfiles, xp->xp_files); xp->xp_numfiles = -1; } + XFREE_CLEAR(xp->xp_orig); } /// Display one line of completion matches. Multiple matches are displayed in -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/cmdexpand.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 1fb8018304..19182b2d5c 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -4,7 +4,6 @@ // cmdexpand.c: functions for command-line completion #include -#include #include #include #include -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/cmdexpand.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 19182b2d5c..d733ffe6ab 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -48,6 +48,7 @@ #include "nvim/menu.h" #include "nvim/message.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/lang.h" #include "nvim/os/os.h" #include "nvim/path.h" -- cgit From f06af5e66981095f3244f67d1587ce7e9853eb4c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 08:13:58 +0800 Subject: vim-patch:9.0.1958: cannot complete option values Problem: cannot complete option values Solution: Add completion functions for several options Add cmdline tab-completion for setting string options Add tab-completion for setting string options on the cmdline using `:set=` (along with `:set+=` and `:set-=`). The existing tab completion for setting options currently only works when nothing is typed yet, and it only fills in with the existing value, e.g. when the user does `:set diffopt=` it will be completed to `set diffopt=internal,filler,closeoff` and nothing else. This isn't too useful as a user usually wants auto-complete to suggest all the possible values, such as 'iblank', or 'algorithm:patience'. For set= and set+=, this adds a new optional callback function for each option that can be invoked when doing completion. This allows for each option to have control over how completion works. For example, in 'diffopt', it will suggest the default enumeration, but if `algorithm:` is selected, it will further suggest different algorithm types like 'meyers' and 'patience'. When using set=, the existing option value will be filled in as the first choice to preserve the existing behavior. When using set+= this won't happen as it doesn't make sense. For flag list options (e.g. 'mouse' and 'guioptions'), completion will take into account existing typed values (and in the case of set+=, the existing option value) to make sure it doesn't suggest duplicates. For set-=, there is a new `ExpandSettingSubtract` function which will handle flag list and comma-separated options smartly, by only suggesting values that currently exist in the option. Note that Vim has some existing code that adds special handling for 'filetype', 'syntax', and misc dir options like 'backupdir'. This change preserves them as they already work, instead of converting to the new callback API for each option. closes: vim/vim#13182 https://github.com/vim/vim/commit/900894b09a95398dfc75599e9f0aa2ea25723384 Co-authored-by: Yee Cheng Chin --- src/nvim/cmdexpand.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index d733ffe6ab..3969162b6e 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -69,9 +69,6 @@ #include "nvim/vim.h" #include "nvim/window.h" -/// Type used by ExpandGeneric() -typedef char *(*CompleteListItemGetter)(expand_T *, int); - /// Type used by call_user_expand_func typedef void *(*user_expand_func_T)(const char *, int, typval_T *); @@ -107,6 +104,8 @@ static bool cmdline_fuzzy_completion_supported(const expand_T *const xp) && xp->xp_context != EXPAND_HELP && xp->xp_context != EXPAND_LUA && xp->xp_context != EXPAND_OLD_SETTING + && xp->xp_context != EXPAND_STRING_SETTING + && xp->xp_context != EXPAND_SETTING_SUBTRACT && xp->xp_context != EXPAND_OWNSYNTAX && xp->xp_context != EXPAND_PACKADD && xp->xp_context != EXPAND_RUNTIME @@ -2694,8 +2693,7 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM return OK; } if (xp->xp_context == EXPAND_OLD_SETTING) { - ExpandOldSetting(numMatches, matches); - return OK; + return ExpandOldSetting(numMatches, matches); } if (xp->xp_context == EXPAND_BUFFERS) { return ExpandBufnames(pat, numMatches, matches, options); @@ -2765,6 +2763,10 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM if (xp->xp_context == EXPAND_SETTINGS || xp->xp_context == EXPAND_BOOL_SETTINGS) { ret = ExpandSettings(xp, ®match, pat, numMatches, matches, fuzzy); + } else if (xp->xp_context == EXPAND_STRING_SETTING) { + ret = ExpandStringSetting(xp, ®match, numMatches, matches); + } else if (xp->xp_context == EXPAND_SETTING_SUBTRACT) { + ret = ExpandSettingSubtract(xp, ®match, numMatches, matches); } else if (xp->xp_context == EXPAND_MAPPINGS) { ret = ExpandMappings(pat, ®match, numMatches, matches); } else if (xp->xp_context == EXPAND_USER_DEFINED) { @@ -2788,9 +2790,8 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM /// program. Matching strings are copied into an array, which is returned. /// /// @param func returns a string from the list -static void ExpandGeneric(const char *const pat, expand_T *xp, regmatch_T *regmatch, - char ***matches, int *numMatches, CompleteListItemGetter func, - int escaped) +void ExpandGeneric(const char *const pat, expand_T *xp, regmatch_T *regmatch, char ***matches, + int *numMatches, CompleteListItemGetter func, bool escaped) { const bool fuzzy = cmdline_fuzzy_complete(pat); *matches = NULL; @@ -2863,6 +2864,7 @@ static void ExpandGeneric(const char *const pat, expand_T *xp, regmatch_T *regma // in the specified order. const bool sort_matches = !fuzzy && xp->xp_context != EXPAND_MENUNAMES + && xp->xp_context != EXPAND_STRING_SETTING && xp->xp_context != EXPAND_MENUS && xp->xp_context != EXPAND_SCRIPTNAMES; @@ -3221,8 +3223,7 @@ void globpath(char *path, char *file, garray_T *ga, int expand_options, bool dir char **p; int num_p = 0; - (void)ExpandFromContext(&xpc, buf, &p, &num_p, - WILD_SILENT | expand_options); + (void)ExpandFromContext(&xpc, buf, &p, &num_p, WILD_SILENT | expand_options); if (num_p > 0) { ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT | expand_options); -- cgit From 01c51a491330bd10202c73aff92c0978984c0692 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 1 Oct 2023 19:07:16 +0800 Subject: feat(completion): support completing more string options --- src/nvim/cmdexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 3969162b6e..893deadd13 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2598,7 +2598,7 @@ static int ExpandOther(char *pat, expand_T *xp, regmatch_T *rmp, char ***matches { EXPAND_MENUNAMES, get_menu_names, false, true }, { EXPAND_SYNTAX, get_syntax_name, true, true }, { EXPAND_SYNTIME, get_syntime_arg, true, true }, - { EXPAND_HIGHLIGHT, (ExpandFunc)get_highlight_name, true, false }, + { EXPAND_HIGHLIGHT, get_highlight_name, true, false }, { EXPAND_EVENTS, expand_get_event_name, true, false }, { EXPAND_AUGROUP, expand_get_augroup_name, true, false }, { EXPAND_SIGN, get_sign_name, true, true }, -- cgit From fd791db0ecebf5d5bf8922ba519f8dd4eef3c5e6 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 3 Oct 2023 00:19:30 +0200 Subject: fix: fix ASAN errors on clang 17 (#25469) --- src/nvim/cmdexpand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 893deadd13..c2469b6574 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -3078,7 +3078,7 @@ static int ExpandUserDefined(const char *const pat, expand_T *xp, regmatch_T *re *matches = NULL; *numMatches = 0; - char *const retstr = call_user_expand_func((user_expand_func_T)call_func_retstr, xp); + char *const retstr = call_user_expand_func(call_func_retstr, xp); if (retstr == NULL) { return FAIL; } @@ -3150,7 +3150,7 @@ static int ExpandUserList(expand_T *xp, char ***matches, int *numMatches) { *matches = NULL; *numMatches = 0; - list_T *const retlist = call_user_expand_func((user_expand_func_T)call_func_retlist, xp); + list_T *const retlist = call_user_expand_func(call_func_retlist, xp); if (retlist == NULL) { return FAIL; } -- cgit From c40a1c0f41ad2557b1e1e1850244eca2d895a07d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 10 Oct 2023 09:15:21 +0800 Subject: vim-patch:9.0.2009: cmdline-completion for comma-separated options wrong (#25569) Problem: cmdline-completion for comma-separated options wrong Solution: Fix command-line expansions for options with filenames with commas Fix command-line expansions for options with filenames with commas Cmdline expansion for option values that take a comma-separated list of file names is currently not handling file names with commas as the commas are not escaped. For such options, the commas in file names need to be escaped (to differentiate from a comma that delimit the list items). The escaped comma is unescaped in `copy_option_part()` during option parsing. Fix as follows: - Cmdline completion for option values with comma-separated file/folder names will not start a new match when seeing `\\,` and will instead consider it as one value. - File/folder regex matching will strip the `\\` when seeing `\\,` to make sure it can match the correct files/folders. - The expanded value will escape `,` with `\\,`, similar to how spaces are escaped to make sure the option value is correct on the cmdline. This fix also takes into account the fact that Win32 Vim handles file name escaping differently. Typing '\,' for a file name results in it being handled literally but in other platforms '\,' is interpreted as a simple ',' and commas need to be escaped using '\\,' instead. Also, make sure this new logic only applies to comma-separated options like 'path'. Non-list options like 'set makeprg=' and regular ex commands like `:edit ` do not require escaping and will continue to work. Also fix up documentation to be clearer. The original docs are slightly misleading in how it discusses triple slashes for 'tags'. closes: vim/vim#13303 related: vim/vim#13301 https://github.com/vim/vim/commit/54844857fd6933fa4f6678e47610c4b9c9f7a091 Co-authored-by: Yee Cheng Chin --- src/nvim/cmdexpand.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index c2469b6574..38be6573c8 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -156,8 +156,9 @@ static void wildescape(expand_T *xp, const char *str, int numfiles, char **files // and wildmatch characters, except '~'. for (int i = 0; i < numfiles; i++) { // for ":set path=" we need to escape spaces twice - if (xp->xp_backslash == XP_BS_THREE) { - p = vim_strsave_escaped(files[i], " "); + if (xp->xp_backslash & XP_BS_THREE) { + char *pat = (xp->xp_backslash & XP_BS_COMMA) ? " ," : " "; + p = vim_strsave_escaped(files[i], pat); xfree(files[i]); files[i] = p; #if defined(BACKSLASH_IN_FILENAME) @@ -165,6 +166,14 @@ static void wildescape(expand_T *xp, const char *str, int numfiles, char **files xfree(files[i]); files[i] = p; #endif + } else if (xp->xp_backslash & XP_BS_COMMA) { + if (vim_strchr(files[i], ',') != NULL) { + p = vim_strsave_escaped(files[i], ","); + if (p != NULL) { + xfree(files[i]); + files[i] = p; + } + } } #ifdef BACKSLASH_IN_FILENAME p = vim_strsave_fnameescape(files[i], vse_what); @@ -2440,15 +2449,23 @@ static int expand_files_and_dirs(expand_T *xp, char *pat, char ***matches, int * pat = xstrdup(pat); for (int i = 0; pat[i]; i++) { if (pat[i] == '\\') { - if (xp->xp_backslash == XP_BS_THREE + if (xp->xp_backslash & XP_BS_THREE && pat[i + 1] == '\\' && pat[i + 2] == '\\' && pat[i + 3] == ' ') { STRMOVE(pat + i, pat + i + 3); - } - if (xp->xp_backslash == XP_BS_ONE - && pat[i + 1] == ' ') { + } else if (xp->xp_backslash & XP_BS_ONE + && pat[i + 1] == ' ') { STRMOVE(pat + i, pat + i + 1); + } else if ((xp->xp_backslash & XP_BS_COMMA) + && pat[i + 1] == '\\' + && pat[i + 2] == ',') { + STRMOVE(pat + i, pat + i + 2); +#ifdef BACKSLASH_IN_FILENAME + } else if ((xp->xp_backslash & XP_BS_COMMA) + && pat[i + 1] == ',') { + STRMOVE(pat + i, pat + i + 1); +#endif } } } -- cgit From 468a3a14072a638865681dad88d3c3b31cf11e23 Mon Sep 17 00:00:00 2001 From: James <89495599+IAKOBVS@users.noreply.github.com> Date: Tue, 10 Oct 2023 21:03:55 +0700 Subject: refactor: use xstpcpy() instead of strcat() (#25572) --- src/nvim/cmdexpand.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 38be6573c8..aef471a17b 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -899,7 +899,6 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) // Concatenate all matching names. Unless interrupted, this can be slow // and the result probably won't be used. - // TODO(philix): use xstpcpy instead of strcat in a loop (ExpandOne) if (mode == WILD_ALL && xp->xp_numfiles > 0 && !got_int) { size_t len = 0; for (int i = 0; i < xp->xp_numfiles; i++) { @@ -914,18 +913,19 @@ char *ExpandOne(expand_T *xp, char *str, char *orig, int options, int mode) } ss = xmalloc(len); *ss = NUL; + char *ssp = ss; for (int i = 0; i < xp->xp_numfiles; i++) { if (i > 0) { if (xp->xp_prefix == XP_PREFIX_NO) { - STRCAT(ss, "no"); + ssp = xstpcpy(ssp, "no"); } else if (xp->xp_prefix == XP_PREFIX_INV) { - STRCAT(ss, "inv"); + ssp = xstpcpy(ssp, "inv"); } } - STRCAT(ss, xp->xp_files[i]); + ssp = xstpcpy(ssp, xp->xp_files[i]); if (i != xp->xp_numfiles - 1) { - STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); + ssp = xstpcpy(ssp, (options & WILD_USE_NL) ? "\n" : " "); } } } -- cgit From 75b488d3ef2e9dafba43c72487839aa78950d453 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 15 Oct 2023 17:52:08 +0800 Subject: vim-patch:9.0.2025: no cmdline completion for ++opt args (#25657) Problem: no cmdline completion for ++opt args Solution: Add cmdline completion for :e ++opt=arg and :terminal [++options] closes: vim/vim#13319 https://github.com/vim/vim/commit/989426be6e9ae23d2413943890206cbe15d9df38 Co-authored-by: Yee Cheng Chin --- src/nvim/cmdexpand.c | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index aef471a17b..bf0aa54bdd 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1567,6 +1567,20 @@ static void set_context_for_wildcard_arg(exarg_T *eap, const char *arg, bool use } } +/// Set the completion context for the "++opt=arg" argument. Always returns NULL. +static const char *set_context_in_argopt(expand_T *xp, const char *arg) +{ + char *p = vim_strchr(arg, '='); + if (p == NULL) { + xp->xp_pattern = (char *)arg; + } else { + xp->xp_pattern = p + 1; + } + + xp->xp_context = EXPAND_ARGOPT; + return NULL; +} + /// Set the completion context for the :filter command. Returns a pointer to the /// next command after the :filter command. static const char *set_context_in_filter_cmd(expand_T *xp, const char *arg) @@ -2238,13 +2252,23 @@ static const char *set_one_cmd_context(expand_T *xp, const char *buff) const char *arg = skipwhite(p); - // Skip over ++argopt argument - if ((ea.argt & EX_ARGOPT) && *arg != NUL && strncmp(arg, "++", 2) == 0) { - p = arg; - while (*p && !ascii_isspace(*p)) { - MB_PTR_ADV(p); + // Does command allow "++argopt" argument? + if (ea.argt & EX_ARGOPT) { + while (*arg != NUL && strncmp(arg, "++", 2) == 0) { + p = arg + 2; + while (*p && !ascii_isspace(*p)) { + MB_PTR_ADV(p); + } + + // Still touching the command after "++"? + if (*p == NUL) { + if (ea.argt & EX_ARGOPT) { + return set_context_in_argopt(xp, arg + 2); + } + } + + arg = skipwhite(p); } - arg = skipwhite(p); } if (ea.cmdidx == CMD_write || ea.cmdidx == CMD_update) { @@ -2786,6 +2810,8 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM ret = ExpandSettingSubtract(xp, ®match, numMatches, matches); } else if (xp->xp_context == EXPAND_MAPPINGS) { ret = ExpandMappings(pat, ®match, numMatches, matches); + } else if (xp->xp_context == EXPAND_ARGOPT) { + ret = expand_argopt(pat, xp, ®match, matches, numMatches); } else if (xp->xp_context == EXPAND_USER_DEFINED) { ret = ExpandUserDefined(pat, xp, ®match, matches, numMatches); } else { @@ -2883,7 +2909,8 @@ void ExpandGeneric(const char *const pat, expand_T *xp, regmatch_T *regmatch, ch && xp->xp_context != EXPAND_MENUNAMES && xp->xp_context != EXPAND_STRING_SETTING && xp->xp_context != EXPAND_MENUS - && xp->xp_context != EXPAND_SCRIPTNAMES; + && xp->xp_context != EXPAND_SCRIPTNAMES + && xp->xp_context != EXPAND_ARGOPT; // functions should be sorted to the end. const bool funcsort = xp->xp_context == EXPAND_EXPRESSION -- cgit From 3a44db510b1661eb92689e328d5191acfcb95433 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 11 Oct 2023 22:16:25 +0200 Subject: refactor(lang): reduce scope of HAVE_WORKING_LIBINTL #ifdefs A lot of code inside HAVE_WORKING_LIBINTL doesn't really depend on a "working libintl". For instance ex_language is also used for ":lang collate" and ":lang time". Also ":lang C" should not fail just because translations aren't available (it just means use the default text). References: https://github.com/neovim/neovim/pull/1 2d00ead2e57653b771354a564f9a760c2ce0d18e separate ifdefs for locale and gettext got merged together. https://github.com/neovim/neovim/commit/8253e29971c54310434ee93d987a99994769d717 Unmotivated switcharoo of get_mess_env() logic. If available, get_locale_val(LC_MESSAGES) is the correct implementation. --- src/nvim/cmdexpand.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index bf0aa54bdd..3cc9515fef 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2130,10 +2130,9 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa set_context_in_runtime_cmd(xp, arg); break; -#ifdef HAVE_WORKING_LIBINTL case CMD_language: return set_context_in_lang_cmd(xp, arg); -#endif + case CMD_profile: set_context_in_profile_cmd(xp, arg); break; @@ -2644,10 +2643,8 @@ static int ExpandOther(char *pat, expand_T *xp, regmatch_T *rmp, char ***matches { EXPAND_AUGROUP, expand_get_augroup_name, true, false }, { EXPAND_SIGN, get_sign_name, true, true }, { EXPAND_PROFILE, get_profile_name, true, true }, -#ifdef HAVE_WORKING_LIBINTL { EXPAND_LANGUAGE, get_lang_arg, true, false }, { EXPAND_LOCALES, get_locales, true, false }, -#endif { EXPAND_ENV_VARS, get_env_name, true, true }, { EXPAND_USER, get_users, true, false }, { EXPAND_ARGLIST, get_arglist_name, true, false }, -- cgit From 356a6728ac077fa7ec4f6fbc51eda33e025d86e0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 17 Oct 2023 21:42:34 +0800 Subject: vim-patch:9.0.2037: A few remaining cmdline completion issues with C-E/Y (#25686) Problem: A few remaining cmdline completion issues with C-E/Y Solution: Fix cmdline completion fuzzy/Ctrl-E/Ctrl-Y/options when not used at the end Fix cmdline completion fuzzy/Ctrl-E/Ctrl-Y/options when not used at the end A few places in the cmdline completion code only works properly when the user hits Tab (or 'wildchar') at the end of the cmdline, even though it's supposed to work even in the middle of the line. For fuzzy search, `:e ++ff`, and `:set hl=`, fix completion code to make sure to use `xp_pattern_len` instead of assuming the entire `xp_pattern` is the search pattern (since it contains texts after the cursor). Fix Ctrl-E / Ctrl-Y to not jump to the end when canceling/accepting a wildmenu completion. Also, make them work even when not using `set wildoptions+=pum` as there is no drawback to doing so. (Related issue where this was brought up: vim/vim#13331) closes: vim/vim#13362 https://github.com/vim/vim/commit/209ec90b9b9bd948d76511c9cd2b17f47a97afe6 Cherry-pick ex_getln.c changes from patch 9.0.2035. Co-authored-by: Yee Cheng Chin --- src/nvim/cmdexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 3cc9515fef..496c047a4a 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -267,7 +267,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) char *p1; if (cmdline_fuzzy_completion_supported(xp)) { // If fuzzy matching, don't modify the search string - p1 = xstrdup(xp->xp_pattern); + p1 = xstrnsave(xp->xp_pattern, xp->xp_pattern_len); } else { p1 = addstar(xp->xp_pattern, xp->xp_pattern_len, xp->xp_context); } -- cgit From cd63a9addd6e1114c3524fa041ece560550cfe7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 08:39:21 +0800 Subject: refactor: change some xstrndup() and xstrnsave() to xmemdupz() (#25959) When the given length is exactly the number of bytes to copy, xmemdupz() makes the intention clearer. --- src/nvim/cmdexpand.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 496c047a4a..6b83664339 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -804,7 +804,7 @@ static char *find_longest_match(expand_T *xp, int options) } } - return xstrndup(xp->xp_files[0], len); + return xmemdupz(xp->xp_files[0], len); } /// Do wildcard expansion on the string "str". @@ -3156,11 +3156,11 @@ static int ExpandUserDefined(const char *const pat, expand_T *xp, regmatch_T *re if (match) { if (!fuzzy) { - GA_APPEND(char *, &ga, xstrnsave(s, (size_t)(e - s))); + GA_APPEND(char *, &ga, xmemdupz(s, (size_t)(e - s))); } else { GA_APPEND(fuzmatch_str_T, &ga, ((fuzmatch_str_T){ .idx = ga.ga_len, - .str = xstrnsave(s, (size_t)(e - s)), + .str = xmemdupz(s, (size_t)(e - s)), .score = score, })); } -- cgit From 3294d654166ec26cac58037a0358b9f7ea75b2d6 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 10 Nov 2023 17:48:45 +0100 Subject: PVS fixes * build(PVS): exclude mpack and klib as they are external dependencies * build(PVS): suppress warning V601 See https://pvs-studio.com/en/docs/warnings/v601/ * fix(PVS/V009): add top-level message * fix(PVS/V547): expression 'p != NULL' is always true * fix(PVS/V547): expression '* termpp == NULL' is always false --- src/nvim/cmdexpand.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 6b83664339..51675b81bc 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -169,10 +169,8 @@ static void wildescape(expand_T *xp, const char *str, int numfiles, char **files } else if (xp->xp_backslash & XP_BS_COMMA) { if (vim_strchr(files[i], ',') != NULL) { p = vim_strsave_escaped(files[i], ","); - if (p != NULL) { - xfree(files[i]); - files[i] = p; - } + xfree(files[i]); + files[i] = p; } } #ifdef BACKSLASH_IN_FILENAME -- cgit From 8e58d37f2e15ac8540377148e55ed08a039aadb6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 11 Nov 2023 11:20:08 +0100 Subject: refactor: remove redundant casts --- src/nvim/cmdexpand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 51675b81bc..23948e16bb 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -2855,7 +2855,7 @@ void ExpandGeneric(const char *const pat, expand_T *xp, regmatch_T *regmatch, ch int score = 0; if (xp->xp_pattern[0] != NUL) { if (!fuzzy) { - match = vim_regexec(regmatch, str, (colnr_T)0); + match = vim_regexec(regmatch, str, 0); } else { score = fuzzy_match_str(str, pat); match = (score != 0); @@ -3141,7 +3141,7 @@ static int ExpandUserDefined(const char *const pat, expand_T *xp, regmatch_T *re int score = 0; if (xp->xp_pattern[0] != NUL) { if (!fuzzy) { - match = vim_regexec(regmatch, s, (colnr_T)0); + match = vim_regexec(regmatch, s, 0); } else { score = fuzzy_match_str(s, pat); match = (score != 0); -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/cmdexpand.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 23948e16bb..6a6cf9e4af 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // cmdexpand.c: functions for command-line completion #include -- cgit From 28f4f3c48498086307ed825d1761edb5789ca0e8 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 15:54:54 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment - use bool to represent boolean values --- src/nvim/cmdexpand.c | 54 +++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 6a6cf9e4af..cba06976c9 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -225,7 +225,6 @@ static void ExpandEscape(expand_T *xp, char *str, int numfiles, char **files, in int nextwild(expand_T *xp, int type, int options, bool escape) { CmdlineInfo *const ccline = get_cmdline_info(); - int i; char *p2; if (xp->xp_numfiles == -1) { @@ -249,7 +248,7 @@ int nextwild(expand_T *xp, int type, int options, bool escape) ui_flush(); } - i = (int)(xp->xp_pattern - ccline->cmdbuff); + int i = (int)(xp->xp_pattern - ccline->cmdbuff); assert(ccline->cmdpos >= i); xp->xp_pattern_len = (size_t)ccline->cmdpos - (size_t)i; @@ -444,11 +443,8 @@ static int wildmenu_match_len(expand_T *xp, char *s) /// @param matches list of matches static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int match, int showtail) { - int row; - char *buf; int len; int clen; // length in screen cells - int fillchar; int attr; int i; bool highlight = true; @@ -463,7 +459,7 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m return; } - buf = xmalloc((size_t)Columns * MB_MAXBYTES + 1); + char *buf = xmalloc((size_t)Columns * MB_MAXBYTES + 1); if (match == -1) { // don't show match but original text match = 0; @@ -511,7 +507,7 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m } } - fillchar = fillchar_status(&attr, curwin); + int fillchar = fillchar_status(&attr, curwin); if (first_match == 0) { *buf = NUL; @@ -570,7 +566,7 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m buf[len] = NUL; - row = cmdline_row - 1; + int row = cmdline_row - 1; if (row >= 0) { if (wild_menu_showing == 0 || wild_menu_showing == WM_LIST) { if (msg_scrolled > 0) { @@ -1032,7 +1028,7 @@ int showmatches(expand_T *xp, int wildmenu) CmdlineInfo *const ccline = get_cmdline_info(); int numMatches; char **matches; - int i, j; + int j; int maxlen; int lines; int columns; @@ -1041,8 +1037,8 @@ int showmatches(expand_T *xp, int wildmenu) if (xp->xp_numfiles == -1) { set_expand_context(xp); - i = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos, - &numMatches, &matches); + int i = expand_cmdline(xp, ccline->cmdbuff, ccline->cmdpos, + &numMatches, &matches); showtail = expand_showtail(xp); if (i != EXPAND_OK) { return i; @@ -1080,7 +1076,7 @@ int showmatches(expand_T *xp, int wildmenu) } else { // find the length of the longest file name maxlen = 0; - for (i = 0; i < numMatches; i++) { + for (int i = 0; i < numMatches; i++) { if (!showtail && (xp->xp_context == EXPAND_FILES || xp->xp_context == EXPAND_SHELLCMD || xp->xp_context == EXPAND_BUFFERS)) { @@ -1116,7 +1112,7 @@ int showmatches(expand_T *xp, int wildmenu) } // list the files line by line - for (i = 0; i < lines; i++) { + for (int i = 0; i < lines; i++) { showmatches_oneline(xp, matches, numMatches, lines, i, maxlen, showtail, attr); if (got_int) { got_int = false; @@ -1140,11 +1136,10 @@ int showmatches(expand_T *xp, int wildmenu) /// Return the tail of file name path "s", ignoring a trailing "/". static char *showmatches_gettail(char *s, bool eager) { - char *p; char *t = s; bool had_sep = false; - for (p = s; *p != NUL;) { + for (char *p = s; *p != NUL;) { if (vim_ispathsep(*p) #ifdef BACKSLASH_IN_FILENAME && !rem_backslash(p) @@ -1169,9 +1164,6 @@ static char *showmatches_gettail(char *s, bool eager) /// returned. static bool expand_showtail(expand_T *xp) { - char *s; - char *end; - // When not completing file names a "/" may mean something different. if (xp->xp_context != EXPAND_FILES && xp->xp_context != EXPAND_SHELLCMD @@ -1179,12 +1171,12 @@ static bool expand_showtail(expand_T *xp) return false; } - end = path_tail(xp->xp_pattern); + char *end = path_tail(xp->xp_pattern); if (end == xp->xp_pattern) { // there is no path separator return false; } - for (s = xp->xp_pattern; s < end; s++) { + for (char *s = xp->xp_pattern; s < end; s++) { // Skip escaped wildcards. Only when the backslash is not a path // separator, on DOS the '*' "path\*\file" must not be skipped. if (rem_backslash(s)) { @@ -1209,9 +1201,6 @@ char *addstar(char *fname, size_t len, int context) { char *retval; size_t i, j; - size_t new_len; - char *tail; - int ends_in_star; if (context != EXPAND_FILES && context != EXPAND_FILES_IN_PATH @@ -1236,7 +1225,7 @@ char *addstar(char *fname, size_t len, int context) || context == EXPAND_LUA) { retval = xstrnsave(fname, len); } else { - new_len = len + 2; // +2 for '^' at start, NUL at end + size_t new_len = len + 2; // +2 for '^' at start, NUL at end for (i = 0; i < len; i++) { if (fname[i] == '*' || fname[i] == '~') { new_len++; // '*' needs to be replaced by ".*" @@ -1304,8 +1293,8 @@ char *addstar(char *fname, size_t len, int context) // $ could be anywhere in the tail. // ` could be anywhere in the file name. // When the name ends in '$' don't add a star, remove the '$'. - tail = path_tail(retval); - ends_in_star = (len > 0 && retval[len - 1] == '*'); + char *tail = path_tail(retval); + int ends_in_star = (len > 0 && retval[len - 1] == '*'); #ifndef BACKSLASH_IN_FILENAME for (ssize_t k = (ssize_t)len - 2; k >= 0; k--) { if (retval[k] != '\\') { @@ -2981,18 +2970,16 @@ static void expand_shellcmd_onedir(char *buf, char *s, size_t l, char *pat, char static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int flagsarg) FUNC_ATTR_NONNULL_ALL { - char *pat; - int i; char *path = NULL; garray_T ga; char *buf = xmalloc(MAXPATHL); - char *s, *e; + char *e; int flags = flagsarg; bool did_curdir = false; // for ":set path=" and ":set tags=" halve backslashes for escaped space - pat = xstrdup(filepat); - for (i = 0; pat[i]; i++) { + char *pat = xstrdup(filepat); + for (int i = 0; pat[i]; i++) { if (pat[i] == '\\' && pat[i + 1] == ' ') { STRMOVE(pat + i, pat + i + 1); } @@ -3022,7 +3009,7 @@ static void expand_shellcmd(char *filepat, char ***matches, int *numMatches, int ga_init(&ga, (int)sizeof(char *), 10); hashtab_T found_ht; hash_init(&found_ht); - for (s = path;; s = e) { + for (char *s = path;; s = e) { e = vim_strchr(s, ENV_SEPCHAR); if (e == NULL) { e = s + strlen(s); @@ -3071,7 +3058,6 @@ static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T CmdlineInfo *const ccline = get_cmdline_info(); char keep = 0; typval_T args[4]; - char *pat = NULL; const sctx_T save_current_sctx = current_sctx; if (xp->xp_arg == NULL || xp->xp_arg[0] == '\0' || xp->xp_line == NULL) { @@ -3083,7 +3069,7 @@ static void *call_user_expand_func(user_expand_func_T user_expand_func, expand_T ccline->cmdbuff[ccline->cmdlen] = 0; } - pat = xstrnsave(xp->xp_pattern, xp->xp_pattern_len); + char *pat = xstrnsave(xp->xp_pattern, xp->xp_pattern_len); args[0].v_type = VAR_STRING; args[1].v_type = VAR_STRING; args[2].v_type = VAR_NUMBER; -- cgit From bb4b4576e384c71890b4df4fa4f1ae76fad3a59d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Nov 2023 10:55:54 +0800 Subject: refactor: iwyu (#26062) --- src/nvim/cmdexpand.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index cba06976c9..487a3ec482 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -7,7 +7,6 @@ #include #include -#include "auto/config.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/arglist.h" @@ -50,7 +49,6 @@ #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/popupmenu.h" -#include "nvim/pos.h" #include "nvim/profile.h" #include "nvim/regexp.h" #include "nvim/runtime.h" -- cgit From ac1113ded5f8f09dd99a9894d7a7e795626fb728 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 13 Nov 2023 23:40:37 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment --- src/nvim/cmdexpand.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 487a3ec482..1f97214401 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -1198,7 +1198,6 @@ char *addstar(char *fname, size_t len, int context) FUNC_ATTR_NONNULL_RET { char *retval; - size_t i, j; if (context != EXPAND_FILES && context != EXPAND_FILES_IN_PATH @@ -1224,7 +1223,7 @@ char *addstar(char *fname, size_t len, int context) retval = xstrnsave(fname, len); } else { size_t new_len = len + 2; // +2 for '^' at start, NUL at end - for (i = 0; i < len; i++) { + for (size_t i = 0; i < len; i++) { if (fname[i] == '*' || fname[i] == '~') { new_len++; // '*' needs to be replaced by ".*" // '~' needs to be replaced by "\~" @@ -1243,8 +1242,8 @@ char *addstar(char *fname, size_t len, int context) retval = xmalloc(new_len); { retval[0] = '^'; - j = 1; - for (i = 0; i < len; i++, j++) { + size_t j = 1; + for (size_t i = 0; i < len; i++, j++) { // Skip backslash. But why? At least keep it for custom // expansion. if (context != EXPAND_USER_DEFINED -- cgit From 6361806aa28edca55ad3316a58bc3e936df9c0eb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 26 Nov 2023 22:58:52 +0800 Subject: refactor: move garray_T to garray_defs.h (#26227) --- src/nvim/cmdexpand.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 1f97214401..9b40a17d20 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -26,6 +26,7 @@ #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" #include "nvim/garray.h" +#include "nvim/garray_defs.h" #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" -- cgit From 38a20dd89f91c45ec8589bf1c50d50732882d38a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 20:58:37 +0800 Subject: build(IWYU): replace most private mappings with pragmas (#26247) --- src/nvim/cmdexpand.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 9b40a17d20..7a6cc02cb8 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -46,6 +46,7 @@ #include "nvim/message.h" #include "nvim/option.h" #include "nvim/option_vars.h" +#include "nvim/os/fs.h" #include "nvim/os/lang.h" #include "nvim/os/os.h" #include "nvim/path.h" -- cgit From 40139738eb479d0913ec6ce751ca5adfa50ad8c3 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 26 Nov 2023 21:36:02 +0100 Subject: build: enable IWYU on mac --- src/nvim/cmdexpand.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 7a6cc02cb8..58ec3d31bf 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/cmdexpand.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 58ec3d31bf..71f0afe604 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -26,6 +26,7 @@ #include "nvim/ex_cmds.h" #include "nvim/ex_docmd.h" #include "nvim/ex_getln.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/garray_defs.h" #include "nvim/getchar.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/cmdexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 71f0afe604..57d79dc420 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -62,7 +62,7 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/tag.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/usercmd.h" #include "nvim/vim.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/cmdexpand.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 57d79dc420..275b284392 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -11,7 +11,7 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/arglist.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/charset.h" @@ -40,7 +40,7 @@ #include "nvim/keycodes.h" #include "nvim/log.h" #include "nvim/lua/executor.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mapping.h" #include "nvim/mbyte.h" #include "nvim/memory.h" @@ -65,7 +65,7 @@ #include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/usercmd.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/window.h" /// Type used by call_user_expand_func -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/cmdexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cmdexpand.c') diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 275b284392..367b86ec55 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -35,7 +35,7 @@ #include "nvim/grid.h" #include "nvim/hashtab.h" #include "nvim/help.h" -#include "nvim/highlight_defs.h" +#include "nvim/highlight.h" #include "nvim/highlight_group.h" #include "nvim/keycodes.h" #include "nvim/log.h" -- cgit