From c8c930ea785aa393ebc819139913a9e05f0ccd45 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:24:46 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22206) --- src/nvim/spell.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 2204cda169..8ef3aed417 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -380,7 +380,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount MB_PTR_ADV(mi.mi_end); } else if (mi.mi_result == SP_BAD && LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak) { - char *p, *fp; + char *p; int save_result = mi.mi_result; // First language in 'spelllang' is NOBREAK. Find first position @@ -388,7 +388,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, 0); if (mi.mi_lp->lp_slang->sl_fidxs != NULL) { p = mi.mi_word; - fp = mi.mi_fword; + char *fp = mi.mi_fword; for (;;) { MB_PTR_ADV(p); MB_PTR_ADV(fp); @@ -2834,7 +2834,6 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) int j, z; int reslen; int k = 0; - int z0; int k0; int n0; int pri; @@ -2875,7 +2874,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) while ((c = word[i]) != NUL) { // Start with the first rule that has the character in the word. int n = slang->sl_sal_first[c & 0xff]; - z0 = 0; + int z0 = 0; if (n >= 0) { // Check all rules for the same index byte. -- cgit From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/spell.c | 70 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 8ef3aed417..117a770e50 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -437,14 +437,14 @@ static void find_word(matchinf_T *mip, int mode) int flen; char *ptr; slang_T *slang = mip->mi_lp->lp_slang; - char_u *byts; + uint8_t *byts; idx_T *idxs; if (mode == FIND_KEEPWORD || mode == FIND_KEEPCOMPOUND) { // Check for word with matching case in keep-case tree. ptr = mip->mi_word; flen = 9999; // no case folding, always enough bytes - byts = (char_u *)slang->sl_kbyts; + byts = (uint8_t *)slang->sl_kbyts; idxs = slang->sl_kidxs; if (mode == FIND_KEEPCOMPOUND) { @@ -455,7 +455,7 @@ static void find_word(matchinf_T *mip, int mode) // Check for case-folded in case-folded tree. ptr = mip->mi_fword; flen = mip->mi_fwordlen; // available case-folded bytes - byts = (char_u *)slang->sl_fbyts; + byts = (uint8_t *)slang->sl_fbyts; idxs = slang->sl_fidxs; if (mode == FIND_PREFIX) { @@ -964,7 +964,7 @@ bool can_compound(slang_T *slang, const char *word, const uint8_t *flags) bool match_compoundrule(slang_T *slang, const char_u *compflags) { // loop over all the COMPOUNDRULE entries - for (char_u *p = (char_u *)slang->sl_comprules; *p != NUL; p++) { + for (char *p = (char *)slang->sl_comprules; *p != NUL; p++) { // loop over the flags in the compound word we have made, match // them against the current rule entry for (int i = 0;; i++) { @@ -982,21 +982,21 @@ bool match_compoundrule(slang_T *slang, const char_u *compflags) // compare against all the flags in [] p++; while (*p != ']' && *p != NUL) { - if (*p++ == c) { + if ((uint8_t)(*p++) == c) { match = true; } } if (!match) { break; // none matches } - } else if (*p != c) { + } else if ((uint8_t)(*p) != c) { break; // flag of word doesn't match flag in pattern } p++; } // Skip to the next "/", where the next pattern starts. - p = (char_u *)vim_strchr((char *)p, '/'); + p = vim_strchr(p, '/'); if (p == NULL) { break; } @@ -1062,13 +1062,13 @@ static void find_prefix(matchinf_T *mip, int mode) int wlen = 0; slang_T *slang = mip->mi_lp->lp_slang; - char_u *byts = (char_u *)slang->sl_pbyts; + uint8_t *byts = (uint8_t *)slang->sl_pbyts; if (byts == NULL) { return; // array is empty } // We use the case-folded word here, since prefixes are always // case-folded. - char_u *ptr = (char_u *)mip->mi_fword; + char *ptr = mip->mi_fword; int flen = mip->mi_fwordlen; // available case-folded bytes if (mode == FIND_COMPOUND) { // Skip over the previously found word(s). @@ -1126,7 +1126,7 @@ static void find_prefix(matchinf_T *mip, int mode) } // Perform a binary search in the list of accepted bytes. - int c = ptr[wlen]; + int c = (uint8_t)ptr[wlen]; idx_T lo = arridx; idx_T hi = arridx + len - 1; while (lo < hi) { @@ -1483,9 +1483,9 @@ theend: // to skip those bytes if the word was OK. void spell_cat_line(char *buf, char *line, int maxlen) { - char_u *p = (char_u *)skipwhite(line); + char *p = skipwhite(line); while (vim_strchr("*#/\"\t", (uint8_t)(*p)) != NULL) { - p = (char_u *)skipwhite((char *)p + 1); + p = skipwhite(p + 1); } if (*p == NUL) { @@ -1494,10 +1494,10 @@ void spell_cat_line(char *buf, char *line, int maxlen) // Only worth concatenating if there is something else than spaces to // concatenate. - int n = (int)(p - (char_u *)line) + 1; + int n = (int)(p - line) + 1; if (n < maxlen - 1) { memset(buf, ' ', (size_t)n); - xstrlcpy(buf + n, (char *)p, (size_t)(maxlen - n)); + xstrlcpy(buf + n, p, (size_t)(maxlen - n)); } } @@ -1775,7 +1775,7 @@ bool byte_in_str(uint8_t *str, int n) int init_syl_tab(slang_T *slang) { ga_init(&slang->sl_syl_items, sizeof(syl_item_T), 4); - char *p = vim_strchr((char *)slang->sl_syllable, '/'); + char *p = vim_strchr(slang->sl_syllable, '/'); while (p != NULL) { *p++ = NUL; if (*p == NUL) { // trailing slash @@ -1838,7 +1838,7 @@ static int count_syllables(slang_T *slang, const char *word) // No recognized syllable item, at least a syllable char then? int c = utf_ptr2char(p); len = utfc_ptr2len(p); - if (vim_strchr((char *)slang->sl_syllable, c) == NULL) { + if (vim_strchr(slang->sl_syllable, c) == NULL) { skip = false; // No, search for next syllable } else if (!skip) { cnt++; // Yes, count it @@ -2167,7 +2167,7 @@ static void use_midword(slang_T *lp, win_T *wp) return; } - for (char *p = (char *)lp->sl_midword; *p != NUL;) { + for (char *p = lp->sl_midword; *p != NUL;) { const int c = utf_ptr2char(p); const int l = utfc_ptr2len(p); if (c < 256 && l <= 2) { @@ -2660,24 +2660,24 @@ void onecap_copy(char *word, char *wcopy, bool upper) // "wcopy[MAXWLEN]". The result is NUL terminated. void allcap_copy(char *word, char *wcopy) { - char_u *d = (char_u *)wcopy; + char *d = wcopy; for (char *s = word; *s != NUL;) { int c = mb_cptr2char_adv((const char **)&s); if (c == 0xdf) { c = 'S'; - if (d - (char_u *)wcopy >= MAXWLEN - 1) { + if (d - wcopy >= MAXWLEN - 1) { break; } - *d++ = (char_u)c; + *d++ = (char)c; } else { c = SPELL_TOUPPER(c); } - if (d - (char_u *)wcopy >= MAXWLEN - MB_MAXBYTES) { + if (d - wcopy >= MAXWLEN - MB_MAXBYTES) { break; } - d += utf_char2bytes(c, (char *)d); + d += utf_char2bytes(c, d); } *d = NUL; } @@ -2846,7 +2846,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) // But keep white space. int wordlen = 0; for (const char *s = (char *)inword; *s != NUL;) { - const char_u *t = (char_u *)s; + const char *t = s; int c = mb_cptr2char_adv(&s); if (slang->sl_rem_accents) { if (utf_class(c) == 0) { @@ -2857,7 +2857,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) did_white = true; } else { did_white = false; - if (!spell_iswordp_nmw((char *)t, curwin)) { + if (!spell_iswordp_nmw(t, curwin)) { continue; } } @@ -2914,10 +2914,10 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) } k++; } - char_u *s = (char_u *)smp[n].sm_rules; + char *s = smp[n].sm_rules; pri = 5; // default priority - p0 = *s; + p0 = (uint8_t)(*s); k0 = k; while (*s == '-' && k > 1) { k--; @@ -2928,7 +2928,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) } if (ascii_isdigit(*s)) { // determine priority - pri = *s - '0'; + pri = (uint8_t)(*s) - '0'; s++; } if (*s == '^' && *(s + 1) == '^') { @@ -2991,7 +2991,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) } p0 = 5; - s = (char_u *)smp[n0].sm_rules; + s = smp[n0].sm_rules; while (*s == '-') { // "k0" gets NOT reduced because // "if (k0 == k)" @@ -3001,7 +3001,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) s++; } if (ascii_isdigit(*s)) { - p0 = *s - '0'; + p0 = (uint8_t)(*s) - '0'; s++; } @@ -3032,8 +3032,8 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) // replace string ws = smp[n].sm_to_w; - s = (char_u *)smp[n].sm_rules; - p0 = (vim_strchr((char *)s, '<') != NULL) ? 1 : 0; + s = smp[n].sm_rules; + p0 = (vim_strchr(s, '<') != NULL) ? 1 : 0; if (p0 == 1 && z == 0) { // rule with '<' is used if (reslen > 0 && ws != NULL && *ws != NUL @@ -3076,7 +3076,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) } else { c = *ws; } - if (strstr((char *)s, "^^") != NULL) { + if (strstr(s, "^^") != NULL) { if (c != NUL) { wres[reslen++] = c; } @@ -3462,7 +3462,7 @@ static linenr_T dump_prefixes(slang_T *slang, char *word, char *pat, Direction * has_word_up = true; } - char_u *byts = (char_u *)slang->sl_pbyts; + char *byts = slang->sl_pbyts; idx_T *idxs = slang->sl_pidxs; if (byts != NULL) { // array not is empty // Loop over all prefixes, building them byte-by-byte in prefix[]. @@ -3472,7 +3472,7 @@ static linenr_T dump_prefixes(slang_T *slang, char *word, char *pat, Direction * curi[0] = 1; while (depth >= 0 && !got_int) { int n = arridx[depth]; - int len = byts[n]; + int len = (uint8_t)byts[n]; if (curi[depth] > len) { // Done all bytes at this node, go up one level. depth--; @@ -3481,7 +3481,7 @@ static linenr_T dump_prefixes(slang_T *slang, char *word, char *pat, Direction * // Do one more byte at this node. n += curi[depth]; curi[depth]++; - c = byts[n]; + c = (uint8_t)byts[n]; if (c == 0) { // End of prefix, find out how many IDs there are. int i; -- cgit From 6cab36e5b7b0d741abe6c5a7c0e20bad30361034 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 4 Mar 2023 13:10:00 +0100 Subject: refactor: replace char_u with char or uint8_t (#22400) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/spell.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 117a770e50..dbe8ad5763 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -737,7 +737,7 @@ static void find_word(matchinf_T *mip, int mode) // If the word ends the sequence of compound flags of the // words must match with one of the COMPOUNDRULE items and // the number of syllables must not be too large. - mip->mi_compflags[mip->mi_complen] = (char_u)((unsigned)flags >> 24); + mip->mi_compflags[mip->mi_complen] = (uint8_t)((unsigned)flags >> 24); mip->mi_compflags[mip->mi_complen + 1] = NUL; if (word_ends) { char fword[MAXWLEN] = { 0 }; @@ -2354,8 +2354,8 @@ void clear_spell_chartab(spelltab_T *sp) CLEAR_FIELD(sp->st_isu); for (int i = 0; i < 256; i++) { - sp->st_fold[i] = (char_u)i; - sp->st_upper[i] = (char_u)i; + sp->st_fold[i] = (uint8_t)i; + sp->st_upper[i] = (uint8_t)i; } // We include digits. A word shouldn't start with a digit, but handling @@ -2366,11 +2366,11 @@ void clear_spell_chartab(spelltab_T *sp) for (int i = 'A'; i <= 'Z'; i++) { sp->st_isw[i] = true; sp->st_isu[i] = true; - sp->st_fold[i] = (char_u)(i + 0x20); + sp->st_fold[i] = (uint8_t)(i + 0x20); } for (int i = 'a'; i <= 'z'; i++) { sp->st_isw[i] = true; - sp->st_upper[i] = (char_u)(i - 0x20); + sp->st_upper[i] = (uint8_t)(i - 0x20); } } @@ -2391,8 +2391,8 @@ void init_spell_chartab(void) // The folded/upper-cased value is different between latin1 and // utf8 for 0xb5, causing E763 for no good reason. Use the latin1 // value for utf-8 to avoid this. - spelltab.st_fold[i] = (f < 256) ? (char_u)f : (char_u)i; - spelltab.st_upper[i] = (u < 256) ? (char_u)u : (char_u)i; + spelltab.st_fold[i] = (f < 256) ? (uint8_t)f : (uint8_t)i; + spelltab.st_upper[i] = (u < 256) ? (uint8_t)u : (uint8_t)i; } } -- cgit From dde5ce46b2e3e77efc27394b946ef49ce565cd95 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Mar 2023 21:09:50 +0800 Subject: refactor(spell): use uint8_t for "byts" variables (#22519) Avoid casting back and forth. --- src/nvim/spell.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index dbe8ad5763..b514ed694d 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -444,7 +444,7 @@ static void find_word(matchinf_T *mip, int mode) // Check for word with matching case in keep-case tree. ptr = mip->mi_word; flen = 9999; // no case folding, always enough bytes - byts = (uint8_t *)slang->sl_kbyts; + byts = slang->sl_kbyts; idxs = slang->sl_kidxs; if (mode == FIND_KEEPCOMPOUND) { @@ -455,7 +455,7 @@ static void find_word(matchinf_T *mip, int mode) // Check for case-folded in case-folded tree. ptr = mip->mi_fword; flen = mip->mi_fwordlen; // available case-folded bytes - byts = (uint8_t *)slang->sl_fbyts; + byts = slang->sl_fbyts; idxs = slang->sl_fidxs; if (mode == FIND_PREFIX) { @@ -1062,7 +1062,7 @@ static void find_prefix(matchinf_T *mip, int mode) int wlen = 0; slang_T *slang = mip->mi_lp->lp_slang; - uint8_t *byts = (uint8_t *)slang->sl_pbyts; + uint8_t *byts = slang->sl_pbyts; if (byts == NULL) { return; // array is empty } @@ -3194,7 +3194,7 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) int curi[MAXWLEN]; char word[MAXWLEN]; int c; - char *byts; + uint8_t *byts; idx_T *idxs; linenr_T lnum = 0; int depth; @@ -3296,7 +3296,7 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) // Do one more byte at this node. n = arridx[depth] + curi[depth]; curi[depth]++; - c = (uint8_t)byts[n]; + c = byts[n]; if (c == 0 || depth >= MAXWLEN - 1) { // End of word or reached maximum length, deal with the // word. @@ -3462,7 +3462,7 @@ static linenr_T dump_prefixes(slang_T *slang, char *word, char *pat, Direction * has_word_up = true; } - char *byts = slang->sl_pbyts; + uint8_t *byts = slang->sl_pbyts; idx_T *idxs = slang->sl_pidxs; if (byts != NULL) { // array not is empty // Loop over all prefixes, building them byte-by-byte in prefix[]. @@ -3472,7 +3472,7 @@ static linenr_T dump_prefixes(slang_T *slang, char *word, char *pat, Direction * curi[0] = 1; while (depth >= 0 && !got_int) { int n = arridx[depth]; - int len = (uint8_t)byts[n]; + int len = byts[n]; if (curi[depth] > len) { // Done all bytes at this node, go up one level. depth--; @@ -3481,7 +3481,7 @@ static linenr_T dump_prefixes(slang_T *slang, char *word, char *pat, Direction * // Do one more byte at this node. n += curi[depth]; curi[depth]++; - c = (uint8_t)byts[n]; + c = byts[n]; if (c == 0) { // End of prefix, find out how many IDs there are. int i; -- cgit From 8021300806e2ccf04b3ec33970b682ee3c7a9cc3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 16 Mar 2023 13:56:05 +0100 Subject: refactor(extmarks): some minor internal API changes extranges and a bunch of other improvements are coming for 0.10 This gets in some minor surrounding API changes to avoid rebase conflicts until then. - decorations will be able to be specific to windows - adjust deletion API to fit with extranges --- src/nvim/spell.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index b514ed694d..c65f822080 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1203,7 +1203,7 @@ bool no_spell_checking(win_T *wp) static void decor_spell_nav_start(win_T *wp) { decor_state = (DecorState){ 0 }; - decor_redraw_reset(wp->w_buffer, &decor_state); + decor_redraw_reset(wp, &decor_state); } static bool decor_spell_nav_col(win_T *wp, linenr_T lnum, linenr_T *decor_lnum, int col, @@ -1211,10 +1211,10 @@ static bool decor_spell_nav_col(win_T *wp, linenr_T lnum, linenr_T *decor_lnum, { if (*decor_lnum != lnum) { decor_providers_invoke_spell(wp, lnum - 1, col, lnum - 1, -1, decor_error); - decor_redraw_line(wp->w_buffer, lnum - 1, &decor_state); + decor_redraw_line(wp, lnum - 1, &decor_state); *decor_lnum = lnum; } - decor_redraw_col(wp->w_buffer, col, col, false, &decor_state); + decor_redraw_col(wp, col, col, false, &decor_state); return decor_state.spell == kTrue; } -- cgit From d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 2 Apr 2023 10:11:42 +0200 Subject: refactor: remove char_u (#22829) Closes https://github.com/neovim/neovim/issues/459 --- src/nvim/spell.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index c65f822080..9108059b4d 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -150,7 +150,7 @@ typedef struct matchinf_S { // for when checking a compound word int mi_compoff; // start of following word offset - char_u mi_compflags[MAXWLEN]; // flags for compound words used + uint8_t mi_compflags[MAXWLEN]; // flags for compound words used int mi_complen; // nr of compound words used int mi_compextra; // nr of COMPOUNDROOT words @@ -961,7 +961,7 @@ bool can_compound(slang_T *slang, const char *word, const uint8_t *flags) // compound rule. This is used to stop trying a compound if the flags // collected so far can't possibly match any compound rule. // Caller must check that slang->sl_comprules is not NULL. -bool match_compoundrule(slang_T *slang, const char_u *compflags) +bool match_compoundrule(slang_T *slang, const uint8_t *compflags) { // loop over all the COMPOUNDRULE entries for (char *p = (char *)slang->sl_comprules; *p != NUL; p++) { @@ -1748,7 +1748,7 @@ void count_common_word(slang_T *lp, char *word, int len, uint8_t count) wc = xmalloc(offsetof(wordcount_T, wc_word) + p_len + 1); memcpy(wc->wc_word, p, p_len + 1); wc->wc_count = count; - hash_add_item(&lp->sl_wordcount, hi, (char *)wc->wc_word, hash); + hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash); } else { wc = HI2WC(hi); wc->wc_count = (uint16_t)(wc->wc_count + count); -- 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/spell.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 9108059b4d..6623ba47af 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3619,9 +3619,9 @@ bool valid_spellfile(const char *val) return true; } -char *did_set_spell_option(bool is_spellfile) +const char *did_set_spell_option(bool is_spellfile) { - char *errmsg = NULL; + const char *errmsg = NULL; if (is_spellfile) { int l = (int)strlen(curwin->w_s->b_p_spf); @@ -3646,7 +3646,7 @@ char *did_set_spell_option(bool is_spellfile) /// Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'. /// Return error message when failed, NULL when OK. -char *compile_cap_prog(synblock_T *synblock) +const char *compile_cap_prog(synblock_T *synblock) FUNC_ATTR_NONNULL_ALL { regprog_T *rp = synblock->b_cap_prog; -- 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/spell.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 6623ba47af..593e2f4d89 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1316,7 +1316,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att // Copy the line into "buf" and append the start of the next line if // possible. Note: this ml_get_buf() may make "line" invalid, check // for empty line first. - bool empty_line = *skipwhite((const char *)line) == NUL; + bool empty_line = *skipwhite(line) == NUL; STRCPY(buf, line); if (lnum < wp->w_buffer->b_ml.ml_line_count) { spell_cat_line(buf + strlen(buf), @@ -1743,7 +1743,7 @@ void count_common_word(slang_T *lp, char *word, int len, uint8_t count) wordcount_T *wc; hash_T hash = hash_hash(p); const size_t p_len = strlen(p); - hashitem_T *hi = hash_lookup(&lp->sl_wordcount, (const char *)p, p_len, hash); + hashitem_T *hi = hash_lookup(&lp->sl_wordcount, p, p_len, hash); if (HASHITEM_EMPTY(hi)) { wc = xmalloc(offsetof(wordcount_T, wc_word) + p_len + 1); memcpy(wc->wc_word, p, p_len + 1); @@ -3129,9 +3129,9 @@ void ex_spellinfo(exarg_T *eap) for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len && !got_int; lpi++) { langp_T *const lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); msg_puts("file: "); - msg_puts((const char *)lp->lp_slang->sl_fname); + msg_puts(lp->lp_slang->sl_fname); msg_putchar('\n'); - const char *const p = (const char *)lp->lp_slang->sl_info; + const char *const p = lp->lp_slang->sl_info; if (p != NULL) { msg_puts(p); msg_putchar('\n'); -- 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/spell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 593e2f4d89..a14a02b9f7 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2845,7 +2845,7 @@ static void spell_soundfold_wsal(slang_T *slang, const char *inword, char *res) // Remove accents, if wanted. We actually remove all non-word characters. // But keep white space. int wordlen = 0; - for (const char *s = (char *)inword; *s != NUL;) { + for (const char *s = inword; *s != NUL;) { const char *t = s; int c = mb_cptr2char_adv(&s); if (slang->sl_rem_accents) { -- 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/spell.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index a14a02b9f7..a571131ba1 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -389,7 +389,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount if (mi.mi_lp->lp_slang->sl_fidxs != NULL) { p = mi.mi_word; char *fp = mi.mi_fword; - for (;;) { + while (true) { MB_PTR_ADV(p); MB_PTR_ADV(fp); if (p >= mi.mi_end) { @@ -482,7 +482,7 @@ static void find_word(matchinf_T *mip, int mode) // - there is a byte that doesn't match, // - we reach the end of the tree, // - or we reach the end of the line. - for (;;) { + while (true) { if (flen <= 0 && *mip->mi_fend != NUL) { flen = fold_more(mip); } @@ -549,7 +549,7 @@ static void find_word(matchinf_T *mip, int mode) // One space in the good word may stand for several spaces in the // checked word. if (c == ' ') { - for (;;) { + while (true) { if (flen <= 0 && *mip->mi_fend != NUL) { flen = fold_more(mip); } @@ -1081,7 +1081,7 @@ static void find_prefix(matchinf_T *mip, int mode) // - there is a byte that doesn't match, // - we reach the end of the tree, // - or we reach the end of the line. - for (;;) { + while (true) { if (flen == 0 && *mip->mi_fend != NUL) { flen = fold_more(mip); } @@ -2558,7 +2558,7 @@ bool check_need_cap(linenr_T lnum, colnr_T col) .rm_ic = false }; char *p = line + endcol; - for (;;) { + while (true) { MB_PTR_BACK(line, p); if (p == line || spell_iswordp_nmw(p, curwin)) { break; @@ -2796,7 +2796,7 @@ static void spell_soundfold_sofo(slang_T *slang, char *inword, char *res) if (ip == NULL) { // empty list, can't match c = NUL; } else { - for (;;) { // find "c" in the list + while (true) { // find "c" in the list if (*ip == 0) { // not found c = NUL; break; -- 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/spell.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index a571131ba1..0784c4c8ff 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1851,7 +1851,7 @@ static int count_syllables(slang_T *slang, const char *word) /// Parse 'spelllang' and set w_s->b_langp accordingly. /// @return NULL if it's OK, an untranslated error message otherwise. -char *did_set_spelllang(win_T *wp) +char *parse_spelllang(win_T *wp) { garray_T ga; char *splp; @@ -2309,7 +2309,7 @@ void spell_reload(void) // window for this buffer in which 'spell' is set. if (*wp->w_s->b_p_spl != NUL) { if (wp->w_p_spell) { - (void)did_set_spelllang(wp); + (void)parse_spelllang(wp); break; } } @@ -3637,7 +3637,7 @@ const char *did_set_spell_option(bool is_spellfile) FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (wp->w_buffer == curbuf && wp->w_p_spell) { - errmsg = did_set_spelllang(wp); + errmsg = parse_spelllang(wp); break; } } -- cgit From a803bff89c89cc63e549a3c791fa07d91d1106c8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 1 May 2023 12:30:55 +0800 Subject: fix(spell): extmark with spell=false should disable spell (#23400) --- src/nvim/spell.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 0784c4c8ff..d1d1b9180f 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1206,8 +1206,8 @@ static void decor_spell_nav_start(win_T *wp) decor_redraw_reset(wp, &decor_state); } -static bool decor_spell_nav_col(win_T *wp, linenr_T lnum, linenr_T *decor_lnum, int col, - char **decor_error) +static TriState decor_spell_nav_col(win_T *wp, linenr_T lnum, linenr_T *decor_lnum, int col, + char **decor_error) { if (*decor_lnum != lnum) { decor_providers_invoke_spell(wp, lnum - 1, col, lnum - 1, -1, decor_error); @@ -1215,7 +1215,7 @@ static bool decor_spell_nav_col(win_T *wp, linenr_T lnum, linenr_T *decor_lnum, *decor_lnum = lnum; } decor_redraw_col(wp, col, col, false, &decor_state); - return decor_state.spell == kTrue; + return decor_state.spell; } static inline bool can_syn_spell(win_T *wp, linenr_T lnum, int col) @@ -1352,9 +1352,18 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att : p - buf) > wp->w_cursor.col)) { col = (colnr_T)(p - buf); - bool can_spell = (!has_syntax && (wp->w_s->b_p_spo_flags & SPO_NPBUFFER) == 0) - || decor_spell_nav_col(wp, lnum, &decor_lnum, col, &decor_error) - || (has_syntax && can_syn_spell(wp, lnum, col)); + bool no_plain_buffer = (wp->w_s->b_p_spo_flags & SPO_NPBUFFER) != 0; + bool can_spell = !no_plain_buffer; + switch (decor_spell_nav_col(wp, lnum, &decor_lnum, col, &decor_error)) { + case kTrue: + can_spell = true; break; + case kFalse: + can_spell = false; break; + case kNone: + if (has_syntax) { + can_spell = can_syn_spell(wp, lnum, col); + } + } if (!can_spell) { attr = HLF_COUNT; -- cgit From 7e70a1e44b223a51f4d8f06b9fe4c4ef77601f83 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 4 May 2023 13:43:23 +0800 Subject: vim-patch:9.0.0138: not enough characters accepted for 'spellfile' Problem: Not enough characters accepted for 'spellfile'. Solution: Add vim_is_fname_char() and use it for 'spellfile'. https://github.com/vim/vim/commit/bc49c5f48f89c2d6f4d88ee77f44a11d68293be3 Cherry-pick related doc update from Vim runtime. Co-authored-by: Bram Moolenaar --- src/nvim/spell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index d1d1b9180f..84875261f1 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3621,7 +3621,7 @@ bool valid_spellfile(const char *val) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT { for (const char *s = val; *s != NUL; s++) { - if (!vim_isfilec((uint8_t)(*s)) && *s != ',' && *s != ' ') { + if (!vim_is_fname_char((uint8_t)(*s))) { return false; } } -- cgit From ad7cded1f3f40912d962796d6965dac17ecb97f0 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Wed, 24 May 2023 20:13:11 +0200 Subject: vim-patch:9.0.0590: after exiting Insert mode spelling not checked in next line Problem: After exiting Insert mode spelling is not checked in the next line. Solution: When spelling is enabled redraw the next line after exiting Insert mode in case the spell highlight needs updating. https://github.com/vim/vim/commit/ee09fcc9b6cf24e02899461809da9a5148208ea5 Co-authored-by: Bram Moolenaar --- src/nvim/spell.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 84875261f1..498bd56b9e 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1189,11 +1189,19 @@ bool spell_valid_case(int wordflags, int treeflags) || (wordflags & WF_ONECAP) != 0)); } -// Returns true if spell checking is not enabled. +/// Return true if spell checking is enabled for "wp". +bool spell_check_window(win_T *wp) +{ + return wp->w_p_spell + && *wp->w_s->b_p_spl != NUL + && wp->w_s->b_langp.ga_len > 0 + && *(char **)(wp->w_s->b_langp.ga_data) != NULL; +} + +/// Return true and give an error if spell checking is not enabled. bool no_spell_checking(win_T *wp) { - if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL - || GA_EMPTY(&wp->w_s->b_langp)) { + if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL || GA_EMPTY(&wp->w_s->b_langp)) { emsg(_(e_no_spell)); return true; } -- cgit From f733595e795cd2b819cb8fd18327cd51f47b2124 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Fri, 26 May 2023 02:08:18 +0200 Subject: vim-patch:9.0.1578: SpellCap highlight not always updated when needed (#23755) Problem: SpellCap highlight not always updated when needed. Solution: Handle updating line below closed fold and other situations where only part of the window is redrawn. (Luuk van Baal, closes vim/vim#12428, closes vim/vim#12420) https://github.com/vim/vim/commit/2ac6497f0ef186f0e3ba67d7f0a485bfb612bb08 --- src/nvim/spell.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 498bd56b9e..778266e5ac 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1312,7 +1312,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att } else if (curline && wp == curwin) { // For spellbadword(): check if first word needs a capital. col = (colnr_T)getwhitecols(line); - if (check_need_cap(lnum, col)) { + if (check_need_cap(curwin, lnum, col)) { capcol = col; } @@ -2536,25 +2536,24 @@ int spell_casefold(const win_T *wp, char *str, int len, char *buf, int buflen) } // Check if the word at line "lnum" column "col" is required to start with a -// capital. This uses 'spellcapcheck' of the current buffer. -bool check_need_cap(linenr_T lnum, colnr_T col) +// capital. This uses 'spellcapcheck' of the buffer in window "wp". +bool check_need_cap(win_T *wp, linenr_T lnum, colnr_T col) { - bool need_cap = false; - - if (curwin->w_s->b_cap_prog == NULL) { + if (wp->w_s->b_cap_prog == NULL) { return false; } - char *line = get_cursor_line_ptr(); + bool need_cap = false; + char *line = col ? ml_get_buf(wp->w_buffer, lnum, false) : NULL; char *line_copy = NULL; colnr_T endcol = 0; - if (getwhitecols(line) >= (int)col) { + if (col == 0 || getwhitecols(line) >= col) { // At start of line, check if previous line is empty or sentence // ends there. if (lnum == 1) { need_cap = true; } else { - line = ml_get(lnum - 1); + line = ml_get_buf(wp->w_buffer, lnum - 1, false); if (*skipwhite(line) == NUL) { need_cap = true; } else { @@ -2571,13 +2570,13 @@ bool check_need_cap(linenr_T lnum, colnr_T col) if (endcol > 0) { // Check if sentence ends before the bad word. regmatch_T regmatch = { - .regprog = curwin->w_s->b_cap_prog, + .regprog = wp->w_s->b_cap_prog, .rm_ic = false }; char *p = line + endcol; while (true) { MB_PTR_BACK(line, p); - if (p == line || spell_iswordp_nmw(p, curwin)) { + if (p == line || spell_iswordp_nmw(p, wp)) { break; } if (vim_regexec(®match, p, 0) @@ -2586,7 +2585,7 @@ bool check_need_cap(linenr_T lnum, colnr_T col) break; } } - curwin->w_s->b_cap_prog = regmatch.regprog; + wp->w_s->b_cap_prog = regmatch.regprog; } xfree(line_copy); @@ -3601,7 +3600,7 @@ static bool spell_expand_need_cap; void spell_expand_check_cap(colnr_T col) { - spell_expand_need_cap = check_need_cap(curwin->w_cursor.lnum, col); + spell_expand_need_cap = check_need_cap(curwin, curwin->w_cursor.lnum, col); } // Get list of spelling suggestions. -- cgit From eceb2dffce3908507092ffe425b1ceef5baeb1ab Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Jun 2023 10:32:30 +0800 Subject: fix(spell): splice extmarks on :spellrepall (#23929) --- src/nvim/spell.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 778266e5ac..9ae2036ee0 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2604,9 +2604,11 @@ void ex_spellrepall(exarg_T *eap) emsg(_("E752: No previous spell replacement")); return; } - int addlen = (int)(strlen(repl_to) - strlen(repl_from)); + const size_t repl_from_len = strlen(repl_from); + const size_t repl_to_len = strlen(repl_to); + int addlen = (int)(repl_to_len - repl_from_len); - size_t frompatlen = strlen(repl_from) + 7; + const size_t frompatlen = repl_from_len + 7; char *frompat = xmalloc(frompatlen); snprintf(frompat, frompatlen, "\\V\\<%s\\>", repl_from); p_ws = false; @@ -2623,14 +2625,15 @@ void ex_spellrepall(exarg_T *eap) // Only replace when the right word isn't there yet. This happens // when changing "etc" to "etc.". char *line = get_cursor_line_ptr(); - if (addlen <= 0 || strncmp(line + curwin->w_cursor.col, - repl_to, strlen(repl_to)) != 0) { + if (addlen <= 0 + || strncmp(line + curwin->w_cursor.col, repl_to, repl_to_len) != 0) { char *p = xmalloc(strlen(line) + (size_t)addlen + 1); memmove(p, line, (size_t)curwin->w_cursor.col); STRCPY(p + curwin->w_cursor.col, repl_to); - STRCAT(p, line + curwin->w_cursor.col + strlen(repl_from)); + STRCAT(p, line + curwin->w_cursor.col + repl_from_len); ml_replace(curwin->w_cursor.lnum, p, false); - changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); + inserted_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col, + (int)repl_from_len, (int)repl_to_len); if (curwin->w_cursor.lnum != prev_lnum) { sub_nlines++; @@ -2638,7 +2641,7 @@ void ex_spellrepall(exarg_T *eap) } sub_nsubs++; } - curwin->w_cursor.col += (colnr_T)strlen(repl_to); + curwin->w_cursor.col += (colnr_T)repl_to_len; } p_ws = save_ws; -- cgit From 9d9af4fe2775a2f74cfc8d7963f0cc768ed08bfa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Jun 2023 23:31:29 +0800 Subject: vim-patch:9.0.1614: strlen() called too often for :spellrepall (#23940) Problem: strlen() called too often for :spellrepall. Solution: Store the result in a variable. (closes vim/vim#12497) https://github.com/vim/vim/commit/59f7038536a370d771758dc34036cc1424be7421 --- src/nvim/spell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 9ae2036ee0..5a1b3f1965 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2606,7 +2606,7 @@ void ex_spellrepall(exarg_T *eap) } const size_t repl_from_len = strlen(repl_from); const size_t repl_to_len = strlen(repl_to); - int addlen = (int)(repl_to_len - repl_from_len); + const int addlen = (int)(repl_to_len - repl_from_len); const size_t frompatlen = repl_from_len + 7; char *frompat = xmalloc(frompatlen); -- cgit From b3d5138fd0066fda26ef7724a542ae45eb42fc84 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 7 Jun 2023 06:05:16 +0600 Subject: refactor(options): remove `getoption_T` and introduce `OptVal` (#23850) Removes the `getoption_T` struct and also introduces the `OptVal` struct to unify the methods of getting/setting different option value types. This is the first of many PRs to reduce code duplication in the Vim option code as well as to make options easier to maintain. It also increases the flexibility and extensibility of options. Which opens the door for things like Array and Dictionary options. --- src/nvim/spell.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 5a1b3f1965..b337504bd9 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3171,17 +3171,15 @@ void ex_spelldump(exarg_T *eap) if (no_spell_checking(curwin)) { return; } - char *spl; - long dummy; - (void)get_option_value("spl", &dummy, &spl, NULL, OPT_LOCAL); + OptVal spl = get_option_value("spl", NULL, OPT_LOCAL, NULL); // Create a new empty buffer in a new window. do_cmdline_cmd("new"); // enable spelling locally in the new window - set_option_value_give_err("spell", true, "", OPT_LOCAL); - set_option_value_give_err("spl", dummy, spl, OPT_LOCAL); - xfree(spl); + set_option_value_give_err("spell", BOOLEAN_OPTVAL(true), OPT_LOCAL); + set_option_value_give_err("spl", spl, OPT_LOCAL); + optval_free(spl); if (!buf_is_empty(curbuf)) { return; -- cgit From 516b173780e39de3ce1e4525f0a8f0ff250c992b Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Thu, 13 Jul 2023 10:17:19 +0100 Subject: perf(rtp): reduce rtp scans (#24191) * perf(rtp): reduce rtp scans Problem: Scanning the filesystem is expensive and particularly affects startuptime. Solution: Reduce the amount of redundant directory scans by relying less on glob patterns and handle vim and lua sourcing lower down. --- src/nvim/spell.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index b337504bd9..c8a7bb2622 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1717,23 +1717,32 @@ void slang_clear_sug(slang_T *lp) // Load one spell file and store the info into a slang_T. // Invoked through do_in_runtimepath(). -static void spell_load_cb(char *fname, void *cookie) +static bool spell_load_cb(int num_fnames, char **fnames, bool all, void *cookie) { spelload_T *slp = (spelload_T *)cookie; - slang_T *slang = spell_load_file(fname, slp->sl_lang, NULL, false); - if (slang == NULL) { - return; - } + for (int i = 0; i < num_fnames; i++) { + slang_T *slang = spell_load_file(fnames[i], slp->sl_lang, NULL, false); + + if (slang == NULL) { + continue; + } - // When a previously loaded file has NOBREAK also use it for the - // ".add" files. - if (slp->sl_nobreak && slang->sl_add) { - slang->sl_nobreak = true; - } else if (slang->sl_nobreak) { - slp->sl_nobreak = true; + // When a previously loaded file has NOBREAK also use it for the + // ".add" files. + if (slp->sl_nobreak && slang->sl_add) { + slang->sl_nobreak = true; + } else if (slang->sl_nobreak) { + slp->sl_nobreak = true; + } + + slp->sl_slang = slang; + + if (!all) { + break; + } } - slp->sl_slang = slang; + return num_fnames > 0; } /// Add a word to the hashtable of common words. -- cgit From 30a5c28c8740d2e07c20cb58822b7d7aa489b728 Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Wed, 19 Jul 2023 17:56:25 +0200 Subject: feat(decoration_provider): log errors as error messages --- src/nvim/spell.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index c8a7bb2622..2ae0863a5c 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1214,11 +1214,10 @@ static void decor_spell_nav_start(win_T *wp) decor_redraw_reset(wp, &decor_state); } -static TriState decor_spell_nav_col(win_T *wp, linenr_T lnum, linenr_T *decor_lnum, int col, - char **decor_error) +static TriState decor_spell_nav_col(win_T *wp, linenr_T lnum, linenr_T *decor_lnum, int col) { if (*decor_lnum != lnum) { - decor_providers_invoke_spell(wp, lnum - 1, col, lnum - 1, -1, decor_error); + decor_providers_invoke_spell(wp, lnum - 1, col, lnum - 1, -1); decor_redraw_line(wp, lnum - 1, &decor_state); *decor_lnum = lnum; } @@ -1277,7 +1276,6 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att linenr_T lnum = wp->w_cursor.lnum; clearpos(&found_pos); - char *decor_error = NULL; // Ephemeral extmarks are currently stored in the global decor_state. // When looking for spell errors, we need to: // - temporarily reset decor_state @@ -1362,7 +1360,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att bool no_plain_buffer = (wp->w_s->b_p_spo_flags & SPO_NPBUFFER) != 0; bool can_spell = !no_plain_buffer; - switch (decor_spell_nav_col(wp, lnum, &decor_lnum, col, &decor_error)) { + switch (decor_spell_nav_col(wp, lnum, &decor_lnum, col)) { case kTrue: can_spell = true; break; case kFalse: @@ -1488,7 +1486,6 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att theend: decor_state_free(&decor_state); - xfree(decor_error); decor_state = saved_decor_start; xfree(buf); return ret; -- cgit From d2efcbf2dca6c2899ba0a1be7fc10dbf3f112d26 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 22 Jul 2023 18:00:55 +0800 Subject: refactor: remove some (const char **) casts (#24423) --- src/nvim/spell.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 2ae0863a5c..ce0d0dd5de 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2238,10 +2238,10 @@ static int find_region(const char *rp, const char *region) /// @param[in] end End of word or NULL for NUL delimited string /// /// @returns Case type of word -int captype(char *word, const char *end) +int captype(const char *word, const char *end) FUNC_ATTR_NONNULL_ARG(1) { - char *p; + const char *p; // find first letter for (p = word; !spell_iswordp_nmw(p, curwin); MB_PTR_ADV(p)) { @@ -2249,7 +2249,7 @@ int captype(char *word, const char *end) return 0; // only non-word characters, illegal word } } - int c = mb_ptr2char_adv((const char **)&p); + int c = mb_ptr2char_adv(&p); bool allcap; bool firstcap = allcap = SPELL_ISUPPER(c); bool past_second = false; // past second word char @@ -2503,7 +2503,7 @@ static bool spell_iswordp_w(const int *p, const win_T *wp) // Uses the character definitions from the .spl file. // When using a multi-byte 'encoding' the length may change! // Returns FAIL when something wrong. -int spell_casefold(const win_T *wp, char *str, int len, char *buf, int buflen) +int spell_casefold(const win_T *wp, const char *str, int len, char *buf, int buflen) FUNC_ATTR_NONNULL_ALL { if (len >= buflen) { @@ -2514,12 +2514,12 @@ int spell_casefold(const win_T *wp, char *str, int len, char *buf, int buflen) int outi = 0; // Fold one character at a time. - for (char *p = str; p < str + len;) { + for (const char *p = str; p < str + len;) { if (outi + MB_MAXBYTES > buflen) { buf[outi] = NUL; return FAIL; } - int c = mb_cptr2char_adv((const char **)&p); + int c = mb_cptr2char_adv(&p); // Exception: greek capital sigma 0x03A3 folds to 0x03C3, except // when it is the last character in a word, then it folds to @@ -2668,10 +2668,10 @@ void ex_spellrepall(exarg_T *eap) /// @param[in] word source string to copy /// @param[in,out] wcopy copied string, with case of first letter changed /// @param[in] upper True to upper case, otherwise lower case -void onecap_copy(char *word, char *wcopy, bool upper) +void onecap_copy(const char *word, char *wcopy, bool upper) { - char *p = word; - int c = mb_cptr2char_adv((const char **)&p); + const char *p = word; + int c = mb_cptr2char_adv(&p); if (upper) { c = SPELL_TOUPPER(c); } else { @@ -2683,11 +2683,11 @@ void onecap_copy(char *word, char *wcopy, bool upper) // Make a copy of "word" with all the letters upper cased into // "wcopy[MAXWLEN]". The result is NUL terminated. -void allcap_copy(char *word, char *wcopy) +void allcap_copy(const char *word, char *wcopy) { char *d = wcopy; - for (char *s = word; *s != NUL;) { - int c = mb_cptr2char_adv((const char **)&s); + for (const char *s = word; *s != NUL;) { + int c = mb_cptr2char_adv(&s); if (c == 0xdf) { c = 'S'; @@ -2802,7 +2802,7 @@ void spell_soundfold(slang_T *slang, char *inword, bool folded, char *res) // Perform sound folding of "inword" into "res" according to SOFOFROM and // SOFOTO lines. -static void spell_soundfold_sofo(slang_T *slang, char *inword, char *res) +static void spell_soundfold_sofo(slang_T *slang, const char *inword, char *res) { int ri = 0; @@ -2810,8 +2810,8 @@ static void spell_soundfold_sofo(slang_T *slang, char *inword, char *res) // The sl_sal_first[] table contains the translation for chars up to // 255, sl_sal the rest. - for (char *s = inword; *s != NUL;) { - int c = mb_cptr2char_adv((const char **)&s); + for (const char *s = inword; *s != NUL;) { + int c = mb_cptr2char_adv(&s); if (utf_class(c) == 0) { c = ' '; } else if (c < 256) { -- cgit From f92bda1dad462de81ec92134dfa9ba637edc7bb7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 16 Aug 2023 07:12:47 +0800 Subject: vim-patch:9.0.1718: dict-completion does not respect region (#24733) Problem: dict-completion does not respect region Solution: respect selected region in dict completion Set do_region to zero as we don't want a complete dump of the matching words, we want the code to filter them according to the user's selected region. closes: vim/vim#12792 closes: vim/vim#7025 https://github.com/vim/vim/commit/e98fb643ec5f84f9088c8b1434a0bd6ff988dc2d Co-authored-by: LemonBoy --- src/nvim/spell.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index ce0d0dd5de..6725674ca7 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3260,11 +3260,9 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) } } - if (do_region && region_names != NULL) { - if (pat == NULL) { - vim_snprintf(IObuff, IOSIZE, "/regions=%s", region_names); - ml_append(lnum++, IObuff, (colnr_T)0, false); - } + if (do_region && region_names != NULL && pat == NULL) { + vim_snprintf(IObuff, IOSIZE, "/regions=%s", region_names); + ml_append(lnum++, IObuff, (colnr_T)0, false); } else { do_region = 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/spell.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 6725674ca7..50c817f155 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1289,7 +1289,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att decor_spell_nav_start(wp); while (!got_int) { - char *line = ml_get_buf(wp->w_buffer, lnum, false); + char *line = ml_get_buf(wp->w_buffer, lnum); len = strlen(line); if (buflen < len + MAXWLEN + 2) { @@ -1316,7 +1316,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att // Need to get the line again, may have looked at the previous // one. - line = ml_get_buf(wp->w_buffer, lnum, false); + line = ml_get_buf(wp->w_buffer, lnum); } // Copy the line into "buf" and append the start of the next line if @@ -1326,7 +1326,7 @@ size_t spell_move_to(win_T *wp, int dir, bool allwords, bool curline, hlf_T *att STRCPY(buf, line); if (lnum < wp->w_buffer->b_ml.ml_line_count) { spell_cat_line(buf + strlen(buf), - ml_get_buf(wp->w_buffer, lnum + 1, false), + ml_get_buf(wp->w_buffer, lnum + 1), MAXWLEN); } char *p = buf + skip; @@ -2550,7 +2550,7 @@ bool check_need_cap(win_T *wp, linenr_T lnum, colnr_T col) } bool need_cap = false; - char *line = col ? ml_get_buf(wp->w_buffer, lnum, false) : NULL; + char *line = col ? ml_get_buf(wp->w_buffer, lnum) : NULL; char *line_copy = NULL; colnr_T endcol = 0; if (col == 0 || getwhitecols(line) >= col) { @@ -2559,7 +2559,7 @@ bool check_need_cap(win_T *wp, linenr_T lnum, colnr_T col) if (lnum == 1) { need_cap = true; } else { - line = ml_get_buf(wp->w_buffer, lnum - 1, false); + line = ml_get_buf(wp->w_buffer, lnum - 1); if (*skipwhite(line) == NUL) { need_cap = true; } else { -- cgit From 656be8a591a1fa1cba1de1a2128944d6a684cc7d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 28 Aug 2023 07:16:15 +0800 Subject: vim-patch:9.0.1810: camel-case spelling has issues with digits (#24909) Problem: camel-case spelling has issues with digits Solution: Improve the camCase spell checking by taking digits and caps into account Rewrite the conditions to check for word boundaries by taking into account the presence of digits and all-caps sequences such as acronyms. closes: vim/vim#12644 closes: vim/vim#12933 https://github.com/vim/vim/commit/d08745040bb82c5e9a81b6c8a414e50951642492 Co-authored-by: LemonBoy --- src/nvim/spell.c | 105 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 82 insertions(+), 23 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 50c817f155..72e21a9130 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -184,12 +184,21 @@ int did_set_spelltab; # include "spell.c.generated.h" #endif -// mode values for find_word -#define FIND_FOLDWORD 0 // find word case-folded -#define FIND_KEEPWORD 1 // find keep-case word -#define FIND_PREFIX 2 // find word after prefix -#define FIND_COMPOUND 3 // find case-folded compound word -#define FIND_KEEPCOMPOUND 4 // find keep-case compound word +/// mode values for find_word +enum { + FIND_FOLDWORD = 0, ///< find word case-folded + FIND_KEEPWORD = 1, ///< find keep-case word + FIND_PREFIX = 2, ///< find word after prefix + FIND_COMPOUND = 3, ///< find case-folded compound word + FIND_KEEPCOMPOUND = 4, ///< find keep-case compound word +}; + +/// type values for get_char_type +enum { + CHAR_OTHER = 0, + CHAR_UPPER = 1, + CHAR_DIGIT = 2, +}; char *e_format = N_("E759: Format error in spell file"); @@ -222,7 +231,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount size_t wrongcaplen = 0; bool count_word = docount; bool use_camel_case = (wp->w_s->b_p_spo_flags & SPO_CAMEL) != 0; - bool camel_case = false; + bool is_camel_case = false; // A word never starts at a space or a control character. Return quickly // then, skipping over the character. @@ -255,24 +264,14 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount mi.mi_word = ptr; mi.mi_fend = ptr; if (spell_iswordp(mi.mi_fend, wp)) { - bool this_upper = false; // init for gcc - if (use_camel_case) { - int c = utf_ptr2char(mi.mi_fend); - this_upper = SPELL_ISUPPER(c); + mi.mi_fend = advance_camelcase_word(ptr, wp, &is_camel_case); + } else { + do { + MB_PTR_ADV(mi.mi_fend); + } while (*mi.mi_fend != NUL && spell_iswordp(mi.mi_fend, wp)); } - do { - MB_PTR_ADV(mi.mi_fend); - if (use_camel_case) { - const bool prev_upper = this_upper; - int c = utf_ptr2char(mi.mi_fend); - this_upper = SPELL_ISUPPER(c); - camel_case = !prev_upper && this_upper; - } - } while (*mi.mi_fend != NUL && spell_iswordp(mi.mi_fend, wp) - && !camel_case); - if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) { // Check word starting with capital letter. int c = utf_ptr2char(ptr); @@ -304,7 +303,7 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount MAXWLEN + 1); mi.mi_fwordlen = (int)strlen(mi.mi_fword); - if (camel_case && mi.mi_fwordlen > 0) { + if (is_camel_case && mi.mi_fwordlen > 0) { // introduce a fake word end space into the folded word. mi.mi_fword[mi.mi_fwordlen - 1] = ' '; } @@ -424,6 +423,66 @@ size_t spell_check(win_T *wp, char *ptr, hlf_T *attrp, int *capcol, bool docount return (size_t)(mi.mi_end - ptr); } +/// Determine the type of character "c". +static int get_char_type(int c) +{ + if (ascii_isdigit(c)) { + return CHAR_DIGIT; + } + if (SPELL_ISUPPER(c)) { + return CHAR_UPPER; + } + return CHAR_OTHER; +} + +/// Returns a pointer to the end of the word starting at "str". +/// Supports camelCase words. +static char *advance_camelcase_word(char *str, win_T *wp, bool *is_camel_case) +{ + char *end = str; + + *is_camel_case = false; + + if (*str == NUL) { + return str; + } + + int c = utf_ptr2char(end); + MB_PTR_ADV(end); + // We need at most the types of the type of the last two chars. + int last_last_type = -1; + int last_type = get_char_type(c); + + while (*end != NUL && spell_iswordp(end, wp)) { + c = utf_ptr2char(end); + int this_type = get_char_type(c); + + if (last_last_type == CHAR_UPPER && last_type == CHAR_UPPER + && this_type == CHAR_OTHER) { + // Handle the following cases: + // UpperUpperLower + *is_camel_case = true; + // Back up by one char. + MB_PTR_BACK(str, end); + break; + } else if ((this_type == CHAR_UPPER && last_type == CHAR_OTHER) + || (this_type != last_type + && (this_type == CHAR_DIGIT || last_type == CHAR_DIGIT))) { + // Handle the following cases: + // LowerUpper LowerDigit UpperDigit DigitUpper DigitLower + *is_camel_case = true; + break; + } + + last_last_type = last_type; + last_type = this_type; + + MB_PTR_ADV(end); + } + + return end; +} + // Check if the word at "mip->mi_word" is in the tree. // When "mode" is FIND_FOLDWORD check in fold-case word tree. // When "mode" is FIND_KEEPWORD check in keep-case word tree. -- cgit From 35e50d79c630b05f67a840ebe21b4043ba9a6066 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 15 Sep 2023 20:30:50 +0800 Subject: fix(extmarks): overlay virt_text position after 'showbreak' (#25175) Also make virt_text_hide work properly. --- src/nvim/spell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 72e21a9130..38e045a08b 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1280,7 +1280,7 @@ static TriState decor_spell_nav_col(win_T *wp, linenr_T lnum, linenr_T *decor_ln decor_redraw_line(wp, lnum - 1, &decor_state); *decor_lnum = lnum; } - decor_redraw_col(wp, col, col, false, &decor_state); + decor_redraw_col(wp, col, 0, false, &decor_state); return decor_state.spell; } -- cgit From bc13bc154aa574e0bb58a50f2e0ca4570efa57c3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 16:10:54 +0200 Subject: refactor(message): smsg_attr -> smsg --- src/nvim/spell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 38e045a08b..1c7707995f 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1626,7 +1626,7 @@ static void spell_load_lang(char *lang) lang); do_cmdline_cmd(autocmd_buf); } else { - smsg(_("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""), + smsg(0, _("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""), lang, spell_enc(), lang); } } else if (sl.sl_slang != NULL) { @@ -2076,7 +2076,7 @@ char *parse_spelllang(win_T *wp) } else { // This is probably an error. Give a warning and // accept the words anyway. - smsg(_("Warning: region %s not supported"), + smsg(0, _("Warning: region %s not supported"), region); } } else { -- 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/spell.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 1c7707995f..a97b9c6a0a 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -90,6 +90,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/fs.h" #include "nvim/os/input.h" #include "nvim/os/os_defs.h" -- 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/spell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index a97b9c6a0a..4b1f8afb15 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2683,7 +2683,7 @@ void ex_spellrepall(exarg_T *eap) sub_nlines = 0; curwin->w_cursor.lnum = 0; while (!got_int) { - if (do_search(NULL, '/', '/', frompat, 1L, SEARCH_KEEP, NULL) == 0 + if (do_search(NULL, '/', '/', frompat, 1, SEARCH_KEEP, NULL) == 0 || u_save_cursor() == FAIL) { break; } -- 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/spell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 4b1f8afb15..864a55b12b 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2257,7 +2257,7 @@ static void use_midword(slang_T *lp, win_T *wp) wp->w_s->b_spell_ismw[c] = true; } else if (wp->w_s->b_spell_ismw_mb == NULL) { // First multi-byte char in "b_spell_ismw_mb". - wp->w_s->b_spell_ismw_mb = xstrnsave(p, (size_t)l); + wp->w_s->b_spell_ismw_mb = xmemdupz(p, (size_t)l); } else { // Append multi-byte chars to "b_spell_ismw_mb". const int n = (int)strlen(wp->w_s->b_spell_ismw_mb); -- 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/spell.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 864a55b12b..5f5cabdc40 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -3322,7 +3322,7 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) if (do_region && region_names != NULL && pat == NULL) { vim_snprintf(IObuff, IOSIZE, "/regions=%s", region_names); - ml_append(lnum++, IObuff, (colnr_T)0, false); + ml_append(lnum++, IObuff, 0, false); } else { do_region = false; } @@ -3337,7 +3337,7 @@ void spell_dump_compl(char *pat, int ic, Direction *dir, int dumpflags_arg) if (pat == NULL) { vim_snprintf(IObuff, IOSIZE, "# file: %s", slang->sl_fname); - ml_append(lnum++, IObuff, (colnr_T)0, false); + ml_append(lnum++, IObuff, 0, false); } // When matching with a pattern and there are no prefixes only use @@ -3506,7 +3506,7 @@ static void dump_word(slang_T *slang, char *word, char *pat, Direction *dir, int } } - ml_append(lnum, p, (colnr_T)0, false); + ml_append(lnum, p, 0, false); } else if (((dumpflags & DUMPFLAG_ICASE) ? mb_strnicmp(p, pat, strlen(pat)) == 0 : strncmp(p, pat, strlen(pat)) == 0) -- 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/spell.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 5f5cabdc40..5f3bd0ae06 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.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 - // spell.c: code for spell checking // // See spellfile.c for the Vim spell file format. -- 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/spell.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 5f3bd0ae06..b145e5964a 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -1943,14 +1943,12 @@ char *parse_spelllang(win_T *wp) int c; char lang[MAXWLEN + 1]; char spf_name[MAXPATHL]; - int len; char *p; int round; char *spf; char *use_region = NULL; bool dont_use_region = false; bool nobreak = false; - langp_T *lp, *lp2; static bool recursive = false; char *ret_msg = NULL; char *spl_copy; @@ -1980,7 +1978,7 @@ char *parse_spelllang(win_T *wp) // Get one language name. copy_option_part(&splp, lang, MAXWLEN, ","); region = NULL; - len = (int)strlen(lang); + int len = (int)strlen(lang); if (!valid_spelllang(lang)) { continue; @@ -2187,7 +2185,7 @@ char *parse_spelllang(win_T *wp) // REP items. If the language doesn't support it itself use another one // with the same name. E.g. for "en-math" use "en". for (int i = 0; i < ga.ga_len; i++) { - lp = LANGP_ENTRY(ga, i); + langp_T *lp = LANGP_ENTRY(ga, i); // sound folding if (!GA_EMPTY(&lp->lp_slang->sl_sal)) { @@ -2196,7 +2194,7 @@ char *parse_spelllang(win_T *wp) } else { // find first similar language that does sound folding for (int j = 0; j < ga.ga_len; j++) { - lp2 = LANGP_ENTRY(ga, j); + langp_T *lp2 = LANGP_ENTRY(ga, j); if (!GA_EMPTY(&lp2->lp_slang->sl_sal) && strncmp(lp->lp_slang->sl_name, lp2->lp_slang->sl_name, 2) == 0) { @@ -2213,7 +2211,7 @@ char *parse_spelllang(win_T *wp) } else { // find first similar language that has REP items for (int j = 0; j < ga.ga_len; j++) { - lp2 = LANGP_ENTRY(ga, j); + langp_T *lp2 = LANGP_ENTRY(ga, j); if (!GA_EMPTY(&lp2->lp_slang->sl_rep) && strncmp(lp->lp_slang->sl_name, lp2->lp_slang->sl_name, 2) == 0) { -- cgit From 488038580934f301c1528a14548ec0cabd16c2cd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 10 Nov 2023 14:06:04 +0100 Subject: build: adjust clang-tidy warning exclusion logic Enable all clang-tidy warnings by default instead of disabling them. This ensures that we don't miss useful warnings on each clang-tidy version upgrade. A drawback of this is that it will force us to either fix or adjust the warnings as soon as possible. --- src/nvim/spell.c | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index b145e5964a..c58284eafc 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -852,9 +852,6 @@ static void find_word(matchinf_T *mip, int mode) mip->mi_compoff = (int)(p - mip->mi_fword); } } -#if 0 - c = mip->mi_compoff; -#endif mip->mi_complen++; if (flags & WF_COMPROOT) { mip->mi_compextra++; @@ -880,16 +877,6 @@ static void find_word(matchinf_T *mip, int mode) // Find following word in keep-case tree. mip->mi_compoff = wlen; find_word(mip, FIND_KEEPCOMPOUND); - -#if 0 // Disabled, a prefix must not appear halfway through a compound - // word, unless the COMPOUNDPERMITFLAG is used, in which case it - // can't be a postponed prefix. - if (!slang->sl_nobreak || mip->mi_result == SP_BAD) { - // Check for following word with prefix. - mip->mi_compoff = c; - find_prefix(mip, FIND_COMPOUND); - } -#endif } if (!slang->sl_nobreak) { -- 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/spell.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index c58284eafc..7c2d58c82b 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -73,6 +73,7 @@ #include "nvim/ex_cmds.h" #include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.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/spell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 7c2d58c82b..2839a1c7cb 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -93,7 +93,7 @@ #include "nvim/os/input.h" #include "nvim/os/os_defs.h" #include "nvim/path.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/regexp.h" #include "nvim/runtime.h" #include "nvim/search.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/spell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 2839a1c7cb..8033e3d46e 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -103,7 +103,7 @@ #include "nvim/spellsuggest.h" #include "nvim/strings.h" #include "nvim/syntax.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/undo.h" #include "nvim/vim.h" #include "nvim/window.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/spell.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 8033e3d46e..0b4f363d64 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -61,7 +61,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/change.h" @@ -81,7 +81,7 @@ #include "nvim/highlight_defs.h" #include "nvim/insexpand.h" #include "nvim/log.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" @@ -105,7 +105,7 @@ #include "nvim/syntax.h" #include "nvim/types_defs.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/window.h" // Result values. Lower number is accepted over higher one. -- cgit From 64b53b71ba5d804b2c8cf186be68931b2621f53c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 12:10:42 +0800 Subject: refactor(IWYU): create normal_defs.h (#26293) --- src/nvim/spell.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/spell.c') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 0b4f363d64..905f5c25b4 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -91,7 +91,6 @@ #include "nvim/option_vars.h" #include "nvim/os/fs.h" #include "nvim/os/input.h" -#include "nvim/os/os_defs.h" #include "nvim/path.h" #include "nvim/pos_defs.h" #include "nvim/regexp.h" -- cgit