diff options
Diffstat (limited to 'src/nvim/spell.c')
-rw-r--r-- | src/nvim/spell.c | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/src/nvim/spell.c b/src/nvim/spell.c index d1428b0117..10cc410e81 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -441,7 +441,8 @@ size_t spell_check( MB_PTR_ADV(mi.mi_fend); } - (void)spell_casefold(ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, MAXWLEN + 1); + (void)spell_casefold(wp, ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, + MAXWLEN + 1); mi.mi_fwordlen = (int)STRLEN(mi.mi_fword); if (camel_case) { @@ -869,10 +870,11 @@ static void find_word(matchinf_T *mip, int mode) if (slang->sl_compsylmax < MAXWLEN) { // "fword" is only needed for checking syllables. - if (ptr == mip->mi_word) - (void)spell_casefold(ptr, wlen, fword, MAXWLEN); - else + if (ptr == mip->mi_word) { + (void)spell_casefold(mip->mi_win, ptr, wlen, fword, MAXWLEN); + } else { STRLCPY(fword, ptr, endlen[endidxcnt] + 1); + } } if (!can_compound(slang, fword, mip->mi_compflags)) continue; @@ -1315,9 +1317,9 @@ static int fold_more(matchinf_T *mip) MB_PTR_ADV(mip->mi_fend); } - (void)spell_casefold(p, (int)(mip->mi_fend - p), - mip->mi_fword + mip->mi_fwordlen, - MAXWLEN - mip->mi_fwordlen); + (void)spell_casefold(mip->mi_win, p, (int)(mip->mi_fend - p), + mip->mi_fword + mip->mi_fwordlen, + MAXWLEN - mip->mi_fwordlen); flen = (int)STRLEN(mip->mi_fword + mip->mi_fwordlen); mip->mi_fwordlen += flen; return flen; @@ -2655,7 +2657,9 @@ 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(char_u *str, int len, char_u *buf, int buflen) +int spell_casefold(const win_T *wp, char_u *str, int len, char_u *buf, + int buflen) + FUNC_ATTR_NONNULL_ALL { if (len >= buflen) { buf[0] = NUL; @@ -2670,8 +2674,22 @@ int spell_casefold(char_u *str, int len, char_u *buf, int buflen) buf[outi] = NUL; return FAIL; } - const int c = mb_cptr2char_adv((const char_u **)&p); - outi += utf_char2bytes(SPELL_TOFOLD(c), buf + outi); + int c = mb_cptr2char_adv((const char_u **)&p); + + // Exception: greek capital sigma 0x03A3 folds to 0x03C3, except + // when it is the last character in a word, then it folds to + // 0x03C2. + if (c == 0x03a3 || c == 0x03c2) { + if (p == str + len || !spell_iswordp(p, wp)) { + c = 0x03c2; + } else { + c = 0x03c3; + } + } else { + c = SPELL_TOFOLD(c); + } + + outi += utf_char2bytes(c, buf + outi); } buf[outi] = NUL; @@ -3155,7 +3173,8 @@ spell_find_suggest ( if (su->su_badlen >= MAXWLEN) su->su_badlen = MAXWLEN - 1; // just in case STRLCPY(su->su_badword, su->su_badptr, su->su_badlen + 1); - (void)spell_casefold(su->su_badptr, su->su_badlen, su->su_fbadword, MAXWLEN); + (void)spell_casefold(curwin, su->su_badptr, su->su_badlen, su->su_fbadword, + MAXWLEN); // TODO(vim): make this work if the case-folded text is longer than the // original text. Currently an illegal byte causes wrong pointer @@ -3535,7 +3554,7 @@ static void suggest_try_change(suginfo_T *su) STRCPY(fword, su->su_fbadword); n = (int)STRLEN(fword); p = su->su_badptr + su->su_badlen; - (void)spell_casefold(p, (int)STRLEN(p), fword + n, MAXWLEN - n); + (void)spell_casefold(curwin, p, (int)STRLEN(p), fword + n, MAXWLEN - n); for (int lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) { lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); @@ -5087,7 +5106,7 @@ stp_sal_score ( pbad = badsound; else { // soundfold the bad word with more characters following - (void)spell_casefold(su->su_badptr, stp->st_orglen, fword, MAXWLEN); + (void)spell_casefold(curwin, su->su_badptr, stp->st_orglen, fword, MAXWLEN); // When joining two words the sound often changes a lot. E.g., "t he" // sounds like "t h" while "the" sounds like "@". Avoid that by @@ -5800,10 +5819,10 @@ void spell_soundfold(slang_T *slang, char_u *inword, bool folded, char_u *res) spell_soundfold_sofo(slang, inword, res); else { // SAL items used. Requires the word to be case-folded. - if (folded) + if (folded) { word = inword; - else { - (void)spell_casefold(inword, (int)STRLEN(inword), fword, MAXWLEN); + } else { + (void)spell_casefold(curwin, inword, (int)STRLEN(inword), fword, MAXWLEN); word = fword; } |