Mercurial > vim
comparison src/spell.c @ 388:f92bb1845823 v7.0101
updated for version 7.0101
author | vimboss |
---|---|
date | Sun, 03 Jul 2005 21:39:27 +0000 |
parents | bd4c7ce1da02 |
children | 4fe8e1a7758e |
comparison
equal
deleted
inserted
replaced
387:a509e3ba61f6 | 388:f92bb1845823 |
---|---|
605 static void spell_reload_one __ARGS((char_u *fname, int added_word)); | 605 static void spell_reload_one __ARGS((char_u *fname, int added_word)); |
606 static int set_spell_charflags __ARGS((char_u *flags, char_u *upp)); | 606 static int set_spell_charflags __ARGS((char_u *flags, char_u *upp)); |
607 static int set_spell_chartab __ARGS((char_u *fol, char_u *low, char_u *upp)); | 607 static int set_spell_chartab __ARGS((char_u *fol, char_u *low, char_u *upp)); |
608 static void write_spell_chartab __ARGS((FILE *fd)); | 608 static void write_spell_chartab __ARGS((FILE *fd)); |
609 static int spell_casefold __ARGS((char_u *p, int len, char_u *buf, int buflen)); | 609 static int spell_casefold __ARGS((char_u *p, int len, char_u *buf, int buflen)); |
610 static void spell_find_suggest __ARGS((char_u *badptr, suginfo_T *su, int maxcount, int banbadword)); | 610 static void spell_find_suggest __ARGS((char_u *badptr, suginfo_T *su, int maxcount, int banbadword, int need_cap)); |
611 #ifdef FEAT_EVAL | 611 #ifdef FEAT_EVAL |
612 static void spell_suggest_expr __ARGS((suginfo_T *su, char_u *expr)); | 612 static void spell_suggest_expr __ARGS((suginfo_T *su, char_u *expr)); |
613 #endif | 613 #endif |
614 static void spell_suggest_file __ARGS((suginfo_T *su, char_u *fname)); | 614 static void spell_suggest_file __ARGS((suginfo_T *su, char_u *fname)); |
615 static void spell_suggest_intern __ARGS((suginfo_T *su)); | 615 static void spell_suggest_intern __ARGS((suginfo_T *su)); |
5950 int i; | 5950 int i; |
5951 int c; | 5951 int c; |
5952 suginfo_T sug; | 5952 suginfo_T sug; |
5953 suggest_T *stp; | 5953 suggest_T *stp; |
5954 int mouse_used; | 5954 int mouse_used; |
5955 int need_cap; | |
5956 regmatch_T regmatch; | |
5957 int endcol; | |
5958 char_u *line_copy = NULL; | |
5955 | 5959 |
5956 /* Find the start of the badly spelled word. */ | 5960 /* Find the start of the badly spelled word. */ |
5957 if (spell_move_to(FORWARD, TRUE, TRUE) == FAIL | 5961 if (spell_move_to(FORWARD, TRUE, TRUE) == FAIL |
5958 || curwin->w_cursor.col > prev_cursor.col) | 5962 || curwin->w_cursor.col > prev_cursor.col) |
5959 { | 5963 { |
5981 } | 5985 } |
5982 | 5986 |
5983 /* Get the word and its length. */ | 5987 /* Get the word and its length. */ |
5984 line = ml_get_curline(); | 5988 line = ml_get_curline(); |
5985 | 5989 |
5990 /* Figure out if the word should be capitalised. */ | |
5991 need_cap = FALSE; | |
5992 if (curbuf->b_cap_prog != NULL) | |
5993 { | |
5994 endcol = 0; | |
5995 if (skipwhite(line) - line == curwin->w_cursor.col) | |
5996 { | |
5997 /* At start of line, check if previous line is empty or sentence | |
5998 * ends there. */ | |
5999 if (curwin->w_cursor.lnum == 1) | |
6000 need_cap = TRUE; | |
6001 else | |
6002 { | |
6003 line = ml_get(curwin->w_cursor.lnum - 1); | |
6004 if (*skipwhite(line) == NUL) | |
6005 need_cap = TRUE; | |
6006 else | |
6007 { | |
6008 /* Append a space in place of the line break. */ | |
6009 line_copy = concat_str(line, (char_u *)" "); | |
6010 line = line_copy; | |
6011 endcol = STRLEN(line); | |
6012 } | |
6013 } | |
6014 } | |
6015 else | |
6016 endcol = curwin->w_cursor.col; | |
6017 | |
6018 if (endcol > 0) | |
6019 { | |
6020 /* Check if sentence ends before the bad word. */ | |
6021 regmatch.regprog = curbuf->b_cap_prog; | |
6022 regmatch.rm_ic = FALSE; | |
6023 p = line + endcol; | |
6024 for (;;) | |
6025 { | |
6026 mb_ptr_back(line, p); | |
6027 if (p == line || SPELL_ISWORDP(p)) | |
6028 break; | |
6029 if (vim_regexec(®match, p, 0) | |
6030 && regmatch.endp[0] == line + endcol) | |
6031 { | |
6032 need_cap = TRUE; | |
6033 break; | |
6034 } | |
6035 } | |
6036 } | |
6037 | |
6038 /* get the line again, we may have been using the previous one */ | |
6039 line = ml_get_curline(); | |
6040 vim_free(line_copy); | |
6041 } | |
6042 | |
5986 /* Get the list of suggestions */ | 6043 /* Get the list of suggestions */ |
5987 spell_find_suggest(line + curwin->w_cursor.col, &sug, (int)Rows - 2, TRUE); | 6044 spell_find_suggest(line + curwin->w_cursor.col, &sug, (int)Rows - 2, |
6045 TRUE, need_cap); | |
5988 | 6046 |
5989 if (sug.su_ga.ga_len == 0) | 6047 if (sug.su_ga.ga_len == 0) |
5990 MSG(_("Sorry, no suggestions")); | 6048 MSG(_("Sorry, no suggestions")); |
5991 else | 6049 else |
5992 { | 6050 { |
6157 suginfo_T sug; | 6215 suginfo_T sug; |
6158 int i; | 6216 int i; |
6159 suggest_T *stp; | 6217 suggest_T *stp; |
6160 char_u *wcopy; | 6218 char_u *wcopy; |
6161 | 6219 |
6162 spell_find_suggest(word, &sug, maxcount, FALSE); | 6220 spell_find_suggest(word, &sug, maxcount, FALSE, FALSE); |
6163 | 6221 |
6164 /* Make room in "gap". */ | 6222 /* Make room in "gap". */ |
6165 ga_init2(gap, sizeof(char_u *), sug.su_ga.ga_len + 1); | 6223 ga_init2(gap, sizeof(char_u *), sug.su_ga.ga_len + 1); |
6166 if (ga_grow(gap, sug.su_ga.ga_len) == FAIL) | 6224 if (ga_grow(gap, sug.su_ga.ga_len) == FAIL) |
6167 return; | 6225 return; |
6190 * The maximum number of suggestions is "maxcount". | 6248 * The maximum number of suggestions is "maxcount". |
6191 * Note: does use info for the current window. | 6249 * Note: does use info for the current window. |
6192 * This is based on the mechanisms of Aspell, but completely reimplemented. | 6250 * This is based on the mechanisms of Aspell, but completely reimplemented. |
6193 */ | 6251 */ |
6194 static void | 6252 static void |
6195 spell_find_suggest(badptr, su, maxcount, banbadword) | 6253 spell_find_suggest(badptr, su, maxcount, banbadword, need_cap) |
6196 char_u *badptr; | 6254 char_u *badptr; |
6197 suginfo_T *su; | 6255 suginfo_T *su; |
6198 int maxcount; | 6256 int maxcount; |
6199 int banbadword; /* don't include badword in suggestions */ | 6257 int banbadword; /* don't include badword in suggestions */ |
6258 int need_cap; /* word should start with capital */ | |
6200 { | 6259 { |
6201 int attr = 0; | 6260 int attr = 0; |
6202 char_u buf[MAXPATHL]; | 6261 char_u buf[MAXPATHL]; |
6203 char_u *p; | 6262 char_u *p; |
6204 int do_combine = FALSE; | 6263 int do_combine = FALSE; |
6228 vim_strncpy(su->su_badword, su->su_badptr, su->su_badlen); | 6287 vim_strncpy(su->su_badword, su->su_badptr, su->su_badlen); |
6229 (void)spell_casefold(su->su_badptr, su->su_badlen, | 6288 (void)spell_casefold(su->su_badptr, su->su_badlen, |
6230 su->su_fbadword, MAXWLEN); | 6289 su->su_fbadword, MAXWLEN); |
6231 /* get caps flags for bad word */ | 6290 /* get caps flags for bad word */ |
6232 su->su_badflags = captype(su->su_badptr, su->su_badptr + su->su_badlen); | 6291 su->su_badflags = captype(su->su_badptr, su->su_badptr + su->su_badlen); |
6292 if (need_cap) | |
6293 su->su_badflags |= WF_ONECAP; | |
6233 | 6294 |
6234 /* If the word is not capitalised and spell_check() doesn't consider the | 6295 /* If the word is not capitalised and spell_check() doesn't consider the |
6235 * word to be bad then it might need to be capitalised. Add a suggestion | 6296 * word to be bad then it might need to be capitalised. Add a suggestion |
6236 * for that. */ | 6297 * for that. */ |
6237 #ifdef FEAT_MBYTE | 6298 #ifdef FEAT_MBYTE |
6238 c = mb_ptr2char(su->su_badptr); | 6299 c = mb_ptr2char(su->su_badptr); |
6239 #else | 6300 #else |
6240 c = *p; | 6301 c = *su->su_badptr; |
6241 #endif | 6302 #endif |
6242 if (!SPELL_ISUPPER(c) && attr == 0) | 6303 if (!SPELL_ISUPPER(c) && attr == 0) |
6243 { | 6304 { |
6244 make_case_word(su->su_badword, buf, WF_ONECAP); | 6305 make_case_word(su->su_badword, buf, WF_ONECAP); |
6245 add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE, | 6306 add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE, |
7970 { | 8031 { |
7971 char_u cword[MAXWLEN]; | 8032 char_u cword[MAXWLEN]; |
7972 char_u *p; | 8033 char_u *p; |
7973 int score; | 8034 int score; |
7974 | 8035 |
8036 flags |= su->su_badflags; | |
7975 if (round == 1 && (flags & WF_CAPMASK) != 0) | 8037 if (round == 1 && (flags & WF_CAPMASK) != 0) |
7976 { | 8038 { |
7977 /* Need to fix case according to | 8039 /* Need to fix case according to |
7978 * "flags". */ | 8040 * "flags". */ |
7979 make_case_word(tword, cword, flags); | 8041 make_case_word(tword, cword, flags); |