From 01d3a64e284749ac1ae40b0caf7165155063fc4f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 1 Feb 2023 18:07:09 +0800 Subject: vim-patch:8.1.1827: allocating more memory than needed for extended structs (#22081) Problem: Allocating more memory than needed for extended structs. Solution: Use offsetof() instead of sizeof(). (Dominique Pelle, closes vim/vim#4786) https://github.com/vim/vim/commit/47ed553fd5bebfc36eb8aa81686eeaa5a84eccac --- src/nvim/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 05c570e52f..49b63ad324 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3736,7 +3736,7 @@ static void add_keyword(char *const name, const int id, const int flags, sizeof(name_folded)) : name; - keyentry_T *const kp = xmalloc(sizeof(keyentry_T) + strlen(name_ic)); + keyentry_T *const kp = xmalloc(offsetof(keyentry_T, keyword) + strlen(name_ic) + 1); STRCPY(kp->keyword, name_ic); kp->k_syn.id = (int16_t)id; kp->k_syn.inc_tag = current_syn_inc_tag; -- cgit From 5f72ab77bff1f1224be5cbbf9423bdddbc25635c Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 12 Feb 2023 18:48:49 +0100 Subject: refactor: reduce scope of locals as per the style guide 3 (#22221) refactor: reduce scope of locals as per the style guide --- src/nvim/syntax.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 49b63ad324..d4161b9ca2 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -1218,7 +1218,6 @@ static synstate_T *store_current_state(void) // Copy a state stack from "from" in b_sst_array[] to current_state; static void load_current_state(synstate_T *from) { - int i; bufstate_T *bp; clear_current_state(); @@ -1231,7 +1230,7 @@ static void load_current_state(synstate_T *from) } else { bp = from->sst_union.sst_stack; } - for (i = 0; i < from->sst_stacksize; i++) { + for (int i = 0; i < from->sst_stacksize; i++) { CUR_STATE(i).si_idx = bp[i].bs_idx; CUR_STATE(i).si_flags = bp[i].bs_flags; CUR_STATE(i).si_seqnr = bp[i].bs_seqnr; @@ -3441,9 +3440,7 @@ static void syn_list_one(const int id, const bool syncing, const bool link_only) static void syn_list_flags(struct name_list *nlist, int flags, int attr) { - int i; - - for (i = 0; nlist[i].flag != 0; i++) { + for (int i = 0; nlist[i].flag != 0; i++) { if (flags & nlist[i].flag) { msg_puts_attr(nlist[i].name, attr); msg_putchar(' '); @@ -4736,17 +4733,15 @@ static void init_syn_patterns(void) /// @return a pointer to the next argument, or NULL in case of an error. static char *get_syn_pattern(char *arg, synpat_T *ci) { - char *end; int *p; int idx; - char *cpo_save; // need at least three chars if (arg == NULL || arg[0] == NUL || arg[1] == NUL || arg[2] == NUL) { return NULL; } - end = skip_regexp(arg + 1, *arg, true); + char *end = skip_regexp(arg + 1, *arg, true); if (*end != *arg) { // end delimiter not found semsg(_("E401: Pattern delimiter not found: %s"), arg); return NULL; @@ -4755,7 +4750,7 @@ static char *get_syn_pattern(char *arg, synpat_T *ci) ci->sp_pattern = xstrnsave(arg + 1, (size_t)(end - arg) - 1); // Make 'cpoptions' empty, to avoid the 'l' flag - cpo_save = p_cpo; + char *cpo_save = p_cpo; p_cpo = empty_option; ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC); p_cpo = cpo_save; @@ -5145,7 +5140,6 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in { int retval; int16_t *scl_list; - int16_t item; int16_t id = ssp->id; static int depth = 0; int r; @@ -5181,7 +5175,7 @@ static int in_id_list(stateitem_T *cur_si, int16_t *list, struct sp_syn *ssp, in // If the first item is "ALLBUT", return true if "id" is NOT in the // contains list. We also require that "id" is at the same ":syn include" // level as the list. - item = *list; + int16_t item = *list; if (item >= SYNID_ALLBUT && item < SYNID_CLUSTER) { if (item < SYNID_TOP) { // ALL or ALLBUT: accept all groups in the same file @@ -5291,9 +5285,6 @@ void ex_syntax(exarg_T *eap) void ex_ownsyntax(exarg_T *eap) { - char *old_value; - char *new_value; - if (curwin->w_s == &curwin->w_buffer->b_s) { curwin->w_s = xcalloc(1, sizeof(synblock_T)); hash_init(&curwin->w_s->b_keywtab); @@ -5309,7 +5300,7 @@ void ex_ownsyntax(exarg_T *eap) } // Save value of b:current_syntax. - old_value = get_var_value("b:current_syntax"); + char *old_value = get_var_value("b:current_syntax"); if (old_value != NULL) { old_value = xstrdup(old_value); } @@ -5318,7 +5309,7 @@ void ex_ownsyntax(exarg_T *eap) apply_autocmds(EVENT_SYNTAX, eap->arg, curbuf->b_fname, true, curbuf); // Move value of b:current_syntax to w:current_syntax. - new_value = get_var_value("b:current_syntax"); + char *new_value = get_var_value("b:current_syntax"); if (new_value != NULL) { set_internal_string_var("w:current_syntax", new_value); } @@ -5483,10 +5474,9 @@ int get_syntax_info(int *seqnrp) int syn_get_concealed_id(win_T *wp, linenr_T lnum, colnr_T col) { int seqnr; - int syntax_flags; (void)syn_get_id(wp, lnum, col, false, NULL, false); - syntax_flags = get_syntax_info(&seqnr); + int syntax_flags = get_syntax_info(&seqnr); if (syntax_flags & HL_CONCEAL) { return seqnr; -- cgit From 7dc9182cf0b27cbfb4e289db55dd7b02998ef5c8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 11 Mar 2023 21:29:25 +0800 Subject: vim-patch:8.2.1398: autoload script sourced twice if sourced directly (#22622) Problem: Autoload script sourced twice if sourced directly. Solution: Do not source an autoload script again. (issue vim/vim#6644) https://github.com/vim/vim/commit/daa2f36573db3e1df7eb1fdbc3a09a2815644048 Cherry-pick ret_sid changes from patch 8.2.0149. Use do_in_runtimepath() as that's what source_runtime() calls in Nvim. Co-authored-by: Bram Moolenaar --- src/nvim/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index d4161b9ca2..14fef19399 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4026,7 +4026,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing) prev_toplvl_grp = curwin->w_s->b_syn_topgrp; curwin->w_s->b_syn_topgrp = sgl_id; if (source - ? do_source(eap->arg, false, DOSO_NONE) == FAIL + ? do_source(eap->arg, false, DOSO_NONE, NULL) == FAIL : source_runtime(eap->arg, DIP_ALL) == FAIL) { semsg(_(e_notopen), eap->arg); } -- 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/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 14fef19399..c0bb7d726e 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -58,7 +58,7 @@ static bool did_syntax_onoff = false; #define SPO_LC_OFF 6 // leading context offset #define SPO_COUNT 7 -static char e_illegal_arg[] = N_("E390: Illegal argument: %s"); +static const char e_illegal_arg[] = N_("E390: Illegal argument: %s"); // The patterns that are being searched for are stored in a syn_pattern. // A match item consists of one pattern. -- cgit From 1d2a29f75ba7d094c8e7444c9b249a4a7211c93c Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:39:04 +0200 Subject: refactor: make char * parameters const in message.c Add const to char * parameters in message.c functions and remove some redundant casts. --- src/nvim/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index c0bb7d726e..6b8cce4858 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3643,7 +3643,7 @@ static bool syn_list_keywords(const int id, const hashtab_T *const ht, bool did_ prev_skipempty = (kp->flags & HL_SKIPEMPTY); } } - msg_outtrans((char *)kp->keyword); + msg_outtrans(kp->keyword); } } } -- 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/syntax.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 6b8cce4858..24c7568651 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3749,7 +3749,7 @@ static void add_keyword(char *const name, const int id, const int flags, hashtab_T *const ht = (curwin->w_s->b_syn_ic) ? &curwin->w_s->b_keywtab_ic : &curwin->w_s->b_keywtab; - hashitem_T *const hi = hash_lookup(ht, (const char *)kp->keyword, + hashitem_T *const hi = hash_lookup(ht, kp->keyword, strlen(kp->keyword), hash); // even though it looks like only the kp->keyword member is @@ -5370,7 +5370,7 @@ void set_context_in_syntax_cmd(expand_T *xp, const char *arg) } // (part of) subcommand already typed - const char *p = (const char *)skiptowhite(arg); + const char *p = skiptowhite(arg); if (*p == NUL) { return; } -- 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/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 24c7568651..60f374466e 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3763,7 +3763,7 @@ static void add_keyword(char *const name, const int id, const int flags, } else { // keyword already exists, prepend to list kp->ke_next = HI2KE(hi); - hi->hi_key = (char *)KE2HIKEY(kp); + hi->hi_key = KE2HIKEY(kp); } } -- cgit From 2d78e656b715119ca11d131a1a932f22f1b4ad36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:43:00 +0200 Subject: refactor: remove redundant casts --- src/nvim/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 60f374466e..5094f0cd6f 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3674,7 +3674,7 @@ static void syn_clear_keyword(int id, hashtab_T *ht) if (kp_next == NULL) { hash_remove(ht, hi); } else { - hi->hi_key = (char *)KE2HIKEY(kp_next); + hi->hi_key = KE2HIKEY(kp_next); } } else { kp_prev->ke_next = kp_next; -- 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/syntax.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 5094f0cd6f..840cd60f13 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -619,7 +619,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) for (current_lnum = lnum; current_lnum < end_lnum; current_lnum++) { syn_start_line(); - for (;;) { + while (true) { had_sync_point = syn_finish_line(true); // When a sync point has been found, remember where, and // continue to look for another one, further on in the line. @@ -2070,7 +2070,7 @@ static void check_state_ends(void) int had_extend; cur_si = &CUR_STATE(current_state.ga_len - 1); - for (;;) { + while (true) { if (cur_si->si_ends && (cur_si->si_m_endpos.lnum < current_lnum || (cur_si->si_m_endpos.lnum == current_lnum @@ -2383,7 +2383,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ } // Find the SKIP or first END pattern after the last START pattern. - for (;;) { + while (true) { spp = &(SYN_ITEMS(syn_block)[idx]); if (spp->sp_type != SPTYPE_START) { break; @@ -2410,7 +2410,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ // use syntax iskeyword option save_chartab(buf_chartab); - for (;;) { + while (true) { // Find end pattern that matches first after "matchcol". best_idx = -1; for (idx = start_idx; idx < syn_block->b_syn_patterns.ga_len; idx++) { @@ -3838,7 +3838,7 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i opt->flags |= HL_CONCEAL; } - for (;;) { + while (true) { // This is used very often when a large number of keywords is defined. // Need to skip quickly when no option name is found. // Also avoid tolower(), it's slow. @@ -4675,7 +4675,7 @@ static void syn_cmd_cluster(exarg_T *eap, int syncing) } scl_id -= SYNID_CLUSTER; - for (;;) { + while (true) { if (STRNICMP(rest, "add", 3) == 0 && (ascii_iswhite(rest[3]) || rest[3] == '=')) { opt_len = 3; -- cgit From 88cfb49bee3c9102082c7010acb92244e4ad1348 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:14:39 +0800 Subject: vim-patch:8.2.4890: inconsistent capitalization in error messages Problem: Inconsistent capitalization in error messages. Solution: Make capitalization consistent. (Doug Kearns) https://github.com/vim/vim/commit/cf030578b26460643dca4a40e7f2e3bc19c749aa Co-authored-by: Bram Moolenaar --- src/nvim/syntax.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 840cd60f13..d237972e40 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -59,6 +59,12 @@ static bool did_syntax_onoff = false; #define SPO_COUNT 7 static const char e_illegal_arg[] = N_("E390: Illegal argument: %s"); +static const char e_contains_argument_not_accepted_here[] + = N_("E395: Contains argument not accepted here"); +static const char e_invalid_cchar_value[] + = N_("E844: Invalid cchar value"); +static const char e_trailing_char_after_rsb_str_str[] + = N_("E890: Trailing char after ']': %s]%s"); // The patterns that are being searched for are stored in a syn_pattern. // A match item consists of one pattern. @@ -3874,7 +3880,7 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i if (flagtab[fidx].argtype == 1) { if (!opt->has_cont_list) { - emsg(_("E395: contains argument not accepted here")); + emsg(_(e_contains_argument_not_accepted_here)); return NULL; } if (get_id_list(&arg, 8, &opt->cont_list, skip) == FAIL) { @@ -3893,7 +3899,7 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i *conceal_char = utf_ptr2char(arg + 6); arg += utfc_ptr2len(arg + 6) - 1; if (!vim_isprintc_strict(*conceal_char)) { - emsg(_("E844: invalid cchar value")); + emsg(_(e_invalid_cchar_value)); return NULL; } arg = skipwhite(arg + 7); @@ -4111,8 +4117,7 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing) } if (p[1] == ']') { if (p[2] != NUL) { - semsg(_("E890: trailing char after ']': %s]%s"), - kw, &p[2]); + semsg(_(e_trailing_char_after_rsb_str_str), kw, &p[2]); goto error; } kw = p + 1; -- cgit From a741c7fd0465c949a0016fcbee5f4526b65f8c02 Mon Sep 17 00:00:00 2001 From: Alexandre Teoi Date: Sat, 1 Jul 2023 10:33:51 -0300 Subject: fix(api): nvim_parse_cmd error message in pcall() #23297 Problem: nvim_parse_cmd() in pcall() may show an error message (side-effect): :lua pcall(vim.api.nvim_parse_cmd, vim.fn.getcmdline(), {}) E16: Invalid range Solution: Avoid emsg() in the nvim_parse_cmd() codepath. - refactor(api): add error message output parameter to get_address() - fix: null check emsg() parameter - refactor: remove emsg_off workaround from do_incsearch_highlighting() - refactor: remove emsg_off workaround from cmdpreview_may_show() - refactor: remove remaining calls to emsg() from parse_cmd_address() and get_address() - (refactor): lint set_cmd_dflall_range() - refactor: addr_error() - move output parameter to return value Fix #20339 TODO: These are the functions called by `get_address()`: ``` nvim_parse_cmd() -> parse_cmdline() -> parse_cmd_address() -> get_address() skipwhite() addr_error() qf_get_cur_idx() qf_get_cur_valid_idx() qf_get_size() qf_get_valid_size() mark_get() mark_check() assert() skip_regexp() magic_isset() > do_search() > searchit() ascii_isdigit() getdigits() getdigits_int32() compute_buffer_local_count() hasFolding() ``` From these functions, I found at least two that call emsg directly: - do_search() - seems to be simple to refactor - searchit() - will be more challenging because it may generate multiple error messages, which can't be handled by the current `errormsg` out-parameter. For example, it makes multiple calls to `vim_regexec_multi()` in a loop that possibly generate error messages, and later `searchit()` itself may generate another one: - https://github.com/neovim/neovim/blob/c194acbfc479d8e5839fa629363f93f6550d035c/src/nvim/search.c#L631-L647 - https://github.com/neovim/neovim/blob/c194acbfc479d8e5839fa629363f93f6550d035c/src/nvim/search.c#L939-L954 --------- Co-authored-by: Justin M. Keyes --- src/nvim/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index d237972e40..ea7f3a085f 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3979,7 +3979,7 @@ static void syn_cmd_include(exarg_T *eap, int syncing) int sgl_id = 1; char *group_name_end; char *rest; - char *errormsg = NULL; + const char *errormsg = NULL; int prev_toplvl_grp; int prev_syn_inc_tag; bool source = false; -- 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/syntax.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index ea7f3a085f..7e3ae4a62c 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -2475,7 +2475,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ break; } - line = ml_get_buf(syn_buf, startpos->lnum, false); + line = ml_get_buf(syn_buf, startpos->lnum); int line_len = (int)strlen(line); // take care of an empty match or negative offset @@ -2611,7 +2611,7 @@ static void syn_add_end_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *spp if (result->lnum > syn_buf->b_ml.ml_line_count) { col = 0; } else if (off != 0) { - base = ml_get_buf(syn_buf, result->lnum, false); + base = ml_get_buf(syn_buf, result->lnum); p = base + col; if (off > 0) { while (off-- > 0 && *p != NUL) { @@ -2653,10 +2653,10 @@ static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *s if (result->lnum > syn_buf->b_ml.ml_line_count) { // a "\n" at the end of the pattern may take us below the last line result->lnum = syn_buf->b_ml.ml_line_count; - col = (int)strlen(ml_get_buf(syn_buf, result->lnum, false)); + col = (int)strlen(ml_get_buf(syn_buf, result->lnum)); } if (off != 0) { - base = ml_get_buf(syn_buf, result->lnum, false); + base = ml_get_buf(syn_buf, result->lnum); p = base + col; if (off > 0) { while (off-- && *p != NUL) { @@ -2675,7 +2675,7 @@ static void syn_add_start_off(lpos_T *result, regmmatch_T *regmatch, synpat_T *s /// Get current line in syntax buffer. static char *syn_getcurline(void) { - return ml_get_buf(syn_buf, current_lnum, false); + return ml_get_buf(syn_buf, current_lnum); } // Call vim_regexec() to find a match with "rmp" in "syn_buf". -- cgit From f91cd31d7d9d70006e0000592637d5d997eab52c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 21:46:39 +0200 Subject: refactor(messages): fold msg_outtrans_attr into msg_outtrans problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/syntax.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 7e3ae4a62c..f4e0fa7fd0 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -2946,9 +2946,9 @@ static void syn_cmd_iskeyword(exarg_T *eap, int syncing) msg_puts("\n"); if (curwin->w_s->b_syn_isk != empty_option) { msg_puts("syntax iskeyword "); - msg_outtrans(curwin->w_s->b_syn_isk); + msg_outtrans(curwin->w_s->b_syn_isk, 0); } else { - msg_outtrans(_("syntax iskeyword not set")); + msg_outtrans(_("syntax iskeyword not set"), 0); } } else { if (STRNICMP(arg, "clear", 5) == 0) { @@ -3427,7 +3427,7 @@ static void syn_list_one(const int id, const bool syncing, const bool link_only) msg_putchar(' '); if (spp->sp_sync_idx >= 0) { msg_outtrans(highlight_group_name(SYN_ITEMS(curwin->w_s) - [spp->sp_sync_idx].sp_syn.id - 1)); + [spp->sp_sync_idx].sp_syn.id - 1), 0); } else { msg_puts("NONE"); } @@ -3440,7 +3440,7 @@ static void syn_list_one(const int id, const bool syncing, const bool link_only) (void)syn_list_header(did_header, 0, id, true); msg_puts_attr("links to", attr); msg_putchar(' '); - msg_outtrans(highlight_group_name(highlight_link_id(id - 1) - 1)); + msg_outtrans(highlight_group_name(highlight_link_id(id - 1) - 1), 0); } } @@ -3461,7 +3461,7 @@ static void syn_list_cluster(int id) // slight hack: roughly duplicate the guts of syn_list_header() msg_putchar('\n'); - msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name); + msg_outtrans(SYN_CLSTR(curwin->w_s)[id].scl_name, 0); if (msg_col >= endcol) { // output at least one space endcol = msg_col + 1; @@ -3498,9 +3498,9 @@ static void put_id_list(const char *const name, const int16_t *const list, const int scl_id = *p - SYNID_CLUSTER; msg_putchar('@'); - msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name); + msg_outtrans(SYN_CLSTR(curwin->w_s)[scl_id].scl_name, 0); } else { - msg_outtrans(highlight_group_name(*p - 1)); + msg_outtrans(highlight_group_name(*p - 1), 0); } if (p[1]) { msg_putchar(','); @@ -3520,9 +3520,9 @@ static void put_pattern(const char *const s, const int c, const synpat_T *const msg_puts_attr("matchgroup", attr); msg_putchar('='); if (last_matchgroup == 0) { - msg_outtrans("NONE"); + msg_outtrans("NONE", 0); } else { - msg_outtrans(highlight_group_name(last_matchgroup - 1)); + msg_outtrans(highlight_group_name(last_matchgroup - 1), 0); } msg_putchar(' '); } @@ -3539,7 +3539,7 @@ static void put_pattern(const char *const s, const int c, const synpat_T *const } } msg_putchar(sepchars[i]); - msg_outtrans(spp->sp_pattern); + msg_outtrans(spp->sp_pattern, 0); msg_putchar(sepchars[i]); // output any pattern options @@ -3649,7 +3649,7 @@ static bool syn_list_keywords(const int id, const hashtab_T *const ht, bool did_ prev_skipempty = (kp->flags & HL_SKIPEMPTY); } } - msg_outtrans(kp->keyword); + msg_outtrans(kp->keyword, 0); } } } @@ -5682,7 +5682,7 @@ static void syntime_report(void) msg_puts(profile_msg(p->average)); msg_puts(" "); msg_advance(50); - msg_outtrans(highlight_group_name(p->id - 1)); + msg_outtrans(highlight_group_name(p->id - 1), 0); msg_puts(" "); msg_advance(69); @@ -5695,7 +5695,7 @@ static void syntime_report(void) if (len > (int)strlen(p->pattern)) { len = (int)strlen(p->pattern); } - msg_outtrans_len(p->pattern, len); + msg_outtrans_len(p->pattern, len, 0); msg_puts("\n"); } ga_clear(&ga); -- 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/syntax.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index f4e0fa7fd0..10f808ad6b 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -2713,7 +2713,7 @@ static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T } if (timed_out && !syn_win->w_s->b_syn_slow) { syn_win->w_s->b_syn_slow = true; - msg(_("'redrawtime' exceeded, syntax highlighting disabled")); + msg(_("'redrawtime' exceeded, syntax highlighting disabled"), 0); } if (r > 0) { @@ -2816,9 +2816,9 @@ static void syn_cmd_conceal(exarg_T *eap, int syncing) next = skiptowhite(arg); if (*arg == NUL) { if (curwin->w_s->b_syn_conceal) { - msg("syntax conceal on"); + msg("syntax conceal on", 0); } else { - msg("syntax conceal off"); + msg("syntax conceal off", 0); } } else if (STRNICMP(arg, "on", 2) == 0 && next - arg == 2) { curwin->w_s->b_syn_conceal = true; @@ -2843,9 +2843,9 @@ static void syn_cmd_case(exarg_T *eap, int syncing) next = skiptowhite(arg); if (*arg == NUL) { if (curwin->w_s->b_syn_ic) { - msg("syntax case ignore"); + msg("syntax case ignore", 0); } else { - msg("syntax case match"); + msg("syntax case match", 0); } } else if (STRNICMP(arg, "match", 5) == 0 && next - arg == 5) { curwin->w_s->b_syn_ic = false; @@ -2870,9 +2870,9 @@ static void syn_cmd_foldlevel(exarg_T *eap, int syncing) if (*arg == NUL) { switch (curwin->w_s->b_syn_foldlevel) { case SYNFLD_START: - msg("syntax foldlevel start"); break; + msg("syntax foldlevel start", 0); break; case SYNFLD_MINIMUM: - msg("syntax foldlevel minimum"); break; + msg("syntax foldlevel minimum", 0); break; default: break; } @@ -2909,11 +2909,11 @@ static void syn_cmd_spell(exarg_T *eap, int syncing) next = skiptowhite(arg); if (*arg == NUL) { if (curwin->w_s->b_syn_spell == SYNSPL_TOP) { - msg("syntax spell toplevel"); + msg("syntax spell toplevel", 0); } else if (curwin->w_s->b_syn_spell == SYNSPL_NOTOP) { - msg("syntax spell notoplevel"); + msg("syntax spell notoplevel", 0); } else { - msg("syntax spell default"); + msg("syntax spell default", 0); } } else if (STRNICMP(arg, "toplevel", 8) == 0 && next - arg == 8) { curwin->w_s->b_syn_spell = SYNSPL_TOP; @@ -3235,7 +3235,7 @@ static void syn_cmd_list(exarg_T *eap, int syncing) } if (!syntax_present(curwin)) { - msg(_(msg_no_items)); + msg(_(msg_no_items), 0); return; } @@ -5590,7 +5590,7 @@ static void syntime_clear(void) synpat_T *spp; if (!syntax_present(curwin)) { - msg(_(msg_no_items)); + msg(_(msg_no_items), 0); return; } for (int idx = 0; idx < curwin->w_s->b_syn_patterns.ga_len; idx++) { @@ -5628,7 +5628,7 @@ static int syn_compare_syntime(const void *v1, const void *v2) static void syntime_report(void) { if (!syntax_present(curwin)) { - msg(_(msg_no_items)); + msg(_(msg_no_items), 0); return; } -- 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/syntax.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 10f808ad6b..59e1a42bb0 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 59e1a42bb0..9b238e6ff9 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -34,7 +34,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/optionstr.h" #include "nvim/os/input.h" #include "nvim/path.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/syntax.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 9b238e6ff9..18f0b796d1 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -15,6 +15,7 @@ #include "nvim/buffer.h" #include "nvim/buffer_defs.h" #include "nvim/charset.h" +#include "nvim/cmdexpand_defs.h" #include "nvim/drawscreen.h" #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" -- cgit From e72b546354cd90bf0cd8ee6dd045538d713009ad Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 18f0b796d1..6bb841b1f8 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3555,7 +3555,7 @@ static void put_pattern(const char *const s, const int c, const synpat_T *const msg_putchar(','); // Separate with commas. } msg_puts(spo_name_tab[i]); - const long n = spp->sp_offsets[i]; + const int n = spp->sp_offsets[i]; if (i != SPO_LC_OFF) { if (spp->sp_off_flags & mask) { msg_putchar('s'); -- 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/syntax.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 6bb841b1f8..a35352136b 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -5646,11 +5646,11 @@ static void syntime_report(void) p = GA_APPEND_VIA_PTR(time_entry_T, &ga); p->total = spp->sp_time.total; total_total = profile_add(total_total, spp->sp_time.total); - p->count = (int)spp->sp_time.count; - p->match = (int)spp->sp_time.match; - total_count += (int)spp->sp_time.count; + p->count = spp->sp_time.count; + p->match = spp->sp_time.match; + total_count += spp->sp_time.count; p->slowest = spp->sp_time.slowest; - proftime_T tm = profile_divide(spp->sp_time.total, (int)spp->sp_time.count); + proftime_T tm = profile_divide(spp->sp_time.total, spp->sp_time.count); p->average = tm; p->id = spp->sp_syn.id; p->pattern = spp->sp_pattern; -- cgit From af010e23f38a23bb74ea5b61e1b1a05e76410b5f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Fri, 13 Oct 2023 20:16:15 +0600 Subject: refactor(options): rename `empty_option` to `empty_string_option` --- src/nvim/syntax.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index a35352136b..8336c33275 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -729,7 +729,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) static void save_chartab(char *chartab) { - if (syn_block->b_syn_isk == empty_option) { + if (syn_block->b_syn_isk == empty_string_option) { return; } @@ -739,7 +739,7 @@ static void save_chartab(char *chartab) static void restore_chartab(char *chartab) { - if (syn_win->w_s->b_syn_isk != empty_option) { + if (syn_win->w_s->b_syn_isk != empty_string_option) { memmove(syn_buf->b_chartab, chartab, (size_t)32); } } @@ -2946,7 +2946,7 @@ static void syn_cmd_iskeyword(exarg_T *eap, int syncing) arg = skipwhite(arg); if (*arg == NUL) { msg_puts("\n"); - if (curwin->w_s->b_syn_isk != empty_option) { + if (curwin->w_s->b_syn_isk != empty_string_option) { msg_puts("syntax iskeyword "); msg_outtrans(curwin->w_s->b_syn_isk, 0); } else { @@ -4758,7 +4758,7 @@ static char *get_syn_pattern(char *arg, synpat_T *ci) // Make 'cpoptions' empty, to avoid the 'l' flag char *cpo_save = p_cpo; - p_cpo = empty_option; + p_cpo = empty_string_option; ci->sp_prog = vim_regcomp(ci->sp_pattern, RE_MAGIC); p_cpo = cpo_save; @@ -4915,7 +4915,7 @@ static void syn_cmd_sync(exarg_T *eap, int syncing) // Make 'cpoptions' empty, to avoid the 'l' flag cpo_save = p_cpo; - p_cpo = empty_option; + p_cpo = empty_string_option; curwin->w_s->b_syn_linecont_prog = vim_regcomp(curwin->w_s->b_syn_linecont_pat, RE_MAGIC); p_cpo = cpo_save; @@ -5298,7 +5298,7 @@ void ex_ownsyntax(exarg_T *eap) hash_init(&curwin->w_s->b_keywtab_ic); // TODO(vim): Keep the spell checking as it was. curwin->w_p_spell = false; // No spell checking - // make sure option values are "empty_option" instead of NULL + // make sure option values are "empty_string_option" instead of NULL clear_string_option(&curwin->w_s->b_p_spc); clear_string_option(&curwin->w_s->b_p_spf); clear_string_option(&curwin->w_s->b_p_spl); -- cgit From 5f03a1eaabfc8de2b3a9c666fcd604763f41e152 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 20 Oct 2023 15:10:33 +0200 Subject: build(lint): remove unnecessary clint.py rules Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. --- src/nvim/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 8336c33275..f13c6b8f1a 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -511,7 +511,7 @@ static void syn_sync(win_T *wp, linenr_T start_lnum, synstate_T *last_valid) int found_flags = 0; int found_match_idx = 0; linenr_T found_current_lnum = 0; - int found_current_col= 0; + int found_current_col = 0; lpos_T found_m_endpos; colnr_T prev_current_col; -- 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/syntax.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index f13c6b8f1a..0d1fd2d966 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -122,7 +122,7 @@ typedef struct state_item { int si_end_idx; // group ID for end pattern or zero int si_ends; // if match ends before si_m_endpos int si_attr; // attributes in this state - long si_flags; // HL_HAS_EOL flag in this state, and + int si_flags; // HL_HAS_EOL flag in this state, and // HL_SKIP* for si_next_list int si_seqnr; // sequence number int si_cchar; // substitution character for conceal @@ -265,7 +265,7 @@ static lpos_T next_match_m_endpos; // position for end of next match static lpos_T next_match_h_startpos; // pos. for highl. start of next match static lpos_T next_match_h_endpos; // pos. for highl. end of next match static int next_match_idx; // index of matched item -static long next_match_flags; // flags for next match +static int next_match_flags; // flags for next match static lpos_T next_match_eos_pos; // end of start pattn (start region) static lpos_T next_match_eoe_pos; // pos. for end of end pattern static int next_match_end_idx; // ID of group for end pattn or zero @@ -1209,7 +1209,7 @@ static synstate_T *store_current_state(void) } for (i = 0; i < sp->sst_stacksize; i++) { bp[i].bs_idx = CUR_STATE(i).si_idx; - bp[i].bs_flags = (int)CUR_STATE(i).si_flags; + bp[i].bs_flags = CUR_STATE(i).si_flags; bp[i].bs_seqnr = CUR_STATE(i).si_seqnr; bp[i].bs_cchar = CUR_STATE(i).si_cchar; bp[i].bs_extmatch = ref_extmatch(CUR_STATE(i).si_extmatch); @@ -1511,7 +1511,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con stateitem_T *cur_si, *sip = NULL; int startcol; int endcol; - long flags; + int flags; int cchar; int16_t *next_list; bool found_match; // found usable match @@ -1884,7 +1884,7 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con current_attr = sip->si_attr; current_id = sip->si_id; current_trans_id = sip->si_trans_id; - current_flags = (int)sip->si_flags; + current_flags = sip->si_flags; current_seqnr = sip->si_seqnr; current_sub_char = sip->si_cchar; break; @@ -2114,7 +2114,7 @@ static void check_state_ends(void) // handle next_list, unless at end of line and no "skipnl" or // "skipempty" current_next_list = cur_si->si_next_list; - current_next_flags = (int)cur_si->si_flags; + current_next_flags = cur_si->si_flags; if (!(current_next_flags & (HL_SKIPNL | HL_SKIPEMPTY)) && syn_getcurline()[current_col] == NUL) { current_next_list = NULL; @@ -2362,8 +2362,8 @@ static void pop_current_state(void) /// @param end_endpos return: end of end pattern match /// @param end_idx return: group ID for end pat. match, or 0 /// @param start_ext submatches from the start pattern -static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_endpos, - long *flagsp, lpos_T *end_endpos, int *end_idx, reg_extmatch_T *start_ext) +static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_endpos, int *flagsp, + lpos_T *end_endpos, int *end_idx, reg_extmatch_T *start_ext) { colnr_T matchcol; synpat_T *spp, *spp_skip; @@ -2700,7 +2700,7 @@ static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T } rmp->rmm_maxcol = (colnr_T)syn_buf->b_p_smc; - long r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, syn_tm, &timed_out); + int r = vim_regexec_multi(rmp, syn_win, syn_buf, lnum, col, syn_tm, &timed_out); if (l_syn_time_on) { pt = profile_end(pt); @@ -2737,7 +2737,7 @@ static int syn_regexec(regmmatch_T *rmp, linenr_T lnum, colnr_T col, syn_time_T /// @param cur_si item at the top of the stack /// @param ccharp conceal substitution char static int check_keyword_id(char *const line, const int startcol, int *const endcolp, - long *const flagsp, int16_t **const next_listp, + int *const flagsp, int16_t **const next_listp, stateitem_T *const cur_si, int *const ccharp) { // Find first character after the keyword. First character was already -- cgit From 8e58d37f2e15ac8540377148e55ed08a039aadb6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 11 Nov 2023 11:20:08 +0100 Subject: refactor: remove redundant casts --- src/nvim/syntax.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 0d1fd2d966..42b2302fa5 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -758,7 +758,7 @@ static int syn_match_linecont(linenr_T lnum) regmatch.rmm_ic = syn_block->b_syn_linecont_ic; regmatch.regprog = syn_block->b_syn_linecont_prog; - int r = syn_regexec(®match, lnum, (colnr_T)0, + int r = syn_regexec(®match, lnum, 0, IF_SYN_TIME(&syn_block->b_syn_linecont_time)); syn_block->b_syn_linecont_prog = regmatch.regprog; @@ -5049,7 +5049,7 @@ static int get_id_list(char **const arg, const int keylen, int16_t **const list, regmatch.rm_ic = true; id = 0; for (int i = highlight_num_groups(); --i >= 0;) { - if (vim_regexec(®match, highlight_group_name(i), (colnr_T)0)) { + if (vim_regexec(®match, highlight_group_name(i), 0)) { if (round == 2) { // Got more items than expected; can happen // when adding items that match: -- 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/syntax.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 42b2302fa5..67d762d546 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.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 - // syntax.c: code for syntax highlighting #include @@ -239,8 +236,6 @@ static keyentry_T dumkey; #define HIKEY2KE(p) ((keyentry_T *)((p) - (dumkey.keyword - (char *)&dumkey))) #define HI2KE(hi) HIKEY2KE((hi)->hi_key) -// -V:HI2KE:782 - // To reduce the time spent in keepend(), remember at which level in the state // stack the first item with "keepend" is present. When "-1", there is no // "keepend" on the stack. @@ -5059,7 +5054,7 @@ static int get_id_list(char **const arg, const int keylen, int16_t **const list, xfree(retval); round = 1; } else { - retval[count] = (int16_t)(i + 1); // -V522 + retval[count] = (int16_t)(i + 1); } } count++; -- 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/syntax.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 67d762d546..d83d58229f 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -307,7 +307,6 @@ void syn_set_timeout(proftime_T *tm) // window. void syntax_start(win_T *wp, linenr_T lnum) { - synstate_T *p; synstate_T *last_valid = NULL; synstate_T *last_min_valid = NULL; synstate_T *sp, *prev = NULL; @@ -362,7 +361,7 @@ void syntax_start(win_T *wp, linenr_T lnum) // Only do this if lnum is not before and not to far beyond a saved state. if (INVALID_STATE(¤t_state) && syn_block->b_sst_array != NULL) { // Find last valid saved state before start_lnum. - for (p = syn_block->b_sst_first; p != NULL; p = p->sst_next) { + for (synstate_T *p = syn_block->b_sst_first; p != NULL; p = p->sst_next) { if (p->sst_lnum > lnum) { break; } @@ -877,13 +876,11 @@ static void syn_update_ends(bool startofline) static void syn_stack_free_block(synblock_T *block) { - synstate_T *p; - if (block->b_sst_array == NULL) { return; } - for (p = block->b_sst_first; p != NULL; p = p->sst_next) { + for (synstate_T *p = block->b_sst_first; p != NULL; p = p->sst_next) { clear_syn_state(p); } XFREE_CLEAR(block->b_sst_array); @@ -1037,7 +1034,7 @@ static void syn_stack_apply_changes_block(synblock_T *block, buf_T *buf) /// @return true if at least one entry was freed. static bool syn_stack_cleanup(void) { - synstate_T *p, *prev; + synstate_T *prev; disptick_T tick; int dist; bool retval = false; @@ -1059,7 +1056,7 @@ static bool syn_stack_cleanup(void) tick = syn_block->b_sst_lasttick; bool above = false; prev = syn_block->b_sst_first; - for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) { + for (synstate_T *p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) { if (prev->sst_lnum + dist > p->sst_lnum) { if (p->sst_tick > syn_block->b_sst_lasttick) { if (!above || p->sst_tick < tick) { @@ -1075,7 +1072,7 @@ static bool syn_stack_cleanup(void) // Go through the list to make the entries for the oldest tick at an // interval of several lines. prev = syn_block->b_sst_first; - for (p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) { + for (synstate_T *p = prev->sst_next; p != NULL; prev = p, p = p->sst_next) { if (p->sst_tick == tick && prev->sst_lnum + dist > p->sst_lnum) { // Move this entry from used list to free list prev->sst_next = p->sst_next; @@ -1101,10 +1098,8 @@ static void syn_stack_free_entry(synblock_T *block, synstate_T *p) // Returns NULL when there is no entry or the first entry is after "lnum". static synstate_T *syn_stack_find_entry(linenr_T lnum) { - synstate_T *p, *prev; - - prev = NULL; - for (p = syn_block->b_sst_first; p != NULL; prev = p, p = p->sst_next) { + synstate_T *prev = NULL; + for (synstate_T *p = syn_block->b_sst_first; p != NULL; prev = p, p = p->sst_next) { if (p->sst_lnum == lnum) { return 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/syntax.c | 49 ++++++++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index d83d58229f..12b0c8ce9b 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -309,8 +309,8 @@ void syntax_start(win_T *wp, linenr_T lnum) { synstate_T *last_valid = NULL; synstate_T *last_min_valid = NULL; - synstate_T *sp, *prev = NULL; - linenr_T parsed_lnum; + synstate_T *sp; + synstate_T *prev = NULL; linenr_T first_stored; int dist; static varnumber_T changedtick = 0; // remember the last change ID @@ -425,7 +425,7 @@ void syntax_start(win_T *wp, linenr_T lnum) if (sp != NULL && sp->sst_lnum == current_lnum && syn_stack_equal(sp)) { - parsed_lnum = current_lnum; + linenr_T parsed_lnum = current_lnum; prev = sp; while (sp != NULL && sp->sst_change_lnum <= parsed_lnum) { if (sp->sst_lnum <= lnum) { @@ -907,9 +907,6 @@ void syn_stack_free_all(synblock_T *block) // Also used to allocate b_sst_array[] for the first time. static void syn_stack_alloc(void) { - synstate_T *to, *from; - synstate_T *sstp; - int len = syn_buf->b_ml.ml_line_count / SST_DIST + Rows * 2; if (len < SST_MIN_ENTRIES) { len = SST_MIN_ENTRIES; @@ -937,12 +934,12 @@ static void syn_stack_alloc(void) } assert(len >= 0); - sstp = xcalloc((size_t)len, sizeof(synstate_T)); + synstate_T *sstp = xcalloc((size_t)len, sizeof(synstate_T)); - to = sstp - 1; + synstate_T *to = sstp - 1; if (syn_block->b_sst_array != NULL) { // Move the states from the old array to the new one. - for (from = syn_block->b_sst_first; from != NULL; + for (synstate_T *from = syn_block->b_sst_first; from != NULL; from = from->sst_next) { to++; *to = *from; @@ -988,16 +985,13 @@ void syn_stack_apply_changes(buf_T *buf) static void syn_stack_apply_changes_block(synblock_T *block, buf_T *buf) { - synstate_T *p, *prev, *np; - linenr_T n; - - prev = NULL; - for (p = block->b_sst_first; p != NULL;) { + synstate_T *prev = NULL; + for (synstate_T *p = block->b_sst_first; p != NULL;) { if (p->sst_lnum + block->b_syn_sync_linebreaks > buf->b_mod_top) { - n = p->sst_lnum + buf->b_mod_xlines; + linenr_T n = p->sst_lnum + buf->b_mod_xlines; if (n <= buf->b_mod_bot) { // this state is inside the changed area, remove it - np = p->sst_next; + synstate_T *np = p->sst_next; if (prev == NULL) { block->b_sst_first = np; } else { @@ -1260,7 +1254,6 @@ static void load_current_state(synstate_T *from) static bool syn_stack_equal(synstate_T *sp) { bufstate_T *bp; - reg_extmatch_T *six, *bsx; // First a quick check if the stacks have the same size end nextlist. if (sp->sst_stacksize != current_state.ga_len @@ -1286,8 +1279,8 @@ static bool syn_stack_equal(synstate_T *sp) } // When the extmatch pointers are different, the strings in them can // still be the same. Check if the extmatch references are equal. - bsx = bp[i].bs_extmatch; - six = CUR_STATE(i).si_extmatch; + reg_extmatch_T *bsx = bp[i].bs_extmatch; + reg_extmatch_T *six = CUR_STATE(i).si_extmatch; // If one of the extmatch pointers is NULL the states are different. if (bsx == NULL || six == NULL) { break; @@ -1498,7 +1491,8 @@ static int syn_current_attr(const bool syncing, const bool displaying, bool *con lpos_T eos_pos; // end-of-start match (start region) lpos_T eoe_pos; // end-of-end pattern int end_idx; // group ID for end pattern - stateitem_T *cur_si, *sip = NULL; + stateitem_T *cur_si; + stateitem_T *sip = NULL; int startcol; int endcol; int flags; @@ -2355,9 +2349,7 @@ static void pop_current_state(void) static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_endpos, int *flagsp, lpos_T *end_endpos, int *end_idx, reg_extmatch_T *start_ext) { - colnr_T matchcol; - synpat_T *spp, *spp_skip; - int start_idx; + synpat_T *spp_skip; int best_idx; regmmatch_T regmatch; regmmatch_T best_regmatch; // startpos/endpos of best match @@ -2374,7 +2366,7 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ // Check for being called with a START pattern. // Can happen with a match that continues to the next line, because it // contained a region. - spp = &(SYN_ITEMS(syn_block)[idx]); + synpat_T *spp = &(SYN_ITEMS(syn_block)[idx]); if (spp->sp_type != SPTYPE_START) { *hl_endpos = *startpos; return; @@ -2401,8 +2393,8 @@ static void find_endpos(int idx, lpos_T *startpos, lpos_T *m_endpos, lpos_T *hl_ unref_extmatch(re_extmatch_in); re_extmatch_in = ref_extmatch(start_ext); - matchcol = startpos->col; // start looking for a match at sstart - start_idx = idx; // remember the first END pattern. + colnr_T matchcol = startpos->col; // start looking for a match at sstart + int start_idx = idx; // remember the first END pattern. best_regmatch.startpos[0].col = 0; // avoid compiler warning // use syntax iskeyword option @@ -3798,7 +3790,6 @@ static char *get_group_name(char *arg, char **name_end) /// Return NULL for any error; static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, int skip) { - char *gname_start, *gname; int syn_id; int len = 0; char *p; @@ -3905,12 +3896,12 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i emsg(_("E393: group[t]here not accepted here")); return NULL; } - gname_start = arg; + char *gname_start = arg; arg = skiptowhite(arg); if (gname_start == arg) { return NULL; } - gname = xstrnsave(gname_start, (size_t)(arg - gname_start)); + char *gname = xstrnsave(gname_start, (size_t)(arg - gname_start)); if (strcmp(gname, "NONE") == 0) { *opt->sync_idx = NONE_IDX; } else { -- 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/syntax.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 12b0c8ce9b..fec5037640 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3719,9 +3719,9 @@ static void add_keyword(char *const name, const int id, const int flags, { char name_folded[MAXKEYWLEN + 1]; const char *const name_ic = (curwin->w_s->b_syn_ic) - ? str_foldcase(name, (int)strlen(name), name_folded, - sizeof(name_folded)) - : name; + ? str_foldcase(name, (int)strlen(name), name_folded, + sizeof(name_folded)) + : name; keyentry_T *const kp = xmalloc(offsetof(keyentry_T, keyword) + strlen(name_ic) + 1); STRCPY(kp->keyword, name_ic); @@ -3737,8 +3737,8 @@ static void add_keyword(char *const name, const int id, const int flags, const hash_T hash = hash_hash(kp->keyword); hashtab_T *const ht = (curwin->w_s->b_syn_ic) - ? &curwin->w_s->b_keywtab_ic - : &curwin->w_s->b_keywtab; + ? &curwin->w_s->b_keywtab_ic + : &curwin->w_s->b_keywtab; hashitem_T *const hi = hash_lookup(ht, kp->keyword, strlen(kp->keyword), hash); @@ -4385,8 +4385,8 @@ static void syn_cmd_region(exarg_T *eap, int syncing) SYN_ITEMS(curwin->w_s)[idx] = *(ppp->pp_synp); SYN_ITEMS(curwin->w_s)[idx].sp_syncing = syncing; SYN_ITEMS(curwin->w_s)[idx].sp_type = - (item == ITEM_START) ? SPTYPE_START : - (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END; + (item == ITEM_START) ? SPTYPE_START + : (item == ITEM_SKIP) ? SPTYPE_SKIP : SPTYPE_END; SYN_ITEMS(curwin->w_s)[idx].sp_flags |= syn_opt_arg.flags; SYN_ITEMS(curwin->w_s)[idx].sp_syn.id = (int16_t)syn_id; SYN_ITEMS(curwin->w_s)[idx].sp_syn.inc_tag = -- cgit From a917da4ca55be8726f26a8305c53bdd5b2c7eea4 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 26 Nov 2023 21:53:07 +0100 Subject: refactor(encoding): remove redundant vim_isprintc_strict This function is identical to vim_isprintc when encoding=utf-8 is used As this is the only internal encoding nvim supports, it is now redundant ref #2905 --- src/nvim/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index fec5037640..68b4382443 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -3881,7 +3881,7 @@ static char *get_syn_options(char *arg, syn_opt_arg_T *opt, int *conceal_char, i // cchar=? *conceal_char = utf_ptr2char(arg + 6); arg += utfc_ptr2len(arg + 6) - 1; - if (!vim_isprintc_strict(*conceal_char)) { + if (!vim_isprintc(*conceal_char)) { emsg(_(e_invalid_cchar_value)); return NULL; } -- 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/syntax.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 68b4382443..7243cc9881 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -20,6 +20,7 @@ #include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/fold.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/gettext.h" #include "nvim/globals.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/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 7243cc9881..c13b2859ce 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -37,7 +37,7 @@ #include "nvim/optionstr.h" #include "nvim/os/input.h" #include "nvim/path.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/profile.h" #include "nvim/regexp.h" #include "nvim/runtime.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/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index c13b2859ce..cf59b14a9a 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -43,7 +43,7 @@ #include "nvim/runtime.h" #include "nvim/strings.h" #include "nvim/syntax.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/vim.h" static bool did_syntax_onoff = false; -- 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/syntax.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index cf59b14a9a..33d0d46d94 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -7,7 +7,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/buffer_defs.h" @@ -28,7 +28,7 @@ #include "nvim/highlight_defs.h" #include "nvim/highlight_group.h" #include "nvim/indent_c.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" @@ -44,7 +44,7 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/types_defs.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" static bool did_syntax_onoff = false; -- 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/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/syntax.c') diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 33d0d46d94..11282ea170 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -25,7 +25,7 @@ #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/hashtab.h" -#include "nvim/highlight_defs.h" +#include "nvim/highlight.h" #include "nvim/highlight_group.h" #include "nvim/indent_c.h" #include "nvim/macros_defs.h" -- cgit