From 361de6d54d41fc0fc8f8a89ec779696f3f7bb46e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 3 Mar 2023 07:44:16 +0800 Subject: vim-patch:9.0.1371: ballooneval interferes with Insert completion (#22487) Problem: Ballooneval interferes with Insert completion. Solution: Ignore mouse-move events when completing. (closes vim/vim#12094, closes vim/vim#12092) https://github.com/vim/vim/commit/440d4cb55b84fd4b188630abc4a1312598649af0 --- src/nvim/insexpand.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 6de3b0a9d0..8928979455 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2096,10 +2096,10 @@ bool ins_compl_prep(int c) edit_submode_extra = NULL; } - // Ignore end of Select mode mapping and mouse scroll buttons. + // Ignore end of Select mode mapping and mouse scroll/movement. if (c == K_SELECT || c == K_MOUSEDOWN || c == K_MOUSEUP - || c == K_MOUSELEFT || c == K_MOUSERIGHT || c == K_EVENT - || c == K_COMMAND || c == K_LUA) { + || c == K_MOUSELEFT || c == K_MOUSERIGHT || c == K_MOUSEMOVE + || c == K_EVENT || c == K_COMMAND || c == K_LUA) { return retval; } @@ -3043,8 +3043,8 @@ static void get_next_spell_completion(linenr_T lnum) /// @param cur_match_pos current match position /// @param match_len /// @param cont_s_ipos next ^X<> will set initial_pos -static char *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_pos, int *match_len, - bool *cont_s_ipos) +static char *ins_compl_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_pos, int *match_len, + bool *cont_s_ipos) { *match_len = 0; char *ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, false) + cur_match_pos->col; @@ -3206,8 +3206,8 @@ static int get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_ continue; } int len; - char *ptr = ins_comp_get_next_word_or_line(st->ins_buf, st->cur_match_pos, - &len, &cont_s_ipos); + char *ptr = ins_compl_get_next_word_or_line(st->ins_buf, st->cur_match_pos, + &len, &cont_s_ipos); if (ptr == NULL) { continue; } -- 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/insexpand.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 8928979455..c61c74c607 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -54,7 +54,6 @@ #include "nvim/popupmenu.h" #include "nvim/pos.h" #include "nvim/regexp.h" -#include "nvim/screen.h" #include "nvim/search.h" #include "nvim/spell.h" #include "nvim/state.h" -- cgit From 063e93864a7e99ac1c4781bbe4ea63c0adb075a8 Mon Sep 17 00:00:00 2001 From: Lucas Merritt Date: Fri, 24 Mar 2023 22:11:14 -0600 Subject: refactor(PVS/V1048): remove duplicated assignments (#21873) --- src/nvim/insexpand.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index c61c74c607..7100146245 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2890,7 +2890,7 @@ static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_ar status = INS_COMPL_CPT_END; } else { if (ctrl_x_mode_line_or_eval()) { - compl_type = -1; + // compl_type = -1; } else if (*st->e_cpt == 'k' || *st->e_cpt == 's') { if (*st->e_cpt == 'k') { compl_type = CTRL_X_DICTIONARY; @@ -2912,8 +2912,6 @@ static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_ar vim_snprintf(IObuff, IOSIZE, "%s", _("Scanning tags.")); (void)msg_trunc_attr(IObuff, true, HL_ATTR(HLF_R)); } - } else { - compl_type = -1; } // in any case e_cpt is advanced to the next entry -- 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/insexpand.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 7100146245..50107cdfea 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -187,8 +187,8 @@ typedef enum { CP_FAST = 32, ///< use fast_breakcheck instead of os_breakcheck } cp_flags_T; -static char e_hitend[] = N_("Hit end of paragraph"); -static char e_compldel[] = N_("E840: Completion function deleted text"); +static const char e_hitend[] = N_("Hit end of paragraph"); +static const char e_compldel[] = N_("E840: Completion function deleted text"); // All the current matches are stored in a list. // "compl_first_match" points to the start of the list. @@ -2257,7 +2257,7 @@ static void copy_global_to_buflocal_cb(Callback *globcb, Callback *bufcb) /// Invoked when the 'completefunc' option is set. The option value can be a /// name of a function (string), or function() or funcref() or a /// lambda expression. -void set_completefunc_option(char **errmsg) +void set_completefunc_option(const char **errmsg) { if (option_set_callback_func(curbuf->b_p_cfu, &cfu_cb) == FAIL) { *errmsg = e_invarg; @@ -2278,7 +2278,7 @@ void set_buflocal_cfu_callback(buf_T *buf) /// Invoked when the 'omnifunc' option is set. The option value can be a /// name of a function (string), or function() or funcref() or a /// lambda expression. -void set_omnifunc_option(buf_T *buf, char **errmsg) +void set_omnifunc_option(buf_T *buf, const char **errmsg) { if (option_set_callback_func(buf->b_p_ofu, &ofu_cb) == FAIL) { *errmsg = e_invarg; @@ -2298,7 +2298,7 @@ void set_buflocal_ofu_callback(buf_T *buf) /// Invoked when the 'thesaurusfunc' option is set. The option value can be a /// name of a function (string), or function() or funcref() or a /// lambda expression. -void set_thesaurusfunc_option(char **errmsg) +void set_thesaurusfunc_option(const char **errmsg) { int retval; -- cgit From 7190dba017e3aac0409c73ff1c954d18858cb3c9 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:39:50 +0200 Subject: refactor: remove use of reserved c++ keywords libnvim couldn't be easily used in C++ due to the use of reserved keywords. Additionally, add explicit casts to *alloc function calls used in inline functions, as C++ doesn't allow implicit casts from void pointers. --- src/nvim/insexpand.c | 54 ++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 50107cdfea..78f400b39d 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -1067,14 +1067,14 @@ static bool pum_enough_matches(void) { // Don't display the popup menu if there are no matches or there is only // one (ignoring the original text). - compl_T *compl = compl_first_match; + compl_T *comp = compl_first_match; int i = 0; do { - if (compl == NULL || (!match_at_original_text(compl) && ++i == 2)) { + if (comp == NULL || (!match_at_original_text(comp) && ++i == 2)) { break; } - compl = compl->cp_next; - } while (!is_first_match(compl)); + comp = comp->cp_next; + } while (!is_first_match(comp)); if (strstr(p_cot, "menuone") != NULL) { return i >= 1; @@ -1138,7 +1138,7 @@ static int ins_compl_build_pum(void) { // Need to build the popup menu list. compl_match_arraysize = 0; - compl_T *compl = compl_first_match; + compl_T *comp = compl_first_match; // If it's user complete function and refresh_always, // do not use "compl_leader" as prefix filter. @@ -1149,13 +1149,13 @@ static int ins_compl_build_pum(void) const int lead_len = compl_leader != NULL ? (int)strlen(compl_leader) : 0; do { - if (!match_at_original_text(compl) + if (!match_at_original_text(comp) && (compl_leader == NULL - || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) { + || ins_compl_equal(comp, compl_leader, (size_t)lead_len))) { compl_match_arraysize++; } - compl = compl->cp_next; - } while (compl != NULL && !is_first_match(compl)); + comp = comp->cp_next; + } while (comp != NULL && !is_first_match(comp)); if (compl_match_arraysize == 0) { return -1; @@ -1172,46 +1172,46 @@ static int ins_compl_build_pum(void) bool did_find_shown_match = false; int cur = -1; int i = 0; - compl = compl_first_match; + comp = compl_first_match; do { - if (!match_at_original_text(compl) + if (!match_at_original_text(comp) && (compl_leader == NULL - || ins_compl_equal(compl, compl_leader, (size_t)lead_len))) { + || ins_compl_equal(comp, compl_leader, (size_t)lead_len))) { if (!shown_match_ok) { - if (compl == compl_shown_match || did_find_shown_match) { + if (comp == compl_shown_match || did_find_shown_match) { // This item is the shown match or this is the // first displayed item after the shown match. - compl_shown_match = compl; + compl_shown_match = comp; did_find_shown_match = true; shown_match_ok = true; } else { // Remember this displayed match for when the // shown match is just below it. - shown_compl = compl; + shown_compl = comp; } cur = i; } - if (compl->cp_text[CPT_ABBR] != NULL) { - compl_match_array[i].pum_text = compl->cp_text[CPT_ABBR]; + if (comp->cp_text[CPT_ABBR] != NULL) { + compl_match_array[i].pum_text = comp->cp_text[CPT_ABBR]; } else { - compl_match_array[i].pum_text = compl->cp_str; + compl_match_array[i].pum_text = comp->cp_str; } - compl_match_array[i].pum_kind = compl->cp_text[CPT_KIND]; - compl_match_array[i].pum_info = compl->cp_text[CPT_INFO]; - if (compl->cp_text[CPT_MENU] != NULL) { - compl_match_array[i++].pum_extra = compl->cp_text[CPT_MENU]; + compl_match_array[i].pum_kind = comp->cp_text[CPT_KIND]; + compl_match_array[i].pum_info = comp->cp_text[CPT_INFO]; + if (comp->cp_text[CPT_MENU] != NULL) { + compl_match_array[i++].pum_extra = comp->cp_text[CPT_MENU]; } else { - compl_match_array[i++].pum_extra = compl->cp_fname; + compl_match_array[i++].pum_extra = comp->cp_fname; } } - if (compl == compl_shown_match) { + if (comp == compl_shown_match) { did_find_shown_match = true; // When the original text is the shown match don't set // compl_shown_match. - if (match_at_original_text(compl)) { + if (match_at_original_text(comp)) { shown_match_ok = true; } @@ -1222,8 +1222,8 @@ static int ins_compl_build_pum(void) shown_match_ok = true; } } - compl = compl->cp_next; - } while (compl != NULL && !is_first_match(compl)); + comp = comp->cp_next; + } while (comp != NULL && !is_first_match(comp)); if (!shown_match_ok) { // no displayed match at all cur = -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/insexpand.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 78f400b39d..122c8393d7 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -1414,7 +1414,7 @@ static int thesaurus_add_words_in_line(char *fname, char **buf_arg, int dir, con // different classes, only separate words // with single-byte non-word characters. while (*ptr != NUL) { - const int l = utfc_ptr2len((const char *)ptr); + const int l = utfc_ptr2len(ptr); if (l < 2 && !vim_iswordc((uint8_t)(*ptr))) { break; @@ -2515,7 +2515,7 @@ static void ins_compl_add_dict(dict_T *dict) compl_opt_refresh_always = false; di_refresh = tv_dict_find(dict, S_LEN("refresh")); if (di_refresh != NULL && di_refresh->di_tv.v_type == VAR_STRING) { - const char *v = (const char *)di_refresh->di_tv.vval.v_string; + const char *v = di_refresh->di_tv.vval.v_string; if (v != NULL && strcmp(v, "always") == 0) { compl_opt_refresh_always = true; @@ -4301,7 +4301,7 @@ static void ins_compl_show_statusmsg(void) if (edit_submode_extra != NULL) { if (!p_smd) { msg_hist_off = true; - msg_attr((const char *)edit_submode_extra, + msg_attr(edit_submode_extra, (edit_submode_highl < HLF_COUNT ? HL_ATTR(edit_submode_highl) : 0)); msg_hist_off = false; -- cgit From 04933b1ea968f958d2541dd65fd33ebb503caac3 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:08:16 +0200 Subject: refactor: remove redundant casts --- src/nvim/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 122c8393d7..800d7e29ca 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -1750,7 +1750,7 @@ void ins_compl_addleader(int c) if ((cc = utf_char2len(c)) > 1) { char buf[MB_MAXBYTES + 1]; - utf_char2bytes(c, (char *)buf); + utf_char2bytes(c, buf); buf[cc] = NUL; ins_char_bytes(buf, (size_t)cc); } else { -- cgit From 431b152726013ec6a5cece0285e7c103673bc511 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Apr 2023 08:12:44 +0800 Subject: vim-patch:9.0.1479: small source file problems; outdated list of distrib. files (#23272) Problem: Small source file problems; outdated list of distributed files. Solution: Small updates to source files and list of distributed files. https://github.com/vim/vim/commit/f39d9e9dca443e42920066be3a98fd9780e4ed33 Co-authored-by: Bram Moolenaar --- src/nvim/insexpand.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 800d7e29ca..5baf090f14 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2651,7 +2651,7 @@ static void ins_compl_update_sequence_numbers(void) compl_T *match; if (compl_dir_forward()) { - // search backwards for the first valid (!= -1) number. + // Search backwards for the first valid (!= -1) number. // This should normally succeed already at the first loop // cycle, so it's fast! for (match = compl_curr_match->cp_prev; @@ -2671,7 +2671,7 @@ static void ins_compl_update_sequence_numbers(void) } } else { // BACKWARD assert(compl_direction == BACKWARD); - // search forwards (upwards) for the first valid (!= -1) + // Search forwards (upwards) for the first valid (!= -1) // number. This should normally succeed already at the // first loop cycle, so it's fast! for (match = compl_curr_match->cp_next; @@ -2682,8 +2682,7 @@ static void ins_compl_update_sequence_numbers(void) } } if (match != NULL) { - // go down and assign all numbers which are not - // assigned yet + // go down and assign all numbers which are not assigned yet for (match = match->cp_prev; match && match->cp_number == -1; match = match->cp_prev) { -- 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/insexpand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 5baf090f14..6624b39d0c 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3147,7 +3147,7 @@ static int get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_ } bool looped_around = false; int found_new_match = FAIL; - for (;;) { + while (true) { bool cont_s_ipos = false; msg_silent++; // Don't want messages for wrapscan. @@ -3311,7 +3311,7 @@ static int ins_compl_get_exp(pos_T *ini) st.cur_match_pos = compl_dir_forward() ? &st.last_match_pos : &st.first_match_pos; // For ^N/^P loop over all the flags/windows/buffers in 'complete' - for (;;) { + while (true) { found_new_match = FAIL; st.set_match_pos = false; -- 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/insexpand.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 6624b39d0c..d6860fff30 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2257,14 +2257,14 @@ static void copy_global_to_buflocal_cb(Callback *globcb, Callback *bufcb) /// Invoked when the 'completefunc' option is set. The option value can be a /// name of a function (string), or function() or funcref() or a /// lambda expression. -void set_completefunc_option(const char **errmsg) +const char *did_set_completefunc(optset_T *args FUNC_ATTR_UNUSED) { if (option_set_callback_func(curbuf->b_p_cfu, &cfu_cb) == FAIL) { - *errmsg = e_invarg; - return; + return e_invarg; } set_buflocal_cfu_callback(curbuf); + return NULL; } /// Copy the global 'completefunc' callback function to the buffer-local @@ -2278,13 +2278,14 @@ void set_buflocal_cfu_callback(buf_T *buf) /// Invoked when the 'omnifunc' option is set. The option value can be a /// name of a function (string), or function() or funcref() or a /// lambda expression. -void set_omnifunc_option(buf_T *buf, const char **errmsg) +const char *did_set_omnifunc(optset_T *args) { + buf_T *buf = (buf_T *)args->os_buf; if (option_set_callback_func(buf->b_p_ofu, &ofu_cb) == FAIL) { - *errmsg = e_invarg; - return; + return e_invarg; } set_buflocal_ofu_callback(buf); + return NULL; } /// Copy the global 'omnifunc' callback function to the buffer-local 'omnifunc' @@ -2298,7 +2299,7 @@ void set_buflocal_ofu_callback(buf_T *buf) /// Invoked when the 'thesaurusfunc' option is set. The option value can be a /// name of a function (string), or function() or funcref() or a /// lambda expression. -void set_thesaurusfunc_option(const char **errmsg) +const char *did_set_thesaurusfunc(optset_T *args FUNC_ATTR_UNUSED) { int retval; @@ -2310,9 +2311,7 @@ void set_thesaurusfunc_option(const char **errmsg) retval = option_set_callback_func(p_tsrfu, &tsrfu_cb); } - if (retval == FAIL) { - *errmsg = e_invarg; - } + return retval == FAIL ? e_invarg : NULL; } /// Mark the global 'completefunc' 'omnifunc' and 'thesaurusfunc' callbacks with -- cgit From 2f17ef1fc4b96cf1106fd95ba090d34a2e4b977b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 22 Jun 2023 04:09:14 -0700 Subject: fix(messages): use "Vimscript" instead of "VimL" #24111 followup to #24109 fix #16150 --- src/nvim/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index d6860fff30..8285c0c2b8 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2432,7 +2432,7 @@ theend: } } -/// Add a match to the list of matches from VimL object +/// Add a match to the list of matches from Vimscript object /// /// @param[in] tv Object to get matches from. /// @param[in] dir Completion direction. -- 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/insexpand.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 8285c0c2b8..1a77679abd 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -64,6 +64,7 @@ #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/vim.h" +#include "nvim/window.h" // Definitions used for CTRL-X submode. // Note: If you change CTRL-X submode, you must also maintain ctrl_x_msgs[] @@ -161,7 +162,8 @@ struct compl_S { /// state information used for getting the next set of insert completion /// matches. typedef struct { - char *e_cpt; ///< current entry in 'complete' + char *e_cpt_copy; ///< copy of 'complete' + char *e_cpt; ///< current entry in "e_cpt_copy" buf_T *ins_buf; ///< buffer being scanned pos_T *cur_match_pos; ///< current match position pos_T prev_match_pos; ///< previous match position @@ -2219,7 +2221,8 @@ static buf_T *ins_compl_next_buf(buf_T *buf, int flag) static win_T *wp = NULL; if (flag == 'w') { // just windows - if (buf == curbuf || wp == NULL) { // first call for this flag/expansion + if (buf == curbuf || !win_valid(wp)) { + // first call for this flag/expansion or window was closed wp = curwin; } assert(wp); @@ -3287,6 +3290,7 @@ static bool get_next_completion_match(int type, ins_compl_next_state_T *st, pos_ static int ins_compl_get_exp(pos_T *ini) { static ins_compl_next_state_T st; + static bool st_cleared = false; int i; int found_new_match; int type = ctrl_x_mode; @@ -3297,9 +3301,16 @@ static int ins_compl_get_exp(pos_T *ini) FOR_ALL_BUFFERS(buf) { buf->b_scanned = false; } + if (!st_cleared) { + CLEAR_FIELD(st); + st_cleared = true; + } st.found_all = false; st.ins_buf = curbuf; - st.e_cpt = (compl_cont_status & CONT_LOCAL) ? "." : curbuf->b_p_cpt; + xfree(st.e_cpt_copy); + // Make a copy of 'complete', in case the buffer is wiped out. + st.e_cpt_copy = xstrdup((compl_cont_status & CONT_LOCAL) ? "." : curbuf->b_p_cpt); + st.e_cpt = st.e_cpt_copy == NULL ? "" : st.e_cpt_copy; st.last_match_pos = st.first_match_pos = *ini; } else if (st.ins_buf != curbuf && !buf_valid(st.ins_buf)) { st.ins_buf = curbuf; // In case the buffer was wiped out. @@ -3599,6 +3610,7 @@ static int ins_compl_next(bool allow_get_expansion, int count, bool insert_match int num_matches = -1; int todo = count; const bool started = compl_started; + buf_T *const orig_curbuf = curbuf; // When user complete function return -1 for findstart which is next // time of 'always', compl_shown_match become NULL. @@ -3634,6 +3646,12 @@ static int ins_compl_next(bool allow_get_expansion, int count, bool insert_match return -1; } + if (curbuf != orig_curbuf) { + // In case some completion function switched buffer, don't want to + // insert the completion elsewhere. + return -1; + } + // Insert the text of the new completion, or the compl_leader. if (compl_no_insert && !started) { ins_bytes(compl_orig_text + get_compl_len()); -- cgit From cefd774fac76b91f5368833555818c80c992c3b1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 24 Aug 2023 15:14:23 +0200 Subject: refactor(memline): distinguish mutating uses of ml_get_buf() ml_get_buf() takes a third parameters to indicate whether the caller wants to mutate the memline data in place. However the vast majority of the call sites is using this function just to specify a buffer but without any mutation. This makes it harder to grep for the places which actually perform mutation. Solution: Remove the bool param from ml_get_buf(). it now works like ml_get() except for a non-current buffer. Add a new ml_get_buf_mut() function for the mutating use-case, which can be grepped along with the other ml_replace() etc functions which can modify the memline. --- src/nvim/insexpand.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 1a77679abd..fe15e21a29 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3045,14 +3045,14 @@ static char *ins_compl_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_po bool *cont_s_ipos) { *match_len = 0; - char *ptr = ml_get_buf(ins_buf, cur_match_pos->lnum, false) + cur_match_pos->col; + char *ptr = ml_get_buf(ins_buf, cur_match_pos->lnum) + cur_match_pos->col; int len; if (ctrl_x_mode_line_or_eval()) { if (compl_status_adding()) { if (cur_match_pos->lnum >= ins_buf->b_ml.ml_line_count) { return NULL; } - ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); + ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1); if (!p_paste) { ptr = skipwhite(ptr); } @@ -3080,7 +3080,7 @@ static char *ins_compl_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_po // normal command "J" was used. IOSIZE is always greater than // compl_length, so the next strncpy always works -- Acevedo strncpy(IObuff, ptr, (size_t)len); // NOLINT(runtime/printf) - ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1, false); + ptr = ml_get_buf(ins_buf, cur_match_pos->lnum + 1); tmp_ptr = ptr = skipwhite(ptr); // Find start of next word. tmp_ptr = find_word_start(tmp_ptr); -- 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/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index fe15e21a29..d961d6664a 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3446,7 +3446,7 @@ void ins_compl_delete(void) // TODO(vim): is this sufficient for redrawing? Redrawing everything // causes flicker, thus we can't do that. - changed_cline_bef_curs(); + changed_cline_bef_curs(curwin); // clear v:completed_item set_vim_var_dict(VV_COMPLETED_ITEM, tv_dict_alloc_lock(VAR_FIXED)); } -- 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/insexpand.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index d961d6664a..80118e9e11 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -467,9 +467,8 @@ bool check_compl_option(bool dict_opt) && *curbuf->b_p_tsrfu == NUL && *p_tsrfu == NUL)) { ctrl_x_mode = CTRL_X_NORMAL; edit_submode = NULL; - msg_attr((dict_opt - ? _("'dictionary' option is empty") - : _("'thesaurus' option is empty")), HL_ATTR(HLF_E)); + msg((dict_opt ? _("'dictionary' option is empty") : _("'thesaurus' option is empty")), + HL_ATTR(HLF_E)); if (emsg_silent == 0 && !in_assert_fails) { vim_beep(BO_COMPL); setcursor(); @@ -3490,7 +3489,7 @@ static void ins_compl_show_filename(void) msg_hist_off = true; vim_snprintf(IObuff, IOSIZE, "%s %s%s", lead, s > compl_shown_match->cp_fname ? "<" : "", s); - msg(IObuff); + msg(IObuff, 0); msg_hist_off = false; redraw_cmdline = false; // don't overwrite! } @@ -4317,9 +4316,8 @@ static void ins_compl_show_statusmsg(void) if (edit_submode_extra != NULL) { if (!p_smd) { msg_hist_off = true; - msg_attr(edit_submode_extra, - (edit_submode_highl < HLF_COUNT - ? HL_ATTR(edit_submode_highl) : 0)); + msg(edit_submode_extra, (edit_submode_highl < HLF_COUNT + ? HL_ATTR(edit_submode_highl) : 0)); msg_hist_off = false; } } else { -- cgit From 448d4837be7f7bd60ac0b5a3100c0217ac48a495 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:24:50 +0200 Subject: refactor(messages): rename msg_trunc_attr and msg_multiline_attr without attr --- src/nvim/insexpand.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 80118e9e11..e1e1750e8e 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -1451,10 +1451,10 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r for (i = 0; i < count && !got_int && !compl_interrupted; i++) { fp = os_fopen(files[i], "r"); // open dictionary file if (flags != DICT_EXACT && !shortmess(SHM_COMPLETIONSCAN)) { - msg_hist_off = true; // reset in msg_trunc_attr() + msg_hist_off = true; // reset in msg_trunc() vim_snprintf(IObuff, IOSIZE, _("Scanning dictionary: %s"), files[i]); - (void)msg_trunc_attr(IObuff, true, HL_ATTR(HLF_R)); + (void)msg_trunc(IObuff, true, HL_ATTR(HLF_R)); } if (fp == NULL) { @@ -2877,14 +2877,14 @@ static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_ar st->dict_f = DICT_EXACT; } if (!shortmess(SHM_COMPLETIONSCAN)) { - msg_hist_off = true; // reset in msg_trunc_attr() + msg_hist_off = true; // reset in msg_trunc() vim_snprintf(IObuff, IOSIZE, _("Scanning: %s"), st->ins_buf->b_fname == NULL ? buf_spname(st->ins_buf) : st->ins_buf->b_sfname == NULL ? st->ins_buf->b_fname : st->ins_buf->b_sfname); - (void)msg_trunc_attr(IObuff, true, HL_ATTR(HLF_R)); + (void)msg_trunc(IObuff, true, HL_ATTR(HLF_R)); } } else if (*st->e_cpt == NUL) { status = INS_COMPL_CPT_END; @@ -2908,9 +2908,9 @@ static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_ar } else if (*st->e_cpt == ']' || *st->e_cpt == 't') { compl_type = CTRL_X_TAGS; if (!shortmess(SHM_COMPLETIONSCAN)) { - msg_hist_off = true; // reset in msg_trunc_attr() + msg_hist_off = true; // reset in msg_trunc() vim_snprintf(IObuff, IOSIZE, "%s", _("Scanning tags.")); - (void)msg_trunc_attr(IObuff, true, HL_ATTR(HLF_R)); + (void)msg_trunc(IObuff, true, HL_ATTR(HLF_R)); } } -- 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/insexpand.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index e1e1750e8e..347b18f908 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -23,7 +23,6 @@ #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" -#include "nvim/eval/typval_defs.h" #include "nvim/eval/userfunc.h" #include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.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/insexpand.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 347b18f908..4a6c819015 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -46,6 +46,8 @@ #include "nvim/message.h" #include "nvim/move.h" #include "nvim/option.h" +#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/os/fs.h" #include "nvim/os/input.h" #include "nvim/os/time.h" -- 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/insexpand.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 4a6c819015..3ada39c800 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -24,7 +24,6 @@ #include "nvim/eval.h" #include "nvim/eval/typval.h" #include "nvim/eval/userfunc.h" -#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/ex_eval.h" #include "nvim/ex_getln.h" -- cgit From 1bbbca267d05709029a691c36e7c1fe415c9facc Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 8 Oct 2023 00:40:23 +0200 Subject: fix(PVS/V547): expression is always true/false --- src/nvim/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 3ada39c800..5ac40d7238 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3309,7 +3309,7 @@ static int ins_compl_get_exp(pos_T *ini) xfree(st.e_cpt_copy); // Make a copy of 'complete', in case the buffer is wiped out. st.e_cpt_copy = xstrdup((compl_cont_status & CONT_LOCAL) ? "." : curbuf->b_p_cpt); - st.e_cpt = st.e_cpt_copy == NULL ? "" : st.e_cpt_copy; + st.e_cpt = st.e_cpt_copy; st.last_match_pos = st.first_match_pos = *ini; } else if (st.ins_buf != curbuf && !buf_valid(st.ins_buf)) { st.ins_buf = curbuf; // In case the buffer was wiped out. -- cgit From d2d38858d1f33a2cd92e9a6182ece2459b0d6f75 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 12 Oct 2023 08:21:01 +0800 Subject: vim-patch:9.0.2018: complete_info() returns wrong index (#25607) Problem: complete_info() returns wrong index Solution: Make order of 'info' in completion_info consistent Start the iteration from the same point and follow the same direction as done when assigning the completion numbers. This way we remove the dependence on the completion direction and make the order of 'info' consistent. closes: vim/vim#12230 closes: vim/vim#12971 https://github.com/vim/vim/commit/69fb5afb3bc9da24c2fb0eafb0027ba9c6502fc2 Co-authored-by: LemonBoy --- src/nvim/insexpand.c | 56 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 22 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 5ac40d7238..6f99708e1d 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2693,6 +2693,38 @@ static void ins_compl_update_sequence_numbers(void) } } +static int info_add_completion_info(list_T *li) +{ + if (compl_first_match == NULL) { + return OK; + } + + // Skip the element with the CP_ORIGINAL_TEXT flag at the beginning, in case of + // forward completion, or at the end, in case of backward completion. + compl_T *match = compl_dir_forward() ? compl_first_match->cp_next + : compl_first_match->cp_prev->cp_prev; + while (match != NULL && !match_at_original_text(match)) { + dict_T *di = tv_dict_alloc(); + + tv_list_append_dict(li, di); + tv_dict_add_str(di, S_LEN("word"), EMPTY_IF_NULL(match->cp_str)); + tv_dict_add_str(di, S_LEN("abbr"), EMPTY_IF_NULL(match->cp_text[CPT_ABBR])); + tv_dict_add_str(di, S_LEN("menu"), EMPTY_IF_NULL(match->cp_text[CPT_MENU])); + tv_dict_add_str(di, S_LEN("kind"), EMPTY_IF_NULL(match->cp_text[CPT_KIND])); + tv_dict_add_str(di, S_LEN("info"), EMPTY_IF_NULL(match->cp_text[CPT_INFO])); + if (match->cp_user_data.v_type == VAR_UNKNOWN) { + // Add an empty string for backwards compatibility + tv_dict_add_str(di, S_LEN("user_data"), ""); + } else { + tv_dict_add_tv(di, S_LEN("user_data"), &match->cp_user_data); + } + + match = compl_dir_forward() ? match->cp_next : match->cp_prev; + } + + return OK; +} + /// Get complete information static void get_complete_info(list_T *what_list, dict_T *retdict) { @@ -2738,29 +2770,9 @@ static void get_complete_info(list_T *what_list, dict_T *retdict) if (ret == OK && (what_flag & CI_WHAT_ITEMS)) { list_T *li = tv_list_alloc(get_compl_len()); - ret = tv_dict_add_list(retdict, S_LEN("items"), li); - if (ret == OK && compl_first_match != NULL) { - compl_T *match = compl_first_match; - do { - if (!match_at_original_text(match)) { - dict_T *di = tv_dict_alloc(); - - tv_list_append_dict(li, di); - tv_dict_add_str(di, S_LEN("word"), EMPTY_IF_NULL(match->cp_str)); - tv_dict_add_str(di, S_LEN("abbr"), EMPTY_IF_NULL(match->cp_text[CPT_ABBR])); - tv_dict_add_str(di, S_LEN("menu"), EMPTY_IF_NULL(match->cp_text[CPT_MENU])); - tv_dict_add_str(di, S_LEN("kind"), EMPTY_IF_NULL(match->cp_text[CPT_KIND])); - tv_dict_add_str(di, S_LEN("info"), EMPTY_IF_NULL(match->cp_text[CPT_INFO])); - if (match->cp_user_data.v_type == VAR_UNKNOWN) { - // Add an empty string for backwards compatibility - tv_dict_add_str(di, S_LEN("user_data"), ""); - } else { - tv_dict_add_tv(di, S_LEN("user_data"), &match->cp_user_data); - } - } - match = match->cp_next; - } while (match != NULL && !is_first_match(match)); + if (ret == OK) { + ret = info_add_completion_info(li); } } -- cgit From c9963e2212bda7a4d2186469ad07078d348353cf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 17 Oct 2023 17:49:22 +0800 Subject: vim-patch:9.0.2039: completion shows current word after completion restart (#25682) Problem: completion shows current word after completion restart Solution: remove the word being completed after completion restart The word being completed is shown in a completion list after completion restart, because it isn't removed from the current buffer before searching for matches. Also adjust `Test_complete_add_onechar` to match the new behavior. closes: vim/vim#13349 https://github.com/vim/vim/commit/2e3cd52fa02b1a208c97992b1bca3b04f7be66d4 Co-authored-by: nwounkn --- src/nvim/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 6f99708e1d..09860a6a40 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3635,7 +3635,7 @@ static int ins_compl_next(bool allow_get_expansion, int count, bool insert_match } if (allow_get_expansion && insert_match - && (!(compl_get_longest || compl_restarting) || compl_used_match)) { + && (!compl_get_longest || compl_used_match)) { // Delete old text to be replaced ins_compl_delete(); } -- cgit From ae4ca4edf89ece433b61e8bf92c412298b58d9ea Mon Sep 17 00:00:00 2001 From: glepnir Date: Fri, 13 Oct 2023 14:49:01 +0800 Subject: feat(complete): support f flag for complete buffer part --- src/nvim/insexpand.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 09860a6a40..427088e414 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -91,6 +91,7 @@ enum { CTRL_X_LOCAL_MSG = 15, ///< only used in "ctrl_x_msgs" CTRL_X_EVAL = 16, ///< for builtin function complete() CTRL_X_CMDLINE_CTRL_X = 17, ///< CTRL-X typed in CTRL_X_CMDLINE + CTRL_X_BUFNAMES = 18, }; #define CTRL_X_MSG(i) ctrl_x_msgs[(i) & ~CTRL_X_WANT_IDENT] @@ -536,6 +537,8 @@ bool vim_is_ctrl_x_key(int c) return c == Ctrl_S || c == Ctrl_P || c == Ctrl_N; case CTRL_X_EVAL: return (c == Ctrl_P || c == Ctrl_N); + case CTRL_X_BUFNAMES: + return (c == Ctrl_P || c == Ctrl_N); } internal_error("vim_is_ctrl_x_key()"); return false; @@ -2917,6 +2920,8 @@ static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_ar compl_type = CTRL_X_PATH_PATTERNS; } else if (*st->e_cpt == 'd') { compl_type = CTRL_X_PATH_DEFINES; + } else if (*st->e_cpt == 'f') { + compl_type = CTRL_X_BUFNAMES; } else if (*st->e_cpt == ']' || *st->e_cpt == 't') { compl_type = CTRL_X_TAGS; if (!shortmess(SHM_COMPLETIONSCAN)) { @@ -3274,6 +3279,9 @@ static bool get_next_completion_match(int type, ins_compl_next_state_T *st, pos_ case CTRL_X_SPELL: get_next_spell_completion(st->first_match_pos.lnum); break; + case CTRL_X_BUFNAMES: + get_next_bufname_token(); + break; default: // normal ^P/^N and ^X^L found_new_match = get_next_default_completion(st, ini); @@ -3291,6 +3299,33 @@ static bool get_next_completion_match(int type, ins_compl_next_state_T *st, pos_ return found_new_match; } +static void get_next_bufname_token(void) +{ + FOR_ALL_BUFFERS(b) { + if (b->b_p_bl) { + char *start = get_past_head(b->b_sfname); + char *current = start; + char *p = (char *)path_next_component(start); + while (true) { + int len = (int)(p - current) - (*p == NUL ? 0 : 1); + // treat . as a separator, unless it is the first char in a filename + char *dot = strchr(current, '.'); + if (dot && *p == NUL && *current != '.') { + len = (int)(dot - current); + p = dot + 1; + } + ins_compl_add(current, len, NULL, NULL, false, NULL, 0, + p_ic ? CP_ICASE : 0, false); + if (*p == NUL) { + break; + } + current = p; + p = (char *)path_next_component(p); + } + } + } +} + /// Get the next expansion(s), using "compl_pattern". /// The search starts at position "ini" in curbuf and in the direction /// compl_direction. -- cgit From 0b23207c73695641e24a77b76a8c331f3644fd0a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 28 Oct 2023 06:13:57 +0800 Subject: vim-patch:9.0.2074: Completion menu may be wrong Problem: Completion menu may be wrong Solution: Check for the original direction of the completion menu, add more tests, make it work with 'noselect' completion: move in right direction when filling completion_info() When moving through the insert completion menu and switching directions, we need to make sure we start at the correct position in the list and move correctly forward/backwards through it, so that we do not skip entries and the selected item points to the correct entry in the list of completion entries generated by the completion_info() function. The general case is this: 1) CTRL-X CTRL-N, we will traverse the list starting from compl_first_match and then go forwards (using the cp->next pointer) through the list (skipping the very first entry, which has the CP_ORIGINAL_TEXT flag set (since that is the empty/non-selected entry 2) CTRL-X CTRL-P, we will traverse the list starting from compl_first_match (which now points to the last entry). The previous entry will have the CP_ORIGINAL_TEXT flag set, so we need to start traversing the list from the second prev pointer. There are in fact 2 special cases after starting the completion menu with CTRL-X: 3) CTRL-N and then going backwards by pressing CTRL-P again. compl_first_match will point to the same entry as in step 1 above, but since compl_dir_foward() has been switched by pressing CTRL-P to backwards we need to pretend to be in still in case 1 and still traverse the list in forward direction using the cp_next pointer 4) CTRL-P and then going forwards by pressing CTRL-N again. compl_first_match will point to the same entry as in step 2 above, but since compl_dir_foward() has been switched by pressing CTRL-N to forwards we need to pretend to be in still in case 2 and still traverse the list in backward direction using the cp_prev pointer For the 'noselect' case however, this is slightly different again. When going backwards, we only need to go one cp_prev pointer back. And resting of the direction works again slightly different. So we need to take the noselect option into account when deciding in which direction to iterate through the list of matches. related: vim/vim#13402 related: vim/vim#12971 closes: vim/vim#13408 https://github.com/vim/vim/commit/daef8c74375141974d61b85199b383017644978c Co-authored-by: Christian Brabandt --- src/nvim/insexpand.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 427088e414..09575c64d9 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2702,10 +2702,41 @@ static int info_add_completion_info(list_T *li) return OK; } + bool forward = compl_dir_forward(); + compl_T *match = compl_first_match; + // There are four cases to consider here: + // 1) when just going forward through the menu, + // compl_first_match should point to the initial entry with + // number zero and CP_ORIGINAL_TEXT flag set + // 2) when just going backwards, + // compl-first_match should point to the last entry before + // the entry with the CP_ORIGINAL_TEXT flag set + // 3) when first going forwards and then backwards, e.g. + // pressing C-N, C-P, compl_first_match points to the + // last entry before the entry with the CP_ORIGINAL_TEXT + // flag set and next-entry moves opposite through the list + // compared to case 2, so pretend the direction is forward again + // 4) when first going backwards and then forwards, e.g. + // pressing C-P, C-N, compl_first_match points to the + // first entry with the CP_ORIGINAL_TEXT + // flag set and next-entry moves in opposite direction through the list + // compared to case 1, so pretend the direction is backwards again + // + // But only do this when the 'noselect' option is not active! + + if (!compl_no_select) { + if (forward && !match_at_original_text(match)) { + forward = false; + } else if (!forward && match_at_original_text(match)) { + forward = true; + } + } + // Skip the element with the CP_ORIGINAL_TEXT flag at the beginning, in case of // forward completion, or at the end, in case of backward completion. - compl_T *match = compl_dir_forward() ? compl_first_match->cp_next - : compl_first_match->cp_prev->cp_prev; + match = forward ? match->cp_next + : (compl_no_select ? match->cp_prev : match->cp_prev->cp_prev); + while (match != NULL && !match_at_original_text(match)) { dict_T *di = tv_dict_alloc(); @@ -2722,7 +2753,7 @@ static int info_add_completion_info(list_T *li) tv_dict_add_tv(di, S_LEN("user_data"), &match->cp_user_data); } - match = compl_dir_forward() ? match->cp_next : match->cp_prev; + match = forward ? match->cp_next : match->cp_prev; } return OK; -- cgit From ec66a95fbc9069a3122838dd3f904582b248691c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Nov 2023 21:59:03 +0800 Subject: vim-patch:9.0.2090: complete_info() skips entries with 'noselect' (#25890) Problem: complete_info() skips entries with 'noselect' Solution: Check, if first entry is at original text state Unfortunately, Commit daef8c74375141974d61b85199b383017644978c introduced a regression, that when ':set completeopt+=noselect' is set and no completion item has been selected yet, it did not fill the complete_info['items'] list. This happened, because the current match item did not have the CP_ORIGINAL_TEXT flag set and then the cp->prev pointer did point to the original flag item, which caused the following while loop to not being run but being skipped instead. So when the 'noselect' is set, only start with to the previous selection item, if the initial completion item has the CP_ORIGINAL_TEXT flag set, else use the 2nd previous item instead. fixes: vim/vim#13451 closes: vim/vim#13452 https://github.com/vim/vim/commit/57f9ce1a0977da13e5923214086795ffa2d28ce1 Co-authored-by: Christian Brabandt --- src/nvim/insexpand.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 09575c64d9..fa08064eb5 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2735,7 +2735,8 @@ static int info_add_completion_info(list_T *li) // Skip the element with the CP_ORIGINAL_TEXT flag at the beginning, in case of // forward completion, or at the end, in case of backward completion. match = forward ? match->cp_next - : (compl_no_select ? match->cp_prev : match->cp_prev->cp_prev); + : (compl_no_select && match_at_original_text(match) + ? match->cp_prev : match->cp_prev->cp_prev); while (match != NULL && !match_at_original_text(match)) { dict_T *di = tv_dict_alloc(); -- 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/insexpand.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index fa08064eb5..78654d8b14 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -474,7 +474,7 @@ bool check_compl_option(bool dict_opt) vim_beep(BO_COMPL); setcursor(); ui_flush(); - os_delay(2004L, false); + os_delay(2004, false); } return false; } @@ -2986,7 +2986,7 @@ static void get_next_include_file_completion(int compl_type) ((compl_type == CTRL_X_PATH_DEFINES && !(compl_cont_status & CONT_SOL)) ? FIND_DEFINE : FIND_ANY), - 1L, ACTION_EXPAND, 1, MAXLNUM); + 1, ACTION_EXPAND, 1, MAXLNUM); } /// Get the next set of words matching "compl_pattern" in dictionary or @@ -3208,7 +3208,7 @@ static int get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_ compl_direction, compl_pattern); } else { found_new_match = searchit(NULL, st->ins_buf, st->cur_match_pos, - NULL, compl_direction, compl_pattern, 1L, + NULL, compl_direction, compl_pattern, 1, SEARCH_KEEP + SEARCH_NFMSG, RE_LAST, NULL); } msg_silent--; -- cgit From d1b2a5cf5fa583b556457d34a46ce7b940913a66 Mon Sep 17 00:00:00 2001 From: mortezadadgar Date: Sat, 11 Nov 2023 02:11:10 +0330 Subject: fix(completion): make sure the buffer name is valid (#25975) Problem: crash from set complete+=f open a empty buffer C-N Solution: make sure the buffer name is valid. regression from ae4ca4edf89ece433b61e8bf92c412298b58d9ea --- src/nvim/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 78654d8b14..31275ff339 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3334,7 +3334,7 @@ static bool get_next_completion_match(int type, ins_compl_next_state_T *st, pos_ static void get_next_bufname_token(void) { FOR_ALL_BUFFERS(b) { - if (b->b_p_bl) { + if (b->b_p_bl && b->b_sfname != NULL) { char *start = get_past_head(b->b_sfname); char *current = start; char *p = (char *)path_next_component(start); -- 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/insexpand.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 31275ff339..b62a48f056 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.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 - // insexpand.c: functions for Insert mode completion #include -- cgit From 2a58aa57098a4876afa8d865d6d9ec32407d7f11 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 13 Nov 2023 10:47:12 +0800 Subject: vim-patch:9.0.2102: matchparen highlight not cleared in completion mode (#26019) Problem: matchparen highlight not cleared in completion mode Solution: Clear matchparen highlighting in completion mode Remove hard-coded hack in insexpand.c to clear the :3match before displaying the completion menu. Add a test for matchparen highlighting. While at it, move all test tests related to the matchparen plugin into a separate test file. closes: vim/vim#13493 closes: vim/vim#13524 https://github.com/vim/vim/commit/9588666360e94de3ff58d4bc79aa9148fbf5fc44 Co-authored-by: Christian Brabandt --- src/nvim/insexpand.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index b62a48f056..42f3a78f27 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -1241,9 +1241,6 @@ void ins_compl_show_pum(void) return; } - // Dirty hard-coded hack: remove any matchparen highlighting. - do_cmdline_cmd("if exists('g:loaded_matchparen')|3match none|endif"); - // Update the screen before drawing the popup menu over it. update_screen(); -- 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/insexpand.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 42f3a78f27..bd32c6e2dc 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -910,7 +910,6 @@ static bool ins_compl_equal(compl_T *match, char *str, size_t len) static void ins_compl_longest_match(compl_T *match) { char *p, *s; - int c1, c2; int had_match; if (compl_leader == NULL) { @@ -936,8 +935,8 @@ static void ins_compl_longest_match(compl_T *match) p = compl_leader; s = match->cp_str; while (*p != NUL) { - c1 = utf_ptr2char(p); - c2 = utf_ptr2char(s); + int c1 = utf_ptr2char(p); + int c2 = utf_ptr2char(s); if ((match->cp_flags & CP_ICASE) ? (mb_tolower(c1) != mb_tolower(c2)) @@ -1442,11 +1441,10 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r { char *ptr; int i; - FILE *fp; int add_r; for (i = 0; i < count && !got_int && !compl_interrupted; i++) { - fp = os_fopen(files[i], "r"); // open dictionary file + FILE *fp = os_fopen(files[i], "r"); // open dictionary file if (flags != DICT_EXACT && !shortmess(SHM_COMPLETIONSCAN)) { msg_hist_off = true; // reset in msg_trunc() vim_snprintf(IObuff, IOSIZE, @@ -2181,7 +2179,6 @@ bool ins_compl_prep(int c) static void ins_compl_fixRedoBufForLeader(char *ptr_arg) { int len; - char *p; char *ptr = ptr_arg; if (ptr == NULL) { @@ -2192,7 +2189,7 @@ static void ins_compl_fixRedoBufForLeader(char *ptr_arg) } } if (compl_orig_text != NULL) { - p = compl_orig_text; + char *p = compl_orig_text; for (len = 0; p[len] != NUL && p[len] == ptr[len]; len++) {} if (len > 0) { len -= utf_head_off(p, p + len); @@ -3853,15 +3850,13 @@ static bool ins_compl_pum_key(int c) /// Returns 1 for most keys, height of the popup menu for page-up/down keys. static int ins_compl_key2count(int c) { - int h; - if (c == K_EVENT || c == K_COMMAND || c == K_LUA) { int offset = pum_want.item - pum_selected_item; return abs(offset); } if (ins_compl_pum_key(c) && c != K_UP && c != K_DOWN) { - h = pum_get_height(); + int h = pum_get_height(); if (h > 3) { h -= 2; // keep some context } -- 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/insexpand.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index bd32c6e2dc..28d1c8216e 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -21,7 +21,6 @@ #include "nvim/eval.h" #include "nvim/eval/typval.h" #include "nvim/eval/userfunc.h" -#include "nvim/ex_docmd.h" #include "nvim/ex_eval.h" #include "nvim/ex_getln.h" #include "nvim/fileio.h" -- cgit From 8dc72789cfad630c2f2da572916490a32d5155e6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Nov 2023 09:12:01 +0800 Subject: vim-patch:9.0.1858: [security] heap use after free in ins_compl_get_exp() Problem: heap use after free in ins_compl_get_exp() Solution: validate buffer before accessing it https://github.com/vim/vim/commit/ee9166eb3b41846661a39b662dc7ebe8b5e15139 Co-authored-by: Christian Brabandt --- src/nvim/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 28d1c8216e..f565d5b9e8 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3435,7 +3435,7 @@ static int ins_compl_get_exp(pos_T *ini) compl_started = true; } else { // Mark a buffer scanned when it has been scanned completely - if (type == 0 || type == CTRL_X_PATH_PATTERNS) { + if (buf_valid(st.ins_buf) && (type == 0 || type == CTRL_X_PATH_PATTERNS)) { assert(st.ins_buf); st.ins_buf->b_scanned = true; } -- cgit From b522cb1ac3fbdf6e68eed5d0b6e1cbeaf3ac2254 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 6 Nov 2023 14:52:27 +0100 Subject: refactor(grid): make screen rendering more multibyte than ever before Problem: buffer text with composing chars are converted from UTF-8 to an array of up to seven UTF-32 values and then converted back to UTF-8 strings. Solution: Convert buffer text directly to UTF-8 based schar_T values. The limit of the text size is now in schar_T bytes, which is currently 31+1 but easily could be raised as it no longer multiplies the size of the entire screen grid when not used, the full size is only required for temporary scratch buffers. Also does some general cleanup to win_line text handling, which was unnecessarily complicated due to multibyte rendering being an "opt-in" feature long ago. Nowadays, a char is just a char, regardless if it consists of one ASCII byte or multiple bytes. --- src/nvim/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index f565d5b9e8..adbd2a5315 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -1743,7 +1743,7 @@ void ins_compl_addleader(int c) return; } if ((cc = utf_char2len(c)) > 1) { - char buf[MB_MAXBYTES + 1]; + char buf[MB_MAXCHAR + 1]; utf_char2bytes(c, buf); buf[cc] = NUL; -- cgit From cdc8bacc7945da816738e330555fa85d3ffffd56 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sat, 18 Nov 2023 12:26:52 +0800 Subject: fix(completion): filter results with complete+=f (#26029) --- src/nvim/insexpand.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index adbd2a5315..c2bec8b045 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3325,24 +3325,10 @@ static void get_next_bufname_token(void) { FOR_ALL_BUFFERS(b) { if (b->b_p_bl && b->b_sfname != NULL) { - char *start = get_past_head(b->b_sfname); - char *current = start; - char *p = (char *)path_next_component(start); - while (true) { - int len = (int)(p - current) - (*p == NUL ? 0 : 1); - // treat . as a separator, unless it is the first char in a filename - char *dot = strchr(current, '.'); - if (dot && *p == NUL && *current != '.') { - len = (int)(dot - current); - p = dot + 1; - } - ins_compl_add(current, len, NULL, NULL, false, NULL, 0, + char *tail = path_tail(b->b_sfname); + if (strncmp(tail, compl_orig_text, strlen(compl_orig_text)) == 0) { + ins_compl_add(tail, (int)strlen(tail), NULL, NULL, false, NULL, 0, p_ic ? CP_ICASE : 0, false); - if (*p == NUL) { - break; - } - current = p; - p = (char *)path_next_component(p); } } } -- 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/insexpand.c | 75 +++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 51 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index c2bec8b045..e41a2ce47c 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -908,7 +908,6 @@ static bool ins_compl_equal(compl_T *match, char *str, size_t len) /// Reduce the longest common string for match "match". static void ins_compl_longest_match(compl_T *match) { - char *p, *s; int had_match; if (compl_leader == NULL) { @@ -931,8 +930,8 @@ static void ins_compl_longest_match(compl_T *match) } // Reduce the text if this match differs from compl_leader. - p = compl_leader; - s = match->cp_str; + char *p = compl_leader; + char *s = match->cp_str; while (*p != NUL) { int c1 = utf_ptr2char(p); int c2 = utf_ptr2char(s); @@ -1293,11 +1292,9 @@ static void ins_compl_dictionaries(char *dict_start, char *pat, int flags, int t { char *dict = dict_start; char *ptr; - char *buf; regmatch_T regmatch; char **files; int count; - int save_p_scs; Direction dir = compl_direction; if (*dict == NUL) { @@ -1310,11 +1307,11 @@ static void ins_compl_dictionaries(char *dict_start, char *pat, int flags, int t } } - buf = xmalloc(LSIZE); + char *buf = xmalloc(LSIZE); regmatch.regprog = NULL; // so that we can goto theend // If 'infercase' is set, don't use 'smartcase' here - save_p_scs = p_scs; + int save_p_scs = p_scs; if (curbuf->b_p_inf) { p_scs = false; } @@ -1438,11 +1435,7 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r char *buf, Direction *dir) FUNC_ATTR_NONNULL_ARG(2, 7) { - char *ptr; - int i; - int add_r; - - for (i = 0; i < count && !got_int && !compl_interrupted; i++) { + for (int i = 0; i < count && !got_int && !compl_interrupted; i++) { FILE *fp = os_fopen(files[i], "r"); // open dictionary file if (flags != DICT_EXACT && !shortmess(SHM_COMPLETIONSCAN)) { msg_hist_off = true; // reset in msg_trunc() @@ -1458,7 +1451,7 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r // Read dictionary file line by line. // Check each line for a match. while (!got_int && !compl_interrupted && !vim_fgets(buf, LSIZE, fp)) { - ptr = buf; + char *ptr = buf; while (vim_regexec(regmatch, buf, (colnr_T)(ptr - buf))) { ptr = regmatch->startp[0]; if (ctrl_x_mode_line_or_eval()) { @@ -1466,9 +1459,9 @@ static void ins_compl_files(int count, char **files, int thesaurus, int flags, r } else { ptr = find_word_end(ptr); } - add_r = ins_compl_add_infercase(regmatch->startp[0], - (int)(ptr - regmatch->startp[0]), - p_ic, files[i], *dir, false); + int add_r = ins_compl_add_infercase(regmatch->startp[0], + (int)(ptr - regmatch->startp[0]), + p_ic, files[i], *dir, false); if (thesaurus) { // For a thesaurus, add all the words in the line ptr = buf; @@ -1526,9 +1519,7 @@ char *find_word_end(char *ptr) /// @return a pointer to just after the line. static char *find_line_end(char *ptr) { - char *s; - - s = ptr + strlen(ptr); + char *s = ptr + strlen(ptr); while (s > ptr && (s[-1] == CAR || s[-1] == NL)) { s--; } @@ -1538,8 +1529,6 @@ static char *find_line_end(char *ptr) /// Free the list of completions static void ins_compl_free(void) { - compl_T *match; - XFREE_CLEAR(compl_pattern); XFREE_CLEAR(compl_leader); @@ -1552,7 +1541,7 @@ static void ins_compl_free(void) compl_curr_match = compl_first_match; do { - match = compl_curr_match; + compl_T *match = compl_curr_match; compl_curr_match = compl_curr_match->cp_next; xfree(match->cp_str); // several entries may use the same fname, free it just once. @@ -1799,12 +1788,9 @@ static void ins_compl_set_original_text(char *str) /// matches. void ins_compl_addfrommatch(void) { - char *p; int len = (int)curwin->w_cursor.col - (int)compl_col; - int c; - compl_T *cp; assert(compl_shown_match != NULL); - p = compl_shown_match->cp_str; + char *p = compl_shown_match->cp_str; if ((int)strlen(p) <= len) { // the match is too short // When still at the original match use the first entry that matches // the leader. @@ -1813,7 +1799,7 @@ void ins_compl_addfrommatch(void) } p = NULL; - for (cp = compl_shown_match->cp_next; cp != NULL + for (compl_T *cp = compl_shown_match->cp_next; cp != NULL && !is_first_match(cp); cp = cp->cp_next) { if (compl_leader == NULL || ins_compl_equal(cp, compl_leader, strlen(compl_leader))) { @@ -1826,7 +1812,7 @@ void ins_compl_addfrommatch(void) } } p += len; - c = utf_ptr2char(p); + int c = utf_ptr2char(p); ins_compl_addleader(c); } @@ -2356,13 +2342,11 @@ static void expand_by_function(int type, char *base) { list_T *matchlist = NULL; dict_T *matchdict = NULL; - char *funcname; - pos_T pos; typval_T rettv; const int save_State = State; assert(curbuf != NULL); - funcname = get_complete_funcname(type); + char *funcname = get_complete_funcname(type); if (*funcname == NUL) { return; } @@ -2375,7 +2359,7 @@ static void expand_by_function(int type, char *base) args[0].vval.v_number = 0; args[1].vval.v_string = base != NULL ? base : ""; - pos = curwin->w_cursor; + pos_T pos = curwin->w_cursor; // Lock the text to avoid weird things from happening. Also disallow // switching to another window, it should not be needed and may end up in // Insert mode in another buffer. @@ -2502,12 +2486,9 @@ static void ins_compl_add_list(list_T *const list) /// Add completions from a dict. static void ins_compl_add_dict(dict_T *dict) { - dictitem_T *di_refresh; - dictitem_T *di_words; - // Check for optional "refresh" item. compl_opt_refresh_always = false; - di_refresh = tv_dict_find(dict, S_LEN("refresh")); + dictitem_T *di_refresh = tv_dict_find(dict, S_LEN("refresh")); if (di_refresh != NULL && di_refresh->di_tv.v_type == VAR_STRING) { const char *v = di_refresh->di_tv.vval.v_string; @@ -2517,7 +2498,7 @@ static void ins_compl_add_dict(dict_T *dict) } // Add completions from a "words" list. - di_words = tv_dict_find(dict, S_LEN("words")); + dictitem_T *di_words = tv_dict_find(dict, S_LEN("words")); if (di_words != NULL && di_words->di_tv.v_type == VAR_LIST) { ins_compl_add_list(di_words->di_tv.vval.v_list); } @@ -3345,7 +3326,6 @@ static int ins_compl_get_exp(pos_T *ini) { static ins_compl_next_state_T st; static bool st_cleared = false; - int i; int found_new_match; int type = ctrl_x_mode; @@ -3436,7 +3416,7 @@ static int ins_compl_get_exp(pos_T *ini) found_new_match = FAIL; } - i = -1; // total of matches, unknown + int i = -1; // total of matches, unknown if (found_new_match == FAIL || (ctrl_x_mode_not_default() && !ctrl_x_mode_line_or_eval())) { i = ins_compl_make_cyclic(); @@ -3486,11 +3466,9 @@ static void ins_compl_update_shown_match(void) /// Delete the old text being completed. void ins_compl_delete(void) { - int col; - // In insert mode: Delete the typed part. // In replace mode: Put the old characters back, if any. - col = compl_col + (compl_status_adding() ? compl_length : 0); + int col = compl_col + (compl_status_adding() ? compl_length : 0); if ((int)curwin->w_cursor.col > col) { if (stop_arrow() == FAIL) { return; @@ -4384,13 +4362,8 @@ static void ins_compl_show_statusmsg(void) /// Returns OK if completion was done, FAIL if something failed. int ins_complete(int c, bool enable_pum) { - int n; - int save_w_wrow; - int save_w_leftcol; - int insert_match; - compl_direction = ins_compl_key2dir(c); - insert_match = ins_compl_use_match(c); + int insert_match = ins_compl_use_match(c); if (!compl_started) { if (ins_compl_start() == FAIL) { @@ -4404,9 +4377,9 @@ int ins_complete(int c, bool enable_pum) compl_shows_dir = compl_direction; // Find next match (and following matches). - save_w_wrow = curwin->w_wrow; - save_w_leftcol = curwin->w_leftcol; - n = ins_compl_next(true, ins_compl_key2count(c), insert_match, false); + int save_w_wrow = curwin->w_wrow; + int save_w_leftcol = curwin->w_leftcol; + int n = ins_compl_next(true, ins_compl_key2count(c), insert_match, false); if (n > 1) { // all matches have been found compl_matches = n; -- cgit From a6e3d93421ba13c407a96fac9cc01fa41ec7ad98 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: refactor: enable formatting for ternaries This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators. --- src/nvim/insexpand.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index e41a2ce47c..de479e8ee2 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -2967,11 +2967,11 @@ static void get_next_dict_tsr_completion(int compl_type, char *dict, int dict_f) if (thesaurus_func_complete(compl_type)) { expand_by_function(compl_type, compl_pattern); } else { - ins_compl_dictionaries(dict != NULL ? dict + ins_compl_dictionaries(dict != NULL + ? dict : (compl_type == CTRL_X_THESAURUS ? (*curbuf->b_p_tsr == NUL ? p_tsr : curbuf->b_p_tsr) - : (*curbuf->b_p_dict == - NUL ? p_dict : curbuf->b_p_dict)), + : (*curbuf->b_p_dict == NUL ? p_dict : curbuf->b_p_dict)), compl_pattern, dict != NULL ? dict_f : 0, compl_type == CTRL_X_THESAURUS); @@ -3427,8 +3427,8 @@ static int ins_compl_get_exp(pos_T *ini) // just been made cyclic then we have to move compl_curr_match to the // next or previous entry (if any) -- Acevedo compl_curr_match = compl_dir_forward() - ? compl_old_match->cp_next - : compl_old_match->cp_prev; + ? compl_old_match->cp_next + : compl_old_match->cp_prev; if (compl_curr_match == NULL) { compl_curr_match = compl_old_match; } -- 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/insexpand.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index de479e8ee2..92fc6c6906 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -24,6 +24,7 @@ #include "nvim/ex_eval.h" #include "nvim/ex_getln.h" #include "nvim/fileio.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/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 92fc6c6906..bb973a5e1b 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -49,7 +49,7 @@ #include "nvim/os/time.h" #include "nvim/path.h" #include "nvim/popupmenu.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/regexp.h" #include "nvim/search.h" #include "nvim/spell.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/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index bb973a5e1b..3f5c860326 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -57,7 +57,7 @@ #include "nvim/strings.h" #include "nvim/tag.h" #include "nvim/textformat.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/vim.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/insexpand.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 3f5c860326..e1a6b1fbf3 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -9,7 +9,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/change.h" @@ -34,7 +34,7 @@ #include "nvim/indent_c.h" #include "nvim/insexpand.h" #include "nvim/keycodes.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" @@ -60,7 +60,7 @@ #include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/window.h" // Definitions used for CTRL-X submode. -- 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/insexpand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/insexpand.c') diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index e1a6b1fbf3..12543a2d42 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -29,7 +29,7 @@ #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/highlight_defs.h" +#include "nvim/highlight.h" #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/insexpand.h" -- cgit