From 1391385ba9f83d32f3b6fc54587f03a1d34960d9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 7 Feb 2023 07:54:33 +0800 Subject: vim-patch:9.0.1290: CTRL-N and -P on cmdline don't trigger CmdlineChanged (#22151) Problem: CTRL-N and -P on cmdline don't trigger CmdlineChanged. Solution: Jump to cmdline_changed instead of cmdline_not_changed. (closes vim/vim#11956) https://github.com/vim/vim/commit/af9e28a5b8f888b79459393ddb26fffe613c3f3c Cherry-pick Test_Cmdline() change from patch 9.0.1039. --- src/nvim/ex_getln.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 76c3680742..eadeb839de 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2015,7 +2015,7 @@ static int command_line_handle_key(CommandLineState *s) if (nextwild(&s->xpc, wild_type, 0, s->firstc != '@') == FAIL) { break; } - return command_line_not_changed(s); + return command_line_changed(s); } FALLTHROUGH; @@ -2037,7 +2037,7 @@ static int command_line_handle_key(CommandLineState *s) if (nextwild(&s->xpc, wild_type, 0, s->firstc != '@') == FAIL) { break; } - return command_line_not_changed(s); + return command_line_changed(s); } else { switch (command_line_browse_history(s)) { case CMDLINE_CHANGED: -- cgit From c8c930ea785aa393ebc819139913a9e05f0ccd45 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:24:46 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22206) --- src/nvim/ex_getln.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index eadeb839de..95564da7cb 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1729,7 +1729,6 @@ static int command_line_browse_history(CommandLineState *s) if (s->hiscnt != s->save_hiscnt) { // jumped to other entry char *p; - int len = 0; int old_firstc; XFREE_CLEAR(ccline.cmdbuff); @@ -1743,6 +1742,7 @@ static int command_line_browse_history(CommandLineState *s) if (s->histype == HIST_SEARCH && p != s->lookfor && (old_firstc = (uint8_t)p[strlen(p) + 1]) != s->firstc) { + int len = 0; // Correct for the separator character used when // adding the history entry vs the one used now. // First loop: count length. @@ -3676,7 +3676,6 @@ static void restore_cmdline(CmdlineInfo *ccp) static bool cmdline_paste(int regname, bool literally, bool remcr) { char *arg; - char *p; bool allocated; // check for valid regname; also accept special characters for CTRL-R in @@ -3708,7 +3707,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) // When 'incsearch' is set and CTRL-R CTRL-W used: skip the duplicate // part of the word. - p = arg; + char *p = arg; if (p_is && regname == Ctrl_W) { char *w; int len; @@ -3743,17 +3742,15 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) // line. void cmdline_paste_str(char *s, int literally) { - int c, cv; - if (literally) { put_on_cmdline(s, -1, true); } else { while (*s != NUL) { - cv = (uint8_t)(*s); + int cv = (uint8_t)(*s); if (cv == Ctrl_V && s[1]) { s++; } - c = mb_cptr2char_adv((const char **)&s); + int c = mb_cptr2char_adv((const char **)&s); if (cv == Ctrl_V || c == ESC || c == Ctrl_C || c == CAR || c == NL || c == Ctrl_L || (c == Ctrl_BSL && *s == Ctrl_N)) { @@ -3781,8 +3778,6 @@ void redrawcmdline(void) static void redrawcmdprompt(void) { - int i; - if (cmd_silent) { return; } @@ -3801,7 +3796,7 @@ static void redrawcmdprompt(void) ccline.cmdindent--; } } else { - for (i = ccline.cmdindent; i > 0; i--) { + for (int i = ccline.cmdindent; i > 0; i--) { msg_putchar(' '); } } @@ -4284,12 +4279,10 @@ void cmdline_init(void) /// Returns NULL if value is OK, error message otherwise. char *check_cedit(void) { - int n; - if (*p_cedit == NUL) { cedit_key = -1; } else { - n = string_to_key(p_cedit); + int n = string_to_key(p_cedit); if (vim_isprintc(n)) { return e_invarg; } @@ -4309,9 +4302,7 @@ static int open_cmdwin(void) bufref_T old_curbuf; bufref_T bufref; win_T *old_curwin = curwin; - win_T *wp; int i; - linenr_T lnum; garray_T winsizes; char typestr[2]; int save_restart_edit = restart_edit; @@ -4392,7 +4383,7 @@ static int open_cmdwin(void) if (get_hislen() > 0 && histtype != HIST_INVALID) { i = *get_hisidx(histtype); if (i >= 0) { - lnum = 0; + linenr_T lnum = 0; do { if (++i == get_hislen()) { i = 0; @@ -4463,6 +4454,7 @@ static int open_cmdwin(void) cmdwin_result = Ctrl_C; emsg(_("E199: Active window or buffer deleted")); } else { + win_T *wp; // autocmds may abort script processing if (aborting() && cmdwin_result != K_IGNORE) { cmdwin_result = Ctrl_C; -- cgit 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/ex_getln.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 95564da7cb..6926a36366 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3380,14 +3380,14 @@ static void ui_ext_cmdline_show(CmdlineInfo *line) ADD_C(item, INTEGER_OBJ(chunk.attr)); assert(chunk.end >= chunk.start); - ADD_C(item, STRING_OBJ(cbuf_as_string((char *)line->cmdbuff + chunk.start, + ADD_C(item, STRING_OBJ(cbuf_as_string(line->cmdbuff + chunk.start, (size_t)(chunk.end - chunk.start)))); ADD_C(content, ARRAY_OBJ(item)); } } else { Array item = arena_array(&arena, 2); ADD_C(item, INTEGER_OBJ(0)); - ADD_C(item, STRING_OBJ(cstr_as_string((char *)(line->cmdbuff)))); + ADD_C(item, STRING_OBJ(cstr_as_string(line->cmdbuff))); content = arena_array(&arena, 1); ADD_C(content, ARRAY_OBJ(item)); } -- cgit From 9437800d280385c018a99aa0fbe9043e4d7715aa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Feb 2023 18:44:06 +0800 Subject: vim-patch:9.0.1298: inserting register on the cmdline does not trigger incsearch Problem: Inserting a register on the command line does not trigger incsearch or update hlsearch. Solution: Have cmdline_insert_reg() return CMDLINE_CHANGED when appropriate and handle it correctly. (Ken Takata, closes vim/vim#11960) https://github.com/vim/vim/commit/c4b7dec38292fe1cfad7aa5f244031fc6f7c7a09 Co-authored-by: K.Takata --- src/nvim/ex_getln.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 6926a36366..d55da46227 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1598,8 +1598,10 @@ static int command_line_insert_reg(CommandLineState *s) } } + bool literally = false; if (s->c != ESC) { // use ESC to cancel inserting register - cmdline_paste(s->c, i == Ctrl_R, false); + literally = i == Ctrl_R; + cmdline_paste(s->c, literally, false); // When there was a serious error abort getting the // command line. @@ -1624,8 +1626,9 @@ static int command_line_insert_reg(CommandLineState *s) ccline.special_char = NUL; redrawcmd(); - // The text has been stuffed, the command line didn't change yet. - return CMDLINE_NOT_CHANGED; + // The text has been stuffed, the command line didn't change yet, but it + // will change soon. The caller must take care of it. + return literally ? CMDLINE_NOT_CHANGED : CMDLINE_CHANGED; } /// Handle the Left and Right mouse clicks in the command-line mode. @@ -1857,12 +1860,13 @@ static int command_line_handle_key(CommandLineState *s) case Ctrl_R: // insert register switch (command_line_insert_reg(s)) { - case CMDLINE_NOT_CHANGED: - return command_line_not_changed(s); case GOTO_NORMAL_MODE: return 0; // back to cmd mode + case CMDLINE_NOT_CHANGED: + s->is_state.incsearch_postponed = true; + FALLTHROUGH; default: - return command_line_changed(s); + return command_line_not_changed(s); } case Ctrl_D: -- cgit From f1fcdcc2c43839b037517d1dd7b1a4570eb970a8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Feb 2023 19:01:43 +0800 Subject: vim-patch:9.0.1299: change for triggering incsearch not sufficiently tested Problem: Change for triggering incsearch not sufficiently tested. Solution: Add a test case. Simplify the code. (closes vim/vim#11971) https://github.com/vim/vim/commit/412e0e4ed903682f352d8ea58ded480930cc664f --- src/nvim/ex_getln.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index d55da46227..af26fe8a1c 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1626,9 +1626,9 @@ static int command_line_insert_reg(CommandLineState *s) ccline.special_char = NUL; redrawcmd(); - // The text has been stuffed, the command line didn't change yet, but it - // will change soon. The caller must take care of it. - return literally ? CMDLINE_NOT_CHANGED : CMDLINE_CHANGED; + // With "literally": the command line has already changed. + // Else: the text has been stuffed, but the command line didn't change yet. + return literally ? CMDLINE_CHANGED : CMDLINE_NOT_CHANGED; } /// Handle the Left and Right mouse clicks in the command-line mode. @@ -1862,9 +1862,8 @@ static int command_line_handle_key(CommandLineState *s) switch (command_line_insert_reg(s)) { case GOTO_NORMAL_MODE: return 0; // back to cmd mode - case CMDLINE_NOT_CHANGED: - s->is_state.incsearch_postponed = true; - FALLTHROUGH; + case CMDLINE_CHANGED: + return command_line_changed(s); default: return command_line_not_changed(s); } -- cgit From 8ecd129f1ef92aefea506247677f2693c5db9efd Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 27 Feb 2023 22:16:12 +0000 Subject: fix: address -Wmaybe-uninitialized warnings (#22436) --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index af26fe8a1c..a7f488458e 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2456,7 +2456,7 @@ static bool cmdpreview_may_show(CommandLineState *s) CpInfo cpinfo; bool icm_split = *p_icm == 's'; // inccommand=split buf_T *cmdpreview_buf; - win_T *cmdpreview_win; + win_T *cmdpreview_win = NULL; emsg_silent++; // Block error reporting as the command may be incomplete, // but still update v:errmsg -- cgit From f113cba3ec127201f54094f9174b50ee3001fbee Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 28 Feb 2023 08:49:02 +0800 Subject: refactor(getchar.c): change most char_u to uint8_t (#22444) --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index a7f488458e..a3e0e650fa 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2693,7 +2693,7 @@ char *getcmdline_prompt(const int firstc, const char *const prompt, const int at /// Read the 'wildmode' option, fill wim_flags[]. int check_opt_wim(void) { - char_u new_wim_flags[4]; + uint8_t new_wim_flags[4]; int i; int idx = 0; -- cgit From cf07f2baabd3a1a072102e0cacb6d70509ada044 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 27 Feb 2023 12:29:20 +0100 Subject: feat(edit)!: remove old c implementation of hebrew keymap This feature has long been obsolete. The 'keymap' option can be used to support language keymaps, including hebrew and hebrewp (phonetic mapping). There is no need to keep the old c code with hardcoded keymaps for some languages. --- src/nvim/ex_getln.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index af26fe8a1c..376352a13b 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -189,8 +189,6 @@ static int cedit_key = -1; ///< key value of 'cedit' option static handle_T cmdpreview_bufnr = 0; static long cmdpreview_ns = 0; -static int cmd_hkmap = 0; // Hebrew mapping during command line - static void save_viewstate(win_T *wp, viewstate_T *vs) FUNC_ATTR_NONNULL_ALL { @@ -680,11 +678,6 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool clea s->break_ctrl_c = true; } - // start without Hebrew mapping for a command line - if (s->firstc == ':' || s->firstc == '=' || s->firstc == '>') { - cmd_hkmap = 0; - } - init_ccline(s->firstc, s->indent); ccline.prompt_id = last_prompt_id++; ccline.level = cmdline_level; @@ -1166,9 +1159,6 @@ static int command_line_execute(VimState *state, int key) if (KeyTyped) { s->some_key_typed = true; - if (cmd_hkmap) { - s->c = hkmap(s->c); - } if (cmdmsg_rl && !KeyStuffed) { // Invert horizontal movements and operations. Only when @@ -2101,7 +2091,6 @@ static int command_line_handle_key(CommandLineState *s) if (!p_ari) { break; } - cmd_hkmap = !cmd_hkmap; return command_line_not_changed(s); default: -- cgit From 419819b6245e120aba8897e3ddea711b2cd0246c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 5 Mar 2023 09:18:42 +0800 Subject: vim-patch:9.0.1380: CTRL-X on 2**64 subtracts two (#22530) Problem: CTRL-X on 2**64 subtracts two. (James McCoy) Solution: Correct computation for large number. (closes vim/vim#12103) https://github.com/vim/vim/commit/5fb78c3fa5c996c08a65431d698bd2c251eef5c7 Co-authored-by: Bram Moolenaar --- src/nvim/ex_getln.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 4b56dfdd3f..e4cb7a5a76 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4241,7 +4241,7 @@ int get_list_range(char **str, int *num1, int *num2) *str = skipwhite((*str)); if (**str == '-' || ascii_isdigit(**str)) { // parse "from" part of range - vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, false); + vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, false, NULL); *str += len; *num1 = (int)num; first = true; @@ -4249,7 +4249,7 @@ int get_list_range(char **str, int *num1, int *num2) *str = skipwhite((*str)); if (**str == ',') { // parse "to" part of range *str = skipwhite((*str) + 1); - vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, false); + vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, false, NULL); if (len > 0) { *num2 = (int)num; *str = skipwhite((*str) + len); -- cgit From fe11079721084b3638ae3d8e5266f95d52028fb7 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Wed, 8 Mar 2023 12:36:03 +0100 Subject: perf(statusline): UI elements are always redrawn on K_EVENT Problem: 'statusline'-format UI elements are redrawn on each K_EVENT. Solution: Only redraw UI elements when something relevant has changed. --- src/nvim/ex_getln.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index e4cb7a5a76..54131986d0 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -907,6 +907,9 @@ theend: ui_call_cmdline_hide(ccline.level); msg_ext_clear_later(); } + if (!cmd_silent) { + status_redraw_all(); // redraw to show mode change + } cmdline_level--; -- cgit From d6ecead36406233cc56353dd05f3380f0497630f Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 14 Mar 2023 11:49:46 +0100 Subject: refactor(screen): screen.c delenda est drawscreen.c vs screen.c makes absolutely no sense. The screen exists only to draw upon it, therefore helper functions are distributed randomly between screen.c and the file that does the redrawing. In addition screen.c does a lot of drawing on the screen. It made more sense for vim/vim as our grid.c is their screen.c Not sure if we want to dump all the code for option chars into optionstr.c, so keep these in a optionchar.c for now. --- src/nvim/ex_getln.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 54131986d0..0f823383a4 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -63,7 +63,6 @@ #include "nvim/pos.h" #include "nvim/profile.h" #include "nvim/regexp.h" -#include "nvim/screen.h" #include "nvim/search.h" #include "nvim/state.h" #include "nvim/strings.h" -- cgit From e1db0e35e4d5859b96e6aff882df62d6c714b569 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 15 Mar 2023 23:30:14 +0000 Subject: feat(api): add filetype option nvim_get_option_value - Also adjust the expr-mapping behaviour so normal commands and text changes are allowed in internal dummy buffers. --- src/nvim/ex_getln.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 0f823383a4..5112505eda 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2740,6 +2740,9 @@ bool text_locked(void) if (cmdwin_type != 0) { return true; } + if (expr_map_locked()) { + return true; + } return textlock != 0; } -- cgit From d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 2 Apr 2023 10:11:42 +0200 Subject: refactor: remove char_u (#22829) Closes https://github.com/neovim/neovim/issues/459 --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 5112505eda..bd7ddbf567 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2117,7 +2117,7 @@ static int command_line_handle_key(CommandLineState *s) // put the character in the command line if (IS_SPECIAL(s->c) || mod_mask != 0) { - put_on_cmdline((char *)get_special_key_name(s->c, mod_mask), -1, true); + put_on_cmdline(get_special_key_name(s->c, mod_mask), -1, true); } else { int j = utf_char2bytes(s->c, IObuff); IObuff[j] = NUL; // exclude composing chars -- cgit From 371823d407d7d7519735131bcad4670c62a731a7 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Wed, 5 Apr 2023 21:13:53 +0200 Subject: refactor: make error message definitions const message.c functions now take const char * as a format. Error message definitions can be made const. --- src/nvim/ex_getln.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index bd7ddbf567..cdbb41c8ae 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2753,7 +2753,7 @@ void text_locked_msg(void) emsg(_(get_text_locked_msg())); } -char *get_text_locked_msg(void) +const char *get_text_locked_msg(void) { if (cmdwin_type != 0) { return e_cmdwin; @@ -4274,7 +4274,7 @@ void cmdline_init(void) /// Check value of 'cedit' and set cedit_key. /// Returns NULL if value is OK, error message otherwise. -char *check_cedit(void) +const char *check_cedit(void) { if (*p_cedit == NUL) { cedit_key = -1; -- 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/ex_getln.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index cdbb41c8ae..4331de1d62 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2947,7 +2947,7 @@ static void color_expr_cmdline(const CmdlineInfo *const colored_ccline, { ParserLine parser_lines[] = { { - .data = (const char *)colored_ccline->cmdbuff, + .data = colored_ccline->cmdbuff, .size = strlen(colored_ccline->cmdbuff), .allocated = false, }, @@ -3051,7 +3051,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) bool can_free_cb = false; TryState tstate; Error err = ERROR_INIT; - const char *err_errmsg = (const char *)e_intern2; + const char *err_errmsg = e_intern2; bool dgc_ret = true; bool tl_ret = true; @@ -3084,8 +3084,7 @@ static bool color_cmdline(CmdlineInfo *colored_ccline) } if (colored_ccline->cmdbuff[colored_ccline->cmdlen] != NUL) { arg_allocated = true; - arg.vval.v_string = xmemdupz((const char *)colored_ccline->cmdbuff, - (size_t)colored_ccline->cmdlen); + arg.vval.v_string = xmemdupz(colored_ccline->cmdbuff, (size_t)colored_ccline->cmdlen); } // msg_start() called by e.g. :echo may shift command-line to the first column // even though msg_silent is here. Two ways to workaround this problem without @@ -3204,8 +3203,7 @@ color_cmdline_end: if (arg_allocated) { ccline_colors->cmdbuff = arg.vval.v_string; } else { - ccline_colors->cmdbuff = xmemdupz((const char *)colored_ccline->cmdbuff, - (size_t)colored_ccline->cmdlen); + ccline_colors->cmdbuff = xmemdupz(colored_ccline->cmdbuff, (size_t)colored_ccline->cmdlen); } tv_clear(&tv); return ret; @@ -4558,7 +4556,7 @@ bool is_in_cmdwin(void) char *script_get(exarg_T *const eap, size_t *const lenp) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC { - const char *const cmd = (const char *)eap->arg; + const char *const cmd = eap->arg; if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) { *lenp = strlen(eap->arg); @@ -4570,7 +4568,7 @@ char *script_get(exarg_T *const eap, size_t *const lenp) ga_init(&ga, 1, 0x400); } - const char *const end_pattern = (cmd[2] != NUL ? (const char *)skipwhite(cmd + 2) : "."); + const char *const end_pattern = (cmd[2] != NUL ? skipwhite(cmd + 2) : "."); for (;;) { char *const theline = eap->getline(eap->cstack->cs_looplevel > 0 ? -1 : NUL, eap->cookie, 0, true); -- cgit From 2d78e656b715119ca11d131a1a932f22f1b4ad36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:43:00 +0200 Subject: refactor: remove redundant casts --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 4331de1d62..ba403e3dd9 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -295,7 +295,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s if (*p == '!') { p = skipwhite(p + 1); } - while (ASCII_ISALPHA(*(p = skipwhite((char *)p)))) { + while (ASCII_ISALPHA(*(p = skipwhite(p)))) { p++; } if (*p == NUL) { -- cgit From 23e9d625cf97715abce2c0dead416d8dcd9e6519 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 12 Apr 2023 23:51:43 +0800 Subject: vim-patch:9.0.1444: crash when passing NULL to setcmdline() (#23048) Problem: Crash when passing NULL to setcmdline(). (Andreas Louv) Solution: Use tv_get_string() instead of using v_string directly. (closes vim/vim#12231, closes vim/vim#12227) https://github.com/vim/vim/commit/ac6cd31afcbdd08bfa92ca33f7d4ce5773ba4353 --- src/nvim/ex_getln.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index ba403e3dd9..f3afbdcaaf 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4209,7 +4209,8 @@ void f_setcmdline(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } - rettv->vval.v_number = set_cmdline_str(argvars[0].vval.v_string, pos); + // Use tv_get_string() to handle a NULL string like an empty string. + rettv->vval.v_number = set_cmdline_str(tv_get_string(&argvars[0]), pos); } /// "setcmdpos()" function -- cgit From 9e5f9c25d9955f8c0ab7de874cf3a40fc077458b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Apr 2023 23:27:04 +0800 Subject: vim-patch:9.0.1460: insufficient testing for getcmdcompltype() (#23159) Problem: Insufficient testing for getcmdcompltype(). Solution: Add a few more test cases. (closes vim/vim#12268) https://github.com/vim/vim/commit/961b2e54bdbe1c06e4bf8ccf7a7e3deb129b45de --- src/nvim/ex_getln.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index f3afbdcaaf..97343e468b 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4096,6 +4096,10 @@ static char *get_cmdline_completion(void) } set_expand_context(p->xpc); + if (p->xpc->xp_context == EXPAND_UNSUCCESSFUL) { + return NULL; + } + char *cmd_compl = get_user_cmd_complete(p->xpc, p->xpc->xp_context); if (cmd_compl != NULL) { return xstrdup(cmd_compl); -- cgit From a114a21eff58492046645b052fa3f703cddc9ce8 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Fri, 21 Apr 2023 11:13:23 +0200 Subject: fix(ex_getln): initialize pointer with NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In function ‘cmdpreview_open_win’, inlined from ‘cmdpreview_may_show’ at gsrc/nvim/ex_getln.c:2487:28: gsrc/nvim/ex_getln.c:2251:16: warning: ‘cmdpreview_buf’ may be used uninitialized [-Wmaybe-uninitialized] 2251 | int result = do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, cmdpreview_buf->handle, 0); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 97343e468b..a8ac6ab439 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2446,7 +2446,7 @@ static bool cmdpreview_may_show(CommandLineState *s) CpInfo cpinfo; bool icm_split = *p_icm == 's'; // inccommand=split - buf_T *cmdpreview_buf; + buf_T *cmdpreview_buf = NULL; win_T *cmdpreview_win = NULL; emsg_silent++; // Block error reporting as the command may be incomplete, -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/ex_getln.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index a8ac6ab439..33a8dcafc2 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1651,7 +1651,7 @@ static void command_line_left_right_mouse(CommandLineState *s) static void command_line_next_histidx(CommandLineState *s, bool next_match) { int j = (int)strlen(s->lookfor); - for (;;) { + while (true) { // one step backwards if (!next_match) { if (s->hiscnt == get_hislen()) { @@ -4574,7 +4574,7 @@ char *script_get(exarg_T *const eap, size_t *const lenp) } const char *const end_pattern = (cmd[2] != NUL ? skipwhite(cmd + 2) : "."); - for (;;) { + while (true) { char *const theline = eap->getline(eap->cstack->cs_looplevel > 0 ? -1 : NUL, eap->cookie, 0, true); -- cgit From ff34c91194f9ab9d02808f2880029c38a4655eb5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Apr 2023 17:23:47 +0100 Subject: vim-patch:9.0.1330: handling new value of an option has a long "else if" chain Problem: Handling new value of an option has a long "else if" chain. Solution: Use a function pointer. (Yegappan Lakshmanan, closes vim/vim#12015) https://github.com/vim/vim/commit/af93691b53f38784efce0b93fe7644c44a7e382e --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 33a8dcafc2..c0c8a5605b 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4277,7 +4277,7 @@ void cmdline_init(void) /// Check value of 'cedit' and set cedit_key. /// Returns NULL if value is OK, error message otherwise. -const char *check_cedit(void) +const char *did_set_cedit(optset_T *args) { if (*p_cedit == NUL) { cedit_key = -1; -- cgit From 4bcf8c15b3079ca72d6557890b50b35565fcd577 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 29 Apr 2023 08:12:32 +0800 Subject: vim-patch:8.2.0578: heredoc for interfaces does not support "trim" Problem: Heredoc for interfaces does not support "trim". Solution: Update the script heredoc support to be same as the :let command. (Yegappan Lakshmanan, closes vim/vim#5916) https://github.com/vim/vim/commit/6c2b7b8055b96463f78abb70f58c4c6d6d4b9d55 --- src/nvim/ex_getln.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index c0c8a5605b..5018c9268b 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -29,6 +29,7 @@ #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" +#include "nvim/eval/vars.h" #include "nvim/ex_cmds.h" #include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" @@ -4561,39 +4562,37 @@ bool is_in_cmdwin(void) char *script_get(exarg_T *const eap, size_t *const lenp) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC { - const char *const cmd = eap->arg; + char *cmd = eap->arg; if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) { *lenp = strlen(eap->arg); return eap->skip ? NULL : xmemdupz(eap->arg, *lenp); } + cmd += 2; garray_T ga = { .ga_data = NULL, .ga_len = 0 }; + + list_T *const l = heredoc_get(eap, cmd, true); + if (l == NULL) { + return NULL; + } + if (!eap->skip) { ga_init(&ga, 1, 0x400); } - const char *const end_pattern = (cmd[2] != NUL ? skipwhite(cmd + 2) : "."); - while (true) { - char *const theline = eap->getline(eap->cstack->cs_looplevel > 0 ? -1 : NUL, eap->cookie, 0, - true); - - if (theline == NULL || strcmp(end_pattern, theline) == 0) { - xfree(theline); - break; - } - + TV_LIST_ITER_CONST(l, li, { if (!eap->skip) { - ga_concat(&ga, theline); + ga_concat(&ga, tv_get_string(TV_LIST_ITEM_TV(li))); ga_append(&ga, '\n'); } - xfree(theline); - } + }); *lenp = (size_t)ga.ga_len; // Set length without trailing NUL. if (!eap->skip) { ga_append(&ga, NUL); } + tv_list_free(l); return (char *)ga.ga_data; } -- cgit From 5e4df766f6e428659221f8eae144e9ed18574f8d Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 27 Apr 2023 05:27:31 +0200 Subject: vim-patch:9.0.0892: may redraw when not needed Problem: May redraw when not needed, causing slow scrolling. Solution: Do not redraw when w_skipcol doesn't change. When w_skipcol changes only redraw from the top. (issue vim/vim#11559) https://github.com/vim/vim/commit/f32fb93e431e4db95a8663d86dfeb6bffa5896f6 Co-authored-by: Bram Moolenaar --- src/nvim/ex_getln.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 5018c9268b..af2ec3356f 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -504,6 +504,7 @@ static void may_do_incsearch_highlighting(int firstc, long count, incsearch_stat } validate_cursor(); + // May redraw the status line to show the cursor position. if (p_ru && (curwin->w_status_height > 0 || global_stl_height() > 0)) { curwin->w_redr_status = true; @@ -598,6 +599,7 @@ static void finish_incsearch_highlighting(int gotesc, incsearch_state_T *s, bool magic_overruled = s->magic_overruled_save; validate_cursor(); // needed for TAB + status_redraw_all(); redraw_all_later(UPD_SOME_VALID); if (call_update_screen) { update_screen(); -- cgit From 5ac2e47acc999472042df4f10f8f7b5ffa72ba3e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 10 May 2023 17:42:14 +0800 Subject: fix(redo): make redo of Lua mappings in op-pending mode work (#23566) --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index af2ec3356f..1345a29a21 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1140,7 +1140,7 @@ static int command_line_execute(VimState *state, int key) } else if (s->c == K_COMMAND) { do_cmdline(NULL, getcmdkeycmd, NULL, DOCMD_NOWAIT); } else { - map_execute_lua(); + map_execute_lua(false); } // nvim_select_popupmenu_item() can be called from the handling of -- cgit From 7eea6b12f98c4319d2f358ee1c1ebd3f5b2dfa62 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 13 May 2023 22:29:07 +0800 Subject: vim-patch:9.0.0490: using freed memory with cmdwin and BufEnter autocmd Problem: Using freed memory with cmdwin and BufEnter autocmd. Solution: Make sure pointer to b_p_iminsert is still valid. https://github.com/vim/vim/commit/1c3dd8ddcba63c1af5112e567215b3cec2de11d0 Co-authored-by: Bram Moolenaar --- src/nvim/ex_getln.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 1345a29a21..a4c1863576 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -127,6 +127,7 @@ typedef struct command_line_state { int break_ctrl_c; expand_T xpc; long *b_im_ptr; + buf_T *b_im_ptr_buf; ///< buffer where b_im_ptr is valid } CommandLineState; typedef struct cmdpreview_win_info { @@ -736,7 +737,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool clea } else { s->b_im_ptr = &curbuf->b_p_imsearch; } - + s->b_im_ptr_buf = curbuf; if (*s->b_im_ptr == B_IMODE_LMAP) { State |= MODE_LANGMAP; } @@ -1538,20 +1539,21 @@ static int command_line_erase_chars(CommandLineState *s) /// language :lmap mappings and/or Input Method. static void command_line_toggle_langmap(CommandLineState *s) { + long *b_im_ptr = buf_valid(s->b_im_ptr_buf) ? s->b_im_ptr : NULL; if (map_to_exists_mode("", MODE_LANGMAP, false)) { // ":lmap" mappings exists, toggle use of mappings. State ^= MODE_LANGMAP; - if (s->b_im_ptr != NULL) { + if (b_im_ptr != NULL) { if (State & MODE_LANGMAP) { - *s->b_im_ptr = B_IMODE_LMAP; + *b_im_ptr = B_IMODE_LMAP; } else { - *s->b_im_ptr = B_IMODE_NONE; + *b_im_ptr = B_IMODE_NONE; } } } - if (s->b_im_ptr != NULL) { - if (s->b_im_ptr == &curbuf->b_p_iminsert) { + if (b_im_ptr != NULL) { + if (b_im_ptr == &curbuf->b_p_iminsert) { set_iminsert_global(curbuf); } else { set_imsearch_global(curbuf); -- cgit From cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 23 May 2023 14:25:10 +0600 Subject: refactor(api): new helper macros Adds new API helper macros `CSTR_AS_OBJ()`, `STATIC_CSTR_AS_OBJ()`, and `STATIC_CSTR_TO_OBJ()`, which cleans up a lot of the current code. These macros will also be used extensively in the upcoming option refactor PRs because then API Objects will be used to get/set options. This PR also modifies pre-existing code to use old API helper macros like `CSTR_TO_OBJ()` to make them cleaner. --- src/nvim/ex_getln.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index a4c1863576..dd23f6ece9 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3387,7 +3387,7 @@ static void ui_ext_cmdline_show(CmdlineInfo *line) } else { Array item = arena_array(&arena, 2); ADD_C(item, INTEGER_OBJ(0)); - ADD_C(item, STRING_OBJ(cstr_as_string(line->cmdbuff))); + ADD_C(item, CSTR_AS_OBJ(line->cmdbuff)); content = arena_array(&arena, 1); ADD_C(content, ARRAY_OBJ(item)); } @@ -3414,7 +3414,7 @@ void ui_ext_cmdline_block_append(size_t indent, const char *line) Array item = ARRAY_DICT_INIT; ADD(item, INTEGER_OBJ(0)); - ADD(item, STRING_OBJ(cstr_as_string(buf))); + ADD(item, CSTR_AS_OBJ(buf)); Array content = ARRAY_DICT_INIT; ADD(content, ARRAY_OBJ(item)); ADD(cmdline_block, ARRAY_OBJ(content)); -- cgit From 55f6a1cab031ecc28c5a7f2558a0cac9df2145e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 30 May 2023 07:18:12 +0800 Subject: vim-patch:9.0.1588: Incsearch not triggered when pasting clipboard register (#23817) Problem: Incsearch not triggered when pasting clipboard register on the command line. Solution: Also set "literally" when using a clipboard register. (Ken Takata, closes vim/vim#12460) https://github.com/vim/vim/commit/9cf6ab133227ac7e9169941752293bb7178d8e38 Co-authored-by: K.Takata --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index dd23f6ece9..b2acc561be 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1597,7 +1597,7 @@ static int command_line_insert_reg(CommandLineState *s) bool literally = false; if (s->c != ESC) { // use ESC to cancel inserting register - literally = i == Ctrl_R; + literally = i == Ctrl_R || is_literal_register(s->c); cmdline_paste(s->c, literally, false); // When there was a serious error abort getting the -- cgit From b3d5138fd0066fda26ef7724a542ae45eb42fc84 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 7 Jun 2023 06:05:16 +0600 Subject: refactor(options): remove `getoption_T` and introduce `OptVal` (#23850) Removes the `getoption_T` struct and also introduces the `OptVal` struct to unify the methods of getting/setting different option value types. This is the first of many PRs to reduce code duplication in the Vim option code as well as to make options easier to maintain. It also increases the flexibility and extensibility of options. Which opens the door for things like Array and Dictionary options. --- src/nvim/ex_getln.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index b2acc561be..77b09a5f73 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4357,7 +4357,7 @@ static int open_cmdwin(void) return Ctrl_C; } // Command-line buffer has bufhidden=wipe, unlike a true "scratch" buffer. - set_option_value_give_err("bh", 0L, "wipe", OPT_LOCAL); + set_option_value_give_err("bh", STATIC_CSTR_AS_OPTVAL("wipe"), OPT_LOCAL); curbuf->b_p_ma = true; curwin->w_p_fen = false; curwin->w_p_rl = cmdmsg_rl; @@ -4375,7 +4375,7 @@ static int open_cmdwin(void) add_map("", "", MODE_INSERT, true); add_map("", "a", MODE_NORMAL, true); } - set_option_value_give_err("ft", 0L, "vim", OPT_LOCAL); + set_option_value_give_err("ft", STATIC_CSTR_AS_OPTVAL("vim"), OPT_LOCAL); } curbuf->b_ro_locked--; -- cgit From 3688735c2b63337ab8d8b12ac08b4e6e064e98a2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 23 Jun 2023 06:40:26 +0800 Subject: fix(cmdline): don't redraw 'tabline' in Ex mode (#24123) Redrawing of 'statusline' and 'winbar' are actually already inhibited by RedawingDisabled in Ex mode. In Vim there is a check for `msg_scrolled == 0` (which is false in Ex mode) since Vim doesn't have msgsep. Add a `!exmode_active` check here in Nvim instead. --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 77b09a5f73..969023b70d 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -791,7 +791,7 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool clea // Redraw the statusline in case it uses the current mode using the mode() // function. - if (!cmd_silent) { + if (!cmd_silent && !exmode_active) { bool found_one = false; FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { -- cgit From a741c7fd0465c949a0016fcbee5f4526b65f8c02 Mon Sep 17 00:00:00 2001 From: Alexandre Teoi Date: Sat, 1 Jul 2023 10:33:51 -0300 Subject: fix(api): nvim_parse_cmd error message in pcall() #23297 Problem: nvim_parse_cmd() in pcall() may show an error message (side-effect): :lua pcall(vim.api.nvim_parse_cmd, vim.fn.getcmdline(), {}) E16: Invalid range Solution: Avoid emsg() in the nvim_parse_cmd() codepath. - refactor(api): add error message output parameter to get_address() - fix: null check emsg() parameter - refactor: remove emsg_off workaround from do_incsearch_highlighting() - refactor: remove emsg_off workaround from cmdpreview_may_show() - refactor: remove remaining calls to emsg() from parse_cmd_address() and get_address() - (refactor): lint set_cmd_dflall_range() - refactor: addr_error() - move output parameter to return value Fix #20339 TODO: These are the functions called by `get_address()`: ``` nvim_parse_cmd() -> parse_cmdline() -> parse_cmd_address() -> get_address() skipwhite() addr_error() qf_get_cur_idx() qf_get_cur_valid_idx() qf_get_size() qf_get_valid_size() mark_get() mark_check() assert() skip_regexp() magic_isset() > do_search() > searchit() ascii_isdigit() getdigits() getdigits_int32() compute_buffer_local_count() hasFolding() ``` From these functions, I found at least two that call emsg directly: - do_search() - seems to be simple to refactor - searchit() - will be more challenging because it may generate multiple error messages, which can't be handled by the current `errormsg` out-parameter. For example, it makes multiple calls to `vim_regexec_multi()` in a loop that possibly generate error messages, and later `searchit()` itself may generate another one: - https://github.com/neovim/neovim/blob/c194acbfc479d8e5839fa629363f93f6550d035c/src/nvim/search.c#L631-L647 - https://github.com/neovim/neovim/blob/c194acbfc479d8e5839fa629363f93f6550d035c/src/nvim/search.c#L939-L954 --------- Co-authored-by: Justin M. Keyes --- src/nvim/ex_getln.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 969023b70d..f77822cec6 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -236,7 +236,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s bool delim_optional = false; int delim; char *end; - char *dummy; + const char *dummy; pos_T save_cursor; bool use_last_pat; bool retval = false; @@ -261,7 +261,6 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s return false; } - emsg_off++; exarg_T ea = { .line1 = 1, .line2 = 1, @@ -369,7 +368,6 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s curwin->w_cursor = save_cursor; retval = true; theend: - emsg_off--; return retval; } @@ -2428,13 +2426,10 @@ static bool cmdpreview_may_show(CommandLineState *s) // Copy the command line so we can modify it. int cmdpreview_type = 0; char *cmdline = xstrdup(ccline.cmdbuff); - char *errormsg = NULL; - emsg_off++; // Block errors when parsing the command line, and don't update v:errmsg + const char *errormsg = NULL; if (!parse_cmdline(cmdline, &ea, &cmdinfo, &errormsg)) { - emsg_off--; goto end; } - emsg_off--; // Check if command is previewable, if not, don't attempt to show preview if (!(ea.argt & EX_PREVIEW)) { -- 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/ex_getln.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index f77822cec6..6bb980d501 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -104,7 +104,7 @@ typedef struct { typedef struct command_line_state { VimState state; int firstc; - long count; + int count; int indent; int c; int gotesc; // true when just typed @@ -372,7 +372,7 @@ theend: } // May do 'incsearch' highlighting if desired. -static void may_do_incsearch_highlighting(int firstc, long count, incsearch_state_T *s) +static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state_T *s) { pos_T end_pos; proftime_T tm; @@ -640,7 +640,7 @@ static void init_ccline(int firstc, int indent) /// @param count only used for incremental search /// @param indent indent for inside conditionals /// @param clear_ccline clear ccline first -static uint8_t *command_line_enter(int firstc, long count, int indent, bool clear_ccline) +static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear_ccline) { // can be invoked recursively, identify each level static int cmdline_level = 0; @@ -1344,7 +1344,7 @@ static int command_line_execute(VimState *state, int key) // May adjust 'incsearch' highlighting for typing CTRL-G and CTRL-T, go to next // or previous match. // Returns FAIL when calling command_line_not_changed. -static int may_do_command_line_next_incsearch(int firstc, long count, incsearch_state_T *s, +static int may_do_command_line_next_incsearch(int firstc, int count, incsearch_state_T *s, bool next_match) FUNC_ATTR_NONNULL_ALL { @@ -2619,7 +2619,7 @@ static void abandon_cmdline(void) /// /// @param count only used for incremental search /// @param indent indent for inside conditionals -char *getcmdline(int firstc, long count, int indent, bool do_concat FUNC_ATTR_UNUSED) +char *getcmdline(int firstc, int count, int indent, bool do_concat FUNC_ATTR_UNUSED) { return (char *)command_line_enter(firstc, count, indent, true); } -- cgit From b60a2ab4cb7bb7d86dcda1dfe2396a9eda384e35 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Jul 2023 10:15:45 +0800 Subject: fix(inccommand): block errors when parsing command line again (#24374) Revert the change to ex_getln.c from a741c7fd0465c949a0016fcbee5f4526b65f8c02 --- src/nvim/ex_getln.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 6bb980d501..927877dc74 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -261,6 +261,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s return false; } + emsg_off++; exarg_T ea = { .line1 = 1, .line2 = 1, @@ -368,6 +369,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s curwin->w_cursor = save_cursor; retval = true; theend: + emsg_off--; return retval; } @@ -2427,9 +2429,12 @@ static bool cmdpreview_may_show(CommandLineState *s) int cmdpreview_type = 0; char *cmdline = xstrdup(ccline.cmdbuff); const char *errormsg = NULL; + emsg_off++; // Block errors when parsing the command line, and don't update v:errmsg if (!parse_cmdline(cmdline, &ea, &cmdinfo, &errormsg)) { + emsg_off--; goto end; } + emsg_off--; // Check if command is previewable, if not, don't attempt to show preview if (!(ea.argt & EX_PREVIEW)) { -- cgit From d2efcbf2dca6c2899ba0a1be7fc10dbf3f112d26 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 22 Jul 2023 18:00:55 +0800 Subject: refactor: remove some (const char **) casts (#24423) --- src/nvim/ex_getln.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 927877dc74..fe72860628 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3530,7 +3530,7 @@ void unputcmdline(void) // part will be redrawn, otherwise it will not. If this function is called // twice in a row, then 'redraw' should be false and redrawcmd() should be // called afterwards. -void put_on_cmdline(char *str, int len, int redraw) +void put_on_cmdline(const char *str, int len, int redraw) { int i; int m; @@ -3740,7 +3740,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr) // When "literally" is true, insert literally. // When "literally" is false, insert as typed, but don't leave the command // line. -void cmdline_paste_str(char *s, int literally) +void cmdline_paste_str(const char *s, int literally) { if (literally) { put_on_cmdline(s, -1, true); @@ -3750,7 +3750,7 @@ void cmdline_paste_str(char *s, int literally) if (cv == Ctrl_V && s[1]) { s++; } - int c = mb_cptr2char_adv((const char **)&s); + int c = mb_cptr2char_adv(&s); if (cv == Ctrl_V || c == ESC || c == Ctrl_C || c == CAR || c == NL || c == Ctrl_L || (c == Ctrl_BSL && *s == Ctrl_N)) { -- cgit From 643bea31b8673f5db70816ecac61f76087019fb5 Mon Sep 17 00:00:00 2001 From: Alexandre Teoi Date: Wed, 26 Jul 2023 00:22:57 -0300 Subject: fix(inccommand): restrict cmdpreview undo calls (#24289) Problem: The cmdpreview saved undo nodes on cmdpreview_prepare() from ex_getln.c may become invalid (free) if the preview function makes undo operations, causing heap-use-after-free errors. Solution: Save the buffer undo list on cmdpreview_prepare)_ and start a new empty one. On cmdpreview_restore_state(), undo all the entries in the new undo list and restore the original one. With this approach, the preview function will be allowed to undo only its own changes. Fix #20036 Fix #20248 --- src/nvim/ex_getln.c | 103 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 77 insertions(+), 26 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index fe72860628..9dcfa99a37 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -130,25 +130,38 @@ typedef struct command_line_state { buf_T *b_im_ptr_buf; ///< buffer where b_im_ptr is valid } CommandLineState; -typedef struct cmdpreview_win_info { - win_T *win; - pos_T save_w_cursor; - viewstate_T save_viewstate; - int save_w_p_cul; - int save_w_p_cuc; -} CpWinInfo; +typedef struct cmdpreview_undo_info { + u_header_T *save_b_u_oldhead; + u_header_T *save_b_u_newhead; + u_header_T *save_b_u_curhead; + int save_b_u_numhead; + bool save_b_u_synced; + long save_b_u_seq_last; + long save_b_u_save_nr_last; + long save_b_u_seq_cur; + time_t save_b_u_time_cur; + long save_b_u_save_nr_cur; + char *save_b_u_line_ptr; + linenr_T save_b_u_line_lnum; + colnr_T save_b_u_line_colnr; +} CpUndoInfo; typedef struct cmdpreview_buf_info { buf_T *buf; - bool save_b_u_synced; - time_t save_b_u_time_cur; - long save_b_u_seq_cur; - u_header_T *save_b_u_newhead; long save_b_p_ul; int save_b_changed; varnumber_T save_changedtick; + CpUndoInfo undo_info; } CpBufInfo; +typedef struct cmdpreview_win_info { + win_T *win; + pos_T save_w_cursor; + viewstate_T save_viewstate; + int save_w_p_cul; + int save_w_p_cuc; +} CpWinInfo; + typedef struct cmdpreview_info { kvec_t(CpWinInfo) win_info; kvec_t(CpBufInfo) buf_info; @@ -2277,8 +2290,48 @@ static void cmdpreview_close_win(void) } } +/// Save the undo state of a buffer for command preview. +static void cmdpreview_save_undo(CpUndoInfo *cp_undoinfo, buf_T *buf) + FUNC_ATTR_NONNULL_ALL +{ + cp_undoinfo->save_b_u_synced = buf->b_u_synced; + cp_undoinfo->save_b_u_oldhead = buf->b_u_oldhead; + cp_undoinfo->save_b_u_newhead = buf->b_u_newhead; + cp_undoinfo->save_b_u_curhead = buf->b_u_curhead; + cp_undoinfo->save_b_u_numhead = buf->b_u_numhead; + cp_undoinfo->save_b_u_seq_last = buf->b_u_seq_last; + cp_undoinfo->save_b_u_save_nr_last = buf->b_u_save_nr_last; + cp_undoinfo->save_b_u_seq_cur = buf->b_u_seq_cur; + cp_undoinfo->save_b_u_time_cur = buf->b_u_time_cur; + cp_undoinfo->save_b_u_save_nr_cur = buf->b_u_save_nr_cur; + cp_undoinfo->save_b_u_line_ptr = buf->b_u_line_ptr; + cp_undoinfo->save_b_u_line_lnum = buf->b_u_line_lnum; + cp_undoinfo->save_b_u_line_colnr = buf->b_u_line_colnr; +} + +/// Restore the undo state of a buffer for command preview. +static void cmdpreview_restore_undo(const CpUndoInfo *cp_undoinfo, buf_T *buf) +{ + buf->b_u_oldhead = cp_undoinfo->save_b_u_oldhead; + buf->b_u_newhead = cp_undoinfo->save_b_u_newhead; + buf->b_u_curhead = cp_undoinfo->save_b_u_curhead; + buf->b_u_numhead = cp_undoinfo->save_b_u_numhead; + buf->b_u_seq_last = cp_undoinfo->save_b_u_seq_last; + buf->b_u_save_nr_last = cp_undoinfo->save_b_u_save_nr_last; + buf->b_u_seq_cur = cp_undoinfo->save_b_u_seq_cur; + buf->b_u_time_cur = cp_undoinfo->save_b_u_time_cur; + buf->b_u_save_nr_cur = cp_undoinfo->save_b_u_save_nr_cur; + buf->b_u_line_ptr = cp_undoinfo->save_b_u_line_ptr; + buf->b_u_line_lnum = cp_undoinfo->save_b_u_line_lnum; + buf->b_u_line_colnr = cp_undoinfo->save_b_u_line_colnr; + if (buf->b_u_curhead == NULL) { + buf->b_u_synced = cp_undoinfo->save_b_u_synced; + } +} + /// Save current state and prepare windows and buffers for command preview. static void cmdpreview_prepare(CpInfo *cpinfo) + FUNC_ATTR_NONNULL_ALL { kv_init(cpinfo->buf_info); kv_init(cpinfo->win_info); @@ -2294,14 +2347,13 @@ static void cmdpreview_prepare(CpInfo *cpinfo) CpBufInfo cp_bufinfo; cp_bufinfo.buf = buf; - cp_bufinfo.save_b_u_synced = buf->b_u_synced; - cp_bufinfo.save_b_u_time_cur = buf->b_u_time_cur; - cp_bufinfo.save_b_u_seq_cur = buf->b_u_seq_cur; - cp_bufinfo.save_b_u_newhead = buf->b_u_newhead; cp_bufinfo.save_b_p_ul = buf->b_p_ul; cp_bufinfo.save_b_changed = buf->b_changed; cp_bufinfo.save_changedtick = buf_get_changedtick(buf); + cmdpreview_save_undo(&cp_bufinfo.undo_info, buf); + u_clearall(buf); + kv_push(cpinfo->buf_info, cp_bufinfo); buf->b_p_ul = LONG_MAX; // Make sure we can undo all changes @@ -2336,8 +2388,9 @@ static void cmdpreview_prepare(CpInfo *cpinfo) u_sync(true); } -// Restore the state of buffers and windows before command preview. +/// Restore the state of buffers and windows for command preview. static void cmdpreview_restore_state(CpInfo *cpinfo) + FUNC_ATTR_NONNULL_ALL { for (size_t i = 0; i < cpinfo->buf_info.size; i++) { CpBufInfo cp_bufinfo = cpinfo->buf_info.items[i]; @@ -2345,31 +2398,29 @@ static void cmdpreview_restore_state(CpInfo *cpinfo) buf->b_changed = cp_bufinfo.save_b_changed; - if (buf->b_u_seq_cur != cp_bufinfo.save_b_u_seq_cur) { + if (buf->b_u_seq_cur != cp_bufinfo.undo_info.save_b_u_seq_cur) { int count = 0; // Calculate how many undo steps are necessary to restore earlier state. for (u_header_T *uhp = buf->b_u_curhead ? buf->b_u_curhead : buf->b_u_newhead; - uhp != NULL && uhp->uh_seq > cp_bufinfo.save_b_u_seq_cur; + uhp != NULL; uhp = uhp->uh_next.ptr, ++count) {} aco_save_T aco; aucmd_prepbuf(&aco, buf); + // Ensure all the entries will be undone + if (curbuf->b_u_synced == false) { + u_sync(true); + } // Undo invisibly. This also moves the cursor! if (!u_undo_and_forget(count, false)) { abort(); } aucmd_restbuf(&aco); - - // Restore newhead. It is meaningless when curhead is valid, but we must - // restore it so that undotree() is identical before/after the preview. - buf->b_u_newhead = cp_bufinfo.save_b_u_newhead; - buf->b_u_time_cur = cp_bufinfo.save_b_u_time_cur; } - if (buf->b_u_curhead == NULL) { - buf->b_u_synced = cp_bufinfo.save_b_u_synced; - } + u_blockfree(buf); + cmdpreview_restore_undo(&cp_bufinfo.undo_info, buf); if (cp_bufinfo.save_changedtick != buf_get_changedtick(buf)) { buf_set_changedtick(buf, cp_bufinfo.save_changedtick); -- cgit From 5d921e28c1cc33eced22bbfa823460ca241e3dc1 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 23 Jul 2023 23:10:28 +0100 Subject: feat(api): allow win_close in cmdwin to close wins except previous Disallow closing the previous window from `nvim_win_close`, as this will cause issues. Again, no telling how safe this is. It also requires exposing old_curwin. :/ Also note that it's possible for the `&cmdheight` to change if, for example, there are 2 tabpages and `nvim_win_close` is used to close the last window in the other tabpage while `&stal` is 1. This is addressed in a later commit. --- src/nvim/ex_getln.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 9dcfa99a37..5f1f5d5adc 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4398,6 +4398,7 @@ static int open_cmdwin(void) // Set "cmdwin_type" before any autocommands may mess things up. cmdwin_type = get_cmdline_type(); cmdwin_level = ccline.level; + cmdwin_old_curwin = old_curwin; // Create empty command-line buffer. if (buf_open_scratch(0, _("[Command Line]")) == FAIL) { @@ -4405,6 +4406,7 @@ static int open_cmdwin(void) win_close(curwin, true, false); ga_clear(&winsizes); cmdwin_type = 0; + cmdwin_old_curwin = NULL; return Ctrl_C; } // Command-line buffer has bufhidden=wipe, unlike a true "scratch" buffer. @@ -4501,6 +4503,7 @@ static int open_cmdwin(void) cmdwin_type = 0; cmdwin_level = 0; + cmdwin_old_curwin = NULL; exmode_active = save_exmode; -- cgit From c1c2a1b5dd1d73e5e97b94e6626aaac25a3db9bc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 28 Jul 2023 15:41:58 +0800 Subject: fix(inccommand): don't save information of a buffer twice (#24501) Problem: 'inccommand' doesn't restore 'undolevels' properly for a buffer shown in multiple windows. Solution: Don't save information of a buffer twice. --- src/nvim/ex_getln.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 5f1f5d5adc..ece6257c4a 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2333,6 +2333,8 @@ static void cmdpreview_restore_undo(const CpUndoInfo *cp_undoinfo, buf_T *buf) static void cmdpreview_prepare(CpInfo *cpinfo) FUNC_ATTR_NONNULL_ALL { + Set(ptr_t) saved_bufs = SET_INIT; + kv_init(cpinfo->buf_info); kv_init(cpinfo->win_info); @@ -2344,19 +2346,19 @@ static void cmdpreview_prepare(CpInfo *cpinfo) continue; } - CpBufInfo cp_bufinfo; - cp_bufinfo.buf = buf; - - cp_bufinfo.save_b_p_ul = buf->b_p_ul; - cp_bufinfo.save_b_changed = buf->b_changed; - cp_bufinfo.save_changedtick = buf_get_changedtick(buf); - - cmdpreview_save_undo(&cp_bufinfo.undo_info, buf); - u_clearall(buf); - - kv_push(cpinfo->buf_info, cp_bufinfo); + if (!set_has(ptr_t, &saved_bufs, buf)) { + CpBufInfo cp_bufinfo; + cp_bufinfo.buf = buf; + cp_bufinfo.save_b_p_ul = buf->b_p_ul; + cp_bufinfo.save_b_changed = buf->b_changed; + cp_bufinfo.save_changedtick = buf_get_changedtick(buf); + cmdpreview_save_undo(&cp_bufinfo.undo_info, buf); + kv_push(cpinfo->buf_info, cp_bufinfo); + set_put(ptr_t, &saved_bufs, buf); - buf->b_p_ul = LONG_MAX; // Make sure we can undo all changes + u_clearall(buf); + buf->b_p_ul = LONG_MAX; // Make sure we can undo all changes + } CpWinInfo cp_wininfo; cp_wininfo.win = win; @@ -2375,6 +2377,8 @@ static void cmdpreview_prepare(CpInfo *cpinfo) win->w_p_cuc = false; // Disable 'cursorcolumn' so it doesn't mess up the highlights } + set_destroy(ptr_t, &saved_bufs); + cpinfo->save_hls = p_hls; cpinfo->save_cmdmod = cmdmod; win_size_save(&cpinfo->save_view); @@ -2431,6 +2435,7 @@ static void cmdpreview_restore_state(CpInfo *cpinfo) // Clear preview highlights. extmark_clear(buf, (uint32_t)cmdpreview_ns, 0, 0, MAXLNUM, MAXCOL); } + for (size_t i = 0; i < cpinfo->win_info.size; i++) { CpWinInfo cp_wininfo = cpinfo->win_info.items[i]; win_T *win = cp_wininfo.win; -- cgit From ef44e597294e4d0d9128ef69b6aa7481a54e17cb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Aug 2023 22:42:34 +0800 Subject: fix(inccommand): don't set an invalid 'undolevels' value (#24575) Problem: Cannot break undo by setting 'undolevels' to itself in 'inccommand' preview callback. Solution: Don't set an invalid 'undolevels' value. Co-authored-by: Michael Henry --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index ece6257c4a..87e45cbb66 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2357,7 +2357,7 @@ static void cmdpreview_prepare(CpInfo *cpinfo) set_put(ptr_t, &saved_bufs, buf); u_clearall(buf); - buf->b_p_ul = LONG_MAX; // Make sure we can undo all changes + buf->b_p_ul = INT_MAX; // Make sure we can undo all changes } CpWinInfo cp_wininfo; -- cgit From 8f9c5ee5ef298883e6de1a3a9c73b348b6398404 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Aug 2023 06:32:13 +0800 Subject: vim-patch:9.0.1691: wrong viewport restored for incsearch and smoothscroll (#24667) Problem: wrong viewport restored for incsearch and smoothscroll Solution: Save and restore skipcol as well closes: vim/vim#12713 https://github.com/vim/vim/commit/7b7b4cb6f274e7bace127107b0d2752133c4020b --- src/nvim/ex_getln.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 87e45cbb66..17c17e60ce 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -82,6 +82,7 @@ static unsigned last_prompt_id = 0; typedef struct { colnr_T vs_curswant; colnr_T vs_leftcol; + colnr_T vs_skipcol; linenr_T vs_topline; int vs_topfill; linenr_T vs_botline; @@ -208,6 +209,7 @@ static void save_viewstate(win_T *wp, viewstate_T *vs) { vs->vs_curswant = wp->w_curswant; vs->vs_leftcol = wp->w_leftcol; + vs->vs_skipcol = wp->w_skipcol; vs->vs_topline = wp->w_topline; vs->vs_topfill = wp->w_topfill; vs->vs_botline = wp->w_botline; @@ -219,6 +221,7 @@ static void restore_viewstate(win_T *wp, viewstate_T *vs) { wp->w_curswant = vs->vs_curswant; wp->w_leftcol = vs->vs_leftcol; + wp->w_skipcol = vs->vs_skipcol; wp->w_topline = vs->vs_topline; wp->w_topfill = vs->vs_topfill; wp->w_botline = vs->vs_botline; -- 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/ex_getln.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 17c17e60ce..89f5e92c33 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4165,11 +4165,19 @@ static char *get_cmdline_completion(void) } char *cmd_compl = get_user_cmd_complete(p->xpc, p->xpc->xp_context); - if (cmd_compl != NULL) { - return xstrdup(cmd_compl); + if (cmd_compl == NULL) { + return NULL; } - return NULL; + if (p->xpc->xp_context == EXPAND_USER_LIST + || p->xpc->xp_context == EXPAND_USER_DEFINED) { + size_t buflen = strlen(cmd_compl) + strlen(p->xpc->xp_arg) + 2; + char *buffer = xmalloc(buflen); + snprintf(buffer, buflen, "%s,%s", cmd_compl, p->xpc->xp_arg); + return buffer; + } + + return xstrdup(cmd_compl); } /// "getcmdcompltype()" function -- cgit From ab45d5bf6d46abd9b29389dee6689044fd63e225 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 21 Aug 2023 10:45:25 +0800 Subject: vim-patch:8.1.2044: no easy way to process postponed work Problem: No easy way to process postponed work. (Paul Jolly) Solution: Add the SafeState autocommand event. https://github.com/vim/vim/commit/8aeec40207b5adcd3a155277dc4f29189343b963 Co-authored-by: Bram Moolenaar --- src/nvim/ex_getln.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 89f5e92c33..6af79bfd21 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -943,6 +943,8 @@ theend: static int command_line_check(VimState *state) { + CommandLineState *s = (CommandLineState *)state; + redir_off = true; // Don't redirect the typed command. // Repeated, because a ":redir" inside // completion may switch it on. @@ -952,6 +954,9 @@ static int command_line_check(VimState *state) // that occurs while typing a command should // cause the command not to be executed. + // Trigger SafeState if nothing is pending. + may_trigger_safestate(s->xpc.xp_numfiles <= 0); + cursorcmd(); // set the cursor on the right spot ui_cursor_shape(); return 1; -- cgit From b84a67f50ed6141f72d433094a1a611ae4f67924 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 22 Aug 2023 22:48:55 +0800 Subject: vim-patch:9.0.0579: using freed memory when 'tagfunc' wipes out buffer (#24838) Problem: Using freed memory when 'tagfunc' wipes out buffer that holds 'complete'. Solution: Make a copy of the option. Make sure cursor position is valid. https://github.com/vim/vim/commit/0ff01835a40f549c5c4a550502f62a2ac9ac447c Cherry-pick a cmdwin change from patch 9.0.0500. Co-authored-by: Bram Moolenaar --- src/nvim/ex_getln.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 6af79bfd21..c401293ccc 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4572,7 +4572,8 @@ static int open_cmdwin(void) ccline.cmdlen = (int)strlen(ccline.cmdbuff); ccline.cmdbufflen = ccline.cmdlen + 1; ccline.cmdpos = curwin->w_cursor.col; - if (ccline.cmdpos > ccline.cmdlen) { + // If the cursor is on the last character, it probably should be after it. + if (ccline.cmdpos == ccline.cmdlen - 1 || ccline.cmdpos > ccline.cmdlen) { ccline.cmdpos = ccline.cmdlen; } if (cmdwin_result == K_IGNORE) { -- cgit From 008154954791001efcc46c28146e21403f3a698b Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 21 Aug 2023 14:52:17 +0200 Subject: refactor(change): do API changes to buffer without curbuf switch Most of the messy things when changing a non-current buffer is not about the buffer, it is about windows. In particular, it is about `curwin`. When editing a non-current buffer which is displayed in some other window in the current tabpage, one such window will be "borrowed" as the curwin. But this means if two or more non-current windows displayed the buffers, one of them will be treated differenty. this is not desirable. In particular, with nvim_buf_set_text, cursor _column_ position was only corrected for one single window. Two new tests are added: the test with just one non-current window passes, but the one with two didn't. Two corresponding such tests were also added for nvim_buf_set_lines. This already worked correctly on master, but make sure this is well-tested for future refactors. Also, nvim_create_buf no longer invokes autocmds just because you happened to use `scratch=true`. No option value was changed, therefore OptionSet must not be fired. --- src/nvim/ex_getln.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index c401293ccc..08b010c153 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -492,7 +492,7 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state // first restore the old curwin values, so the screen is // positioned in the same way as the actual search command restore_viewstate(curwin, &s->old_viewstate); - changed_cline_bef_curs(); + changed_cline_bef_curs(curwin); update_topline(curwin); if (found != 0) { @@ -1460,7 +1460,7 @@ static int may_do_command_line_next_incsearch(int firstc, int count, incsearch_s set_search_match(&s->match_end); curwin->w_cursor = s->match_start; - changed_cline_bef_curs(); + changed_cline_bef_curs(curwin); update_topline(curwin); validate_cursor(); highlight_match = true; @@ -4480,7 +4480,7 @@ static int open_cmdwin(void) curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_cursor.col = ccline.cmdpos; changed_line_abv_curs(); - invalidate_botline(); + invalidate_botline(curwin); if (ui_has(kUICmdline)) { ccline.redraw_state = kCmdRedrawNone; ui_call_cmdline_hide(ccline.level); -- cgit From b04286a187d57c50f01cd36cd4668b7a69026579 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 22 Nov 2020 10:10:37 +0100 Subject: feat(extmark): support proper multiline ranges The removes the previous restriction that nvim_buf_set_extmark() could not be used to highlight arbitrary multi-line regions The problem can be summarized as follows: let's assume an extmark with a hl_group is placed covering the region (5,0) to (50,0) Now, consider what happens if nvim needs to redraw a window covering the lines 20-30. It needs to be able to ask the marktree what extmarks cover this region, even if they don't begin or end here. Therefore the marktree needs to be augmented with the information covers a point, not just what marks begin or end there. To do this, we augment each node with a field "intersect" which is a set the ids of the marks which overlap this node, but only if it is not part of the set of any parent. This ensures the number of nodes that need to be explicitly marked grows only logarithmically with the total number of explicitly nodes (and thus the number of of overlapping marks). Thus we can quickly iterate all marks which overlaps any query position by looking up what leaf node contains that position. Then we only need to consider all "start" marks within that leaf node, and the "intersect" set of that node and all its parents. Now, and the major source of complexity is that the tree restructuring operations (to ensure that each node has T-1 <= size <= 2*T-1) also need to update these sets. If a full inner node is split in two, one of the new parents might start to completely overlap some ranges and its ids will need to be moved from its children's sets to its own set. Similarly, if two undersized nodes gets joined into one, it might no longer completely overlap some ranges, and now the children which do needs to have the have the ids in its set instead. And then there are the pivots! Yes the pivot operations when a child gets moved from one parent to another. --- src/nvim/ex_getln.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 08b010c153..09781f392a 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2410,6 +2410,9 @@ static void cmdpreview_restore_state(CpInfo *cpinfo) buf->b_changed = cp_bufinfo.save_b_changed; + // Clear preview highlights. + extmark_clear(buf, (uint32_t)cmdpreview_ns, 0, 0, MAXLNUM, MAXCOL); + if (buf->b_u_seq_cur != cp_bufinfo.undo_info.save_b_u_seq_cur) { int count = 0; @@ -2439,9 +2442,6 @@ static void cmdpreview_restore_state(CpInfo *cpinfo) } buf->b_p_ul = cp_bufinfo.save_b_p_ul; // Restore 'undolevels' - - // Clear preview highlights. - extmark_clear(buf, (uint32_t)cmdpreview_ns, 0, 0, MAXLNUM, MAXCOL); } for (size_t i = 0; i < cpinfo->win_info.size; i++) { -- 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/ex_getln.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 09781f392a..4ec6d24d94 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -3400,7 +3400,7 @@ static void draw_cmdline(int start, int len) } } - msg_outtrans_len(arshape_buf, newlen); + msg_outtrans_len(arshape_buf, newlen, 0); } else { draw_cmdline_no_arabicshape: if (kv_size(ccline.last_colors.colors)) { @@ -3410,12 +3410,10 @@ draw_cmdline_no_arabicshape: continue; } const int chunk_start = MAX(chunk.start, start); - msg_outtrans_len_attr(ccline.cmdbuff + chunk_start, - chunk.end - chunk_start, - chunk.attr); + msg_outtrans_len(ccline.cmdbuff + chunk_start, chunk.end - chunk_start, chunk.attr); } } else { - msg_outtrans_len(ccline.cmdbuff + start, len); + msg_outtrans_len(ccline.cmdbuff + start, len, 0); } } } -- cgit From b85f1dafc7c0a19704135617454f1c66f41202c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:21:17 +0200 Subject: refactor(messages): fold msg_attr into msg problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 4ec6d24d94..c6fbd6bf1d 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2664,7 +2664,7 @@ static void abandon_cmdline(void) if (msg_scrolled == 0) { compute_cmdrow(); } - msg(""); + msg("", 0); redraw_cmdline = true; } -- cgit From af7d317f3ff31d5ac5d8724b5057a422e1451b54 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 26 Sep 2023 22:36:08 +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/ex_getln.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index c6fbd6bf1d..b3010bea11 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -127,7 +127,7 @@ typedef struct command_line_state { int ignore_drag_release; int break_ctrl_c; expand_T xpc; - long *b_im_ptr; + OptInt *b_im_ptr; buf_T *b_im_ptr_buf; ///< buffer where b_im_ptr is valid } CommandLineState; @@ -149,7 +149,7 @@ typedef struct cmdpreview_undo_info { typedef struct cmdpreview_buf_info { buf_T *buf; - long save_b_p_ul; + OptInt save_b_p_ul; int save_b_changed; varnumber_T save_changedtick; CpUndoInfo undo_info; @@ -1560,7 +1560,7 @@ static int command_line_erase_chars(CommandLineState *s) /// language :lmap mappings and/or Input Method. static void command_line_toggle_langmap(CommandLineState *s) { - long *b_im_ptr = buf_valid(s->b_im_ptr_buf) ? s->b_im_ptr : NULL; + OptInt *b_im_ptr = buf_valid(s->b_im_ptr_buf) ? s->b_im_ptr : NULL; if (map_to_exists_mode("", MODE_LANGMAP, false)) { // ":lmap" mappings exists, toggle use of mappings. State ^= MODE_LANGMAP; -- 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/ex_getln.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index b3010bea11..911e03ea9e 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,7 @@ #include "nvim/highlight_group.h" #include "nvim/keycodes.h" #include "nvim/macros.h" +#include "nvim/map.h" #include "nvim/mapping.h" #include "nvim/mark.h" #include "nvim/mbyte.h" -- 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/ex_getln.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 911e03ea9e..6fa607d569 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -58,6 +58,8 @@ #include "nvim/normal.h" #include "nvim/ops.h" #include "nvim/option.h" +#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/optionstr.h" #include "nvim/os/input.h" #include "nvim/os/os.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/ex_getln.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 6fa607d569..2d1633f312 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2766,6 +2766,7 @@ int check_opt_wim(void) } for (char *p = p_wim; *p; p++) { + // Note: Keep this in sync with p_wim_values. for (i = 0; ASCII_ISALPHA(p[i]); i++) {} if (p[i] != NUL && p[i] != ',' && p[i] != ':') { return FAIL; -- cgit From 09a17f91d0d362c6e58bfdbe3ccdeacffb0b44b9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 2 Oct 2023 10:45:33 +0800 Subject: refactor: move cmdline completion types to cmdexpand_defs.h (#25465) --- src/nvim/ex_getln.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 2d1633f312..4ec5e890b9 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -71,6 +71,7 @@ #include "nvim/search.h" #include "nvim/state.h" #include "nvim/strings.h" +#include "nvim/types.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/usercmd.h" -- cgit From a9a48d6b5f00241e16e7131c997f0117bc5e9047 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 30 Sep 2023 10:31:55 +0200 Subject: refactor(message): simplify msg_puts_display and use batched grid updates msg_puts_display was more complex than necessary in nvim, as in nvim, it no longer talks directly with a terminal. In particular we don't need to scroll the grid before emiting the last char. The TUI already takes care of things like that, for terminals where it matters. --- src/nvim/ex_getln.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 4ec5e890b9..d1871c11e2 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1329,7 +1329,7 @@ static int command_line_execute(VimState *state, int key) if (!cmd_silent) { if (!ui_has(kUICmdline)) { - cmd_cursor_goto(msg_row, 0); + msg_cursor_goto(msg_row, 0); } ui_flush(); } @@ -3884,7 +3884,7 @@ void redrawcmd(void) // when 'incsearch' is set there may be no command line while redrawing if (ccline.cmdbuff == NULL) { - cmd_cursor_goto(cmdline_row, 0); + msg_cursor_goto(cmdline_row, 0); msg_clr_eos(); return; } @@ -3961,14 +3961,7 @@ void cursorcmd(void) } } - cmd_cursor_goto(msg_row, msg_col); -} - -static void cmd_cursor_goto(int row, int col) -{ - ScreenGrid *grid = &msg_grid_adj; - grid_adjust(&grid, &row, &col); - ui_grid_cursor_goto(grid->handle, row, col); + msg_cursor_goto(msg_row, msg_col); } void gotocmdline(bool clr) @@ -3985,7 +3978,7 @@ void gotocmdline(bool clr) if (clr) { // clear the bottom line(s) msg_clr_eos(); // will reset clear_cmdline } - cmd_cursor_goto(cmdline_row, 0); + msg_cursor_goto(cmdline_row, 0); } // Check the word in front of the cursor for an abbreviation. -- cgit From e72b546354cd90bf0cd8ee6dd045538d713009ad Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/ex_getln.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index d1871c11e2..2a1dffacb7 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -142,11 +142,11 @@ typedef struct cmdpreview_undo_info { u_header_T *save_b_u_curhead; int save_b_u_numhead; bool save_b_u_synced; - long save_b_u_seq_last; - long save_b_u_save_nr_last; - long save_b_u_seq_cur; + int save_b_u_seq_last; + int save_b_u_save_nr_last; + int save_b_u_seq_cur; time_t save_b_u_time_cur; - long save_b_u_save_nr_cur; + int save_b_u_save_nr_cur; char *save_b_u_line_ptr; linenr_T save_b_u_line_lnum; colnr_T save_b_u_line_colnr; @@ -207,7 +207,7 @@ static int cedit_key = -1; ///< key value of 'cedit' option #endif static handle_T cmdpreview_bufnr = 0; -static long cmdpreview_ns = 0; +static int cmdpreview_ns = 0; static void save_viewstate(win_T *wp, viewstate_T *vs) FUNC_ATTR_NONNULL_ALL -- cgit From ddef39299f357d3131644647379e88a69749bf40 Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 19 Sep 2023 14:30:02 +0200 Subject: refactor(grid): do arabic shaping in one place The 'arabicshape' feature of vim is a transformation of unicode text to make arabic and some related scripts look better at display time. In particular the content of a cell will be adjusted depending on the (original) content of the cells just before and after it. This is implemented by the arabic_shape() function in nvim. Before this commit, shaping was invoked in four different contexts: - when rendering buffer text in win_line() - in line_putchar() for rendering virtual text - as part of grid_line_puts, used by messages and statuslines and similar - as part of draw_cmdline() for drawing the cmdline This replaces all these with a post-processing step in grid_put_linebuf(), which has become the entry point for all text rendering after recent refactors. An aim of this is to make the handling of multibyte text yet simpler. One of the main reasons multibyte chars needs to be "parsed" into codepoint arrays of composing chars is so that these could be inspected for the purpose of shaping. This can likely be vastly simplified in many contexts where only the total length (in bytes) and width of composed char is needed. --- src/nvim/ex_getln.c | 101 ---------------------------------------------------- 1 file changed, 101 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 2a1dffacb7..be0192789e 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2998,16 +2998,6 @@ void realloc_cmdbuff(int len) } } -static char *arshape_buf = NULL; - -#if defined(EXITFREE) -void free_arshape_buf(void) -{ - xfree(arshape_buf); -} - -#endif - enum { MAX_CB_ERRORS = 1, }; /// Color expression cmdline using built-in expressions parser @@ -3317,98 +3307,7 @@ static void draw_cmdline(int start, int len) msg_putchar('*'); i += utfc_ptr2len(ccline.cmdbuff + start + i) - 1; } - } else if (p_arshape && !p_tbidi && len > 0) { - bool do_arabicshape = false; - int mb_l; - for (int i = start; i < start + len; i += mb_l) { - char *p = ccline.cmdbuff + i; - int u8cc[MAX_MCO]; - int u8c = utfc_ptr2char_len(p, u8cc, start + len - i); - mb_l = utfc_ptr2len_len(p, start + len - i); - if (ARABIC_CHAR(u8c)) { - do_arabicshape = true; - break; - } - } - if (!do_arabicshape) { - goto draw_cmdline_no_arabicshape; - } - - static size_t buflen = 0; - assert(len >= 0); - - // Do arabic shaping into a temporary buffer. This is very - // inefficient! - if ((size_t)len * 2 + 2 > buflen) { - // Re-allocate the buffer. We keep it around to avoid a lot of - // alloc()/free() calls. - xfree(arshape_buf); - buflen = (size_t)len * 2 + 2; - arshape_buf = xmalloc(buflen); - } - - int newlen = 0; - if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) { - // Prepend a space to draw the leading composing char on. - arshape_buf[0] = ' '; - newlen = 1; - } - - int prev_c = 0; - int prev_c1 = 0; - for (int i = start; i < start + len; i += mb_l) { - char *p = ccline.cmdbuff + i; - int u8cc[MAX_MCO]; - int u8c = utfc_ptr2char_len(p, u8cc, start + len - i); - mb_l = utfc_ptr2len_len(p, start + len - i); - if (ARABIC_CHAR(u8c)) { - int pc; - int pc1 = 0; - int nc = 0; - // Do Arabic shaping. - if (cmdmsg_rl) { - // Displaying from right to left. - pc = prev_c; - pc1 = prev_c1; - prev_c1 = u8cc[0]; - if (i + mb_l >= start + len) { - nc = NUL; - } else { - nc = utf_ptr2char(p + mb_l); - } - } else { - // Displaying from left to right. - if (i + mb_l >= start + len) { - pc = NUL; - } else { - int pcc[MAX_MCO]; - - pc = utfc_ptr2char_len(p + mb_l, pcc, start + len - i - mb_l); - pc1 = pcc[0]; - } - nc = prev_c; - } - prev_c = u8c; - - u8c = arabic_shape(u8c, NULL, &u8cc[0], pc, pc1, nc); - - newlen += utf_char2bytes(u8c, arshape_buf + newlen); - if (u8cc[0] != 0) { - newlen += utf_char2bytes(u8cc[0], arshape_buf + newlen); - if (u8cc[1] != 0) { - newlen += utf_char2bytes(u8cc[1], arshape_buf + newlen); - } - } - } else { - prev_c = u8c; - memmove(arshape_buf + newlen, p, (size_t)mb_l); - newlen += mb_l; - } - } - - msg_outtrans_len(arshape_buf, newlen, 0); } else { -draw_cmdline_no_arabicshape: if (kv_size(ccline.last_colors.colors)) { for (size_t i = 0; i < kv_size(ccline.last_colors.colors); i++) { CmdlineColorChunk chunk = kv_A(ccline.last_colors.colors, i); -- cgit From 8e932480f61d6101bf8bea1abc07ed93826221fd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index be0192789e..2759dc9bb5 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -2208,7 +2208,7 @@ handle_T cmdpreview_get_bufnr(void) return cmdpreview_bufnr; } -long cmdpreview_get_ns(void) +int cmdpreview_get_ns(void) { return cmdpreview_ns; } -- 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/ex_getln.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 2759dc9bb5..9d0e3d542a 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -861,6 +861,16 @@ static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear cmdmsg_rl = false; + // We could have reached here without having a chance to clean up wild menu + // if certain special keys like or were used as wildchar. Make + // sure to still clean up to avoid memory corruption. + if (cmdline_pum_active()) { + cmdline_pum_remove(); + } + wildmenu_cleanup(&ccline); + s->did_wild_list = false; + s->wim_index = 0; + ExpandCleanup(&s->xpc); ccline.xpc = NULL; @@ -1247,13 +1257,14 @@ static int command_line_execute(VimState *state, int key) s->c = wildmenu_translate_key(&ccline, s->c, &s->xpc, s->did_wild_list); } - if (cmdline_pum_active() || s->did_wild_list) { + int wild_type = 0; + const bool key_is_wc = (s->c == p_wc && KeyTyped) || s->c == p_wcm; + if ((cmdline_pum_active() || s->did_wild_list) && !key_is_wc) { // Ctrl-Y: Accept the current selection and close the popup menu. // Ctrl-E: cancel the cmdline popup menu and return the original text. if (s->c == Ctrl_E || s->c == Ctrl_Y) { - const int wild_type = (s->c == Ctrl_E) ? WILD_CANCEL : WILD_APPLY; + wild_type = (s->c == Ctrl_E) ? WILD_CANCEL : WILD_APPLY; (void)nextwild(&s->xpc, wild_type, WILD_NO_BEEP, s->firstc != '@'); - s->c = Ctrl_E; } } @@ -1262,7 +1273,7 @@ static int command_line_execute(VimState *state, int key) // 'wildcharm' or Ctrl-N or Ctrl-P or Ctrl-A or Ctrl-L). // If the popup menu is displayed, then PageDown and PageUp keys are // also used to navigate the menu. - bool end_wildmenu = (!(s->c == p_wc && KeyTyped) && s->c != p_wcm && s->c != Ctrl_Z + bool end_wildmenu = (!key_is_wc && s->c != Ctrl_Z && s->c != Ctrl_N && s->c != Ctrl_P && s->c != Ctrl_A && s->c != Ctrl_L); end_wildmenu = end_wildmenu && (!cmdline_pum_active() @@ -1366,6 +1377,12 @@ static int command_line_execute(VimState *state, int key) } s->do_abbr = true; // default: check for abbreviation + + // If already used to cancel/accept wildmenu, don't process the key further. + if (wild_type == WILD_CANCEL || wild_type == WILD_APPLY) { + return command_line_not_changed(s); + } + return command_line_handle_key(s); } -- cgit From 9dc440400cdb470b317c4169ba916e1cd9a316e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 27 Oct 2023 06:37:52 +0800 Subject: vim-patch:9.0.2068: [security] overflow in :history (#25794) Problem: [security] overflow in :history Solution: Check that value fits into int The get_list_range() function, used to parse numbers for the :history and :clist command internally uses long variables to store the numbers. However function arguments are integer pointers, which can then overflow. Check that the return value from the vim_str2nr() function is not larger than INT_MAX and if yes, bail out with an error. I guess nobody uses a cmdline/clist history that needs so many entries... (famous last words). It is only a moderate vulnerability, so impact should be low. Github Advisory: https://github.com/vim/vim/security/advisories/GHSA-q22m-h7m2-9mgm https://github.com/vim/vim/commit/9198c1f2b1ddecde22af918541e0de2a32f0f45a N/A patch: vim-patch:9.0.2073: typo in quickfix.c comments Co-authored-by: Christian Brabandt --- src/nvim/ex_getln.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 9d0e3d542a..93fd62f107 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4241,6 +4241,11 @@ int get_list_range(char **str, int *num1, int *num2) if (**str == '-' || ascii_isdigit(**str)) { // parse "from" part of range vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, false, NULL); *str += len; + // overflow + if (num > INT_MAX) { + return FAIL; + } + *num1 = (int)num; first = true; } @@ -4249,8 +4254,13 @@ int get_list_range(char **str, int *num1, int *num2) *str = skipwhite((*str) + 1); vim_str2nr(*str, NULL, &len, 0, &num, NULL, 0, false, NULL); if (len > 0) { - *num2 = (int)num; *str = skipwhite((*str) + len); + // overflow + if (num > INT_MAX) { + return FAIL; + } + + *num2 = (int)num; } else if (!first) { // no number given at all return FAIL; } -- cgit From 44f0480a22af8f87f8784dac430416cb9913adea Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 31 Oct 2023 21:33:00 +0100 Subject: refactor(grid): implement rightleftcmd as a post-processing step Previously, 'rightleftcmd' was implemented by having all code which would affect msg_col or output screen cells be conditional on `cmdmsg_rl`. This change removes all that and instead implements rightleft as a mirroring post-processing step. --- src/nvim/ex_getln.c | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 93fd62f107..80a1410dbc 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -715,12 +715,8 @@ static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear ExpandInit(&s->xpc); ccline.xpc = &s->xpc; - if (curwin->w_p_rl && *curwin->w_p_rlc == 's' - && (s->firstc == '/' || s->firstc == '?')) { - cmdmsg_rl = true; - } else { - cmdmsg_rl = false; - } + cmdmsg_rl = (curwin->w_p_rl && *curwin->w_p_rlc == 's' + && (s->firstc == '/' || s->firstc == '?')); msg_grid_validate(); @@ -1564,11 +1560,7 @@ static int command_line_erase_chars(CommandLineState *s) XFREE_CLEAR(ccline.cmdbuff); // no commandline to return if (!cmd_silent && !ui_has(kUICmdline)) { - if (cmdmsg_rl) { - msg_col = Columns; - } else { - msg_col = 0; - } + msg_col = 0; msg_putchar(' '); // delete ':' } s->is_state.search_start = s->is_state.save_cursor; @@ -2664,7 +2656,7 @@ static int command_line_changed(CommandLineState *s) } } - if (cmdmsg_rl || (p_arshape && !p_tbidi)) { + if (p_arshape && !p_tbidi) { // Always redraw the whole command line to fix shaping and // right-left typing. Not efficient, but it works. // Do it only when there are no characters left to read @@ -3863,18 +3855,10 @@ void cursorcmd(void) return; } - if (cmdmsg_rl) { - msg_row = cmdline_row + (ccline.cmdspos / (Columns - 1)); - msg_col = Columns - (ccline.cmdspos % (Columns - 1)) - 1; - if (msg_row <= 0) { - msg_row = Rows - 1; - } - } else { - msg_row = cmdline_row + (ccline.cmdspos / Columns); - msg_col = ccline.cmdspos % Columns; - if (msg_row >= Rows) { - msg_row = Rows - 1; - } + msg_row = cmdline_row + (ccline.cmdspos / Columns); + msg_col = ccline.cmdspos % Columns; + if (msg_row >= Rows) { + msg_row = Rows - 1; } msg_cursor_goto(msg_row, msg_col); @@ -3886,11 +3870,7 @@ void gotocmdline(bool clr) return; } msg_start(); - if (cmdmsg_rl) { - msg_col = Columns - 1; - } else { - msg_col = 0; // always start in column 0 - } + msg_col = 0; // always start in column 0 if (clr) { // clear the bottom line(s) msg_clr_eos(); // will reset clear_cmdline } -- cgit From acc646ad8fc3ef11fcc63b69f3d8484e4a91accd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/ex_getln.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 80a1410dbc..dbf14f20ad 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -453,7 +453,7 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state ui_flush(); emsg_off++; // So it doesn't beep if bad expr // Set the time limit to half a second. - tm = profile_setlimit(500L); + tm = profile_setlimit(500); if (!p_hls) { search_flags += SEARCH_KEEP; } @@ -2747,7 +2747,7 @@ char *getcmdline_prompt(const int firstc, const char *const prompt, const int at int msg_silent_saved = msg_silent; msg_silent = 0; - char *const ret = (char *)command_line_enter(firstc, 1L, 0, false); + char *const ret = (char *)command_line_enter(firstc, 1, 0, false); if (did_save_ccline) { restore_cmdline(&save_ccline); @@ -2947,7 +2947,7 @@ char *getexline(int c, void *cookie, int indent, bool do_concat) (void)vgetc(); } - return getcmdline(c, 1L, indent, do_concat); + return getcmdline(c, 1, indent, do_concat); } bool cmdline_overstrike(void) -- 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/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index dbf14f20ad..ce47471976 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4371,7 +4371,7 @@ static int open_cmdwin(void) i = 0; } if (get_histentry(histtype)[i].hisstr != NULL) { - ml_append(lnum++, get_histentry(histtype)[i].hisstr, (colnr_T)0, false); + ml_append(lnum++, get_histentry(histtype)[i].hisstr, 0, false); } } while (i != *get_hisidx(histtype)); } -- 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/ex_getln.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index ce47471976..912eab2a31 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.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 - // ex_getln.c: Functions for entering and editing an Ex command line. #include @@ -609,7 +606,7 @@ static void finish_incsearch_highlighting(int gotesc, incsearch_state_T *s, bool curwin->w_cursor = s->save_cursor; setpcmark(); } - curwin->w_cursor = s->search_start; // -V519 + curwin->w_cursor = s->search_start; } restore_viewstate(curwin, &s->old_viewstate); highlight_match = false; @@ -3386,7 +3383,7 @@ void ui_ext_cmdline_block_append(size_t indent, const char *line) { char *buf = xmallocz(indent + strlen(line)); memset(buf, ' ', indent); - memcpy(buf + indent, line, strlen(line)); // -V575 + memcpy(buf + indent, line, strlen(line)); Array item = ARRAY_DICT_INIT; ADD(item, INTEGER_OBJ(0)); -- 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/ex_getln.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 912eab2a31..69025d81c7 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -249,14 +249,9 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s int *skiplen, int *patlen) FUNC_ATTR_NONNULL_ALL { - char *cmd; char *p; bool delim_optional = false; - int delim; - char *end; const char *dummy; - pos_T save_cursor; - bool use_last_pat; bool retval = false; magic_T magic = 0; @@ -290,7 +285,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s cmdmod_T dummy_cmdmod; parse_command_modifiers(&ea, &dummy, &dummy_cmdmod, true); - cmd = skip_range(ea.cmd, NULL); + char *cmd = skip_range(ea.cmd, NULL); if (vim_strchr("sgvl", (uint8_t)(*cmd)) == NULL) { goto theend; } @@ -341,11 +336,11 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s } p = skipwhite(p); - delim = (delim_optional && vim_isIDc((uint8_t)(*p))) ? ' ' : *p++; + int delim = (delim_optional && vim_isIDc((uint8_t)(*p))) ? ' ' : *p++; *search_delim = delim; - end = skip_regexp_ex(p, delim, magic_isset(), NULL, NULL, &magic); + char *end = skip_regexp_ex(p, delim, magic_isset(), NULL, NULL, &magic); - use_last_pat = end == p && *end == delim; + bool use_last_pat = end == p && *end == delim; if (end == p && !use_last_pat) { goto theend; } @@ -366,7 +361,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s *patlen = (int)(end - p); // parse the address range - save_cursor = curwin->w_cursor; + pos_T save_cursor = curwin->w_cursor; curwin->w_cursor = s->search_start; parse_cmd_address(&ea, &dummy, true); if (ea.addr_count > 0) { @@ -395,10 +390,7 @@ theend: static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state_T *s) { pos_T end_pos; - proftime_T tm; int skiplen, patlen; - char next_char; - bool use_last_pat; int search_delim; // Parsing range may already set the last search pattern. @@ -435,9 +427,9 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state int found; // do_search() result // Use the previous pattern for ":s//". - next_char = ccline.cmdbuff[skiplen + patlen]; - use_last_pat = patlen == 0 && skiplen > 0 - && ccline.cmdbuff[skiplen - 1] == next_char; + char next_char = ccline.cmdbuff[skiplen + patlen]; + bool use_last_pat = patlen == 0 && skiplen > 0 + && ccline.cmdbuff[skiplen - 1] == next_char; // If there is no pattern, don't do anything. if (patlen == 0 && !use_last_pat) { @@ -450,7 +442,7 @@ static void may_do_incsearch_highlighting(int firstc, int count, incsearch_state ui_flush(); emsg_off++; // So it doesn't beep if bad expr // Set the time limit to half a second. - tm = profile_setlimit(500); + proftime_T tm = profile_setlimit(500); if (!p_hls) { search_flags += SEARCH_KEEP; } @@ -1408,7 +1400,6 @@ static int may_do_command_line_next_incsearch(int firstc, int count, incsearch_s pos_T t; char *pat; int search_flags = SEARCH_NOOF; - char save; if (search_delim == ccline.cmdbuff[skiplen]) { pat = last_search_pattern(); @@ -1437,7 +1428,7 @@ static int may_do_command_line_next_incsearch(int firstc, int count, incsearch_s search_flags += SEARCH_KEEP; } emsg_off++; - save = pat[patlen]; + char save = pat[patlen]; pat[patlen] = NUL; int found = searchit(curwin, curbuf, &t, NULL, next_match ? FORWARD : BACKWARD, @@ -3971,11 +3962,9 @@ void escape_fname(char **pp) /// If 'orig_pat' starts with "~/", replace the home directory with "~". void tilde_replace(char *orig_pat, int num_files, char **files) { - char *p; - if (orig_pat[0] == '~' && vim_ispathsep(orig_pat[1])) { for (int i = 0; i < num_files; i++) { - p = home_replace_save(NULL, files[i]); + char *p = home_replace_save(NULL, files[i]); xfree(files[i]); files[i] = p; } -- 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/ex_getln.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 69025d81c7..cae3a65825 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -38,7 +38,6 @@ #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/grid.h" #include "nvim/highlight_defs.h" #include "nvim/highlight_group.h" #include "nvim/keycodes.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/ex_getln.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index cae3a65825..005966fa75 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1501,10 +1501,8 @@ static int command_line_erase_chars(CommandLineState *s) } if (ccline.cmdpos > 0) { - char *p; - int j = ccline.cmdpos; - p = mb_prevptr(ccline.cmdbuff, ccline.cmdbuff + j); + char *p = mb_prevptr(ccline.cmdbuff, ccline.cmdbuff + j); if (s->c == Ctrl_W) { while (p > ccline.cmdbuff && ascii_isspace(*p)) { -- 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/ex_getln.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 005966fa75..0d2247ead8 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -34,6 +34,7 @@ #include "nvim/ex_eval.h" #include "nvim/ex_getln.h" #include "nvim/extmark.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/getchar.h" #include "nvim/gettext.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- src/nvim/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 0d2247ead8..7d8d63d569 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -62,7 +62,7 @@ #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/popupmenu.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/profile.h" #include "nvim/regexp.h" #include "nvim/search.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/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 7d8d63d569..f302f44dad 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -68,7 +68,7 @@ #include "nvim/search.h" #include "nvim/state.h" #include "nvim/strings.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/usercmd.h" -- cgit From e6d38c7dac2e079d9b0f1621fef193bca858664f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 28 Nov 2023 11:46:20 +0800 Subject: vim-patch:9.0.2133: Cannot detect overstrike mode in Cmdline mode (#26263) Problem: Cannot detect overstrike mode in Cmdline mode Solution: Make mode() return "cr" for overstrike closes: vim/vim#13569 https://github.com/vim/vim/commit/d1c3ef1f47c87d1da056c56564e1985fe6f2931d --- src/nvim/ex_getln.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index f302f44dad..37af6b6a44 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1835,8 +1835,10 @@ static int command_line_handle_key(CommandLineState *s) case K_INS: case K_KINS: ccline.overstrike = !ccline.overstrike; - ui_cursor_shape(); // may show different cursor shape + may_trigger_modechanged(); + status_redraw_curbuf(); + redraw_statuslines(); return command_line_not_changed(s); case Ctrl_HAT: -- 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/ex_getln.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 37af6b6a44..b078f77b98 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -15,7 +15,7 @@ #include "nvim/api/private/helpers.h" #include "nvim/api/vim.h" #include "nvim/arabic.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/charset.h" @@ -42,8 +42,8 @@ #include "nvim/highlight_defs.h" #include "nvim/highlight_group.h" #include "nvim/keycodes.h" -#include "nvim/macros.h" -#include "nvim/map.h" +#include "nvim/macros_defs.h" +#include "nvim/map_defs.h" #include "nvim/mapping.h" #include "nvim/mark.h" #include "nvim/mbyte.h" @@ -72,7 +72,7 @@ #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/usercmd.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/viml/parser/expressions.h" #include "nvim/viml/parser/parser.h" #include "nvim/window.h" -- 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/ex_getln.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index b078f77b98..64ef17b157 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -39,7 +39,7 @@ #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/highlight_defs.h" +#include "nvim/highlight.h" #include "nvim/highlight_group.h" #include "nvim/keycodes.h" #include "nvim/macros_defs.h" -- cgit