From fb1edb2f5728d74ae811c6ab32395598cea5609b Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/usercmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 5b2101587f..9cc9fb5588 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -531,7 +531,7 @@ static void uc_list(char *name, size_t name_len) } } - msg_outtrans_special((char_u *)cmd->uc_rep, false, + msg_outtrans_special(cmd->uc_rep, false, name_len == 0 ? Columns - 47 : 0); if (p_verbose > 0) { last_set_msg(cmd->uc_script_ctx); -- cgit From 56bf026deac8eddb1abc8e1d46fde992cfc67ac2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 20:25:34 +0800 Subject: vim-patch:9.0.0346: :horizontal modifier not fully supported Problem: :horizontal modifier not fully supported. Solution: Also use :horizontal for completion and user commands. (closes vim/vim#11025) https://github.com/vim/vim/commit/d3de178e5352fedf0f30b979f46a2fcbca24ea40 --- src/nvim/usercmd.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 9cc9fb5588..3726273d28 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -1247,6 +1247,10 @@ size_t add_win_cmd_modifers(char *buf, const cmdmod_T *cmod, bool *multi_mods) if (cmod->cmod_split & WSP_VERT) { result += add_cmd_modifier(buf, "vertical", multi_mods); } + // :horizontal + if (cmod->cmod_split & WSP_HOR) { + result += add_cmd_modifier(buf, "horizontal", multi_mods); + } return result; } -- cgit From c5322e752e9e568de907f7a1ef733bbfe342140c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/usercmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 3726273d28..6d6ba2466e 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -280,7 +280,7 @@ char *get_user_commands(expand_T *xp FUNC_ATTR_UNUSED, int idx) char *name = USER_CMD(idx)->uc_name; for (int i = 0; i < buf->b_ucmds.ga_len; i++) { - if (STRCMP(name, USER_CMD_GA(&buf->b_ucmds, i)->uc_name) == 0) { + if (strcmp(name, USER_CMD_GA(&buf->b_ucmds, i)->uc_name) == 0) { // global command is overruled by buffer-local one return ""; } @@ -1006,7 +1006,7 @@ void ex_delcommand(exarg_T *eap) for (;;) { for (i = 0; i < gap->ga_len; i++) { cmd = USER_CMD_GA(gap, i); - res = STRCMP(arg, cmd->uc_name); + res = strcmp(arg, cmd->uc_name); if (res <= 0) { break; } -- cgit From 3ff46544c9872b4161fd098569c30b55fe3abd36 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/usercmd.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 6d6ba2466e..c3cf0b6df8 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -435,7 +435,7 @@ static void uc_list(char *name, size_t name_len) } msg_outtrans_attr(cmd->uc_name, HL_ATTR(HLF_D)); - len = (int)STRLEN(cmd->uc_name) + 4; + len = (int)strlen(cmd->uc_name) + 4; do { msg_putchar(' '); @@ -476,14 +476,14 @@ static void uc_list(char *name, size_t name_len) // -count=N snprintf((char *)IObuff + len, IOSIZE, "%" PRId64 "c", (int64_t)cmd->uc_def); - len += (int)STRLEN(IObuff + len); + len += (int)strlen(IObuff + len); } else if (a & EX_DFLALL) { IObuff[len++] = '%'; } else if (cmd->uc_def >= 0) { // -range=N snprintf((char *)IObuff + len, IOSIZE, "%" PRId64 "", (int64_t)cmd->uc_def); - len += (int)STRLEN(IObuff + len); + len += (int)strlen(IObuff + len); } else { IObuff[len++] = '.'; } @@ -498,7 +498,7 @@ static void uc_list(char *name, size_t name_len) if (addr_type_complete[j].expand != ADDR_LINES && addr_type_complete[j].expand == cmd->uc_addr_type) { STRCPY(IObuff + len, addr_type_complete[j].shortname); - len += (int)STRLEN(IObuff + len); + len += (int)strlen(IObuff + len); break; } } @@ -511,7 +511,7 @@ static void uc_list(char *name, size_t name_len) char *cmd_compl = get_command_complete(cmd->uc_compl); if (cmd_compl != NULL) { STRCPY(IObuff + len, get_command_complete(cmd->uc_compl)); - len += (int)STRLEN(IObuff + len); + len += (int)strlen(IObuff + len); } do { @@ -559,7 +559,7 @@ int parse_addr_type_arg(char *value, int vallen, cmd_addr_T *addr_type_arg) int i, a, b; for (i = 0; addr_type_complete[i].expand != ADDR_NONE; i++) { - a = (int)STRLEN(addr_type_complete[i].name) == vallen; + a = (int)strlen(addr_type_complete[i].name) == vallen; b = STRNCMP(value, addr_type_complete[i].name, vallen) == 0; if (a && b) { *addr_type_arg = addr_type_complete[i].expand; @@ -607,7 +607,7 @@ int parse_compl_arg(const char *value, int vallen, int *complp, uint32_t *argt, if (get_command_complete(i) == NULL) { continue; } - if ((int)STRLEN(command_complete[i]) == valend + if ((int)strlen(command_complete[i]) == valend && STRNCMP(value, command_complete[i], valend) == 0) { *complp = i; if (i == EXPAND_BUFFERS) { @@ -816,7 +816,7 @@ int uc_add_command(char *name, size_t name_len, const char *rep, uint32_t argt, char *rep_buf = NULL; garray_T *gap; - replace_termcodes(rep, STRLEN(rep), &rep_buf, 0, NULL, CPO_TO_CPO_FLAGS); + replace_termcodes(rep, strlen(rep), &rep_buf, 0, NULL, CPO_TO_CPO_FLAGS); if (rep_buf == NULL) { // Can't replace termcodes - try using the string as is rep_buf = xstrdup(rep); @@ -837,7 +837,7 @@ int uc_add_command(char *name, size_t name_len, const char *rep, uint32_t argt, size_t len; cmd = USER_CMD_GA(gap, i); - len = STRLEN(cmd->uc_name); + len = strlen(cmd->uc_name); cmp = STRNCMP(name, cmd->uc_name, name_len); if (cmp == 0) { if (name_len < len) { @@ -1198,7 +1198,7 @@ static char *uc_split_args(char *arg, char **args, size_t *arglens, size_t argc, static size_t add_cmd_modifier(char *buf, char *mod_str, bool *multi_mods) { - size_t result = STRLEN(mod_str); + size_t result = strlen(mod_str); if (*multi_mods) { result++; } @@ -1405,13 +1405,13 @@ static size_t uc_check_code(char *code, size_t len, char *buf, ucmd_T *cmd, exar switch (quote) { case 0: // No quoting, no splitting - result = STRLEN(eap->arg); + result = strlen(eap->arg); if (buf != NULL) { STRCPY(buf, eap->arg); } break; case 1: // Quote, but don't split - result = STRLEN(eap->arg) + 2; + result = strlen(eap->arg) + 2; for (p = eap->arg; *p; p++) { if (*p == '\\' || *p == '"') { result++; @@ -1475,7 +1475,7 @@ static size_t uc_check_code(char *code, size_t len, char *buf, ucmd_T *cmd, exar size_t num_len; snprintf(num_buf, sizeof(num_buf), "%" PRId64, (int64_t)num); - num_len = STRLEN(num_buf); + num_len = strlen(num_buf); result = num_len; if (quote) { @@ -1637,7 +1637,7 @@ int do_ucmd(exarg_T *eap, bool preview) break; } - totlen += STRLEN(p); // Add on the trailing characters + totlen += strlen(p); // Add on the trailing characters buf = xmalloc(totlen + 1); } -- cgit From 288208257c8d6b3c8dcce7ee6c7b6c7bb7bafb27 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 8 Oct 2022 15:48:07 +0100 Subject: feat(cscope)!: remove --- src/nvim/usercmd.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index c3cf0b6df8..0e045c773f 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -46,7 +46,6 @@ static const char *command_complete[] = [EXPAND_COLORS] = "color", [EXPAND_COMMANDS] = "command", [EXPAND_COMPILER] = "compiler", - [EXPAND_CSCOPE] = "cscope", [EXPAND_USER_DEFINED] = "custom", [EXPAND_USER_LIST] = "customlist", [EXPAND_USER_LUA] = "", -- cgit From 4d896be681d9b93ebe34cce38a5e787cd0332261 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 18 Oct 2022 20:46:42 +0800 Subject: vim-patch:9.0.0786: user command does not get number from :tab modifier (#20716) Problem: User command does not get number from :tab modifier. Solution: Include the number. (closes vim/vim#11393, closes vim/vim#6901) https://github.com/vim/vim/commit/208567e9d744ef7b89bed1f62e951ae4ee2f6f5f --- src/nvim/usercmd.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 0e045c773f..4c2ea75047 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -1236,8 +1236,18 @@ size_t add_win_cmd_modifers(char *buf, const cmdmod_T *cmod, bool *multi_mods) // :tab if (cmod->cmod_tab > 0) { - result += add_cmd_modifier(buf, "tab", multi_mods); + int tabnr = cmod->cmod_tab - 1; + if (tabnr == tabpage_index(curtab)) { + // For compatibility, don't add a tabpage number if it is the same + // as the default number for :tab. + result += add_cmd_modifier(buf, "tab", multi_mods); + } else { + char tab_buf[NUMBUFLEN + 3]; + snprintf(tab_buf, sizeof(tab_buf), "%dtab", tabnr); + result += add_cmd_modifier(buf, tab_buf, multi_mods); + } } + // :topleft if (cmod->cmod_split & WSP_TOP) { result += add_cmd_modifier(buf, "topleft", multi_mods); @@ -1307,7 +1317,7 @@ size_t uc_mods(char *buf, const cmdmod_T *cmod, bool quote) result += add_cmd_modifier(buf, "verbose", &multi_mods); } else { char verbose_buf[NUMBUFLEN]; - snprintf(verbose_buf, NUMBUFLEN, "%dverbose", verbose_value); + snprintf(verbose_buf, sizeof(verbose_buf), "%dverbose", verbose_value); result += add_cmd_modifier(buf, verbose_buf, &multi_mods); } } -- cgit From 784e498c4a9c1f03266ced5ec3f55c3a6c94b80d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 21 Oct 2022 14:47:44 +0200 Subject: refactor: clang-tidy fixes to silence clangd warning (#20683) * refactor: readability-uppercase-literal-suffix * refactor: readability-named-parameter * refactor: bugprone-suspicious-string-compare * refactor: google-readability-casting * refactor: readability-redundant-control-flow * refactor: bugprone-too-small-loop-variable * refactor: readability-non-const-parameter * refactor: readability-avoid-const-params-in-decls * refactor: google-readability-todo * refactor: readability-inconsistent-declaration-parameter-name * refactor: bugprone-suspicious-missing-comma * refactor: remove noisy or slow warnings --- src/nvim/usercmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 4c2ea75047..1cb3b18345 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -1077,7 +1077,7 @@ bool uc_split_args_iter(const char *arg, size_t arglen, size_t *end, char *buf, } /// split and quote args for -static char *uc_split_args(char *arg, char **args, size_t *arglens, size_t argc, size_t *lenp) +static char *uc_split_args(char *arg, char **args, const size_t *arglens, size_t argc, size_t *lenp) { char *buf; char *p; -- cgit From b05d1943f063c382ea96b76d250877bc58297314 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 1 Nov 2022 15:39:49 +0100 Subject: build(lint): remove clint.py rules for braces #20880 Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. See also https://github.com/neovim/neovim/pull/18563 --- src/nvim/usercmd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 1cb3b18345..408cdc93a7 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -36,8 +36,7 @@ static char e_no_such_user_defined_command_in_current_buffer_str[] /// List of names for completion for ":command" with the EXPAND_ flag. /// Must be alphabetical for completion. -static const char *command_complete[] = -{ +static const char *command_complete[] = { [EXPAND_ARGLIST] = "arglist", [EXPAND_AUGROUP] = "augroup", [EXPAND_BEHAVE] = "behave", @@ -86,8 +85,7 @@ static struct { cmd_addr_T expand; char *name; char *shortname; -} addr_type_complete[] = -{ +} addr_type_complete[] = { { ADDR_ARGUMENTS, "arguments", "arg" }, { ADDR_LINES, "lines", "line" }, { ADDR_LOADED_BUFFERS, "loaded_buffers", "load" }, -- cgit From 4716a578ae0c3516d685495bb55e40c939a4ac87 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 23 Oct 2022 10:17:45 +0200 Subject: docs: fix typos --- src/nvim/usercmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 408cdc93a7..bed4d55d4e 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -1215,7 +1215,7 @@ static size_t add_cmd_modifier(char *buf, char *mod_str, bool *multi_mods) /// was added. /// /// @return the number of bytes added -size_t add_win_cmd_modifers(char *buf, const cmdmod_T *cmod, bool *multi_mods) +size_t add_win_cmd_modifiers(char *buf, const cmdmod_T *cmod, bool *multi_mods) { size_t result = 0; @@ -1320,7 +1320,7 @@ size_t uc_mods(char *buf, const cmdmod_T *cmod, bool quote) } } // flags from cmod->cmod_split - result += add_win_cmd_modifers(buf, cmod, &multi_mods); + result += add_win_cmd_modifiers(buf, cmod, &multi_mods); if (quote && buf != NULL) { buf += result - 2; -- cgit From 731cdde28ea8d48cc23ba2752a08c261c87eee92 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 22 Oct 2022 12:36:38 +0200 Subject: refactor: fix clang-tidy warnings Enable and fix bugprone-misplaced-widening-cast warning. Fix some modernize-macro-to-enum and readability-else-after-return warnings, but don't enable them. While the warnings can be useful, they are in general too noisy to enable. --- src/nvim/usercmd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index bed4d55d4e..21a433d855 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -343,9 +343,8 @@ static char *get_command_complete(int arg) { if (arg >= (int)(ARRAY_SIZE(command_complete))) { return NULL; - } else { - return (char *)command_complete[arg]; } + return (char *)command_complete[arg]; } /// Function given to ExpandGeneric() to obtain the list of values for -complete. @@ -357,9 +356,8 @@ char *get_user_cmd_complete(expand_T *xp, int idx) char *cmd_compl = get_command_complete(idx); if (cmd_compl == NULL) { return ""; - } else { - return cmd_compl; } + return cmd_compl; } int cmdcomplete_str_to_type(const char *complete_str) -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/usercmd.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 21a433d855..ebb7c9d6ca 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -6,19 +6,34 @@ #include #include #include -#include +#include #include +#include "auto/config.h" +#include "lauxlib.h" +#include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii.h" +#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/eval.h" #include "nvim/ex_docmd.h" #include "nvim/garray.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/highlight_defs.h" +#include "nvim/keycodes.h" #include "nvim/lua/executor.h" +#include "nvim/macros.h" +#include "nvim/mbyte.h" +#include "nvim/memory.h" +#include "nvim/message.h" +#include "nvim/option_defs.h" #include "nvim/os/input.h" #include "nvim/runtime.h" +#include "nvim/strings.h" #include "nvim/usercmd.h" +#include "nvim/vim.h" #include "nvim/window.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit From 3b96ccf7d35be90e49029dec76344d3d92ad91dc Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/usercmd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index ebb7c9d6ca..ca5307fe24 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -406,7 +406,7 @@ static void uc_list(char *name, size_t name_len) // Skip commands which don't match the requested prefix and // commands filtered out. - if (STRNCMP(name, cmd->uc_name, name_len) != 0 + if (strncmp(name, cmd->uc_name, name_len) != 0 || message_filtered(cmd->uc_name)) { continue; } @@ -570,7 +570,7 @@ int parse_addr_type_arg(char *value, int vallen, cmd_addr_T *addr_type_arg) for (i = 0; addr_type_complete[i].expand != ADDR_NONE; i++) { a = (int)strlen(addr_type_complete[i].name) == vallen; - b = STRNCMP(value, addr_type_complete[i].name, vallen) == 0; + b = strncmp(value, addr_type_complete[i].name, (size_t)vallen) == 0; if (a && b) { *addr_type_arg = addr_type_complete[i].expand; break; @@ -618,7 +618,7 @@ int parse_compl_arg(const char *value, int vallen, int *complp, uint32_t *argt, continue; } if ((int)strlen(command_complete[i]) == valend - && STRNCMP(value, command_complete[i], valend) == 0) { + && strncmp(value, command_complete[i], (size_t)valend) == 0) { *complp = i; if (i == EXPAND_BUFFERS) { *argt |= EX_BUFNAME; @@ -848,7 +848,7 @@ int uc_add_command(char *name, size_t name_len, const char *rep, uint32_t argt, cmd = USER_CMD_GA(gap, i); len = strlen(cmd->uc_name); - cmp = STRNCMP(name, cmd->uc_name, name_len); + cmp = strncmp(name, cmd->uc_name, name_len); if (cmp == 0) { if (name_len < len) { cmp = -1; @@ -964,7 +964,7 @@ void ex_command(exarg_T *eap) uc_list(name, name_len); } else if (!ASCII_ISUPPER(*name)) { emsg(_("E183: User defined commands must start with an uppercase letter")); - } else if (name_len <= 4 && STRNCMP(name, "Next", name_len) == 0) { + } else if (name_len <= 4 && strncmp(name, "Next", name_len) == 0) { emsg(_("E841: Reserved name, cannot be used for user defined command")); } else if (compl > 0 && (argt & EX_EXTRA) == 0) { emsg(_(e_complete_used_without_allowing_arguments)); @@ -1007,7 +1007,7 @@ void ex_delcommand(exarg_T *eap) const char *arg = eap->arg; bool buffer_only = false; - if (STRNCMP(arg, "-buffer", 7) == 0 && ascii_iswhite(arg[7])) { + if (strncmp(arg, "-buffer", 7) == 0 && ascii_iswhite(arg[7])) { buffer_only = true; arg = skipwhite(arg + 7); } -- cgit From ff62d761938e72129f6ba7ed2c2d56455444ebe7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 20 Dec 2022 05:24:03 +0800 Subject: vim-patch:9.0.1079: leaking memory when defining a user command fails Problem: Leaking memory when defining a user command fails. Solution: Free "compl_arg" when needed. (closes vim/vim#11726) https://github.com/vim/vim/commit/33e543038b84af7557ab9ecff500fc4ab98dd2a3 --- src/nvim/usercmd.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index ca5307fe24..bc47b1b807 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -943,7 +943,7 @@ void ex_command(exarg_T *eap) end = skiptowhite(p); if (uc_scan_attr(p, (size_t)(end - p), &argt, &def, &flags, &compl, (char_u **)&compl_arg, &addr_type_arg) == FAIL) { - return; + goto theend; } p = skipwhite(end); } @@ -953,7 +953,7 @@ void ex_command(exarg_T *eap) end = uc_validate_name(name); if (!end) { emsg(_("E182: Invalid command name")); - return; + goto theend; } name_len = (size_t)(end - name); @@ -971,7 +971,12 @@ void ex_command(exarg_T *eap) } else { uc_add_command(name, name_len, p, argt, def, flags, compl, compl_arg, LUA_NOREF, LUA_NOREF, addr_type_arg, LUA_NOREF, eap->forceit); + + return; // success } + +theend: + xfree(compl_arg); } /// ":comclear" -- cgit From 50f03773f4b9f4638489ccfd0503dc9e39e5de78 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:37:34 +0100 Subject: refactor: replace char_u with char 18 (#21237) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/usercmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index bc47b1b807..0109c048ec 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -484,14 +484,14 @@ static void uc_list(char *name, size_t name_len) if (a & (EX_RANGE | EX_COUNT)) { if (a & EX_COUNT) { // -count=N - snprintf((char *)IObuff + len, IOSIZE, "%" PRId64 "c", + snprintf(IObuff + len, IOSIZE, "%" PRId64 "c", (int64_t)cmd->uc_def); len += (int)strlen(IObuff + len); } else if (a & EX_DFLALL) { IObuff[len++] = '%'; } else if (cmd->uc_def >= 0) { // -range=N - snprintf((char *)IObuff + len, IOSIZE, "%" PRId64 "", + snprintf(IObuff + len, IOSIZE, "%" PRId64 "", (int64_t)cmd->uc_def); len += (int)strlen(IObuff + len); } else { @@ -529,7 +529,7 @@ static void uc_list(char *name, size_t name_len) } while (len < 25 - over); IObuff[len] = '\0'; - msg_outtrans((char *)IObuff); + msg_outtrans(IObuff); if (cmd->uc_luaref != LUA_NOREF) { char *fn = nlua_funcref_str(cmd->uc_luaref); -- cgit From ef6750332008b7b61dde9eeab0da454bf3323ebb Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 10 Jan 2023 03:28:01 +0100 Subject: refactor: replace char_u with char 19 (#21241) * refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/usercmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 0109c048ec..e175bd5b61 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -653,7 +653,7 @@ int parse_compl_arg(const char *value, int vallen, int *complp, uint32_t *argt, } static int uc_scan_attr(char *attr, size_t len, uint32_t *argt, long *def, int *flags, int *complp, - char_u **compl_arg, cmd_addr_T *addr_type_arg) + char **compl_arg, cmd_addr_T *addr_type_arg) FUNC_ATTR_NONNULL_ALL { char *p; @@ -764,7 +764,7 @@ invalid_count: return FAIL; } - if (parse_compl_arg(val, (int)vallen, complp, argt, (char **)compl_arg) + if (parse_compl_arg(val, (int)vallen, complp, argt, compl_arg) == FAIL) { return FAIL; } @@ -941,7 +941,7 @@ void ex_command(exarg_T *eap) while (*p == '-') { p++; end = skiptowhite(p); - if (uc_scan_attr(p, (size_t)(end - p), &argt, &def, &flags, &compl, (char_u **)&compl_arg, + if (uc_scan_attr(p, (size_t)(end - p), &argt, &def, &flags, &compl, &compl_arg, &addr_type_arg) == FAIL) { goto theend; } -- cgit From e89c39d6f016a4140293755250e968e839009617 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 14 Jan 2023 08:58:28 +0100 Subject: refactor: replace char_u with char 21 (#21779) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/usercmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index e175bd5b61..f8ed190fb2 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -1608,10 +1608,10 @@ int do_ucmd(exarg_T *eap, bool preview) end = vim_strchr(start + 1, '>'); } if (buf != NULL) { - for (ksp = p; *ksp != NUL && (char_u)(*ksp) != K_SPECIAL; ksp++) {} - if ((char_u)(*ksp) == K_SPECIAL + for (ksp = p; *ksp != NUL && (uint8_t)(*ksp) != K_SPECIAL; ksp++) {} + if ((uint8_t)(*ksp) == K_SPECIAL && (start == NULL || ksp < start || end == NULL) - && ((char_u)ksp[1] == KS_SPECIAL && ksp[2] == KE_FILLER)) { + && ((uint8_t)ksp[1] == KS_SPECIAL && ksp[2] == KE_FILLER)) { // K_SPECIAL has been put in the buffer as K_SPECIAL // KS_SPECIAL KE_FILLER, like for mappings, but // do_cmdline() doesn't handle that, so convert it back. -- cgit From 686168c648e46986088f677028c2b245f6b78303 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 Jan 2023 22:28:21 +0800 Subject: vim-patch:8.2.4398: some command completion functions are too long (#21799) Problem: Some command completion functions are too long. Solution: Refactor code into separate functions. Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#9785) https://github.com/vim/vim/commit/b31aec3b9387ed12677dca09069c3ae98c6c7447 Co-authored-by: Yegappan Lakshmanan --- src/nvim/usercmd.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index f8ed190fb2..883d7321d2 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -25,8 +25,10 @@ #include "nvim/keycodes.h" #include "nvim/lua/executor.h" #include "nvim/macros.h" +#include "nvim/mapping.h" #include "nvim/mbyte.h" #include "nvim/memory.h" +#include "nvim/menu.h" #include "nvim/message.h" #include "nvim/option_defs.h" #include "nvim/os/input.h" @@ -220,6 +222,7 @@ char *find_ucmd(exarg_T *eap, char *p, int *full, expand_T *xp, int *complp) return p; } +/// Set completion context for :command const char *set_context_in_user_cmd(expand_T *xp, const char *arg_in) { const char *arg = arg_in; @@ -271,6 +274,47 @@ const char *set_context_in_user_cmd(expand_T *xp, const char *arg_in) return (const char *)skipwhite(p); } +/// Set the completion context for the argument of a user defined command. +const char *set_context_in_user_cmdarg(const char *cmd FUNC_ATTR_UNUSED, const char *arg, + uint32_t argt, int context, expand_T *xp, bool forceit) +{ + if (context == EXPAND_NOTHING) { + return NULL; + } + + if (argt & EX_XFILE) { + // EX_XFILE: file names are handled above. + xp->xp_context = context; + return NULL; + } + + if (context == EXPAND_MENUS) { + return (const char *)set_context_in_menu_cmd(xp, cmd, (char *)arg, forceit); + } + if (context == EXPAND_COMMANDS) { + return arg; + } + if (context == EXPAND_MAPPINGS) { + return (const char *)set_context_in_map_cmd(xp, "map", (char *)arg, forceit, false, false, + CMD_map); + } + // Find start of last argument. + const char *p = arg; + while (*p) { + if (*p == ' ') { + // argument starts after a space + arg = p + 1; + } else if (*p == '\\' && *(p + 1) != NUL) { + p++; // skip over escaped character + } + MB_PTR_ADV(p); + } + xp->xp_pattern = (char *)arg; + xp->xp_context = context; + + return NULL; +} + char *expand_user_command_name(int idx) { return get_user_commands(NULL, idx - CMD_SIZE); -- cgit From f2056e4045a667447392f5e17c27b0f72ec7b8e0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 15 Jan 2023 06:20:01 +0800 Subject: vim-patch:8.2.4565: no command line completion for :breakadd and :breakdel Problem: No command line completion for :breakadd and :breakdel. Solution: Add completion for :breakadd and :breakdel. (Yegappan Lakshmanan, closes vim/vim#9950) https://github.com/vim/vim/commit/6e2e2cc95b913e33145047e0fade5193da6e4379 --- src/nvim/usercmd.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/usercmd.c') diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c index 883d7321d2..22e092781c 100644 --- a/src/nvim/usercmd.c +++ b/src/nvim/usercmd.c @@ -95,6 +95,7 @@ static const char *command_complete[] = { [EXPAND_TAGS_LISTFILES] = "tag_listfiles", [EXPAND_USER] = "user", [EXPAND_USER_VARS] = "var", + [EXPAND_BREAKPOINT] = "breakpoint", }; /// List of names of address types. Must be alphabetical for completion. -- cgit