From 27177e581902967dcf4f2f426464da1b636ca420 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 14:14:24 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22211) --- src/nvim/match.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 6663dfd7ec..93c8a58051 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -419,7 +419,6 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_ colnr_T mincol, matchitem_T *cur) FUNC_ATTR_NONNULL_ARG(2) { - linenr_T l; colnr_T matchcol; long nmatched = 0; const int called_emsg_before = called_emsg; @@ -435,7 +434,7 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_ // 1. If the "lnum" is below a previous match, start a new search. // 2. If the previous match includes "mincol", use it. // 3. Continue after the previous match. - l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; + linenr_T l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; if (lnum > l) { shl->lnum = 0; } else if (lnum < l || shl->rm.endpos[0].col > mincol) { -- cgit From d5f6176e6dc4b4e12fc5061ca6e87f4af533e46a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Sat, 1 Apr 2023 02:49:51 +0200 Subject: refactor: add const and remove unnecessary casts (#22841) --- src/nvim/match.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 93c8a58051..29d4b7c225 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -98,7 +98,7 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in if ((hlg_id = syn_check_group(grp, strlen(grp))) == 0) { return -1; } - if (pat != NULL && (regprog = vim_regcomp((char *)pat, RE_MAGIC)) == NULL) { + if (pat != NULL && (regprog = vim_regcomp(pat, RE_MAGIC)) == NULL) { semsg(_(e_invarg2), pat); return -1; } @@ -1232,7 +1232,7 @@ void ex_match(exarg_T *eap) if (!eap->skip) { if (*end != NUL && !ends_excmd(*skipwhite(end + 1))) { xfree(g); - eap->errmsg = ex_errmsg(e_trailing_arg, (const char *)end); + eap->errmsg = ex_errmsg(e_trailing_arg, end); return; } if (*end != *p) { @@ -1243,8 +1243,7 @@ void ex_match(exarg_T *eap) c = (uint8_t)(*end); *end = NUL; - match_add(curwin, (const char *)g, (const char *)p + 1, 10, id, - NULL, NULL); + match_add(curwin, g, p + 1, 10, id, NULL, NULL); xfree(g); *end = (char)c; } -- 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/match.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 29d4b7c225..ccce78e59d 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -42,7 +42,7 @@ # include "match.c.generated.h" #endif -static char *e_invalwindow = N_("E957: Invalid window number"); +static const char *e_invalwindow = N_("E957: Invalid window number"); #define SEARCH_HL_PRIORITY 0 -- 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/match.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index ccce78e59d..31a628bbff 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -938,10 +938,9 @@ void f_getmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) tv_dict_add_list(dict, buf, (size_t)len, l); } } else { - tv_dict_add_str(dict, S_LEN("pattern"), (const char *)cur->mit_pattern); + tv_dict_add_str(dict, S_LEN("pattern"), cur->mit_pattern); } - tv_dict_add_str(dict, S_LEN("group"), - (const char *)syn_id2name(cur->mit_hlg_id)); + tv_dict_add_str(dict, S_LEN("group"), syn_id2name(cur->mit_hlg_id)); tv_dict_add_nr(dict, S_LEN("priority"), (varnumber_T)cur->mit_priority); tv_dict_add_nr(dict, S_LEN("id"), (varnumber_T)cur->mit_id); @@ -1166,9 +1165,8 @@ void f_matcharg(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) matchitem_T *const m = get_match(curwin, id); if (m != NULL) { - tv_list_append_string(rettv->vval.v_list, - (const char *)syn_id2name(m->mit_hlg_id), -1); - tv_list_append_string(rettv->vval.v_list, (const char *)m->mit_pattern, -1); + tv_list_append_string(rettv->vval.v_list, syn_id2name(m->mit_hlg_id), -1); + tv_list_append_string(rettv->vval.v_list, m->mit_pattern, -1); } else { tv_list_append_string(rettv->vval.v_list, NULL, 0); tv_list_append_string(rettv->vval.v_list, NULL, 0); -- 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/match.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 31a628bbff..6903c0a851 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -111,7 +111,7 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in } m->mit_id = id; m->mit_priority = prio; - m->mit_pattern = pat == NULL ? NULL: xstrdup(pat); + m->mit_pattern = pat == NULL ? NULL : xstrdup(pat); m->mit_hlg_id = hlg_id; m->mit_match.regprog = regprog; m->mit_match.rmm_ic = false; @@ -388,7 +388,7 @@ static int next_search_hl_pos(match_T *shl, linenr_T lnum, matchitem_T *match, c match->mit_pos_cur = 0; if (found >= 0) { colnr_T start = match->mit_pos_array[found].col == 0 - ? 0: match->mit_pos_array[found].col - 1; + ? 0 : match->mit_pos_array[found].col - 1; colnr_T end = match->mit_pos_array[found].col == 0 ? MAXCOL : start + match->mit_pos_array[found].len; @@ -444,7 +444,7 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_ // Repeat searching for a match until one is found that includes "mincol" // or none is found in this line. - for (;;) { + while (true) { // Stop searching after passing the time limit. if (profile_passed_limit(shl->tm)) { shl->lnum = 0; // no match found in time -- 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/match.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 6903c0a851..ece4de2199 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -658,7 +658,7 @@ bool prepare_search_hl_line(win_T *wp, linenr_T lnum, colnr_T mincol, char **lin shl->endcol++; } } - if ((long)shl->startcol < mincol) { // match at leftcol + if (shl->startcol < mincol) { // match at leftcol shl->attr_cur = shl->attr; *search_attr = shl->attr; *search_attr_from_match = shl != search_hl; @@ -808,28 +808,28 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char **line, match_T return search_attr; } -bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, long curcol) +bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, colnr_T curcol) { - long prevcol = curcol; + colnr_T prevcol = curcol; matchitem_T *cur; // points to the match list // we're not really at that column when skipping some text - if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) { + if ((wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) { prevcol++; } // Highlight a character after the end of the line if the match started // at the end of the line or when the match continues in the next line // (match includes the line break). - if (!search_hl->is_addpos && (prevcol == (long)search_hl->startcol - || (prevcol > (long)search_hl->startcol + if (!search_hl->is_addpos && (prevcol == search_hl->startcol + || (prevcol > search_hl->startcol && search_hl->endcol == MAXCOL))) { return true; } cur = wp->w_match_head; while (cur != NULL) { - if (!cur->mit_hl.is_addpos && (prevcol == (long)cur->mit_hl.startcol - || (prevcol > (long)cur->mit_hl.startcol + if (!cur->mit_hl.is_addpos && (prevcol == cur->mit_hl.startcol + || (prevcol > cur->mit_hl.startcol && cur->mit_hl.endcol == MAXCOL))) { return true; } @@ -841,7 +841,7 @@ bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, long curcol) /// Get highlighting for the char after the text in "char_attr" from 'hlsearch' /// or match highlighting. -void get_search_match_hl(win_T *wp, match_T *search_hl, long col, int *char_attr) +void get_search_match_hl(win_T *wp, match_T *search_hl, colnr_T col, int *char_attr) { matchitem_T *cur = wp->w_match_head; // points to the match list match_T *shl; // points to search_hl or a match @@ -856,7 +856,7 @@ void get_search_match_hl(win_T *wp, match_T *search_hl, long col, int *char_attr } else { shl = &cur->mit_hl; } - if (col - 1 == (long)shl->startcol + if (col - 1 == shl->startcol && (shl == search_hl || !shl->is_addpos)) { *char_attr = shl->attr; } -- cgit From 59289fb987bd51b072f91ae0de8ee8515bf07e21 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Jul 2023 21:36:32 +0800 Subject: fix(highlight): make CurSearch work properly with 'winhl' (#24448) --- src/nvim/match.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index ece4de2199..d0e7fe0ef9 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -716,8 +716,8 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char **line, match_T } // Highlight the match were the cursor is using the CurSearch // group. - if (shl == search_hl && shl->has_cursor && (HL_ATTR(HLF_LC) || win_hl_attr(wp, HLF_LC))) { - shl->attr_cur = win_hl_attr(wp, HLF_LC) ? win_hl_attr(wp, HLF_LC) : HL_ATTR(HLF_LC); + if (shl == search_hl && shl->has_cursor) { + shl->attr_cur = win_hl_attr(wp, HLF_LC); } else { shl->attr_cur = shl->attr; } -- 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/match.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index d0e7fe0ef9..6d5873bc85 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -463,7 +463,7 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_ char *ml; matchcol = shl->rm.startpos[0].col; - ml = ml_get_buf(shl->buf, lnum, false) + matchcol; + ml = ml_get_buf(shl->buf, lnum) + matchcol; if (*ml == NUL) { matchcol++; shl->lnum = 0; @@ -630,7 +630,7 @@ bool prepare_search_hl_line(win_T *wp, linenr_T lnum, colnr_T mincol, char **lin // Need to get the line again, a multi-line regexp may have made it // invalid. - *line = ml_get_buf(wp->w_buffer, lnum, false); + *line = ml_get_buf(wp->w_buffer, lnum); if (shl->lnum != 0 && shl->lnum <= lnum) { if (shl->lnum == lnum) { @@ -740,7 +740,7 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char **line, match_T // Need to get the line again, a multi-line regexp // may have made it invalid. - *line = ml_get_buf(wp->w_buffer, lnum, false); + *line = ml_get_buf(wp->w_buffer, lnum); if (shl->lnum == lnum) { shl->startcol = shl->rm.startpos[0].col; -- 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/match.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 6d5873bc85..093de21c40 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -15,7 +15,6 @@ #include "nvim/drawscreen.h" #include "nvim/eval/funcs.h" #include "nvim/eval/typval.h" -#include "nvim/eval/typval_defs.h" #include "nvim/eval/window.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/match.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 093de21c40..d54e2ce58a 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -29,7 +29,7 @@ #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/pos.h" #include "nvim/profile.h" #include "nvim/regexp.h" -- 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/match.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index d54e2ce58a..e087d4f45d 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -419,7 +419,7 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_ FUNC_ATTR_NONNULL_ARG(2) { colnr_T matchcol; - long nmatched = 0; + int nmatched = 0; const int called_emsg_before = called_emsg; // for :{range}s/pat only highlight inside the range -- cgit From cd63a9addd6e1114c3524fa041ece560550cfe7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 08:39:21 +0800 Subject: refactor: change some xstrndup() and xstrnsave() to xmemdupz() (#25959) When the given length is exactly the number of bytes to copy, xmemdupz() makes the intention clearer. --- src/nvim/match.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index e087d4f45d..d153ea042d 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -1216,7 +1216,7 @@ void ex_match(exarg_T *eap) } else { p = skiptowhite(eap->arg); if (!eap->skip) { - g = xstrnsave(eap->arg, (size_t)(p - eap->arg)); + g = xmemdupz(eap->arg, (size_t)(p - eap->arg)); } p = skipwhite(p); if (*p == NUL) { -- 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/match.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index d153ea042d..5ecccdd1dd 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.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 - // match.c: functions for highlighting matches #include @@ -536,7 +533,7 @@ void prepare_search_hl(win_T *wp, match_T *search_hl, linenr_T lnum) shl = search_hl; shl_flag = true; } else { - shl = &cur->mit_hl; // -V595 + shl = &cur->mit_hl; } if (shl->rm.regprog != NULL && shl->lnum == 0 @@ -614,7 +611,7 @@ bool prepare_search_hl_line(win_T *wp, linenr_T lnum, colnr_T mincol, char **lin shl = search_hl; shl_flag = true; } else { - shl = &cur->mit_hl; // -V595 + shl = &cur->mit_hl; } shl->startcol = MAXCOL; shl->endcol = MAXCOL; -- 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/match.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 5ecccdd1dd..3420455e5f 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -354,11 +354,10 @@ void init_search_hl(win_T *wp, match_T *search_hl) static int next_search_hl_pos(match_T *shl, linenr_T lnum, matchitem_T *match, colnr_T mincol) FUNC_ATTR_NONNULL_ALL { - int i; int found = -1; shl->lnum = 0; - for (i = match->mit_pos_cur; i < match->mit_pos_count; i++) { + for (int i = match->mit_pos_cur; i < match->mit_pos_count; i++) { llpos_T *pos = &match->mit_pos_array[i]; if (pos->lnum == 0) { @@ -902,7 +901,6 @@ void f_clearmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) void f_getmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { matchitem_T *cur; - int i; win_T *win = get_optional_window(argvars, 0); tv_list_alloc_ret(rettv, kListLenMayKnow); @@ -915,7 +913,7 @@ void f_getmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) dict_T *dict = tv_dict_alloc(); if (cur->mit_match.regprog == NULL) { // match added with matchaddpos() - for (i = 0; i < cur->mit_pos_count; i++) { + for (int i = 0; i < cur->mit_pos_count; i++) { llpos_T *llpos; char buf[30]; // use 30 to avoid compiler warning -- 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/match.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 3420455e5f..0cd0426cff 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -939,7 +939,7 @@ void f_getmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) tv_dict_add_nr(dict, S_LEN("id"), (varnumber_T)cur->mit_id); if (cur->mit_conceal_char) { - char buf[MB_MAXBYTES + 1]; + char buf[MB_MAXCHAR + 1]; buf[utf_char2bytes(cur->mit_conceal_char, buf)] = NUL; tv_dict_add_str(dict, S_LEN("conceal"), buf); -- 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/match.c | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 0cd0426cff..743dfb9953 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -55,9 +55,6 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in list_T *pos_list, const char *const conceal_char) FUNC_ATTR_NONNULL_ARG(1, 2) { - matchitem_T *cur; - matchitem_T *prev; - matchitem_T *m; int hlg_id; regprog_T *regprog = NULL; int rtype = UPD_SOME_VALID; @@ -76,7 +73,7 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in id = wp->w_next_match_id++; } else { // check the given ID is not already in use - for (cur = wp->w_match_head; cur != NULL; cur = cur->mit_next) { + for (matchitem_T *cur = wp->w_match_head; cur != NULL; cur = cur->mit_next) { if (cur->mit_id == id) { semsg(_("E801: ID already taken: %" PRId64), (int64_t)id); return -1; @@ -100,7 +97,7 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in } // Build new match. - m = xcalloc(1, sizeof(matchitem_T)); + matchitem_T *m = xcalloc(1, sizeof(matchitem_T)); if (pos_list != NULL) { m->mit_pos_array = xcalloc((size_t)tv_list_len(pos_list), sizeof(llpos_T)); m->mit_pos_count = tv_list_len(pos_list); @@ -211,8 +208,8 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in // Insert new match. The match list is in ascending order with regard to // the match priorities. - cur = wp->w_match_head; - prev = cur; + matchitem_T *cur = wp->w_match_head; + matchitem_T *prev = cur; while (cur != NULL && prio >= cur->mit_priority) { prev = cur; cur = cur->mit_next; @@ -292,10 +289,8 @@ static int match_delete(win_T *wp, int id, bool perr) /// Delete all matches in the match list of window 'wp'. void clear_matches(win_T *wp) { - matchitem_T *m; - while (wp->w_match_head != NULL) { - m = wp->w_match_head->mit_next; + matchitem_T *m = wp->w_match_head->mit_next; vim_regfree(wp->w_match_head->mit_match.regprog); xfree(wp->w_match_head->mit_pattern); xfree(wp->w_match_head->mit_pos_array); @@ -517,16 +512,13 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_ void prepare_search_hl(win_T *wp, match_T *search_hl, linenr_T lnum) FUNC_ATTR_NONNULL_ALL { - matchitem_T *cur; // points to the match list + matchitem_T *cur = wp->w_match_head; // points to the match list match_T *shl; // points to search_hl or a match - bool shl_flag; // flag to indicate whether search_hl - // has been processed or not + bool shl_flag = false; // flag to indicate whether search_hl has been processed or not // When using a multi-line pattern, start searching at the top // of the window or just after a closed fold. // Do this both for search_hl and the match list. - cur = wp->w_match_head; - shl_flag = false; while (cur != NULL || shl_flag == false) { if (shl_flag == false) { shl = search_hl; @@ -806,7 +798,6 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char **line, match_T bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, colnr_T curcol) { colnr_T prevcol = curcol; - matchitem_T *cur; // points to the match list // we're not really at that column when skipping some text if ((wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) { @@ -821,7 +812,7 @@ bool get_prevcol_hl_flag(win_T *wp, match_T *search_hl, colnr_T curcol) && search_hl->endcol == MAXCOL))) { return true; } - cur = wp->w_match_head; + matchitem_T *cur = wp->w_match_head; // points to the match list while (cur != NULL) { if (!cur->mit_hl.is_addpos && (prevcol == cur->mit_hl.startcol || (prevcol > cur->mit_hl.startcol @@ -900,7 +891,6 @@ void f_clearmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "getmatches()" function void f_getmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - matchitem_T *cur; win_T *win = get_optional_window(argvars, 0); tv_list_alloc_ret(rettv, kListLenMayKnow); @@ -908,7 +898,7 @@ void f_getmatches(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) return; } - cur = win->w_match_head; + matchitem_T *cur = win->w_match_head; while (cur != NULL) { dict_T *dict = tv_dict_alloc(); if (cur->mit_match.regprog == NULL) { @@ -1185,10 +1175,8 @@ void f_matchdelete(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// skipping commands to find the next command. void ex_match(exarg_T *eap) { - char *p; char *g = NULL; char *end; - int c; int id; if (eap->line2 <= 3) { @@ -1209,7 +1197,7 @@ void ex_match(exarg_T *eap) && (ascii_iswhite(eap->arg[4]) || ends_excmd(eap->arg[4])))) { end = eap->arg + 4; } else { - p = skiptowhite(eap->arg); + char *p = skiptowhite(eap->arg); if (!eap->skip) { g = xmemdupz(eap->arg, (size_t)(p - eap->arg)); } @@ -1233,7 +1221,7 @@ void ex_match(exarg_T *eap) return; } - c = (uint8_t)(*end); + int c = (uint8_t)(*end); *end = NUL; match_add(curwin, g, p + 1, 10, id, NULL, NULL); xfree(g); -- 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/match.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 743dfb9953..670cf6ea16 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -16,6 +16,7 @@ #include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/fold.h" +#include "nvim/func_attr.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/highlight.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/match.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 670cf6ea16..aab676c207 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -28,7 +28,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_vars.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/profile.h" #include "nvim/regexp.h" #include "nvim/strings.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/match.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index aab676c207..4599619a6f 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -32,7 +32,7 @@ #include "nvim/profile.h" #include "nvim/regexp.h" #include "nvim/strings.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -- 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/match.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/match.c') diff --git a/src/nvim/match.c b/src/nvim/match.c index 4599619a6f..0a7c264d4f 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -6,7 +6,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/drawscreen.h" @@ -21,7 +21,7 @@ #include "nvim/globals.h" #include "nvim/highlight.h" #include "nvim/highlight_group.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/match.h" #include "nvim/mbyte.h" #include "nvim/memline.h" @@ -33,7 +33,7 @@ #include "nvim/regexp.h" #include "nvim/strings.h" #include "nvim/types_defs.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "match.c.generated.h" -- cgit