Mercurial > vim
annotate src/spell.c @ 22096:e0eedfb389af
Added tag v8.2.1597 for changeset 2cc0de1e05a6dec34f7a216c5ca4c38dad56d4c0
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 05 Sep 2020 16:00:04 +0200 |
parents | f9245f58c134 |
children | 9368f75273d9 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9953
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
223 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * spell.c: code for spell checking | |
226 | 12 * |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
13 * See spellfile.c for the Vim spell file format. |
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
14 * |
300 | 15 * The spell checking mechanism uses a tree (aka trie). Each node in the tree |
16 * has a list of bytes that can appear (siblings). For each byte there is a | |
17 * pointer to the node with the byte that follows in the word (child). | |
324 | 18 * |
19 * A NUL byte is used where the word may end. The bytes are sorted, so that | |
20 * binary searching can be used and the NUL bytes are at the start. The | |
21 * number of possible bytes is stored before the list of bytes. | |
22 * | |
23 * The tree uses two arrays: "byts" stores the characters, "idxs" stores | |
24 * either the next index or flags. The tree starts at index 0. For example, | |
25 * to lookup "vi" this sequence is followed: | |
26 * i = 0 | |
27 * len = byts[i] | |
28 * n = where "v" appears in byts[i + 1] to byts[i + len] | |
29 * i = idxs[n] | |
30 * len = byts[i] | |
31 * n = where "i" appears in byts[i + 1] to byts[i + len] | |
32 * i = idxs[n] | |
33 * len = byts[i] | |
34 * find that byts[i + 1] is 0, idxs[i + 1] has flags for "vi". | |
300 | 35 * |
339 | 36 * There are two word trees: one with case-folded words and one with words in |
300 | 37 * original case. The second one is only used for keep-case words and is |
38 * usually small. | |
39 * | |
481 | 40 * There is one additional tree for when not all prefixes are applied when |
339 | 41 * generating the .spl file. This tree stores all the possible prefixes, as |
42 * if they were words. At each word (prefix) end the prefix nr is stored, the | |
43 * following word must support this prefix nr. And the condition nr is | |
44 * stored, used to lookup the condition that the word must match with. | |
45 * | |
300 | 46 * Thanks to Olaf Seibert for providing an example implementation of this tree |
47 * and the compression mechanism. | |
625 | 48 * LZ trie ideas: |
49 * http://www.irb.hr/hr/home/ristov/papers/RistovLZtrieRevision1.pdf | |
50 * More papers: http://www-igm.univ-mlv.fr/~laporte/publi_en.html | |
243 | 51 * |
52 * Matching involves checking the caps type: Onecap ALLCAP KeepCap. | |
53 * | |
236 | 54 * Why doesn't Vim use aspell/ispell/myspell/etc.? |
55 * See ":help develop-spell". | |
56 */ | |
57 | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
58 #define IN_SPELL_C |
223 | 59 #include "vim.h" |
60 | |
737 | 61 #if defined(FEAT_SPELL) || defined(PROTO) |
223 | 62 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
63 #ifndef UNIX // it's in os_unix.h for Unix |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
64 # include <time.h> // for time_t |
625 | 65 #endif |
66 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
67 #define REGION_ALL 0xff // word valid in all regions |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
68 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
69 #define VIMSUGMAGIC "VIMsug" // string at start of Vim .sug file |
625 | 70 #define VIMSUGMAGICL 6 |
71 #define VIMSUGVERSION 1 | |
72 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
73 // Result values. Lower number is accepted over higher one. |
307 | 74 #define SP_BANNED -1 |
236 | 75 #define SP_OK 0 |
307 | 76 #define SP_RARE 1 |
77 #define SP_LOCAL 2 | |
78 #define SP_BAD 3 | |
236 | 79 |
323 | 80 /* |
236 | 81 * Structure to store info for word matching. |
82 */ | |
83 typedef struct matchinf_S | |
84 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
85 langp_T *mi_lp; // info for language and region |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
86 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
87 // pointers to original text to be checked |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
88 char_u *mi_word; // start of word being checked |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
89 char_u *mi_end; // end of matching word so far |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
90 char_u *mi_fend; // next char to be added to mi_fword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
91 char_u *mi_cend; // char after what was used for |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
92 // mi_capflags |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
93 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
94 // case-folded text |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
95 char_u mi_fword[MAXWLEN + 1]; // mi_word case-folded |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
96 int mi_fwordlen; // nr of valid bytes in mi_fword |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
97 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
98 // for when checking word after a prefix |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
99 int mi_prefarridx; // index in sl_pidxs with list of |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
100 // affixID/condition |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
101 int mi_prefcnt; // number of entries at mi_prefarridx |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
102 int mi_prefixlen; // byte length of prefix |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
103 int mi_cprefixlen; // byte length of prefix in original |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
104 // case |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
105 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
106 // for when checking a compound word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
107 int mi_compoff; // start of following word offset |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
108 char_u mi_compflags[MAXWLEN]; // flags for compound words used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
109 int mi_complen; // nr of compound words used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
110 int mi_compextra; // nr of COMPOUNDROOT words |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
111 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
112 // others |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
113 int mi_result; // result so far: SP_BAD, SP_OK, etc. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
114 int mi_capflags; // WF_ONECAP WF_ALLCAP WF_KEEPCAP |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
115 win_T *mi_win; // buffer being checked |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
116 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
117 // for NOBREAK |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
118 int mi_result2; // "mi_resul" without following word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
119 char_u *mi_end2; // "mi_end" without following word |
236 | 120 } matchinf_T; |
121 | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
122 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
123 static int spell_mb_isword_class(int cl, win_T *wp); |
307 | 124 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
125 // mode values for find_word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
126 #define FIND_FOLDWORD 0 // find word case-folded |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
127 #define FIND_KEEPWORD 1 // find keep-case word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
128 #define FIND_PREFIX 2 // find word after prefix |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
129 #define FIND_COMPOUND 3 // find case-folded compound word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
130 #define FIND_KEEPCOMPOUND 4 // find keep-case compound word |
339 | 131 |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
132 static void find_word(matchinf_T *mip, int mode); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
133 static void find_prefix(matchinf_T *mip, int mode); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
134 static int fold_more(matchinf_T *mip); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
135 static void spell_load_cb(char_u *fname, void *cookie); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
136 static int count_syllables(slang_T *slang, char_u *word); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
137 static void clear_midword(win_T *buf); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
138 static void use_midword(slang_T *lp, win_T *buf); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
139 static int find_region(char_u *rp, char_u *region); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
140 static void spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
141 static void spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
142 static void spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
143 static void dump_word(slang_T *slang, char_u *word, char_u *pat, int *dir, int round, int flags, linenr_T lnum); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7526
diff
changeset
|
144 static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, int *dir, int round, int flags, linenr_T startlnum); |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
145 |
236 | 146 /* |
147 * Main spell-checking function. | |
300 | 148 * "ptr" points to a character that could be the start of a word. |
534 | 149 * "*attrp" is set to the highlight index for a badly spelled word. For a |
150 * non-word or when it's OK it remains unchanged. | |
236 | 151 * This must only be called when 'spelllang' is not empty. |
323 | 152 * |
385 | 153 * "capcol" is used to check for a Capitalised word after the end of a |
154 * sentence. If it's zero then perform the check. Return the column where to | |
155 * check next, or -1 when no sentence end was found. If it's NULL then don't | |
156 * worry. | |
323 | 157 * |
236 | 158 * Returns the length of the word in bytes, also when it's OK, so that the |
159 * caller can skip over the word. | |
160 */ | |
161 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
162 spell_check( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
163 win_T *wp, // current window |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
164 char_u *ptr, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
165 hlf_T *attrp, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
166 int *capcol, // column to check for Capital |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
167 int docount) // count good words |
236 | 168 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
169 matchinf_T mi; // Most things are put in "mi" so that it can |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
170 // be passed to functions quickly. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
171 int nrlen = 0; // found a number first |
385 | 172 int c; |
483 | 173 int wrongcaplen = 0; |
500 | 174 int lpi; |
625 | 175 int count_word = docount; |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
176 int use_camel_case = *wp->w_s->b_p_spo != NUL; |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
177 int camel_case = 0; |
236 | 178 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
179 // A word never starts at a space or a control character. Return quickly |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
180 // then, skipping over the character. |
307 | 181 if (*ptr <= ' ') |
182 return 1; | |
690 | 183 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
184 // Return here when loading language files failed. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
185 if (wp->w_s->b_langp.ga_len == 0) |
690 | 186 return 1; |
187 | |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
188 CLEAR_FIELD(mi); |
236 | 189 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
190 // A number is always OK. Also skip hexadecimal numbers 0xFF99 and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
191 // 0X99FF. But always do check spelling to find "3GPP" and "11 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
192 // julifeest". |
300 | 193 if (*ptr >= '0' && *ptr <= '9') |
194 { | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
195 if (*ptr == '0' && (ptr[1] == 'b' || ptr[1] == 'B')) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
196 mi.mi_end = skipbin(ptr + 2); |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
197 else if (*ptr == '0' && (ptr[1] == 'x' || ptr[1] == 'X')) |
316 | 198 mi.mi_end = skiphex(ptr + 2); |
300 | 199 else |
344 | 200 mi.mi_end = skipdigits(ptr); |
835 | 201 nrlen = (int)(mi.mi_end - ptr); |
584 | 202 } |
346 | 203 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
204 // Find the normal end of the word (until the next non-word character). |
344 | 205 mi.mi_word = ptr; |
584 | 206 mi.mi_fend = ptr; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
207 if (spell_iswordp(mi.mi_fend, wp)) |
344 | 208 { |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
209 int prev_upper; |
20810
f9245f58c134
patch 8.2.0957: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
20808
diff
changeset
|
210 int this_upper = FALSE; // init for gcc |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
211 |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
212 if (use_camel_case) |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
213 { |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
214 c = PTR2CHAR(mi.mi_fend); |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
215 this_upper = SPELL_ISUPPER(c); |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
216 } |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
217 |
344 | 218 do |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
219 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
220 MB_PTR_ADV(mi.mi_fend); |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
221 if (use_camel_case) |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
222 { |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
223 prev_upper = this_upper; |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
224 c = PTR2CHAR(mi.mi_fend); |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
225 this_upper = SPELL_ISUPPER(c); |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
226 camel_case = !prev_upper && this_upper; |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
227 } |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
228 } while (*mi.mi_fend != NUL && spell_iswordp(mi.mi_fend, wp) |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
229 && !camel_case); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
230 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
231 if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) |
385 | 232 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
233 // Check word starting with capital letter. |
455 | 234 c = PTR2CHAR(ptr); |
385 | 235 if (!SPELL_ISUPPER(c)) |
483 | 236 wrongcaplen = (int)(mi.mi_fend - ptr); |
385 | 237 } |
238 } | |
239 if (capcol != NULL) | |
240 *capcol = -1; | |
344 | 241 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
242 // We always use the characters up to the next non-word character, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
243 // also for bad words. |
344 | 244 mi.mi_end = mi.mi_fend; |
245 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
246 // Check caps type later. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
247 mi.mi_capflags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
248 mi.mi_cend = NULL; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
249 mi.mi_win = wp; |
344 | 250 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
251 // case-fold the word with one non-word character, so that we can check |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
252 // for the word end. |
344 | 253 if (*mi.mi_fend != NUL) |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
254 MB_PTR_ADV(mi.mi_fend); |
344 | 255 |
256 (void)spell_casefold(ptr, (int)(mi.mi_fend - ptr), mi.mi_fword, | |
257 MAXWLEN + 1); | |
835 | 258 mi.mi_fwordlen = (int)STRLEN(mi.mi_fword); |
344 | 259 |
20808
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
260 if (camel_case) |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
261 // Introduce a fake word end space into the folded word. |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
262 mi.mi_fword[mi.mi_fwordlen - 1] = ' '; |
411348fb49ba
patch 8.2.0956: spell test fails
Bram Moolenaar <Bram@vim.org>
parents:
20786
diff
changeset
|
263 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
264 // The word is bad unless we recognize it. |
344 | 265 mi.mi_result = SP_BAD; |
492 | 266 mi.mi_result2 = SP_BAD; |
344 | 267 |
268 /* | |
269 * Loop over the languages specified in 'spelllang'. | |
625 | 270 * We check them all, because a word may be matched longer in another |
271 * language. | |
344 | 272 */ |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
273 for (lpi = 0; lpi < wp->w_s->b_langp.ga_len; ++lpi) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
274 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
275 mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, lpi); |
500 | 276 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
277 // If reloading fails the language is still in the list but everything |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
278 // has been cleared. |
500 | 279 if (mi.mi_lp->lp_slang->sl_fidxs == NULL) |
280 continue; | |
281 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
282 // Check for a matching word in case-folded words. |
344 | 283 find_word(&mi, FIND_FOLDWORD); |
284 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
285 // Check for a matching word in keep-case words. |
344 | 286 find_word(&mi, FIND_KEEPWORD); |
287 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
288 // Check for matching prefixes. |
485 | 289 find_prefix(&mi, FIND_FOLDWORD); |
492 | 290 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
291 // For a NOBREAK language, may want to use a word without a following |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
292 // word as a backup. |
492 | 293 if (mi.mi_lp->lp_slang->sl_nobreak && mi.mi_result == SP_BAD |
294 && mi.mi_result2 != SP_BAD) | |
295 { | |
296 mi.mi_result = mi.mi_result2; | |
297 mi.mi_end = mi.mi_end2; | |
298 } | |
625 | 299 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
300 // Count the word in the first language where it's found to be OK. |
625 | 301 if (count_word && mi.mi_result == SP_OK) |
302 { | |
303 count_common_word(mi.mi_lp->lp_slang, ptr, | |
304 (int)(mi.mi_end - ptr), 1); | |
305 count_word = FALSE; | |
306 } | |
344 | 307 } |
308 | |
309 if (mi.mi_result != SP_OK) | |
310 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
311 // If we found a number skip over it. Allows for "42nd". Do flag |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
312 // rare and local words, e.g., "3GPP". |
344 | 313 if (nrlen > 0) |
346 | 314 { |
315 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) | |
316 return nrlen; | |
317 } | |
344 | 318 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
319 // When we are at a non-word character there is no error, just |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
320 // skip over the character (try looking for a word after it). |
5477 | 321 else if (!spell_iswordp_nmw(ptr, wp)) |
243 | 322 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
323 if (capcol != NULL && wp->w_s->b_cap_prog != NULL) |
385 | 324 { |
325 regmatch_T regmatch; | |
6375 | 326 int r; |
385 | 327 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
328 // Check for end of sentence. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
329 regmatch.regprog = wp->w_s->b_cap_prog; |
385 | 330 regmatch.rm_ic = FALSE; |
6375 | 331 r = vim_regexec(®match, ptr, 0); |
332 wp->w_s->b_cap_prog = regmatch.regprog; | |
333 if (r) | |
385 | 334 *capcol = (int)(regmatch.endp[0] - ptr); |
335 } | |
336 | |
344 | 337 if (has_mbyte) |
474 | 338 return (*mb_ptr2len)(ptr); |
344 | 339 return 1; |
300 | 340 } |
483 | 341 else if (mi.mi_end == ptr) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
342 // Always include at least one character. Required for when there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
343 // is a mixup in "midword". |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
344 MB_PTR_ADV(mi.mi_end); |
492 | 345 else if (mi.mi_result == SP_BAD |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
346 && LANGP_ENTRY(wp->w_s->b_langp, 0)->lp_slang->sl_nobreak) |
492 | 347 { |
348 char_u *p, *fp; | |
349 int save_result = mi.mi_result; | |
350 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
351 // First language in 'spelllang' is NOBREAK. Find first position |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
352 // at which any word would be valid. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
353 mi.mi_lp = LANGP_ENTRY(wp->w_s->b_langp, 0); |
500 | 354 if (mi.mi_lp->lp_slang->sl_fidxs != NULL) |
355 { | |
356 p = mi.mi_word; | |
357 fp = mi.mi_fword; | |
358 for (;;) | |
359 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
360 MB_PTR_ADV(p); |
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
361 MB_PTR_ADV(fp); |
500 | 362 if (p >= mi.mi_end) |
363 break; | |
835 | 364 mi.mi_compoff = (int)(fp - mi.mi_fword); |
500 | 365 find_word(&mi, FIND_COMPOUND); |
366 if (mi.mi_result != SP_BAD) | |
367 { | |
368 mi.mi_end = p; | |
369 break; | |
370 } | |
371 } | |
372 mi.mi_result = save_result; | |
373 } | |
492 | 374 } |
243 | 375 |
344 | 376 if (mi.mi_result == SP_BAD || mi.mi_result == SP_BANNED) |
534 | 377 *attrp = HLF_SPB; |
344 | 378 else if (mi.mi_result == SP_RARE) |
534 | 379 *attrp = HLF_SPR; |
344 | 380 else |
534 | 381 *attrp = HLF_SPL; |
243 | 382 } |
383 | |
483 | 384 if (wrongcaplen > 0 && (mi.mi_result == SP_OK || mi.mi_result == SP_RARE)) |
385 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
386 // Report SpellCap only when the word isn't badly spelled. |
534 | 387 *attrp = HLF_SPC; |
483 | 388 return wrongcaplen; |
389 } | |
390 | |
300 | 391 return (int)(mi.mi_end - ptr); |
236 | 392 } |
393 | |
394 /* | |
300 | 395 * Check if the word at "mip->mi_word" is in the tree. |
339 | 396 * When "mode" is FIND_FOLDWORD check in fold-case word tree. |
397 * When "mode" is FIND_KEEPWORD check in keep-case word tree. | |
398 * When "mode" is FIND_PREFIX check for word after prefix in fold-case word | |
399 * tree. | |
300 | 400 * |
401 * For a match mip->mi_result is updated. | |
243 | 402 */ |
403 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
404 find_word(matchinf_T *mip, int mode) |
243 | 405 { |
324 | 406 idx_T arridx = 0; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
407 int endlen[MAXWLEN]; // length at possible word endings |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
408 idx_T endidx[MAXWLEN]; // possible word endings |
300 | 409 int endidxcnt = 0; |
410 int len; | |
411 int wlen = 0; | |
412 int flen; | |
413 int c; | |
414 char_u *ptr; | |
324 | 415 idx_T lo, hi, m; |
300 | 416 char_u *s; |
339 | 417 char_u *p; |
307 | 418 int res = SP_BAD; |
300 | 419 slang_T *slang = mip->mi_lp->lp_slang; |
420 unsigned flags; | |
421 char_u *byts; | |
324 | 422 idx_T *idxs; |
481 | 423 int word_ends; |
485 | 424 int prefix_found; |
492 | 425 int nobreak_result; |
481 | 426 |
427 if (mode == FIND_KEEPWORD || mode == FIND_KEEPCOMPOUND) | |
236 | 428 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
429 // Check for word with matching case in keep-case tree. |
300 | 430 ptr = mip->mi_word; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
431 flen = 9999; // no case folding, always enough bytes |
300 | 432 byts = slang->sl_kbyts; |
433 idxs = slang->sl_kidxs; | |
481 | 434 |
435 if (mode == FIND_KEEPCOMPOUND) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
436 // Skip over the previously found word(s). |
481 | 437 wlen += mip->mi_compoff; |
236 | 438 } |
439 else | |
440 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
441 // Check for case-folded in case-folded tree. |
300 | 442 ptr = mip->mi_fword; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
443 flen = mip->mi_fwordlen; // available case-folded bytes |
300 | 444 byts = slang->sl_fbyts; |
445 idxs = slang->sl_fidxs; | |
339 | 446 |
447 if (mode == FIND_PREFIX) | |
448 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
449 // Skip over the prefix. |
339 | 450 wlen = mip->mi_prefixlen; |
451 flen -= mip->mi_prefixlen; | |
452 } | |
481 | 453 else if (mode == FIND_COMPOUND) |
454 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
455 // Skip over the previously found word(s). |
481 | 456 wlen = mip->mi_compoff; |
457 flen -= mip->mi_compoff; | |
458 } | |
459 | |
243 | 460 } |
461 | |
300 | 462 if (byts == NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
463 return; // array is empty |
236 | 464 |
465 /* | |
307 | 466 * Repeat advancing in the tree until: |
467 * - there is a byte that doesn't match, | |
468 * - we reach the end of the tree, | |
469 * - or we reach the end of the line. | |
236 | 470 */ |
300 | 471 for (;;) |
236 | 472 { |
346 | 473 if (flen <= 0 && *mip->mi_fend != NUL) |
339 | 474 flen = fold_more(mip); |
300 | 475 |
476 len = byts[arridx++]; | |
477 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
478 // If the first possible byte is a zero the word could end here. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
479 // Remember this index, we first check for the longest word. |
300 | 480 if (byts[arridx] == 0) |
481 { | |
307 | 482 if (endidxcnt == MAXWLEN) |
483 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
484 // Must be a corrupted spell file. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
485 emsg(_(e_format)); |
307 | 486 return; |
487 } | |
300 | 488 endlen[endidxcnt] = wlen; |
489 endidx[endidxcnt++] = arridx++; | |
490 --len; | |
491 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
492 // Skip over the zeros, there can be several flag/region |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
493 // combinations. |
300 | 494 while (len > 0 && byts[arridx] == 0) |
495 { | |
496 ++arridx; | |
497 --len; | |
498 } | |
499 if (len == 0) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
500 break; // no children, word must end here |
300 | 501 } |
502 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
503 // Stop looking at end of the line. |
300 | 504 if (ptr[wlen] == NUL) |
505 break; | |
506 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
507 // Perform a binary search in the list of accepted bytes. |
300 | 508 c = ptr[wlen]; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
509 if (c == TAB) // <Tab> is handled like <Space> |
346 | 510 c = ' '; |
300 | 511 lo = arridx; |
512 hi = arridx + len - 1; | |
513 while (lo < hi) | |
514 { | |
515 m = (lo + hi) / 2; | |
516 if (byts[m] > c) | |
517 hi = m - 1; | |
518 else if (byts[m] < c) | |
519 lo = m + 1; | |
520 else | |
521 { | |
522 lo = hi = m; | |
523 break; | |
236 | 524 } |
525 } | |
300 | 526 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
527 // Stop if there is no matching byte. |
300 | 528 if (hi < lo || byts[lo] != c) |
529 break; | |
530 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
531 // Continue at the child (if there is one). |
300 | 532 arridx = idxs[lo]; |
533 ++wlen; | |
534 --flen; | |
346 | 535 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
536 // One space in the good word may stand for several spaces in the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
537 // checked word. |
346 | 538 if (c == ' ') |
539 { | |
540 for (;;) | |
541 { | |
542 if (flen <= 0 && *mip->mi_fend != NUL) | |
543 flen = fold_more(mip); | |
544 if (ptr[wlen] != ' ' && ptr[wlen] != TAB) | |
545 break; | |
546 ++wlen; | |
547 --flen; | |
548 } | |
549 } | |
236 | 550 } |
551 | |
300 | 552 /* |
553 * Verify that one of the possible endings is valid. Try the longest | |
554 * first. | |
555 */ | |
556 while (endidxcnt > 0) | |
557 { | |
558 --endidxcnt; | |
559 arridx = endidx[endidxcnt]; | |
560 wlen = endlen[endidxcnt]; | |
236 | 561 |
300 | 562 if ((*mb_head_off)(ptr, ptr + wlen) > 0) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
563 continue; // not at first byte of character |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
564 if (spell_iswordp(ptr + wlen, mip->mi_win)) |
481 | 565 { |
492 | 566 if (slang->sl_compprog == NULL && !slang->sl_nobreak) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
567 continue; // next char is a word character |
481 | 568 word_ends = FALSE; |
569 } | |
570 else | |
571 word_ends = TRUE; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
572 // The prefix flag is before compound flags. Once a valid prefix flag |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
573 // has been found we try compound flags. |
485 | 574 prefix_found = FALSE; |
300 | 575 |
339 | 576 if (mode != FIND_KEEPWORD && has_mbyte) |
300 | 577 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
578 // Compute byte length in original word, length may change |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
579 // when folding case. This can be slow, take a shortcut when the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
580 // case-folded word is equal to the keep-case word. |
300 | 581 p = mip->mi_word; |
339 | 582 if (STRNCMP(ptr, p, wlen) != 0) |
583 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
584 for (s = ptr; s < ptr + wlen; MB_PTR_ADV(s)) |
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
585 MB_PTR_ADV(p); |
835 | 586 wlen = (int)(p - mip->mi_word); |
339 | 587 } |
300 | 588 } |
236 | 589 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
590 // Check flags and region. For FIND_PREFIX check the condition and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
591 // prefix ID. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
592 // Repeat this if there are more flags/region alternatives until there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
593 // is a match. |
339 | 594 res = SP_BAD; |
595 for (len = byts[arridx - 1]; len > 0 && byts[arridx] == 0; | |
596 --len, ++arridx) | |
300 | 597 { |
598 flags = idxs[arridx]; | |
324 | 599 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
600 // For the fold-case tree check that the case of the checked word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
601 // matches with what the word in the tree requires. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
602 // For keep-case tree the case is always right. For prefixes we |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
603 // don't bother to check. |
339 | 604 if (mode == FIND_FOLDWORD) |
300 | 605 { |
606 if (mip->mi_cend != mip->mi_word + wlen) | |
607 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
608 // mi_capflags was set for a different word length, need |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
609 // to do it again. |
300 | 610 mip->mi_cend = mip->mi_word + wlen; |
323 | 611 mip->mi_capflags = captype(mip->mi_word, mip->mi_cend); |
300 | 612 } |
613 | |
346 | 614 if (mip->mi_capflags == WF_KEEPCAP |
615 || !spell_valid_case(mip->mi_capflags, flags)) | |
339 | 616 continue; |
300 | 617 } |
236 | 618 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
619 // When mode is FIND_PREFIX the word must support the prefix: |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
620 // check the prefix ID and the condition. Do that for the list at |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
621 // mip->mi_prefarridx that find_prefix() filled. |
485 | 622 else if (mode == FIND_PREFIX && !prefix_found) |
481 | 623 { |
366 | 624 c = valid_word_prefix(mip->mi_prefcnt, mip->mi_prefarridx, |
390 | 625 flags, |
455 | 626 mip->mi_word + mip->mi_cprefixlen, slang, |
627 FALSE); | |
366 | 628 if (c == 0) |
339 | 629 continue; |
366 | 630 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
631 // Use the WF_RARE flag for a rare prefix. |
366 | 632 if (c & WF_RAREPFX) |
633 flags |= WF_RARE; | |
485 | 634 prefix_found = TRUE; |
339 | 635 } |
636 | |
492 | 637 if (slang->sl_nobreak) |
638 { | |
639 if ((mode == FIND_COMPOUND || mode == FIND_KEEPCOMPOUND) | |
640 && (flags & WF_BANNED) == 0) | |
641 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
642 // NOBREAK: found a valid following word. That's all we |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
643 // need to know, so return. |
492 | 644 mip->mi_result = SP_OK; |
645 break; | |
646 } | |
647 } | |
648 | |
649 else if ((mode == FIND_COMPOUND || mode == FIND_KEEPCOMPOUND | |
650 || !word_ends)) | |
481 | 651 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
652 // If there is no compound flag or the word is shorter than |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
653 // COMPOUNDMIN reject it quickly. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
654 // Makes you wonder why someone puts a compound flag on a word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
655 // that's too short... Myspell compatibility requires this |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
656 // anyway. |
490 | 657 if (((unsigned)flags >> 24) == 0 |
658 || wlen - mip->mi_compoff < slang->sl_compminlen) | |
483 | 659 continue; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
660 // For multi-byte chars check character length against |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
661 // COMPOUNDMIN. |
500 | 662 if (has_mbyte |
501 | 663 && slang->sl_compminlen > 0 |
500 | 664 && mb_charlen_len(mip->mi_word + mip->mi_compoff, |
665 wlen - mip->mi_compoff) < slang->sl_compminlen) | |
666 continue; | |
483 | 667 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
668 // Limit the number of compound words to COMPOUNDWORDMAX if no |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
669 // maximum for syllables is specified. |
809 | 670 if (!word_ends && mip->mi_complen + mip->mi_compextra + 2 |
671 > slang->sl_compmax | |
490 | 672 && slang->sl_compsylmax == MAXWLEN) |
483 | 673 continue; |
674 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
675 // Don't allow compounding on a side where an affix was added, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
676 // unless COMPOUNDPERMITFLAG was used. |
819 | 677 if (mip->mi_complen > 0 && (flags & WF_NOCOMPBEF)) |
678 continue; | |
679 if (!word_ends && (flags & WF_NOCOMPAFT)) | |
680 continue; | |
681 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
682 // Quickly check if compounding is possible with this flag. |
495 | 683 if (!byte_in_str(mip->mi_complen == 0 |
485 | 684 ? slang->sl_compstartflags |
685 : slang->sl_compallflags, | |
495 | 686 ((unsigned)flags >> 24))) |
481 | 687 continue; |
688 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
689 // If there is a match with a CHECKCOMPOUNDPATTERN rule |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
690 // discard the compound word. |
1762 | 691 if (match_checkcompoundpattern(ptr, wlen, &slang->sl_comppat)) |
692 continue; | |
693 | |
490 | 694 if (mode == FIND_COMPOUND) |
695 { | |
696 int capflags; | |
697 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
698 // Need to check the caps type of the appended compound |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
699 // word. |
490 | 700 if (has_mbyte && STRNCMP(ptr, mip->mi_word, |
701 mip->mi_compoff) != 0) | |
702 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
703 // case folding may have changed the length |
490 | 704 p = mip->mi_word; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
705 for (s = ptr; s < ptr + mip->mi_compoff; MB_PTR_ADV(s)) |
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
706 MB_PTR_ADV(p); |
490 | 707 } |
708 else | |
709 p = mip->mi_word + mip->mi_compoff; | |
710 capflags = captype(p, mip->mi_word + wlen); | |
711 if (capflags == WF_KEEPCAP || (capflags == WF_ALLCAP | |
712 && (flags & WF_FIXCAP) != 0)) | |
713 continue; | |
714 | |
715 if (capflags != WF_ALLCAP) | |
716 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
717 // When the character before the word is a word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
718 // character we do not accept a Onecap word. We do |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
719 // accept a no-caps word, even when the dictionary |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
720 // word specifies ONECAP. |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
721 MB_PTR_BACK(mip->mi_word, p); |
5477 | 722 if (spell_iswordp_nmw(p, mip->mi_win) |
490 | 723 ? capflags == WF_ONECAP |
724 : (flags & WF_ONECAP) != 0 | |
725 && capflags != WF_ONECAP) | |
726 continue; | |
727 } | |
728 } | |
729 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
730 // If the word ends the sequence of compound flags of the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
731 // words must match with one of the COMPOUNDRULE items and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
732 // the number of syllables must not be too large. |
483 | 733 mip->mi_compflags[mip->mi_complen] = ((unsigned)flags >> 24); |
734 mip->mi_compflags[mip->mi_complen + 1] = NUL; | |
735 if (word_ends) | |
736 { | |
737 char_u fword[MAXWLEN]; | |
738 | |
739 if (slang->sl_compsylmax < MAXWLEN) | |
740 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
741 // "fword" is only needed for checking syllables. |
483 | 742 if (ptr == mip->mi_word) |
743 (void)spell_casefold(ptr, wlen, fword, MAXWLEN); | |
744 else | |
745 vim_strncpy(fword, ptr, endlen[endidxcnt]); | |
746 } | |
747 if (!can_compound(slang, fword, mip->mi_compflags)) | |
748 continue; | |
749 } | |
1762 | 750 else if (slang->sl_comprules != NULL |
751 && !match_compoundrule(slang, mip->mi_compflags)) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
752 // The compound flags collected so far do not match any |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
753 // COMPOUNDRULE, discard the compounded word. |
1762 | 754 continue; |
481 | 755 } |
756 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
757 // Check NEEDCOMPOUND: can't use word without compounding. |
500 | 758 else if (flags & WF_NEEDCOMP) |
759 continue; | |
760 | |
492 | 761 nobreak_result = SP_OK; |
762 | |
481 | 763 if (!word_ends) |
764 { | |
492 | 765 int save_result = mip->mi_result; |
766 char_u *save_end = mip->mi_end; | |
501 | 767 langp_T *save_lp = mip->mi_lp; |
768 int lpi; | |
492 | 769 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
770 // Check that a valid word follows. If there is one and we |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
771 // are compounding, it will set "mi_result", thus we are |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
772 // always finished here. For NOBREAK we only check that a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
773 // valid word follows. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
774 // Recursive! |
492 | 775 if (slang->sl_nobreak) |
776 mip->mi_result = SP_BAD; | |
481 | 777 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
778 // Find following word in case-folded tree. |
481 | 779 mip->mi_compoff = endlen[endidxcnt]; |
780 if (has_mbyte && mode == FIND_KEEPWORD) | |
781 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
782 // Compute byte length in case-folded word from "wlen": |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
783 // byte length in keep-case word. Length may change when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
784 // folding case. This can be slow, take a shortcut when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
785 // the case-folded word is equal to the keep-case word. |
481 | 786 p = mip->mi_fword; |
787 if (STRNCMP(ptr, p, wlen) != 0) | |
788 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
789 for (s = ptr; s < ptr + wlen; MB_PTR_ADV(s)) |
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
790 MB_PTR_ADV(p); |
835 | 791 mip->mi_compoff = (int)(p - mip->mi_fword); |
481 | 792 } |
793 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
794 #if 0 // Disabled, see below |
485 | 795 c = mip->mi_compoff; |
8956
d9e671c5afe6
commit https://github.com/vim/vim/commit/ba53435144f46eaaa53c63a62e748b3feee9742c
Christian Brabandt <cb@256bit.org>
parents:
8524
diff
changeset
|
796 #endif |
483 | 797 ++mip->mi_complen; |
809 | 798 if (flags & WF_COMPROOT) |
799 ++mip->mi_compextra; | |
501 | 800 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
801 // For NOBREAK we need to try all NOBREAK languages, at least |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
802 // to find the ".add" file(s). |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
803 for (lpi = 0; lpi < mip->mi_win->w_s->b_langp.ga_len; ++lpi) |
501 | 804 { |
805 if (slang->sl_nobreak) | |
806 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
807 mip->mi_lp = LANGP_ENTRY(mip->mi_win->w_s->b_langp, lpi); |
501 | 808 if (mip->mi_lp->lp_slang->sl_fidxs == NULL |
809 || !mip->mi_lp->lp_slang->sl_nobreak) | |
810 continue; | |
811 } | |
812 | |
813 find_word(mip, FIND_COMPOUND); | |
814 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
815 // When NOBREAK any word that matches is OK. Otherwise we |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
816 // need to find the longest match, thus try with keep-case |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
817 // and prefix too. |
492 | 818 if (!slang->sl_nobreak || mip->mi_result == SP_BAD) |
819 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
820 // Find following word in keep-case tree. |
501 | 821 mip->mi_compoff = wlen; |
822 find_word(mip, FIND_KEEPCOMPOUND); | |
823 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
824 #if 0 // Disabled, a prefix must not appear halfway a compound word, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
825 // unless the COMPOUNDPERMITFLAG is used and then it can't be a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
826 // postponed prefix. |
501 | 827 if (!slang->sl_nobreak || mip->mi_result == SP_BAD) |
828 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
829 // Check for following word with prefix. |
501 | 830 mip->mi_compoff = c; |
831 find_prefix(mip, FIND_COMPOUND); | |
832 } | |
819 | 833 #endif |
492 | 834 } |
501 | 835 |
836 if (!slang->sl_nobreak) | |
837 break; | |
492 | 838 } |
483 | 839 --mip->mi_complen; |
809 | 840 if (flags & WF_COMPROOT) |
841 --mip->mi_compextra; | |
501 | 842 mip->mi_lp = save_lp; |
485 | 843 |
492 | 844 if (slang->sl_nobreak) |
845 { | |
846 nobreak_result = mip->mi_result; | |
847 mip->mi_result = save_result; | |
848 mip->mi_end = save_end; | |
849 } | |
850 else | |
851 { | |
852 if (mip->mi_result == SP_OK) | |
853 break; | |
854 continue; | |
855 } | |
481 | 856 } |
857 | |
339 | 858 if (flags & WF_BANNED) |
859 res = SP_BANNED; | |
860 else if (flags & WF_REGION) | |
861 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
862 // Check region. |
390 | 863 if ((mip->mi_lp->lp_region & (flags >> 16)) != 0) |
300 | 864 res = SP_OK; |
339 | 865 else |
866 res = SP_LOCAL; | |
300 | 867 } |
339 | 868 else if (flags & WF_RARE) |
869 res = SP_RARE; | |
307 | 870 else |
339 | 871 res = SP_OK; |
872 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
873 // Always use the longest match and the best result. For NOBREAK |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
874 // we separately keep the longest match without a following good |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
875 // word as a fall-back. |
492 | 876 if (nobreak_result == SP_BAD) |
877 { | |
878 if (mip->mi_result2 > res) | |
879 { | |
880 mip->mi_result2 = res; | |
881 mip->mi_end2 = mip->mi_word + wlen; | |
882 } | |
883 else if (mip->mi_result2 == res | |
884 && mip->mi_end2 < mip->mi_word + wlen) | |
885 mip->mi_end2 = mip->mi_word + wlen; | |
886 } | |
887 else if (mip->mi_result > res) | |
339 | 888 { |
889 mip->mi_result = res; | |
890 mip->mi_end = mip->mi_word + wlen; | |
891 } | |
351 | 892 else if (mip->mi_result == res && mip->mi_end < mip->mi_word + wlen) |
339 | 893 mip->mi_end = mip->mi_word + wlen; |
894 | |
492 | 895 if (mip->mi_result == SP_OK) |
339 | 896 break; |
300 | 897 } |
898 | |
492 | 899 if (mip->mi_result == SP_OK) |
300 | 900 break; |
901 } | |
236 | 902 } |
903 | |
323 | 904 /* |
1762 | 905 * Return TRUE if there is a match between the word ptr[wlen] and |
906 * CHECKCOMPOUNDPATTERN rules, assuming that we will concatenate with another | |
907 * word. | |
908 * A match means that the first part of CHECKCOMPOUNDPATTERN matches at the | |
909 * end of ptr[wlen] and the second part matches after it. | |
910 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
911 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
912 match_checkcompoundpattern( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
913 char_u *ptr, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
914 int wlen, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
915 garray_T *gap) // &sl_comppat |
1762 | 916 { |
917 int i; | |
918 char_u *p; | |
919 int len; | |
920 | |
921 for (i = 0; i + 1 < gap->ga_len; i += 2) | |
922 { | |
923 p = ((char_u **)gap->ga_data)[i + 1]; | |
924 if (STRNCMP(ptr + wlen, p, STRLEN(p)) == 0) | |
925 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
926 // Second part matches at start of following compound word, now |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
927 // check if first part matches at end of previous word. |
1762 | 928 p = ((char_u **)gap->ga_data)[i]; |
1771 | 929 len = (int)STRLEN(p); |
1762 | 930 if (len <= wlen && STRNCMP(ptr + wlen - len, p, len) == 0) |
931 return TRUE; | |
932 } | |
933 } | |
934 return FALSE; | |
935 } | |
936 | |
937 /* | |
626 | 938 * Return TRUE if "flags" is a valid sequence of compound flags and "word" |
939 * does not have too many syllables. | |
482 | 940 */ |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
941 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
942 can_compound(slang_T *slang, char_u *word, char_u *flags) |
483 | 943 { |
495 | 944 char_u uflags[MAXWLEN * 2]; |
945 int i; | |
946 char_u *p; | |
483 | 947 |
948 if (slang->sl_compprog == NULL) | |
949 return FALSE; | |
495 | 950 if (enc_utf8) |
951 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
952 // Need to convert the single byte flags to utf8 characters. |
495 | 953 p = uflags; |
954 for (i = 0; flags[i] != NUL; ++i) | |
11269
121d29004998
patch 8.0.0520: using a function pointer while the function is known
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
955 p += utf_char2bytes(flags[i], p); |
495 | 956 *p = NUL; |
957 p = uflags; | |
958 } | |
959 else | |
960 p = flags; | |
6375 | 961 if (!vim_regexec_prog(&slang->sl_compprog, FALSE, p, 0)) |
483 | 962 return FALSE; |
963 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
964 // Count the number of syllables. This may be slow, do it last. If there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
965 // are too many syllables AND the number of compound words is above |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
966 // COMPOUNDWORDMAX then compounding is not allowed. |
483 | 967 if (slang->sl_compsylmax < MAXWLEN |
968 && count_syllables(slang, word) > slang->sl_compsylmax) | |
495 | 969 return (int)STRLEN(flags) < slang->sl_compmax; |
483 | 970 return TRUE; |
482 | 971 } |
972 | |
973 /* | |
1762 | 974 * Return TRUE if the compound flags in compflags[] match the start of any |
975 * compound rule. This is used to stop trying a compound if the flags | |
976 * collected so far can't possibly match any compound rule. | |
977 * Caller must check that slang->sl_comprules is not NULL. | |
978 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
979 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
980 match_compoundrule(slang_T *slang, char_u *compflags) |
1762 | 981 { |
982 char_u *p; | |
983 int i; | |
984 int c; | |
985 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
986 // loop over all the COMPOUNDRULE entries |
1762 | 987 for (p = slang->sl_comprules; *p != NUL; ++p) |
988 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
989 // loop over the flags in the compound word we have made, match |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
990 // them against the current rule entry |
1762 | 991 for (i = 0; ; ++i) |
992 { | |
993 c = compflags[i]; | |
994 if (c == NUL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
995 // found a rule that matches for the flags we have so far |
1762 | 996 return TRUE; |
997 if (*p == '/' || *p == NUL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
998 break; // end of rule, it's too short |
1762 | 999 if (*p == '[') |
1000 { | |
1001 int match = FALSE; | |
1002 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1003 // compare against all the flags in [] |
1762 | 1004 ++p; |
1005 while (*p != ']' && *p != NUL) | |
1006 if (*p++ == c) | |
1007 match = TRUE; | |
1008 if (!match) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1009 break; // none matches |
1762 | 1010 } |
1011 else if (*p != c) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1012 break; // flag of word doesn't match flag in pattern |
1762 | 1013 ++p; |
1014 } | |
1015 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1016 // Skip to the next "/", where the next pattern starts. |
1762 | 1017 p = vim_strchr(p, '/'); |
1018 if (p == NULL) | |
1019 break; | |
1020 } | |
1021 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1022 // Checked all the rules and none of them match the flags, so there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1023 // can't possibly be a compound starting with these flags. |
1762 | 1024 return FALSE; |
1025 } | |
1026 | |
1027 /* | |
390 | 1028 * Return non-zero if the prefix indicated by "arridx" matches with the prefix |
1029 * ID in "flags" for the word "word". | |
366 | 1030 * The WF_RAREPFX flag is included in the return value for a rare prefix. |
351 | 1031 */ |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1032 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1033 valid_word_prefix( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1034 int totprefcnt, // nr of prefix IDs |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1035 int arridx, // idx in sl_pidxs[] |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1036 int flags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1037 char_u *word, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1038 slang_T *slang, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1039 int cond_req) // only use prefixes with a condition |
351 | 1040 { |
1041 int prefcnt; | |
1042 int pidx; | |
6375 | 1043 regprog_T **rp; |
390 | 1044 int prefid; |
1045 | |
1046 prefid = (unsigned)flags >> 24; | |
351 | 1047 for (prefcnt = totprefcnt - 1; prefcnt >= 0; --prefcnt) |
1048 { | |
1049 pidx = slang->sl_pidxs[arridx + prefcnt]; | |
1050 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1051 // Check the prefix ID. |
351 | 1052 if (prefid != (pidx & 0xff)) |
1053 continue; | |
1054 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1055 // Check if the prefix doesn't combine and the word already has a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1056 // suffix. |
390 | 1057 if ((flags & WF_HAS_AFF) && (pidx & WF_PFX_NC)) |
1058 continue; | |
1059 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1060 // Check the condition, if there is one. The condition index is |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1061 // stored in the two bytes above the prefix ID byte. |
6375 | 1062 rp = &slang->sl_prefprog[((unsigned)pidx >> 8) & 0xffff]; |
1063 if (*rp != NULL) | |
1064 { | |
1065 if (!vim_regexec_prog(rp, FALSE, word, 0)) | |
351 | 1066 continue; |
1067 } | |
455 | 1068 else if (cond_req) |
1069 continue; | |
1070 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1071 // It's a match! Return the WF_ flags. |
366 | 1072 return pidx; |
1073 } | |
1074 return 0; | |
351 | 1075 } |
1076 | |
1077 /* | |
339 | 1078 * Check if the word at "mip->mi_word" has a matching prefix. |
1079 * If it does, then check the following word. | |
1080 * | |
485 | 1081 * If "mode" is "FIND_COMPOUND" then do the same after another word, find a |
1082 * prefix in a compound word. | |
1083 * | |
339 | 1084 * For a match mip->mi_result is updated. |
1085 */ | |
1086 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1087 find_prefix(matchinf_T *mip, int mode) |
339 | 1088 { |
1089 idx_T arridx = 0; | |
1090 int len; | |
1091 int wlen = 0; | |
1092 int flen; | |
1093 int c; | |
1094 char_u *ptr; | |
1095 idx_T lo, hi, m; | |
1096 slang_T *slang = mip->mi_lp->lp_slang; | |
1097 char_u *byts; | |
1098 idx_T *idxs; | |
1099 | |
375 | 1100 byts = slang->sl_pbyts; |
1101 if (byts == NULL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1102 return; // array is empty |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1103 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1104 // We use the case-folded word here, since prefixes are always |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1105 // case-folded. |
339 | 1106 ptr = mip->mi_fword; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1107 flen = mip->mi_fwordlen; // available case-folded bytes |
485 | 1108 if (mode == FIND_COMPOUND) |
1109 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1110 // Skip over the previously found word(s). |
485 | 1111 ptr += mip->mi_compoff; |
1112 flen -= mip->mi_compoff; | |
1113 } | |
339 | 1114 idxs = slang->sl_pidxs; |
1115 | |
1116 /* | |
1117 * Repeat advancing in the tree until: | |
1118 * - there is a byte that doesn't match, | |
1119 * - we reach the end of the tree, | |
1120 * - or we reach the end of the line. | |
1121 */ | |
1122 for (;;) | |
1123 { | |
1124 if (flen == 0 && *mip->mi_fend != NUL) | |
1125 flen = fold_more(mip); | |
1126 | |
1127 len = byts[arridx++]; | |
1128 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1129 // If the first possible byte is a zero the prefix could end here. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1130 // Check if the following word matches and supports the prefix. |
339 | 1131 if (byts[arridx] == 0) |
1132 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1133 // There can be several prefixes with different conditions. We |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1134 // try them all, since we don't know which one will give the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1135 // longest match. The word is the same each time, pass the list |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1136 // of possible prefixes to find_word(). |
339 | 1137 mip->mi_prefarridx = arridx; |
1138 mip->mi_prefcnt = len; | |
1139 while (len > 0 && byts[arridx] == 0) | |
1140 { | |
1141 ++arridx; | |
1142 --len; | |
1143 } | |
1144 mip->mi_prefcnt -= len; | |
1145 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1146 // Find the word that comes after the prefix. |
339 | 1147 mip->mi_prefixlen = wlen; |
485 | 1148 if (mode == FIND_COMPOUND) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1149 // Skip over the previously found word(s). |
485 | 1150 mip->mi_prefixlen += mip->mi_compoff; |
1151 | |
455 | 1152 if (has_mbyte) |
1153 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1154 // Case-folded length may differ from original length. |
485 | 1155 mip->mi_cprefixlen = nofold_len(mip->mi_fword, |
1156 mip->mi_prefixlen, mip->mi_word); | |
455 | 1157 } |
1158 else | |
485 | 1159 mip->mi_cprefixlen = mip->mi_prefixlen; |
339 | 1160 find_word(mip, FIND_PREFIX); |
1161 | |
1162 | |
1163 if (len == 0) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1164 break; // no children, word must end here |
339 | 1165 } |
1166 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1167 // Stop looking at end of the line. |
339 | 1168 if (ptr[wlen] == NUL) |
1169 break; | |
1170 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1171 // Perform a binary search in the list of accepted bytes. |
339 | 1172 c = ptr[wlen]; |
1173 lo = arridx; | |
1174 hi = arridx + len - 1; | |
1175 while (lo < hi) | |
1176 { | |
1177 m = (lo + hi) / 2; | |
1178 if (byts[m] > c) | |
1179 hi = m - 1; | |
1180 else if (byts[m] < c) | |
1181 lo = m + 1; | |
1182 else | |
1183 { | |
1184 lo = hi = m; | |
1185 break; | |
1186 } | |
1187 } | |
1188 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1189 // Stop if there is no matching byte. |
339 | 1190 if (hi < lo || byts[lo] != c) |
1191 break; | |
1192 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1193 // Continue at the child (if there is one). |
339 | 1194 arridx = idxs[lo]; |
1195 ++wlen; | |
1196 --flen; | |
1197 } | |
1198 } | |
1199 | |
1200 /* | |
1201 * Need to fold at least one more character. Do until next non-word character | |
626 | 1202 * for efficiency. Include the non-word character too. |
339 | 1203 * Return the length of the folded chars in bytes. |
1204 */ | |
1205 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1206 fold_more(matchinf_T *mip) |
339 | 1207 { |
1208 int flen; | |
1209 char_u *p; | |
1210 | |
1211 p = mip->mi_fend; | |
1212 do | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1213 MB_PTR_ADV(mip->mi_fend); |
16162
cd5c83115ec6
patch 8.1.1086: too many curly braces
Bram Moolenaar <Bram@vim.org>
parents:
16142
diff
changeset
|
1214 while (*mip->mi_fend != NUL && spell_iswordp(mip->mi_fend, mip->mi_win)); |
339 | 1215 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1216 // Include the non-word character so that we can check for the word end. |
339 | 1217 if (*mip->mi_fend != NUL) |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
1218 MB_PTR_ADV(mip->mi_fend); |
339 | 1219 |
1220 (void)spell_casefold(p, (int)(mip->mi_fend - p), | |
1221 mip->mi_fword + mip->mi_fwordlen, | |
1222 MAXWLEN - mip->mi_fwordlen); | |
835 | 1223 flen = (int)STRLEN(mip->mi_fword + mip->mi_fwordlen); |
339 | 1224 mip->mi_fwordlen += flen; |
1225 return flen; | |
1226 } | |
1227 | |
1228 /* | |
323 | 1229 * Check case flags for a word. Return TRUE if the word has the requested |
1230 * case. | |
1231 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1232 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1233 spell_valid_case( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1234 int wordflags, // flags for the checked word. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1235 int treeflags) // flags for the word in the spell tree |
323 | 1236 { |
389 | 1237 return ((wordflags == WF_ALLCAP && (treeflags & WF_FIXCAP) == 0) |
323 | 1238 || ((treeflags & (WF_ALLCAP | WF_KEEPCAP)) == 0 |
474 | 1239 && ((treeflags & WF_ONECAP) == 0 |
1240 || (wordflags & WF_ONECAP) != 0))); | |
323 | 1241 } |
1242 | |
351 | 1243 /* |
1244 * Return TRUE if spell checking is not enabled. | |
1245 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
1246 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1247 no_spell_checking(win_T *wp) |
498 | 1248 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1249 if (!wp->w_p_spell || *wp->w_s->b_p_spl == NUL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1250 || wp->w_s->b_langp.ga_len == 0) |
351 | 1251 { |
20786
90b96fa35e4b
patch 8.2.0945: cannot use "z=" when 'spell' is off
Bram Moolenaar <Bram@vim.org>
parents:
20760
diff
changeset
|
1252 emsg(_(e_no_spell)); |
351 | 1253 return TRUE; |
1254 } | |
1255 return FALSE; | |
1256 } | |
300 | 1257 |
236 | 1258 /* |
1259 * Move to next spell error. | |
500 | 1260 * "curline" is FALSE for "[s", "]s", "[S" and "]S". |
1261 * "curline" is TRUE to find word under/after cursor in the same line. | |
483 | 1262 * For Insert mode completion "dir" is BACKWARD and "curline" is TRUE: move |
1263 * to after badly spelled word before the cursor. | |
495 | 1264 * Return 0 if not found, length of the badly spelled word otherwise. |
236 | 1265 */ |
1266 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1267 spell_move_to( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1268 win_T *wp, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1269 int dir, // FORWARD or BACKWARD |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1270 int allwords, // TRUE for "[s"/"]s", FALSE for "[S"/"]S" |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1271 int curline, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1272 hlf_T *attrp) // return: attributes of bad word or NULL |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1273 // (only when "dir" is FORWARD) |
236 | 1274 { |
249 | 1275 linenr_T lnum; |
1276 pos_T found_pos; | |
495 | 1277 int found_len = 0; |
236 | 1278 char_u *line; |
1279 char_u *p; | |
346 | 1280 char_u *endp; |
534 | 1281 hlf_T attr; |
236 | 1282 int len; |
5519 | 1283 #ifdef FEAT_SYN_HL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1284 int has_syntax = syntax_present(wp); |
5519 | 1285 #endif |
249 | 1286 int col; |
1287 int can_spell; | |
346 | 1288 char_u *buf = NULL; |
1289 int buflen = 0; | |
1290 int skip = 0; | |
385 | 1291 int capcol = -1; |
500 | 1292 int found_one = FALSE; |
1293 int wrapped = FALSE; | |
236 | 1294 |
498 | 1295 if (no_spell_checking(wp)) |
495 | 1296 return 0; |
236 | 1297 |
249 | 1298 /* |
1299 * Start looking for bad word at the start of the line, because we can't | |
817 | 1300 * start halfway a word, we don't know where it starts or ends. |
249 | 1301 * |
1302 * When searching backwards, we continue in the line to find the last | |
1303 * bad word (in the cursor line: before the cursor). | |
346 | 1304 * |
1305 * We concatenate the start of the next line, so that wrapped words work | |
1306 * (e.g. "et<line-break>cetera"). Doesn't work when searching backwards | |
1307 * though... | |
249 | 1308 */ |
498 | 1309 lnum = wp->w_cursor.lnum; |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10950
diff
changeset
|
1310 CLEAR_POS(&found_pos); |
236 | 1311 |
1312 while (!got_int) | |
1313 { | |
498 | 1314 line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
346 | 1315 |
835 | 1316 len = (int)STRLEN(line); |
346 | 1317 if (buflen < len + MAXWLEN + 2) |
1318 { | |
1319 vim_free(buf); | |
1320 buflen = len + MAXWLEN + 2; | |
1321 buf = alloc(buflen); | |
1322 if (buf == NULL) | |
1323 break; | |
1324 } | |
1325 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1326 // In first line check first word for Capital. |
385 | 1327 if (lnum == 1) |
1328 capcol = 0; | |
1329 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1330 // For checking first word with a capital skip white space. |
385 | 1331 if (capcol == 0) |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1332 capcol = getwhitecols(line); |
835 | 1333 else if (curline && wp == curwin) |
1334 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1335 // For spellbadword(): check if first word needs a capital. |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
1336 col = getwhitecols(line); |
835 | 1337 if (check_need_cap(lnum, col)) |
1338 capcol = col; | |
1339 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1340 // Need to get the line again, may have looked at the previous |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1341 // one. |
835 | 1342 line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
1343 } | |
385 | 1344 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1345 // Copy the line into "buf" and append the start of the next line if |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1346 // possible. |
346 | 1347 STRCPY(buf, line); |
498 | 1348 if (lnum < wp->w_buffer->b_ml.ml_line_count) |
883 | 1349 spell_cat_line(buf + STRLEN(buf), |
1350 ml_get_buf(wp->w_buffer, lnum + 1, FALSE), MAXWLEN); | |
346 | 1351 |
1352 p = buf + skip; | |
1353 endp = buf + len; | |
1354 while (p < endp) | |
236 | 1355 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1356 // When searching backward don't search after the cursor. Unless |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1357 // we wrapped around the end of the buffer. |
300 | 1358 if (dir == BACKWARD |
498 | 1359 && lnum == wp->w_cursor.lnum |
500 | 1360 && !wrapped |
498 | 1361 && (colnr_T)(p - buf) >= wp->w_cursor.col) |
300 | 1362 break; |
249 | 1363 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1364 // start of word |
534 | 1365 attr = HLF_COUNT; |
625 | 1366 len = spell_check(wp, p, &attr, &capcol, FALSE); |
249 | 1367 |
534 | 1368 if (attr != HLF_COUNT) |
300 | 1369 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1370 // We found a bad word. Check the attribute. |
534 | 1371 if (allwords || attr == HLF_SPB) |
236 | 1372 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1373 // When searching forward only accept a bad word after |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1374 // the cursor. |
300 | 1375 if (dir == BACKWARD |
500 | 1376 || lnum != wp->w_cursor.lnum |
498 | 1377 || (lnum == wp->w_cursor.lnum |
500 | 1378 && (wrapped |
1379 || (colnr_T)(curline ? p - buf + len | |
346 | 1380 : p - buf) |
500 | 1381 > wp->w_cursor.col))) |
236 | 1382 { |
5519 | 1383 #ifdef FEAT_SYN_HL |
300 | 1384 if (has_syntax) |
249 | 1385 { |
835 | 1386 col = (int)(p - buf); |
498 | 1387 (void)syn_get_id(wp, lnum, (colnr_T)col, |
1504 | 1388 FALSE, &can_spell, FALSE); |
857 | 1389 if (!can_spell) |
1390 attr = HLF_COUNT; | |
300 | 1391 } |
1392 else | |
737 | 1393 #endif |
300 | 1394 can_spell = TRUE; |
249 | 1395 |
300 | 1396 if (can_spell) |
1397 { | |
857 | 1398 found_one = TRUE; |
300 | 1399 found_pos.lnum = lnum; |
835 | 1400 found_pos.col = (int)(p - buf); |
300 | 1401 found_pos.coladd = 0; |
1402 if (dir == FORWARD) | |
1403 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1404 // No need to search further. |
498 | 1405 wp->w_cursor = found_pos; |
346 | 1406 vim_free(buf); |
498 | 1407 if (attrp != NULL) |
1408 *attrp = attr; | |
495 | 1409 return len; |
249 | 1410 } |
483 | 1411 else if (curline) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1412 // Insert mode completion: put cursor after |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1413 // the bad word. |
483 | 1414 found_pos.col += len; |
495 | 1415 found_len = len; |
249 | 1416 } |
236 | 1417 } |
857 | 1418 else |
1419 found_one = TRUE; | |
236 | 1420 } |
1421 } | |
1422 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1423 // advance to character after the word |
300 | 1424 p += len; |
385 | 1425 capcol -= len; |
236 | 1426 } |
1427 | |
483 | 1428 if (dir == BACKWARD && found_pos.lnum != 0) |
1429 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1430 // Use the last match in the line (before the cursor). |
498 | 1431 wp->w_cursor = found_pos; |
483 | 1432 vim_free(buf); |
495 | 1433 return found_len; |
483 | 1434 } |
1435 | |
323 | 1436 if (curline) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1437 break; // only check cursor line |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1438 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1439 // If we are back at the starting line and searched it again there |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1440 // is no match, give up. |
10950
2297aae8e127
patch 8.0.0364: ]s does not move cursor with two spell errors in one line
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1441 if (lnum == wp->w_cursor.lnum && wrapped) |
2297aae8e127
patch 8.0.0364: ]s does not move cursor with two spell errors in one line
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1442 break; |
2297aae8e127
patch 8.0.0364: ]s does not move cursor with two spell errors in one line
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1443 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1444 // Advance to next line. |
249 | 1445 if (dir == BACKWARD) |
1446 { | |
500 | 1447 if (lnum > 1) |
1448 --lnum; | |
1449 else if (!p_ws) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1450 break; // at first line and 'nowrapscan' |
500 | 1451 else |
1452 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1453 // Wrap around to the end of the buffer. May search the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1454 // starting line again and accept the last match. |
500 | 1455 lnum = wp->w_buffer->b_ml.ml_line_count; |
1456 wrapped = TRUE; | |
503 | 1457 if (!shortmess(SHM_SEARCH)) |
1458 give_warning((char_u *)_(top_bot_msg), TRUE); | |
500 | 1459 } |
385 | 1460 capcol = -1; |
249 | 1461 } |
1462 else | |
1463 { | |
500 | 1464 if (lnum < wp->w_buffer->b_ml.ml_line_count) |
1465 ++lnum; | |
1466 else if (!p_ws) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1467 break; // at first line and 'nowrapscan' |
500 | 1468 else |
1469 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1470 // Wrap around to the start of the buffer. May search the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1471 // starting line again and accept the first match. |
500 | 1472 lnum = 1; |
1473 wrapped = TRUE; | |
503 | 1474 if (!shortmess(SHM_SEARCH)) |
1475 give_warning((char_u *)_(bot_top_msg), TRUE); | |
500 | 1476 } |
1477 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1478 // If we are back at the starting line and there is no match then |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1479 // give up. |
10950
2297aae8e127
patch 8.0.0364: ]s does not move cursor with two spell errors in one line
Christian Brabandt <cb@256bit.org>
parents:
10359
diff
changeset
|
1480 if (lnum == wp->w_cursor.lnum && !found_one) |
346 | 1481 break; |
1482 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1483 // Skip the characters at the start of the next line that were |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1484 // included in a match crossing line boundaries. |
534 | 1485 if (attr == HLF_COUNT) |
835 | 1486 skip = (int)(p - endp); |
346 | 1487 else |
1488 skip = 0; | |
385 | 1489 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1490 // Capcol skips over the inserted space. |
385 | 1491 --capcol; |
1492 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1493 // But after empty line check first word in next line |
385 | 1494 if (*skipwhite(line) == NUL) |
1495 capcol = 0; | |
249 | 1496 } |
236 | 1497 |
1498 line_breakcheck(); | |
1499 } | |
1500 | |
346 | 1501 vim_free(buf); |
495 | 1502 return 0; |
346 | 1503 } |
1504 | |
1505 /* | |
1506 * For spell checking: concatenate the start of the following line "line" into | |
1507 * "buf", blanking-out special characters. Copy less then "maxlen" bytes. | |
1577 | 1508 * Keep the blanks at the start of the next line, this is used in win_line() |
1509 * to skip those bytes if the word was OK. | |
346 | 1510 */ |
1511 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1512 spell_cat_line(char_u *buf, char_u *line, int maxlen) |
346 | 1513 { |
1514 char_u *p; | |
1515 int n; | |
1516 | |
1517 p = skipwhite(line); | |
1518 while (vim_strchr((char_u *)"*#/\"\t", *p) != NULL) | |
1519 p = skipwhite(p + 1); | |
1520 | |
1521 if (*p != NUL) | |
1522 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1523 // Only worth concatenating if there is something else than spaces to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1524 // concatenate. |
1577 | 1525 n = (int)(p - line) + 1; |
1526 if (n < maxlen - 1) | |
1527 { | |
1528 vim_memset(buf, ' ', n); | |
1529 vim_strncpy(buf + n, p, maxlen - 1 - n); | |
1530 } | |
346 | 1531 } |
236 | 1532 } |
1533 | |
626 | 1534 /* |
1535 * Structure used for the cookie argument of do_in_runtimepath(). | |
1536 */ | |
501 | 1537 typedef struct spelload_S |
1538 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1539 char_u sl_lang[MAXWLEN + 1]; // language name |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1540 slang_T *sl_slang; // resulting slang_T struct |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1541 int sl_nobreak; // NOBREAK language found |
501 | 1542 } spelload_T; |
1543 | |
236 | 1544 /* |
307 | 1545 * Load word list(s) for "lang" from Vim spell file(s). |
310 | 1546 * "lang" must be the language without the region: e.g., "en". |
236 | 1547 */ |
307 | 1548 static void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1549 spell_load_lang(char_u *lang) |
236 | 1550 { |
310 | 1551 char_u fname_enc[85]; |
236 | 1552 int r; |
501 | 1553 spelload_T sl; |
649 | 1554 int round; |
307 | 1555 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1556 // Copy the language name to pass it to spell_load_cb() as a cookie. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1557 // It's truncated when an error is detected. |
501 | 1558 STRCPY(sl.sl_lang, lang); |
1559 sl.sl_slang = NULL; | |
1560 sl.sl_nobreak = FALSE; | |
307 | 1561 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1562 // We may retry when no spell file is found for the language, an |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1563 // autocommand may load it then. |
649 | 1564 for (round = 1; round <= 2; ++round) |
1565 { | |
1566 /* | |
1567 * Find the first spell file for "lang" in 'runtimepath' and load it. | |
1568 */ | |
1569 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5, | |
2660 | 1570 #ifdef VMS |
1571 "spell/%s_%s.spl", | |
1572 #else | |
1573 "spell/%s.%s.spl", | |
1574 #endif | |
1575 lang, spell_enc()); | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
1576 r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl); |
649 | 1577 |
1578 if (r == FAIL && *sl.sl_lang != NUL) | |
1579 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1580 // Try loading the ASCII version. |
649 | 1581 vim_snprintf((char *)fname_enc, sizeof(fname_enc) - 5, |
2660 | 1582 #ifdef VMS |
1583 "spell/%s_ascii.spl", | |
1584 #else | |
1585 "spell/%s.ascii.spl", | |
1586 #endif | |
1587 lang); | |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
1588 r = do_in_runtimepath(fname_enc, 0, spell_load_cb, &sl); |
649 | 1589 |
1590 if (r == FAIL && *sl.sl_lang != NUL && round == 1 | |
1591 && apply_autocmds(EVENT_SPELLFILEMISSING, lang, | |
1592 curbuf->b_fname, FALSE, curbuf)) | |
1593 continue; | |
1594 break; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13308
diff
changeset
|
1595 } |
714 | 1596 break; |
307 | 1597 } |
1598 | |
1599 if (r == FAIL) | |
649 | 1600 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
1601 smsg( |
2660 | 1602 #ifdef VMS |
1603 _("Warning: Cannot find word list \"%s_%s.spl\" or \"%s_ascii.spl\""), | |
1604 #else | |
1605 _("Warning: Cannot find word list \"%s.%s.spl\" or \"%s.ascii.spl\""), | |
1606 #endif | |
483 | 1607 lang, spell_enc(), lang); |
649 | 1608 } |
501 | 1609 else if (sl.sl_slang != NULL) |
1610 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1611 // At least one file was loaded, now load ALL the additions. |
310 | 1612 STRCPY(fname_enc + STRLEN(fname_enc) - 3, "add.spl"); |
8524
2f57bbe870ea
commit https://github.com/vim/vim/commit/7f8989dd8a627af2185df381195351a913f3777f
Christian Brabandt <cb@256bit.org>
parents:
7835
diff
changeset
|
1613 do_in_runtimepath(fname_enc, DIP_ALL, spell_load_cb, &sl); |
310 | 1614 } |
1615 } | |
1616 | |
1617 /* | |
1618 * Return the encoding used for spell checking: Use 'encoding', except that we | |
1619 * use "latin1" for "latin9". And limit to 60 characters (just in case). | |
1620 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1621 char_u * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1622 spell_enc(void) |
310 | 1623 { |
1624 | |
1625 if (STRLEN(p_enc) < 60 && STRCMP(p_enc, "iso-8859-15") != 0) | |
1626 return p_enc; | |
1627 return (char_u *)"latin1"; | |
236 | 1628 } |
1629 | |
1630 /* | |
385 | 1631 * Get the name of the .spl file for the internal wordlist into |
1632 * "fname[MAXPATHL]". | |
1633 */ | |
1634 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1635 int_wordlist_spl(char_u *fname) |
385 | 1636 { |
2660 | 1637 vim_snprintf((char *)fname, MAXPATHL, SPL_FNAME_TMPL, |
385 | 1638 int_wordlist, spell_enc()); |
1639 } | |
1640 | |
1641 /* | |
625 | 1642 * Allocate a new slang_T for language "lang". "lang" can be NULL. |
236 | 1643 * Caller must fill "sl_next". |
1644 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1645 slang_T * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1646 slang_alloc(char_u *lang) |
236 | 1647 { |
1648 slang_T *lp; | |
1649 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1650 lp = ALLOC_CLEAR_ONE(slang_T); |
236 | 1651 if (lp != NULL) |
1652 { | |
625 | 1653 if (lang != NULL) |
1654 lp->sl_name = vim_strsave(lang); | |
323 | 1655 ga_init2(&lp->sl_rep, sizeof(fromto_T), 10); |
625 | 1656 ga_init2(&lp->sl_repsal, sizeof(fromto_T), 10); |
483 | 1657 lp->sl_compmax = MAXWLEN; |
1658 lp->sl_compsylmax = MAXWLEN; | |
625 | 1659 hash_init(&lp->sl_wordcount); |
1660 } | |
1661 | |
236 | 1662 return lp; |
1663 } | |
1664 | |
1665 /* | |
1666 * Free the contents of an slang_T and the structure itself. | |
1667 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1668 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1669 slang_free(slang_T *lp) |
236 | 1670 { |
1671 vim_free(lp->sl_name); | |
310 | 1672 vim_free(lp->sl_fname); |
1673 slang_clear(lp); | |
1674 vim_free(lp); | |
1675 } | |
1676 | |
1677 /* | |
1678 * Clear an slang_T so that the file can be reloaded. | |
1679 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1680 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1681 slang_clear(slang_T *lp) |
310 | 1682 { |
339 | 1683 garray_T *gap; |
1684 fromto_T *ftp; | |
344 | 1685 salitem_T *smp; |
339 | 1686 int i; |
625 | 1687 int round; |
323 | 1688 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1689 VIM_CLEAR(lp->sl_fbyts); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1690 VIM_CLEAR(lp->sl_kbyts); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1691 VIM_CLEAR(lp->sl_pbyts); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1692 |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1693 VIM_CLEAR(lp->sl_fidxs); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1694 VIM_CLEAR(lp->sl_kidxs); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1695 VIM_CLEAR(lp->sl_pidxs); |
323 | 1696 |
625 | 1697 for (round = 1; round <= 2; ++round) |
1698 { | |
1699 gap = round == 1 ? &lp->sl_rep : &lp->sl_repsal; | |
1700 while (gap->ga_len > 0) | |
1701 { | |
1702 ftp = &((fromto_T *)gap->ga_data)[--gap->ga_len]; | |
1703 vim_free(ftp->ft_from); | |
1704 vim_free(ftp->ft_to); | |
1705 } | |
1706 ga_clear(gap); | |
1707 } | |
344 | 1708 |
1709 gap = &lp->sl_sal; | |
375 | 1710 if (lp->sl_sofo) |
376 | 1711 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1712 // "ga_len" is set to 1 without adding an item for latin1 |
376 | 1713 if (gap->ga_data != NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1714 // SOFOFROM and SOFOTO items: free lists of wide characters. |
376 | 1715 for (i = 0; i < gap->ga_len; ++i) |
1716 vim_free(((int **)gap->ga_data)[i]); | |
1717 } | |
375 | 1718 else |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1719 // SAL items: free salitem_T items |
375 | 1720 while (gap->ga_len > 0) |
1721 { | |
1722 smp = &((salitem_T *)gap->ga_data)[--gap->ga_len]; | |
1723 vim_free(smp->sm_lead); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1724 // Don't free sm_oneof and sm_rules, they point into sm_lead. |
375 | 1725 vim_free(smp->sm_to); |
1726 vim_free(smp->sm_lead_w); | |
1727 vim_free(smp->sm_oneof_w); | |
1728 vim_free(smp->sm_to_w); | |
1729 } | |
344 | 1730 ga_clear(gap); |
323 | 1731 |
339 | 1732 for (i = 0; i < lp->sl_prefixcnt; ++i) |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1733 vim_regfree(lp->sl_prefprog[i]); |
376 | 1734 lp->sl_prefixcnt = 0; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1735 VIM_CLEAR(lp->sl_prefprog); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1736 |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1737 VIM_CLEAR(lp->sl_info); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1738 |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1739 VIM_CLEAR(lp->sl_midword); |
339 | 1740 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
1741 vim_regfree(lp->sl_compprog); |
483 | 1742 lp->sl_compprog = NULL; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1743 VIM_CLEAR(lp->sl_comprules); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1744 VIM_CLEAR(lp->sl_compstartflags); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1745 VIM_CLEAR(lp->sl_compallflags); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1746 |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1747 VIM_CLEAR(lp->sl_syllable); |
483 | 1748 ga_clear(&lp->sl_syl_items); |
481 | 1749 |
809 | 1750 ga_clear_strings(&lp->sl_comppat); |
1751 | |
625 | 1752 hash_clear_all(&lp->sl_wordcount, WC_KEY_OFF); |
1753 hash_init(&lp->sl_wordcount); | |
1754 | |
1755 hash_clear_all(&lp->sl_map_hash, 0); | |
1756 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1757 // Clear info from .sug file. |
625 | 1758 slang_clear_sug(lp); |
483 | 1759 |
1760 lp->sl_compmax = MAXWLEN; | |
501 | 1761 lp->sl_compminlen = 0; |
483 | 1762 lp->sl_compsylmax = MAXWLEN; |
1763 lp->sl_regions[0] = NUL; | |
236 | 1764 } |
1765 | |
1766 /* | |
625 | 1767 * Clear the info from the .sug file in "lp". |
1768 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1769 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1770 slang_clear_sug(slang_T *lp) |
625 | 1771 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1772 VIM_CLEAR(lp->sl_sbyts); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
1773 VIM_CLEAR(lp->sl_sidxs); |
625 | 1774 close_spellbuf(lp->sl_sugbuf); |
1775 lp->sl_sugbuf = NULL; | |
1776 lp->sl_sugloaded = FALSE; | |
1777 lp->sl_sugtime = 0; | |
1778 } | |
1779 | |
1780 /* | |
307 | 1781 * Load one spell file and store the info into a slang_T. |
236 | 1782 * Invoked through do_in_runtimepath(). |
1783 */ | |
1784 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1785 spell_load_cb(char_u *fname, void *cookie) |
501 | 1786 { |
1787 spelload_T *slp = (spelload_T *)cookie; | |
1788 slang_T *slang; | |
1789 | |
1790 slang = spell_load_file(fname, slp->sl_lang, NULL, FALSE); | |
1791 if (slang != NULL) | |
1792 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1793 // When a previously loaded file has NOBREAK also use it for the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1794 // ".add" files. |
501 | 1795 if (slp->sl_nobreak && slang->sl_add) |
1796 slang->sl_nobreak = TRUE; | |
1797 else if (slang->sl_nobreak) | |
1798 slp->sl_nobreak = TRUE; | |
1799 | |
1800 slp->sl_slang = slang; | |
1801 } | |
310 | 1802 } |
1803 | |
625 | 1804 |
1805 /* | |
1806 * Add a word to the hashtable of common words. | |
1807 * If it's already there then the counter is increased. | |
1808 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1809 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1810 count_common_word( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1811 slang_T *lp, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1812 char_u *word, |
19195
2ef19eed524a
patch 8.2.0156: various typos in source files and tests
Bram Moolenaar <Bram@vim.org>
parents:
18814
diff
changeset
|
1813 int len, // word length, -1 for up to NUL |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1814 int count) // 1 to count once, 10 to init |
625 | 1815 { |
1816 hash_T hash; | |
1817 hashitem_T *hi; | |
1818 wordcount_T *wc; | |
1819 char_u buf[MAXWLEN]; | |
1820 char_u *p; | |
1821 | |
1822 if (len == -1) | |
1823 p = word; | |
17653
cc68aca87c17
patch 8.1.1824: crash when correctly spelled word is very long
Bram Moolenaar <Bram@vim.org>
parents:
17434
diff
changeset
|
1824 else if (len >= MAXWLEN) |
cc68aca87c17
patch 8.1.1824: crash when correctly spelled word is very long
Bram Moolenaar <Bram@vim.org>
parents:
17434
diff
changeset
|
1825 return; |
625 | 1826 else |
1827 { | |
1828 vim_strncpy(buf, word, len); | |
1829 p = buf; | |
1830 } | |
1831 | |
1832 hash = hash_hash(p); | |
1833 hi = hash_lookup(&lp->sl_wordcount, p, hash); | |
1834 if (HASHITEM_EMPTY(hi)) | |
1835 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
1836 wc = alloc(sizeof(wordcount_T) + STRLEN(p)); |
625 | 1837 if (wc == NULL) |
1838 return; | |
1839 STRCPY(wc->wc_word, p); | |
1840 wc->wc_count = count; | |
1841 hash_add_item(&lp->sl_wordcount, hi, wc->wc_word, hash); | |
1842 } | |
1843 else | |
1844 { | |
1845 wc = HI2WC(hi); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1846 if ((wc->wc_count += count) < (unsigned)count) // check for overflow |
625 | 1847 wc->wc_count = MAXWORDCOUNT; |
1848 } | |
1849 } | |
1850 | |
1851 /* | |
498 | 1852 * Return TRUE if byte "n" appears in "str". |
495 | 1853 * Like strchr() but independent of locale. |
1854 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1855 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1856 byte_in_str(char_u *str, int n) |
495 | 1857 { |
1858 char_u *p; | |
1859 | |
1860 for (p = str; *p != NUL; ++p) | |
498 | 1861 if (*p == n) |
495 | 1862 return TRUE; |
1863 return FALSE; | |
1864 } | |
1865 | |
483 | 1866 #define SY_MAXLEN 30 |
1867 typedef struct syl_item_S | |
1868 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1869 char_u sy_chars[SY_MAXLEN]; // the sequence of chars |
483 | 1870 int sy_len; |
1871 } syl_item_T; | |
1872 | |
1873 /* | |
1874 * Truncate "slang->sl_syllable" at the first slash and put the following items | |
1875 * in "slang->sl_syl_items". | |
1876 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
1877 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1878 init_syl_tab(slang_T *slang) |
483 | 1879 { |
1880 char_u *p; | |
1881 char_u *s; | |
1882 int l; | |
1883 syl_item_T *syl; | |
1884 | |
1885 ga_init2(&slang->sl_syl_items, sizeof(syl_item_T), 4); | |
1886 p = vim_strchr(slang->sl_syllable, '/'); | |
1887 while (p != NULL) | |
1888 { | |
1889 *p++ = NUL; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1890 if (*p == NUL) // trailing slash |
483 | 1891 break; |
1892 s = p; | |
1893 p = vim_strchr(p, '/'); | |
1894 if (p == NULL) | |
835 | 1895 l = (int)STRLEN(s); |
483 | 1896 else |
835 | 1897 l = (int)(p - s); |
483 | 1898 if (l >= SY_MAXLEN) |
1899 return SP_FORMERROR; | |
1900 if (ga_grow(&slang->sl_syl_items, 1) == FAIL) | |
495 | 1901 return SP_OTHERERROR; |
483 | 1902 syl = ((syl_item_T *)slang->sl_syl_items.ga_data) |
1903 + slang->sl_syl_items.ga_len++; | |
1904 vim_strncpy(syl->sy_chars, s, l); | |
1905 syl->sy_len = l; | |
1906 } | |
1907 return OK; | |
1908 } | |
1909 | |
1910 /* | |
1911 * Count the number of syllables in "word". | |
1912 * When "word" contains spaces the syllables after the last space are counted. | |
1913 * Returns zero if syllables are not defines. | |
1914 */ | |
1915 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1916 count_syllables(slang_T *slang, char_u *word) |
483 | 1917 { |
1918 int cnt = 0; | |
1919 int skip = FALSE; | |
1920 char_u *p; | |
1921 int len; | |
1922 int i; | |
1923 syl_item_T *syl; | |
1924 int c; | |
1925 | |
1926 if (slang->sl_syllable == NULL) | |
1927 return 0; | |
1928 | |
1929 for (p = word; *p != NUL; p += len) | |
1930 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1931 // When running into a space reset counter. |
483 | 1932 if (*p == ' ') |
1933 { | |
1934 len = 1; | |
1935 cnt = 0; | |
1936 continue; | |
1937 } | |
1938 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1939 // Find longest match of syllable items. |
483 | 1940 len = 0; |
1941 for (i = 0; i < slang->sl_syl_items.ga_len; ++i) | |
1942 { | |
1943 syl = ((syl_item_T *)slang->sl_syl_items.ga_data) + i; | |
1944 if (syl->sy_len > len | |
1945 && STRNCMP(p, syl->sy_chars, syl->sy_len) == 0) | |
1946 len = syl->sy_len; | |
1947 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1948 if (len != 0) // found a match, count syllable |
483 | 1949 { |
1950 ++cnt; | |
1951 skip = FALSE; | |
1952 } | |
1953 else | |
1954 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1955 // No recognized syllable item, at least a syllable char then? |
483 | 1956 c = mb_ptr2char(p); |
1957 len = (*mb_ptr2len)(p); | |
1958 if (vim_strchr(slang->sl_syllable, c) == NULL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1959 skip = FALSE; // No, search for next syllable |
483 | 1960 else if (!skip) |
1961 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1962 ++cnt; // Yes, count it |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
1963 skip = TRUE; // don't count following syllable chars |
483 | 1964 } |
1965 } | |
1966 } | |
1967 return cnt; | |
376 | 1968 } |
1969 | |
381 | 1970 /* |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
1971 * Parse 'spelllang' and set w_s->b_langp accordingly. |
351 | 1972 * Returns NULL if it's OK, an error message otherwise. |
236 | 1973 */ |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
1974 char * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1975 did_set_spelllang(win_T *wp) |
236 | 1976 { |
1977 garray_T ga; | |
351 | 1978 char_u *splp; |
236 | 1979 char_u *region; |
416 | 1980 char_u region_cp[3]; |
355 | 1981 int filename; |
236 | 1982 int region_mask; |
503 | 1983 slang_T *slang; |
236 | 1984 int c; |
351 | 1985 char_u lang[MAXWLEN + 1]; |
323 | 1986 char_u spf_name[MAXPATHL]; |
351 | 1987 int len; |
1988 char_u *p; | |
381 | 1989 int round; |
385 | 1990 char_u *spf; |
389 | 1991 char_u *use_region = NULL; |
1992 int dont_use_region = FALSE; | |
501 | 1993 int nobreak = FALSE; |
503 | 1994 int i, j; |
1995 langp_T *lp, *lp2; | |
1185 | 1996 static int recursive = FALSE; |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
1997 char *ret_msg = NULL; |
1185 | 1998 char_u *spl_copy; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
1999 bufref_T bufref; |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2000 |
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2001 set_bufref(&bufref, wp->w_buffer); |
1185 | 2002 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2003 // We don't want to do this recursively. May happen when a language is |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2004 // not available and the SpellFileMissing autocommand opens a new buffer |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2005 // in which 'spell' is set. |
1185 | 2006 if (recursive) |
2007 return NULL; | |
2008 recursive = TRUE; | |
236 | 2009 |
2010 ga_init2(&ga, sizeof(langp_T), 2); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2011 clear_midword(wp); |
236 | 2012 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2013 // Make a copy of 'spelllang', the SpellFileMissing autocommands may change |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2014 // it under our fingers. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2015 spl_copy = vim_strsave(wp->w_s->b_p_spl); |
1185 | 2016 if (spl_copy == NULL) |
2017 goto theend; | |
2018 | |
5477 | 2019 wp->w_s->b_cjk = 0; |
2020 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2021 // Loop over comma separated language names. |
1185 | 2022 for (splp = spl_copy; *splp != NUL; ) |
351 | 2023 { |
16277
5ef25fa57f71
patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
2024 // Get one language name. |
351 | 2025 copy_option_part(&splp, lang, MAXWLEN, ","); |
240 | 2026 region = NULL; |
835 | 2027 len = (int)STRLEN(lang); |
355 | 2028 |
20760
813b9a7064a4
patch 8.2.0932: missspelling spelllang
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
2029 if (!valid_spelllang(lang)) |
16277
5ef25fa57f71
patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
2030 continue; |
5ef25fa57f71
patch 8.1.1143: may pass weird strings to file name expansion
Bram Moolenaar <Bram@vim.org>
parents:
16239
diff
changeset
|
2031 |
5477 | 2032 if (STRCMP(lang, "cjk") == 0) |
2033 { | |
2034 wp->w_s->b_cjk = 1; | |
2035 continue; | |
2036 } | |
2037 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2038 // If the name ends in ".spl" use it as the name of the spell file. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2039 // If there is a region name let "region" point to it and remove it |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2040 // from the name. |
355 | 2041 if (len > 4 && fnamecmp(lang + len - 4, ".spl") == 0) |
236 | 2042 { |
355 | 2043 filename = TRUE; |
2044 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2045 // Locate a region and remove it from the file name. |
416 | 2046 p = vim_strchr(gettail(lang), '_'); |
2047 if (p != NULL && ASCII_ISALPHA(p[1]) && ASCII_ISALPHA(p[2]) | |
2048 && !ASCII_ISALPHA(p[3])) | |
2049 { | |
2050 vim_strncpy(region_cp, p + 1, 2); | |
2051 mch_memmove(p, p + 3, len - (p - lang) - 2); | |
2052 region = region_cp; | |
2053 } | |
2054 else | |
2055 dont_use_region = TRUE; | |
2056 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2057 // Check if we loaded this language before. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
2058 FOR_ALL_SPELL_LANGS(slang) |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2059 if (fullpathcmp(lang, slang->sl_fname, FALSE, TRUE) == FPC_SAME) |
355 | 2060 break; |
236 | 2061 } |
355 | 2062 else |
2063 { | |
2064 filename = FALSE; | |
2065 if (len > 3 && lang[len - 3] == '_') | |
2066 { | |
2067 region = lang + len - 2; | |
2068 len -= 3; | |
2069 lang[len] = NUL; | |
389 | 2070 } |
2071 else | |
2072 dont_use_region = TRUE; | |
355 | 2073 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2074 // Check if we loaded this language before. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
2075 FOR_ALL_SPELL_LANGS(slang) |
503 | 2076 if (STRICMP(lang, slang->sl_name) == 0) |
355 | 2077 break; |
2078 } | |
236 | 2079 |
416 | 2080 if (region != NULL) |
2081 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2082 // If the region differs from what was used before then don't |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2083 // use it for 'spellfile'. |
416 | 2084 if (use_region != NULL && STRCMP(region, use_region) != 0) |
2085 dont_use_region = TRUE; | |
2086 use_region = region; | |
2087 } | |
2088 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2089 // If not found try loading the language now. |
503 | 2090 if (slang == NULL) |
355 | 2091 { |
2092 if (filename) | |
2093 (void)spell_load_file(lang, lang, NULL, FALSE); | |
2094 else | |
1185 | 2095 { |
355 | 2096 spell_load_lang(lang); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2097 // SpellFileMissing autocommands may do anything, including |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2098 // destroying the buffer we are using... |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
2099 if (!bufref_valid(&bufref)) |
1185 | 2100 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
2101 ret_msg = N_("E797: SpellFileMissing autocommand deleted buffer"); |
1185 | 2102 goto theend; |
2103 } | |
2104 } | |
355 | 2105 } |
236 | 2106 |
307 | 2107 /* |
351 | 2108 * Loop over the languages, there can be several files for "lang". |
307 | 2109 */ |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
2110 FOR_ALL_SPELL_LANGS(slang) |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2111 if (filename ? fullpathcmp(lang, slang->sl_fname, FALSE, TRUE) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2112 == FPC_SAME |
503 | 2113 : STRICMP(lang, slang->sl_name) == 0) |
236 | 2114 { |
316 | 2115 region_mask = REGION_ALL; |
355 | 2116 if (!filename && region != NULL) |
236 | 2117 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2118 // find region in sl_regions |
503 | 2119 c = find_region(slang->sl_regions, region); |
307 | 2120 if (c == REGION_ALL) |
2121 { | |
503 | 2122 if (slang->sl_add) |
389 | 2123 { |
503 | 2124 if (*slang->sl_regions != NUL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2125 // This addition file is for other regions. |
389 | 2126 region_mask = 0; |
2127 } | |
2128 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2129 // This is probably an error. Give a warning and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2130 // accept the words anyway. |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
2131 smsg(_("Warning: region %s not supported"), |
351 | 2132 region); |
307 | 2133 } |
2134 else | |
2135 region_mask = 1 << c; | |
236 | 2136 } |
307 | 2137 |
389 | 2138 if (region_mask != 0) |
307 | 2139 { |
389 | 2140 if (ga_grow(&ga, 1) == FAIL) |
2141 { | |
2142 ga_clear(&ga); | |
1185 | 2143 ret_msg = e_outofmem; |
2144 goto theend; | |
389 | 2145 } |
503 | 2146 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang; |
389 | 2147 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask; |
2148 ++ga.ga_len; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2149 use_midword(slang, wp); |
503 | 2150 if (slang->sl_nobreak) |
501 | 2151 nobreak = TRUE; |
307 | 2152 } |
385 | 2153 } |
2154 } | |
2155 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2156 // round 0: load int_wordlist, if possible. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2157 // round 1: load first name in 'spellfile'. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2158 // round 2: load second name in 'spellfile. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2159 // etc. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2160 spf = curwin->w_s->b_p_spf; |
385 | 2161 for (round = 0; round == 0 || *spf != NUL; ++round) |
2162 { | |
2163 if (round == 0) | |
2164 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2165 // Internal wordlist, if there is one. |
385 | 2166 if (int_wordlist == NULL) |
381 | 2167 continue; |
385 | 2168 int_wordlist_spl(spf_name); |
381 | 2169 } |
2170 else | |
2171 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2172 // One entry in 'spellfile'. |
385 | 2173 copy_option_part(&spf, spf_name, MAXPATHL - 5, ","); |
2174 STRCAT(spf_name, ".spl"); | |
2175 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2176 // If it was already found above then skip it. |
385 | 2177 for (c = 0; c < ga.ga_len; ++c) |
500 | 2178 { |
2179 p = LANGP_ENTRY(ga, c)->lp_slang->sl_fname; | |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2180 if (p != NULL && fullpathcmp(spf_name, p, FALSE, TRUE) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2181 == FPC_SAME) |
385 | 2182 break; |
500 | 2183 } |
385 | 2184 if (c < ga.ga_len) |
381 | 2185 continue; |
2186 } | |
2187 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2188 // Check if it was loaded already. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19475
diff
changeset
|
2189 FOR_ALL_SPELL_LANGS(slang) |
16738
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2190 if (fullpathcmp(spf_name, slang->sl_fname, FALSE, TRUE) |
b52ea9c5f1db
patch 8.1.1371: cannot recover from a swap file
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2191 == FPC_SAME) |
323 | 2192 break; |
503 | 2193 if (slang == NULL) |
323 | 2194 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2195 // Not loaded, try loading it now. The language name includes the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2196 // region name, the region is ignored otherwise. for int_wordlist |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2197 // use an arbitrary name. |
385 | 2198 if (round == 0) |
2199 STRCPY(lang, "internal wordlist"); | |
2200 else | |
2201 { | |
2202 vim_strncpy(lang, gettail(spf_name), MAXWLEN); | |
381 | 2203 p = vim_strchr(lang, '.'); |
2204 if (p != NULL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2205 *p = NUL; // truncate at ".encoding.add" |
381 | 2206 } |
503 | 2207 slang = spell_load_file(spf_name, lang, NULL, TRUE); |
501 | 2208 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2209 // If one of the languages has NOBREAK we assume the addition |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2210 // files also have this. |
503 | 2211 if (slang != NULL && nobreak) |
2212 slang->sl_nobreak = TRUE; | |
2213 } | |
2214 if (slang != NULL && ga_grow(&ga, 1) == OK) | |
323 | 2215 { |
389 | 2216 region_mask = REGION_ALL; |
2217 if (use_region != NULL && !dont_use_region) | |
2218 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2219 // find region in sl_regions |
503 | 2220 c = find_region(slang->sl_regions, use_region); |
389 | 2221 if (c != REGION_ALL) |
2222 region_mask = 1 << c; | |
503 | 2223 else if (*slang->sl_regions != NUL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2224 // This spell file is for other regions. |
389 | 2225 region_mask = 0; |
2226 } | |
2227 | |
2228 if (region_mask != 0) | |
2229 { | |
503 | 2230 LANGP_ENTRY(ga, ga.ga_len)->lp_slang = slang; |
2231 LANGP_ENTRY(ga, ga.ga_len)->lp_sallang = NULL; | |
2232 LANGP_ENTRY(ga, ga.ga_len)->lp_replang = NULL; | |
389 | 2233 LANGP_ENTRY(ga, ga.ga_len)->lp_region = region_mask; |
2234 ++ga.ga_len; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2235 use_midword(slang, wp); |
389 | 2236 } |
323 | 2237 } |
2238 } | |
2239 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2240 // Everything is fine, store the new b_langp value. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2241 ga_clear(&wp->w_s->b_langp); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2242 wp->w_s->b_langp = ga; |
236 | 2243 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2244 // For each language figure out what language to use for sound folding and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2245 // REP items. If the language doesn't support it itself use another one |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2246 // with the same name. E.g. for "en-math" use "en". |
503 | 2247 for (i = 0; i < ga.ga_len; ++i) |
2248 { | |
2249 lp = LANGP_ENTRY(ga, i); | |
2250 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2251 // sound folding |
503 | 2252 if (lp->lp_slang->sl_sal.ga_len > 0) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2253 // language does sound folding itself |
503 | 2254 lp->lp_sallang = lp->lp_slang; |
2255 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2256 // find first similar language that does sound folding |
503 | 2257 for (j = 0; j < ga.ga_len; ++j) |
2258 { | |
2259 lp2 = LANGP_ENTRY(ga, j); | |
2260 if (lp2->lp_slang->sl_sal.ga_len > 0 | |
2261 && STRNCMP(lp->lp_slang->sl_name, | |
2262 lp2->lp_slang->sl_name, 2) == 0) | |
2263 { | |
2264 lp->lp_sallang = lp2->lp_slang; | |
2265 break; | |
2266 } | |
2267 } | |
2268 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2269 // REP items |
503 | 2270 if (lp->lp_slang->sl_rep.ga_len > 0) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2271 // language has REP items itself |
503 | 2272 lp->lp_replang = lp->lp_slang; |
2273 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2274 // find first similar language that has REP items |
503 | 2275 for (j = 0; j < ga.ga_len; ++j) |
2276 { | |
2277 lp2 = LANGP_ENTRY(ga, j); | |
2278 if (lp2->lp_slang->sl_rep.ga_len > 0 | |
2279 && STRNCMP(lp->lp_slang->sl_name, | |
2280 lp2->lp_slang->sl_name, 2) == 0) | |
2281 { | |
2282 lp->lp_replang = lp2->lp_slang; | |
2283 break; | |
2284 } | |
2285 } | |
2286 } | |
2287 | |
1185 | 2288 theend: |
2289 vim_free(spl_copy); | |
2290 recursive = FALSE; | |
5891 | 2291 redraw_win_later(wp, NOT_VALID); |
1185 | 2292 return ret_msg; |
236 | 2293 } |
2294 | |
2295 /* | |
376 | 2296 * Clear the midword characters for buffer "buf". |
2297 */ | |
2298 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2299 clear_midword(win_T *wp) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2300 { |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2301 CLEAR_FIELD(wp->w_s->b_spell_ismw); |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2302 VIM_CLEAR(wp->w_s->b_spell_ismw_mb); |
376 | 2303 } |
2304 | |
2305 /* | |
2306 * Use the "sl_midword" field of language "lp" for buffer "buf". | |
2307 * They add up to any currently used midword characters. | |
2308 */ | |
2309 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2310 use_midword(slang_T *lp, win_T *wp) |
376 | 2311 { |
2312 char_u *p; | |
2313 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2314 if (lp->sl_midword == NULL) // there aren't any |
389 | 2315 return; |
2316 | |
376 | 2317 for (p = lp->sl_midword; *p != NUL; ) |
2318 if (has_mbyte) | |
2319 { | |
2320 int c, l, n; | |
2321 char_u *bp; | |
2322 | |
2323 c = mb_ptr2char(p); | |
474 | 2324 l = (*mb_ptr2len)(p); |
2325 if (c < 256 && l <= 2) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2326 wp->w_s->b_spell_ismw[c] = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2327 else if (wp->w_s->b_spell_ismw_mb == NULL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2328 // First multi-byte char in "b_spell_ismw_mb". |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2329 wp->w_s->b_spell_ismw_mb = vim_strnsave(p, l); |
376 | 2330 else |
2331 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2332 // Append multi-byte chars to "b_spell_ismw_mb". |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2333 n = (int)STRLEN(wp->w_s->b_spell_ismw_mb); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2334 bp = vim_strnsave(wp->w_s->b_spell_ismw_mb, n + l); |
376 | 2335 if (bp != NULL) |
2336 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2337 vim_free(wp->w_s->b_spell_ismw_mb); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2338 wp->w_s->b_spell_ismw_mb = bp; |
376 | 2339 vim_strncpy(bp + n, p, l); |
2340 } | |
2341 } | |
2342 p += l; | |
2343 } | |
2344 else | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2345 wp->w_s->b_spell_ismw[*p++] = TRUE; |
376 | 2346 } |
2347 | |
2348 /* | |
236 | 2349 * Find the region "region[2]" in "rp" (points to "sl_regions"). |
15034
6e4e0d43b20b
patch 8.1.0528: various typos in comments
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2350 * Each region is simply stored as the two characters of its name. |
381 | 2351 * Returns the index if found (first is 0), REGION_ALL if not found. |
236 | 2352 */ |
2353 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2354 find_region(char_u *rp, char_u *region) |
236 | 2355 { |
2356 int i; | |
2357 | |
2358 for (i = 0; ; i += 2) | |
2359 { | |
2360 if (rp[i] == NUL) | |
2361 return REGION_ALL; | |
2362 if (rp[i] == region[0] && rp[i + 1] == region[1]) | |
2363 break; | |
2364 } | |
2365 return i / 2; | |
2366 } | |
2367 | |
2368 /* | |
323 | 2369 * Return case type of word: |
236 | 2370 * w word 0 |
300 | 2371 * Word WF_ONECAP |
2372 * W WORD WF_ALLCAP | |
2373 * WoRd wOrd WF_KEEPCAP | |
236 | 2374 */ |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2375 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2376 captype( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2377 char_u *word, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2378 char_u *end) // When NULL use up to NUL byte. |
236 | 2379 { |
2380 char_u *p; | |
2381 int c; | |
2382 int firstcap; | |
2383 int allcap; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2384 int past_second = FALSE; // past second word char |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2385 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2386 // find first letter |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2387 for (p = word; !spell_iswordp_nmw(p, curwin); MB_PTR_ADV(p)) |
323 | 2388 if (end == NULL ? *p == NUL : p >= end) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2389 return 0; // only non-word characters, illegal word |
310 | 2390 if (has_mbyte) |
2391 c = mb_ptr2char_adv(&p); | |
2392 else | |
2393 c = *p++; | |
324 | 2394 firstcap = allcap = SPELL_ISUPPER(c); |
236 | 2395 |
2396 /* | |
2397 * Need to check all letters to find a word with mixed upper/lower. | |
2398 * But a word with an upper char only at start is a ONECAP. | |
2399 */ | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2400 for ( ; end == NULL ? *p != NUL : p < end; MB_PTR_ADV(p)) |
5477 | 2401 if (spell_iswordp_nmw(p, curwin)) |
236 | 2402 { |
455 | 2403 c = PTR2CHAR(p); |
324 | 2404 if (!SPELL_ISUPPER(c)) |
236 | 2405 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2406 // UUl -> KEEPCAP |
236 | 2407 if (past_second && allcap) |
300 | 2408 return WF_KEEPCAP; |
236 | 2409 allcap = FALSE; |
2410 } | |
2411 else if (!allcap) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2412 // UlU -> KEEPCAP |
300 | 2413 return WF_KEEPCAP; |
236 | 2414 past_second = TRUE; |
2415 } | |
2416 | |
2417 if (allcap) | |
300 | 2418 return WF_ALLCAP; |
236 | 2419 if (firstcap) |
300 | 2420 return WF_ONECAP; |
236 | 2421 return 0; |
2422 } | |
2423 | |
474 | 2424 /* |
5519 | 2425 * Delete the internal wordlist and its .spl file. |
2426 */ | |
2427 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2428 spell_delete_wordlist(void) |
5519 | 2429 { |
2430 char_u fname[MAXPATHL]; | |
2431 | |
2432 if (int_wordlist != NULL) | |
2433 { | |
2434 mch_remove(int_wordlist); | |
2435 int_wordlist_spl(fname); | |
2436 mch_remove(fname); | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2437 VIM_CLEAR(int_wordlist); |
5519 | 2438 } |
2439 } | |
2440 | |
355 | 2441 /* |
2442 * Free all languages. | |
2443 */ | |
2444 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2445 spell_free_all(void) |
355 | 2446 { |
503 | 2447 slang_T *slang; |
355 | 2448 buf_T *buf; |
2449 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2450 // Go through all buffers and handle 'spelllang'. <VN> |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9583
diff
changeset
|
2451 FOR_ALL_BUFFERS(buf) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2452 ga_clear(&buf->b_s.b_langp); |
355 | 2453 |
2454 while (first_lang != NULL) | |
2455 { | |
503 | 2456 slang = first_lang; |
2457 first_lang = slang->sl_next; | |
2458 slang_free(slang); | |
355 | 2459 } |
366 | 2460 |
5519 | 2461 spell_delete_wordlist(); |
381 | 2462 |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2463 VIM_CLEAR(repl_to); |
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12674
diff
changeset
|
2464 VIM_CLEAR(repl_from); |
355 | 2465 } |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
2466 |
236 | 2467 /* |
2468 * Clear all spelling tables and reload them. | |
307 | 2469 * Used after 'encoding' is set and when ":mkspell" was used. |
236 | 2470 */ |
2471 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2472 spell_reload(void) |
236 | 2473 { |
316 | 2474 win_T *wp; |
236 | 2475 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2476 // Initialize the table for spell_iswordp(). |
236 | 2477 init_spell_chartab(); |
2478 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2479 // Unload all allocated memory. |
355 | 2480 spell_free_all(); |
236 | 2481 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2482 // Go through all buffers and handle 'spelllang'. |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9583
diff
changeset
|
2483 FOR_ALL_WINDOWS(wp) |
236 | 2484 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2485 // Only load the wordlists when 'spelllang' is set and there is a |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2486 // window for this buffer in which 'spell' is set. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2487 if (*wp->w_s->b_p_spl != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2488 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2489 if (wp->w_p_spell) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2490 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2491 (void)did_set_spelllang(wp); |
316 | 2492 break; |
2493 } | |
2494 } | |
236 | 2495 } |
2496 } | |
2497 | |
310 | 2498 /* |
625 | 2499 * Open a spell buffer. This is a nameless buffer that is not in the buffer |
2500 * list and only contains text lines. Can use a swapfile to reduce memory | |
2501 * use. | |
2502 * Most other fields are invalid! Esp. watch out for string options being | |
2503 * NULL and there is no undo info. | |
2504 * Returns NULL when out of memory. | |
2505 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2506 buf_T * |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2507 open_spellbuf(void) |
625 | 2508 { |
2509 buf_T *buf; | |
2510 | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
2511 buf = ALLOC_CLEAR_ONE(buf_T); |
625 | 2512 if (buf != NULL) |
2513 { | |
2514 buf->b_spell = TRUE; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2515 buf->b_p_swf = TRUE; // may create a swap file |
5204
7aca84c0cd37
updated for version 7.4a.028
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2516 #ifdef FEAT_CRYPT |
7aca84c0cd37
updated for version 7.4a.028
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2517 buf->b_p_key = empty_option; |
7aca84c0cd37
updated for version 7.4a.028
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2518 #endif |
625 | 2519 ml_open(buf); |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2520 ml_open_file(buf); // create swap file now |
625 | 2521 } |
2522 return buf; | |
2523 } | |
2524 | |
2525 /* | |
2526 * Close the buffer used for spell info. | |
2527 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2528 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2529 close_spellbuf(buf_T *buf) |
625 | 2530 { |
2531 if (buf != NULL) | |
2532 { | |
2533 ml_close(buf, TRUE); | |
2534 vim_free(buf); | |
2535 } | |
2536 } | |
2537 | |
307 | 2538 /* |
2539 * Init the chartab used for spelling for ASCII. | |
2540 * EBCDIC is not supported! | |
2541 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2542 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2543 clear_spell_chartab(spelltab_T *sp) |
307 | 2544 { |
324 | 2545 int i; |
307 | 2546 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2547 // Init everything to FALSE (zero). |
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2548 CLEAR_FIELD(sp->st_isw); |
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
2549 CLEAR_FIELD(sp->st_isu); |
307 | 2550 for (i = 0; i < 256; ++i) |
324 | 2551 { |
307 | 2552 sp->st_fold[i] = i; |
324 | 2553 sp->st_upper[i] = i; |
2554 } | |
307 | 2555 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2556 // We include digits. A word shouldn't start with a digit, but handling |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2557 // that is done separately. |
307 | 2558 for (i = '0'; i <= '9'; ++i) |
2559 sp->st_isw[i] = TRUE; | |
2560 for (i = 'A'; i <= 'Z'; ++i) | |
2561 { | |
2562 sp->st_isw[i] = TRUE; | |
2563 sp->st_isu[i] = TRUE; | |
2564 sp->st_fold[i] = i + 0x20; | |
2565 } | |
2566 for (i = 'a'; i <= 'z'; ++i) | |
324 | 2567 { |
307 | 2568 sp->st_isw[i] = TRUE; |
324 | 2569 sp->st_upper[i] = i - 0x20; |
2570 } | |
307 | 2571 } |
2572 | |
2573 /* | |
2574 * Init the chartab used for spelling. Only depends on 'encoding'. | |
2575 * Called once while starting up and when 'encoding' changes. | |
2576 * The default is to use isalpha(), but the spell file should define the word | |
2577 * characters to make it possible that 'encoding' differs from the current | |
390 | 2578 * locale. For utf-8 we don't use isalpha() but our own functions. |
307 | 2579 */ |
2580 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2581 init_spell_chartab(void) |
307 | 2582 { |
2583 int i; | |
2584 | |
2585 did_set_spelltab = FALSE; | |
2586 clear_spell_chartab(&spelltab); | |
2587 if (enc_dbcs) | |
2588 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2589 // DBCS: assume double-wide characters are word characters. |
307 | 2590 for (i = 128; i <= 255; ++i) |
2591 if (MB_BYTE2LEN(i) == 2) | |
2592 spelltab.st_isw[i] = TRUE; | |
2593 } | |
324 | 2594 else if (enc_utf8) |
2595 { | |
2596 for (i = 128; i < 256; ++i) | |
2597 { | |
2140
12aba62fa7c6
updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents:
2046
diff
changeset
|
2598 int f = utf_fold(i); |
12aba62fa7c6
updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents:
2046
diff
changeset
|
2599 int u = utf_toupper(i); |
12aba62fa7c6
updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents:
2046
diff
changeset
|
2600 |
324 | 2601 spelltab.st_isu[i] = utf_isupper(i); |
2602 spelltab.st_isw[i] = spelltab.st_isu[i] || utf_islower(i); | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2603 // The folded/upper-cased value is different between latin1 and |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2604 // utf8 for 0xb5, causing E763 for no good reason. Use the latin1 |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2605 // value for utf-8 to avoid this. |
2140
12aba62fa7c6
updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents:
2046
diff
changeset
|
2606 spelltab.st_fold[i] = (f < 256) ? f : i; |
12aba62fa7c6
updated for version 7.2.422
Bram Moolenaar <bram@zimbu.org>
parents:
2046
diff
changeset
|
2607 spelltab.st_upper[i] = (u < 256) ? u : i; |
324 | 2608 } |
2609 } | |
307 | 2610 else |
2611 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2612 // Rough guess: use locale-dependent library functions. |
307 | 2613 for (i = 128; i < 256; ++i) |
2614 { | |
2615 if (MB_ISUPPER(i)) | |
2616 { | |
324 | 2617 spelltab.st_isw[i] = TRUE; |
307 | 2618 spelltab.st_isu[i] = TRUE; |
2619 spelltab.st_fold[i] = MB_TOLOWER(i); | |
2620 } | |
324 | 2621 else if (MB_ISLOWER(i)) |
2622 { | |
2623 spelltab.st_isw[i] = TRUE; | |
2624 spelltab.st_upper[i] = MB_TOUPPER(i); | |
2625 } | |
307 | 2626 } |
2627 } | |
2628 } | |
2629 | |
2630 | |
2631 /* | |
358 | 2632 * Return TRUE if "p" points to a word character. |
366 | 2633 * As a special case we see "midword" characters as word character when it is |
358 | 2634 * followed by a word character. This finds they'there but not 'they there'. |
366 | 2635 * Thus this only works properly when past the first character of the word. |
358 | 2636 */ |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
2637 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2638 spell_iswordp( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2639 char_u *p, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2640 win_T *wp) // buffer used |
358 | 2641 { |
2642 char_u *s; | |
366 | 2643 int l; |
2644 int c; | |
2645 | |
2646 if (has_mbyte) | |
2647 { | |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18172
diff
changeset
|
2648 l = mb_ptr2len(p); |
358 | 2649 s = p; |
366 | 2650 if (l == 1) |
2651 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2652 // be quick for ASCII |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2653 if (wp->w_s->b_spell_ismw[*p]) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2654 s = p + 1; // skip a mid-word character |
366 | 2655 } |
2656 else | |
2657 { | |
2658 c = mb_ptr2char(p); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2659 if (c < 256 ? wp->w_s->b_spell_ismw[c] |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2660 : (wp->w_s->b_spell_ismw_mb != NULL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2661 && vim_strchr(wp->w_s->b_spell_ismw_mb, c) != NULL)) |
366 | 2662 s = p + l; |
2663 } | |
2664 | |
390 | 2665 c = mb_ptr2char(s); |
2666 if (c > 255) | |
5477 | 2667 return spell_mb_isword_class(mb_get_class(s), wp); |
390 | 2668 return spelltab.st_isw[c]; |
366 | 2669 } |
2670 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2671 return spelltab.st_isw[wp->w_s->b_spell_ismw[*p] ? p[1] : p[0]]; |
376 | 2672 } |
2673 | |
2674 /* | |
2675 * Return TRUE if "p" points to a word character. | |
2676 * Unlike spell_iswordp() this doesn't check for "midword" characters. | |
2677 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
2678 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2679 spell_iswordp_nmw(char_u *p, win_T *wp) |
376 | 2680 { |
390 | 2681 int c; |
2682 | |
2683 if (has_mbyte) | |
2684 { | |
2685 c = mb_ptr2char(p); | |
2686 if (c > 255) | |
5477 | 2687 return spell_mb_isword_class(mb_get_class(p), wp); |
390 | 2688 return spelltab.st_isw[c]; |
2689 } | |
376 | 2690 return spelltab.st_isw[*p]; |
358 | 2691 } |
2692 | |
372 | 2693 /* |
1580 | 2694 * Return TRUE if word class indicates a word character. |
2695 * Only for characters above 255. | |
2696 * Unicode subscript and superscript are not considered word characters. | |
5477 | 2697 * See also dbcs_class() and utf_class() in mbyte.c. |
2698 */ | |
2699 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2700 spell_mb_isword_class(int cl, win_T *wp) |
5477 | 2701 { |
2702 if (wp->w_s->b_cjk) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2703 // East Asian characters are not considered word characters. |
5477 | 2704 return cl == 2 || cl == 0x2800; |
17434
26e8d42987ca
patch 8.1.1715: emoji characters are seen as word characters for spelling
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
2705 return cl >= 2 && cl != 0x2070 && cl != 0x2080 && cl != 3; |
1580 | 2706 } |
2707 | |
2708 /* | |
372 | 2709 * Return TRUE if "p" points to a word character. |
2710 * Wide version of spell_iswordp(). | |
2711 */ | |
2712 static int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2713 spell_iswordp_w(int *p, win_T *wp) |
372 | 2714 { |
2715 int *s; | |
2716 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2717 if (*p < 256 ? wp->w_s->b_spell_ismw[*p] |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2718 : (wp->w_s->b_spell_ismw_mb != NULL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2719 && vim_strchr(wp->w_s->b_spell_ismw_mb, *p) != NULL)) |
372 | 2720 s = p + 1; |
2721 else | |
2722 s = p; | |
2723 | |
390 | 2724 if (*s > 255) |
372 | 2725 { |
2726 if (enc_utf8) | |
5477 | 2727 return spell_mb_isword_class(utf_class(*s), wp); |
372 | 2728 if (enc_dbcs) |
5477 | 2729 return spell_mb_isword_class( |
2730 dbcs_class((unsigned)*s >> 8, *s & 0xff), wp); | |
372 | 2731 return 0; |
2732 } | |
2733 return spelltab.st_isw[*s]; | |
2734 } | |
2735 | |
358 | 2736 /* |
324 | 2737 * Case-fold "str[len]" into "buf[buflen]". The result is NUL terminated. |
2738 * Uses the character definitions from the .spl file. | |
307 | 2739 * When using a multi-byte 'encoding' the length may change! |
2740 * Returns FAIL when something wrong. | |
2741 */ | |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2742 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2743 spell_casefold( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2744 char_u *str, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2745 int len, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2746 char_u *buf, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2747 int buflen) |
307 | 2748 { |
2749 int i; | |
2750 | |
2751 if (len >= buflen) | |
2752 { | |
2753 buf[0] = NUL; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2754 return FAIL; // result will not fit |
307 | 2755 } |
2756 | |
2757 if (has_mbyte) | |
2758 { | |
324 | 2759 int outi = 0; |
2760 char_u *p; | |
307 | 2761 int c; |
2762 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2763 // Fold one character at a time. |
324 | 2764 for (p = str; p < str + len; ) |
307 | 2765 { |
2766 if (outi + MB_MAXBYTES > buflen) | |
2767 { | |
2768 buf[outi] = NUL; | |
2769 return FAIL; | |
2770 } | |
474 | 2771 c = mb_cptr2char_adv(&p); |
324 | 2772 outi += mb_char2bytes(SPELL_TOFOLD(c), buf + outi); |
307 | 2773 } |
2774 buf[outi] = NUL; | |
2775 } | |
2776 else | |
2777 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2778 // Be quick for non-multibyte encodings. |
307 | 2779 for (i = 0; i < len; ++i) |
324 | 2780 buf[i] = spelltab.st_fold[str[i]]; |
307 | 2781 buf[i] = NUL; |
2782 } | |
2783 | |
2784 return OK; | |
2785 } | |
2786 | |
344 | 2787 /* |
475 | 2788 * Check if the word at line "lnum" column "col" is required to start with a |
2789 * capital. This uses 'spellcapcheck' of the current buffer. | |
2790 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
2791 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2792 check_need_cap(linenr_T lnum, colnr_T col) |
475 | 2793 { |
2794 int need_cap = FALSE; | |
2795 char_u *line; | |
2796 char_u *line_copy = NULL; | |
2797 char_u *p; | |
2798 colnr_T endcol; | |
2799 regmatch_T regmatch; | |
2800 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2801 if (curwin->w_s->b_cap_prog == NULL) |
475 | 2802 return FALSE; |
2803 | |
2804 line = ml_get_curline(); | |
2805 endcol = 0; | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
2806 if (getwhitecols(line) >= (int)col) |
475 | 2807 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2808 // At start of line, check if previous line is empty or sentence |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2809 // ends there. |
475 | 2810 if (lnum == 1) |
2811 need_cap = TRUE; | |
2812 else | |
2813 { | |
2814 line = ml_get(lnum - 1); | |
2815 if (*skipwhite(line) == NUL) | |
2816 need_cap = TRUE; | |
2817 else | |
2818 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2819 // Append a space in place of the line break. |
475 | 2820 line_copy = concat_str(line, (char_u *)" "); |
2821 line = line_copy; | |
835 | 2822 endcol = (colnr_T)STRLEN(line); |
475 | 2823 } |
2824 } | |
2825 } | |
2826 else | |
2827 endcol = col; | |
2828 | |
2829 if (endcol > 0) | |
2830 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2831 // Check if sentence ends before the bad word. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
2832 regmatch.regprog = curwin->w_s->b_cap_prog; |
475 | 2833 regmatch.rm_ic = FALSE; |
2834 p = line + endcol; | |
2835 for (;;) | |
2836 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2837 MB_PTR_BACK(line, p); |
5477 | 2838 if (p == line || spell_iswordp_nmw(p, curwin)) |
475 | 2839 break; |
2840 if (vim_regexec(®match, p, 0) | |
2841 && regmatch.endp[0] == line + endcol) | |
2842 { | |
2843 need_cap = TRUE; | |
2844 break; | |
2845 } | |
2846 } | |
6375 | 2847 curwin->w_s->b_cap_prog = regmatch.regprog; |
475 | 2848 } |
2849 | |
2850 vim_free(line_copy); | |
2851 | |
2852 return need_cap; | |
2853 } | |
2854 | |
2855 | |
2856 /* | |
372 | 2857 * ":spellrepall" |
2858 */ | |
2859 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2860 ex_spellrepall(exarg_T *eap UNUSED) |
372 | 2861 { |
2862 pos_T pos = curwin->w_cursor; | |
2863 char_u *frompat; | |
2864 int addlen; | |
2865 char_u *line; | |
2866 char_u *p; | |
2867 int save_ws = p_ws; | |
483 | 2868 linenr_T prev_lnum = 0; |
372 | 2869 |
2870 if (repl_from == NULL || repl_to == NULL) | |
2871 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
2872 emsg(_("E752: No previous spell replacement")); |
372 | 2873 return; |
2874 } | |
835 | 2875 addlen = (int)(STRLEN(repl_to) - STRLEN(repl_from)); |
2876 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
2877 frompat = alloc(STRLEN(repl_from) + 7); |
372 | 2878 if (frompat == NULL) |
2879 return; | |
2880 sprintf((char *)frompat, "\\V\\<%s\\>", repl_from); | |
2881 p_ws = FALSE; | |
2882 | |
483 | 2883 sub_nsubs = 0; |
2884 sub_nlines = 0; | |
372 | 2885 curwin->w_cursor.lnum = 0; |
2886 while (!got_int) | |
2887 { | |
19475
5512aa74cb62
patch 8.2.0295: highlighting for :s wrong when using different separator
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
2888 if (do_search(NULL, '/', '/', frompat, 1L, SEARCH_KEEP, NULL) == 0 |
372 | 2889 || u_save_cursor() == FAIL) |
2890 break; | |
2891 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2892 // Only replace when the right word isn't there yet. This happens |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2893 // when changing "etc" to "etc.". |
372 | 2894 line = ml_get_curline(); |
2895 if (addlen <= 0 || STRNCMP(line + curwin->w_cursor.col, | |
2896 repl_to, STRLEN(repl_to)) != 0) | |
2897 { | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16738
diff
changeset
|
2898 p = alloc(STRLEN(line) + addlen + 1); |
372 | 2899 if (p == NULL) |
2900 break; | |
2901 mch_memmove(p, line, curwin->w_cursor.col); | |
2902 STRCPY(p + curwin->w_cursor.col, repl_to); | |
2903 STRCAT(p, line + curwin->w_cursor.col + STRLEN(repl_from)); | |
2904 ml_replace(curwin->w_cursor.lnum, p, FALSE); | |
2905 changed_bytes(curwin->w_cursor.lnum, curwin->w_cursor.col); | |
483 | 2906 |
2907 if (curwin->w_cursor.lnum != prev_lnum) | |
2908 { | |
2909 ++sub_nlines; | |
2910 prev_lnum = curwin->w_cursor.lnum; | |
2911 } | |
2912 ++sub_nsubs; | |
372 | 2913 } |
835 | 2914 curwin->w_cursor.col += (colnr_T)STRLEN(repl_to); |
372 | 2915 } |
2916 | |
2917 p_ws = save_ws; | |
2918 curwin->w_cursor = pos; | |
2919 vim_free(frompat); | |
2920 | |
483 | 2921 if (sub_nsubs == 0) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15034
diff
changeset
|
2922 semsg(_("E753: Not found: %s"), repl_from); |
483 | 2923 else |
2924 do_sub_msg(FALSE); | |
372 | 2925 } |
2926 | |
2927 /* | |
324 | 2928 * Make a copy of "word", with the first letter upper or lower cased, to |
2929 * "wcopy[MAXWLEN]". "word" must not be empty. | |
2930 * The result is NUL terminated. | |
323 | 2931 */ |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
2932 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2933 onecap_copy( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2934 char_u *word, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2935 char_u *wcopy, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2936 int upper) // TRUE: first letter made upper case |
323 | 2937 { |
2938 char_u *p; | |
2939 int c; | |
2940 int l; | |
2941 | |
2942 p = word; | |
2943 if (has_mbyte) | |
474 | 2944 c = mb_cptr2char_adv(&p); |
323 | 2945 else |
2946 c = *p++; | |
2947 if (upper) | |
324 | 2948 c = SPELL_TOUPPER(c); |
323 | 2949 else |
324 | 2950 c = SPELL_TOFOLD(c); |
323 | 2951 if (has_mbyte) |
2952 l = mb_char2bytes(c, wcopy); | |
2953 else | |
2954 { | |
2955 l = 1; | |
2956 wcopy[0] = c; | |
2957 } | |
376 | 2958 vim_strncpy(wcopy + l, p, MAXWLEN - l - 1); |
323 | 2959 } |
2960 | |
2961 /* | |
324 | 2962 * Make a copy of "word" with all the letters upper cased into |
2963 * "wcopy[MAXWLEN]". The result is NUL terminated. | |
323 | 2964 */ |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
2965 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2966 allcap_copy(char_u *word, char_u *wcopy) |
323 | 2967 { |
2968 char_u *s; | |
2969 char_u *d; | |
2970 int c; | |
2971 | |
2972 d = wcopy; | |
2973 for (s = word; *s != NUL; ) | |
2974 { | |
2975 if (has_mbyte) | |
474 | 2976 c = mb_cptr2char_adv(&s); |
323 | 2977 else |
2978 c = *s++; | |
492 | 2979 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2980 // We only change 0xdf to SS when we are certain latin1 is used. It |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
2981 // would cause weird errors in other 8-bit encodings. |
492 | 2982 if (enc_latin1like && c == 0xdf) |
2983 { | |
2984 c = 'S'; | |
2985 if (d - wcopy >= MAXWLEN - 1) | |
2986 break; | |
2987 *d++ = c; | |
2988 } | |
2989 else | |
2990 c = SPELL_TOUPPER(c); | |
323 | 2991 |
2992 if (has_mbyte) | |
2993 { | |
2994 if (d - wcopy >= MAXWLEN - MB_MAXBYTES) | |
2995 break; | |
2996 d += mb_char2bytes(c, d); | |
2997 } | |
2998 else | |
2999 { | |
3000 if (d - wcopy >= MAXWLEN - 1) | |
3001 break; | |
3002 *d++ = c; | |
3003 } | |
3004 } | |
3005 *d = NUL; | |
3006 } | |
3007 | |
3008 /* | |
455 | 3009 * Case-folding may change the number of bytes: Count nr of chars in |
3010 * fword[flen] and return the byte length of that many chars in "word". | |
3011 */ | |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
3012 int |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3013 nofold_len(char_u *fword, int flen, char_u *word) |
455 | 3014 { |
3015 char_u *p; | |
3016 int i = 0; | |
3017 | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3018 for (p = fword; p < fword + flen; MB_PTR_ADV(p)) |
455 | 3019 ++i; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3020 for (p = word; i > 0; MB_PTR_ADV(p)) |
455 | 3021 --i; |
3022 return (int)(p - word); | |
3023 } | |
3024 | |
323 | 3025 /* |
324 | 3026 * Copy "fword" to "cword", fixing case according to "flags". |
323 | 3027 */ |
18172
6e53d83e021d
patch 8.1.2081: the spell.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
17940
diff
changeset
|
3028 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3029 make_case_word(char_u *fword, char_u *cword, int flags) |
323 | 3030 { |
3031 if (flags & WF_ALLCAP) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3032 // Make it all upper-case |
323 | 3033 allcap_copy(fword, cword); |
3034 else if (flags & WF_ONECAP) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3035 // Make the first letter upper-case |
324 | 3036 onecap_copy(fword, cword, TRUE); |
323 | 3037 else |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3038 // Use goodword as-is. |
323 | 3039 STRCPY(cword, fword); |
3040 } | |
3041 | |
372 | 3042 #if defined(FEAT_EVAL) || defined(PROTO) |
3043 /* | |
3044 * Soundfold a string, for soundfold(). | |
3045 * Result is in allocated memory, NULL for an error. | |
3046 */ | |
3047 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3048 eval_soundfold(char_u *word) |
372 | 3049 { |
3050 langp_T *lp; | |
3051 char_u sound[MAXWLEN]; | |
500 | 3052 int lpi; |
372 | 3053 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3054 if (curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3055 // Use the sound-folding of the first language that supports it. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3056 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3057 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3058 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
372 | 3059 if (lp->lp_slang->sl_sal.ga_len > 0) |
3060 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3061 // soundfold the word |
375 | 3062 spell_soundfold(lp->lp_slang, word, FALSE, sound); |
372 | 3063 return vim_strsave(sound); |
3064 } | |
500 | 3065 } |
372 | 3066 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3067 // No language with sound folding, return word as-is. |
372 | 3068 return vim_strsave(word); |
3069 } | |
3070 #endif | |
3071 | |
323 | 3072 /* |
3073 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]". | |
485 | 3074 * |
3075 * There are many ways to turn a word into a sound-a-like representation. The | |
3076 * oldest is Soundex (1918!). A nice overview can be found in "Approximate | |
3077 * swedish name matching - survey and test of different algorithms" by Klas | |
3078 * Erikson. | |
3079 * | |
3080 * We support two methods: | |
3081 * 1. SOFOFROM/SOFOTO do a simple character mapping. | |
3082 * 2. SAL items define a more advanced sound-folding (and much slower). | |
323 | 3083 */ |
9583
b0c7061d6439
commit https://github.com/vim/vim/commit/9ccfebddc3ff2a3c2853cf706fd4c26f639bf381
Christian Brabandt <cb@256bit.org>
parents:
9570
diff
changeset
|
3084 void |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3085 spell_soundfold( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3086 slang_T *slang, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3087 char_u *inword, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3088 int folded, // "inword" is already case-folded |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3089 char_u *res) |
375 | 3090 { |
3091 char_u fword[MAXWLEN]; | |
3092 char_u *word; | |
3093 | |
3094 if (slang->sl_sofo) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3095 // SOFOFROM and SOFOTO used |
375 | 3096 spell_soundfold_sofo(slang, inword, res); |
3097 else | |
3098 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3099 // SAL items used. Requires the word to be case-folded. |
375 | 3100 if (folded) |
3101 word = inword; | |
3102 else | |
3103 { | |
835 | 3104 (void)spell_casefold(inword, (int)STRLEN(inword), fword, MAXWLEN); |
375 | 3105 word = fword; |
3106 } | |
3107 | |
3108 if (has_mbyte) | |
3109 spell_soundfold_wsal(slang, word, res); | |
3110 else | |
3111 spell_soundfold_sal(slang, word, res); | |
3112 } | |
3113 } | |
3114 | |
3115 /* | |
3116 * Perform sound folding of "inword" into "res" according to SOFOFROM and | |
3117 * SOFOTO lines. | |
3118 */ | |
3119 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3120 spell_soundfold_sofo(slang_T *slang, char_u *inword, char_u *res) |
375 | 3121 { |
3122 char_u *s; | |
3123 int ri = 0; | |
3124 int c; | |
3125 | |
3126 if (has_mbyte) | |
3127 { | |
3128 int prevc = 0; | |
3129 int *ip; | |
3130 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3131 // The sl_sal_first[] table contains the translation for chars up to |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3132 // 255, sl_sal the rest. |
375 | 3133 for (s = inword; *s != NUL; ) |
3134 { | |
474 | 3135 c = mb_cptr2char_adv(&s); |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3136 if (enc_utf8 ? utf_class(c) == 0 : VIM_ISWHITE(c)) |
375 | 3137 c = ' '; |
3138 else if (c < 256) | |
3139 c = slang->sl_sal_first[c]; | |
3140 else | |
3141 { | |
3142 ip = ((int **)slang->sl_sal.ga_data)[c & 0xff]; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3143 if (ip == NULL) // empty list, can't match |
375 | 3144 c = NUL; |
3145 else | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3146 for (;;) // find "c" in the list |
375 | 3147 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3148 if (*ip == 0) // not found |
375 | 3149 { |
3150 c = NUL; | |
3151 break; | |
3152 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3153 if (*ip == c) // match! |
375 | 3154 { |
3155 c = ip[1]; | |
3156 break; | |
3157 } | |
3158 ip += 2; | |
3159 } | |
3160 } | |
3161 | |
3162 if (c != NUL && c != prevc) | |
3163 { | |
3164 ri += mb_char2bytes(c, res + ri); | |
3165 if (ri + MB_MAXBYTES > MAXWLEN) | |
3166 break; | |
3167 prevc = c; | |
3168 } | |
3169 } | |
3170 } | |
3171 else | |
3172 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3173 // The sl_sal_first[] table contains the translation. |
375 | 3174 for (s = inword; (c = *s) != NUL; ++s) |
3175 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3176 if (VIM_ISWHITE(c)) |
375 | 3177 c = ' '; |
3178 else | |
3179 c = slang->sl_sal_first[c]; | |
3180 if (c != NUL && (ri == 0 || res[ri - 1] != c)) | |
3181 res[ri++] = c; | |
3182 } | |
3183 } | |
3184 | |
3185 res[ri] = NUL; | |
3186 } | |
3187 | |
3188 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3189 spell_soundfold_sal(slang_T *slang, char_u *inword, char_u *res) |
323 | 3190 { |
344 | 3191 salitem_T *smp; |
323 | 3192 char_u word[MAXWLEN]; |
375 | 3193 char_u *s = inword; |
323 | 3194 char_u *t; |
344 | 3195 char_u *pf; |
323 | 3196 int i, j, z; |
344 | 3197 int reslen; |
323 | 3198 int n, k = 0; |
3199 int z0; | |
3200 int k0; | |
3201 int n0; | |
3202 int c; | |
3203 int pri; | |
3204 int p0 = -333; | |
3205 int c0; | |
3206 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3207 // Remove accents, if wanted. We actually remove all non-word characters. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3208 // But keep white space. We need a copy, the word may be changed here. |
323 | 3209 if (slang->sl_rem_accents) |
3210 { | |
3211 t = word; | |
375 | 3212 while (*s != NUL) |
323 | 3213 { |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3214 if (VIM_ISWHITE(*s)) |
344 | 3215 { |
3216 *t++ = ' '; | |
3217 s = skipwhite(s); | |
3218 } | |
323 | 3219 else |
3220 { | |
5477 | 3221 if (spell_iswordp_nmw(s, curwin)) |
323 | 3222 *t++ = *s; |
3223 ++s; | |
3224 } | |
3225 } | |
3226 *t = NUL; | |
3227 } | |
3228 else | |
2768 | 3229 vim_strncpy(word, s, MAXWLEN - 1); |
323 | 3230 |
344 | 3231 smp = (salitem_T *)slang->sl_sal.ga_data; |
323 | 3232 |
3233 /* | |
3234 * This comes from Aspell phonet.cpp. Converted from C++ to C. | |
324 | 3235 * Changed to keep spaces. |
323 | 3236 */ |
344 | 3237 i = reslen = z = 0; |
323 | 3238 while ((c = word[i]) != NUL) |
3239 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3240 // Start with the first rule that has the character in the word. |
323 | 3241 n = slang->sl_sal_first[c]; |
3242 z0 = 0; | |
3243 | |
3244 if (n >= 0) | |
3245 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3246 // check all rules for the same letter |
344 | 3247 for (; (s = smp[n].sm_lead)[0] == c; ++n) |
323 | 3248 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3249 // Quickly skip entries that don't match the word. Most |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3250 // entries are less then three chars, optimize for that. |
344 | 3251 k = smp[n].sm_leadlen; |
3252 if (k > 1) | |
323 | 3253 { |
344 | 3254 if (word[i + 1] != s[1]) |
3255 continue; | |
3256 if (k > 2) | |
3257 { | |
3258 for (j = 2; j < k; ++j) | |
3259 if (word[i + j] != s[j]) | |
3260 break; | |
3261 if (j < k) | |
3262 continue; | |
3263 } | |
323 | 3264 } |
3265 | |
375 | 3266 if ((pf = smp[n].sm_oneof) != NULL) |
323 | 3267 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3268 // Check for match with one of the chars in "sm_oneof". |
344 | 3269 while (*pf != NUL && *pf != word[i + k]) |
3270 ++pf; | |
3271 if (*pf == NUL) | |
3272 continue; | |
3273 ++k; | |
323 | 3274 } |
344 | 3275 s = smp[n].sm_rules; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3276 pri = 5; // default priority |
323 | 3277 |
3278 p0 = *s; | |
3279 k0 = k; | |
3280 while (*s == '-' && k > 1) | |
3281 { | |
3282 k--; | |
3283 s++; | |
3284 } | |
3285 if (*s == '<') | |
3286 s++; | |
344 | 3287 if (VIM_ISDIGIT(*s)) |
323 | 3288 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3289 // determine priority |
323 | 3290 pri = *s - '0'; |
3291 s++; | |
3292 } | |
3293 if (*s == '^' && *(s + 1) == '^') | |
3294 s++; | |
3295 | |
3296 if (*s == NUL | |
3297 || (*s == '^' | |
324 | 3298 && (i == 0 || !(word[i - 1] == ' ' |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3299 || spell_iswordp(word + i - 1, curwin))) |
323 | 3300 && (*(s + 1) != '$' |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3301 || (!spell_iswordp(word + i + k0, curwin)))) |
323 | 3302 || (*s == '$' && i > 0 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3303 && spell_iswordp(word + i - 1, curwin) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3304 && (!spell_iswordp(word + i + k0, curwin)))) |
323 | 3305 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3306 // search for followup rules, if: |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3307 // followup and k > 1 and NO '-' in searchstring |
323 | 3308 c0 = word[i + k - 1]; |
3309 n0 = slang->sl_sal_first[c0]; | |
3310 | |
3311 if (slang->sl_followup && k > 1 && n0 >= 0 | |
344 | 3312 && p0 != '-' && word[i + k] != NUL) |
323 | 3313 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3314 // test follow-up rule for "word[i + k]" |
344 | 3315 for ( ; (s = smp[n0].sm_lead)[0] == c0; ++n0) |
323 | 3316 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3317 // Quickly skip entries that don't match the word. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3318 // |
344 | 3319 k0 = smp[n0].sm_leadlen; |
3320 if (k0 > 1) | |
323 | 3321 { |
344 | 3322 if (word[i + k] != s[1]) |
3323 continue; | |
3324 if (k0 > 2) | |
3325 { | |
3326 pf = word + i + k + 1; | |
3327 for (j = 2; j < k0; ++j) | |
3328 if (*pf++ != s[j]) | |
3329 break; | |
3330 if (j < k0) | |
3331 continue; | |
3332 } | |
323 | 3333 } |
344 | 3334 k0 += k - 1; |
3335 | |
375 | 3336 if ((pf = smp[n0].sm_oneof) != NULL) |
323 | 3337 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3338 // Check for match with one of the chars in |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3339 // "sm_oneof". |
344 | 3340 while (*pf != NUL && *pf != word[i + k0]) |
3341 ++pf; | |
3342 if (*pf == NUL) | |
3343 continue; | |
3344 ++k0; | |
323 | 3345 } |
344 | 3346 |
3347 p0 = 5; | |
3348 s = smp[n0].sm_rules; | |
323 | 3349 while (*s == '-') |
3350 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3351 // "k0" gets NOT reduced because |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3352 // "if (k0 == k)" |
323 | 3353 s++; |
3354 } | |
3355 if (*s == '<') | |
3356 s++; | |
344 | 3357 if (VIM_ISDIGIT(*s)) |
323 | 3358 { |
3359 p0 = *s - '0'; | |
3360 s++; | |
3361 } | |
3362 | |
3363 if (*s == NUL | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3364 // *s == '^' cuts |
323 | 3365 || (*s == '$' |
376 | 3366 && !spell_iswordp(word + i + k0, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3367 curwin))) |
323 | 3368 { |
3369 if (k0 == k) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3370 // this is just a piece of the string |
323 | 3371 continue; |
3372 | |
3373 if (p0 < pri) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3374 // priority too low |
323 | 3375 continue; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3376 // rule fits; stop search |
323 | 3377 break; |
3378 } | |
3379 } | |
3380 | |
344 | 3381 if (p0 >= pri && smp[n0].sm_lead[0] == c0) |
323 | 3382 continue; |
3383 } | |
3384 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3385 // replace string |
344 | 3386 s = smp[n].sm_to; |
389 | 3387 if (s == NULL) |
3388 s = (char_u *)""; | |
344 | 3389 pf = smp[n].sm_rules; |
3390 p0 = (vim_strchr(pf, '<') != NULL) ? 1 : 0; | |
323 | 3391 if (p0 == 1 && z == 0) |
3392 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3393 // rule with '<' is used |
344 | 3394 if (reslen > 0 && *s != NUL && (res[reslen - 1] == c |
3395 || res[reslen - 1] == *s)) | |
3396 reslen--; | |
323 | 3397 z0 = 1; |
3398 z = 1; | |
3399 k0 = 0; | |
372 | 3400 while (*s != NUL && word[i + k0] != NUL) |
323 | 3401 { |
3402 word[i + k0] = *s; | |
3403 k0++; | |
3404 s++; | |
3405 } | |
3406 if (k > k0) | |
1619 | 3407 STRMOVE(word + i + k0, word + i + k); |
323 | 3408 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3409 // new "actual letter" |
323 | 3410 c = word[i]; |
3411 } | |
3412 else | |
3413 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3414 // no '<' rule used |
323 | 3415 i += k - 1; |
3416 z = 0; | |
344 | 3417 while (*s != NUL && s[1] != NUL && reslen < MAXWLEN) |
323 | 3418 { |
344 | 3419 if (reslen == 0 || res[reslen - 1] != *s) |
372 | 3420 res[reslen++] = *s; |
323 | 3421 s++; |
3422 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3423 // new "actual letter" |
323 | 3424 c = *s; |
344 | 3425 if (strstr((char *)pf, "^^") != NULL) |
323 | 3426 { |
3427 if (c != NUL) | |
372 | 3428 res[reslen++] = c; |
1619 | 3429 STRMOVE(word, word + i + 1); |
323 | 3430 i = 0; |
3431 z0 = 1; | |
3432 } | |
3433 } | |
3434 break; | |
3435 } | |
3436 } | |
3437 } | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3438 else if (VIM_ISWHITE(c)) |
324 | 3439 { |
3440 c = ' '; | |
3441 k = 1; | |
3442 } | |
323 | 3443 |
3444 if (z0 == 0) | |
3445 { | |
344 | 3446 if (k && !p0 && reslen < MAXWLEN && c != NUL |
3447 && (!slang->sl_collapse || reslen == 0 | |
3448 || res[reslen - 1] != c)) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3449 // condense only double letters |
372 | 3450 res[reslen++] = c; |
323 | 3451 |
3452 i++; | |
3453 z = 0; | |
3454 k = 0; | |
3455 } | |
3456 } | |
3457 | |
344 | 3458 res[reslen] = NUL; |
323 | 3459 } |
3460 | |
372 | 3461 /* |
3462 * Turn "inword" into its sound-a-like equivalent in "res[MAXWLEN]". | |
3463 * Multi-byte version of spell_soundfold(). | |
3464 */ | |
3465 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3466 spell_soundfold_wsal(slang_T *slang, char_u *inword, char_u *res) |
372 | 3467 { |
375 | 3468 salitem_T *smp = (salitem_T *)slang->sl_sal.ga_data; |
372 | 3469 int word[MAXWLEN]; |
3470 int wres[MAXWLEN]; | |
3471 int l; | |
3472 char_u *s; | |
3473 int *ws; | |
3474 char_u *t; | |
3475 int *pf; | |
3476 int i, j, z; | |
3477 int reslen; | |
3478 int n, k = 0; | |
3479 int z0; | |
3480 int k0; | |
3481 int n0; | |
3482 int c; | |
3483 int pri; | |
3484 int p0 = -333; | |
3485 int c0; | |
3486 int did_white = FALSE; | |
3520 | 3487 int wordlen; |
3488 | |
372 | 3489 |
3490 /* | |
3491 * Convert the multi-byte string to a wide-character string. | |
3492 * Remove accents, if wanted. We actually remove all non-word characters. | |
3493 * But keep white space. | |
3494 */ | |
3520 | 3495 wordlen = 0; |
372 | 3496 for (s = inword; *s != NUL; ) |
3497 { | |
3498 t = s; | |
474 | 3499 c = mb_cptr2char_adv(&s); |
372 | 3500 if (slang->sl_rem_accents) |
3501 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3502 if (enc_utf8 ? utf_class(c) == 0 : VIM_ISWHITE(c)) |
372 | 3503 { |
3504 if (did_white) | |
3505 continue; | |
3506 c = ' '; | |
3507 did_white = TRUE; | |
3508 } | |
3509 else | |
3510 { | |
3511 did_white = FALSE; | |
5477 | 3512 if (!spell_iswordp_nmw(t, curwin)) |
372 | 3513 continue; |
3514 } | |
3515 } | |
3520 | 3516 word[wordlen++] = c; |
3517 } | |
3518 word[wordlen] = NUL; | |
372 | 3519 |
3520 /* | |
3520 | 3521 * This algorithm comes from Aspell phonet.cpp. |
372 | 3522 * Converted from C++ to C. Added support for multi-byte chars. |
3523 * Changed to keep spaces. | |
3524 */ | |
3525 i = reslen = z = 0; | |
3526 while ((c = word[i]) != NUL) | |
3527 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3528 // Start with the first rule that has the character in the word. |
372 | 3529 n = slang->sl_sal_first[c & 0xff]; |
3530 z0 = 0; | |
3531 | |
3532 if (n >= 0) | |
3533 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3534 // Check all rules for the same index byte. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3535 // If c is 0x300 need extra check for the end of the array, as |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3536 // (c & 0xff) is NUL. |
2455
9367de3e2e1b
Fix: crash in spell checking with a 0x300 character.
Bram Moolenaar <bram@vim.org>
parents:
2454
diff
changeset
|
3537 for (; ((ws = smp[n].sm_lead_w)[0] & 0xff) == (c & 0xff) |
9367de3e2e1b
Fix: crash in spell checking with a 0x300 character.
Bram Moolenaar <bram@vim.org>
parents:
2454
diff
changeset
|
3538 && ws[0] != NUL; ++n) |
372 | 3539 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3540 // Quickly skip entries that don't match the word. Most |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3541 // entries are less then three chars, optimize for that. |
375 | 3542 if (c != ws[0]) |
3543 continue; | |
372 | 3544 k = smp[n].sm_leadlen; |
3545 if (k > 1) | |
3546 { | |
3547 if (word[i + 1] != ws[1]) | |
3548 continue; | |
3549 if (k > 2) | |
3550 { | |
3551 for (j = 2; j < k; ++j) | |
3552 if (word[i + j] != ws[j]) | |
3553 break; | |
3554 if (j < k) | |
3555 continue; | |
3556 } | |
3557 } | |
3558 | |
375 | 3559 if ((pf = smp[n].sm_oneof_w) != NULL) |
372 | 3560 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3561 // Check for match with one of the chars in "sm_oneof". |
372 | 3562 while (*pf != NUL && *pf != word[i + k]) |
3563 ++pf; | |
3564 if (*pf == NUL) | |
3565 continue; | |
3566 ++k; | |
3567 } | |
3568 s = smp[n].sm_rules; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3569 pri = 5; // default priority |
372 | 3570 |
3571 p0 = *s; | |
3572 k0 = k; | |
3573 while (*s == '-' && k > 1) | |
3574 { | |
3575 k--; | |
3576 s++; | |
3577 } | |
3578 if (*s == '<') | |
3579 s++; | |
3580 if (VIM_ISDIGIT(*s)) | |
3581 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3582 // determine priority |
372 | 3583 pri = *s - '0'; |
3584 s++; | |
3585 } | |
3586 if (*s == '^' && *(s + 1) == '^') | |
3587 s++; | |
3588 | |
3589 if (*s == NUL | |
3590 || (*s == '^' | |
3591 && (i == 0 || !(word[i - 1] == ' ' | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3592 || spell_iswordp_w(word + i - 1, curwin))) |
372 | 3593 && (*(s + 1) != '$' |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3594 || (!spell_iswordp_w(word + i + k0, curwin)))) |
372 | 3595 || (*s == '$' && i > 0 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3596 && spell_iswordp_w(word + i - 1, curwin) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3597 && (!spell_iswordp_w(word + i + k0, curwin)))) |
372 | 3598 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3599 // search for followup rules, if: |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3600 // followup and k > 1 and NO '-' in searchstring |
372 | 3601 c0 = word[i + k - 1]; |
3602 n0 = slang->sl_sal_first[c0 & 0xff]; | |
3603 | |
3604 if (slang->sl_followup && k > 1 && n0 >= 0 | |
3605 && p0 != '-' && word[i + k] != NUL) | |
3606 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3607 // Test follow-up rule for "word[i + k]"; loop over |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3608 // all entries with the same index byte. |
372 | 3609 for ( ; ((ws = smp[n0].sm_lead_w)[0] & 0xff) |
3610 == (c0 & 0xff); ++n0) | |
3611 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3612 // Quickly skip entries that don't match the word. |
375 | 3613 if (c0 != ws[0]) |
3614 continue; | |
372 | 3615 k0 = smp[n0].sm_leadlen; |
3616 if (k0 > 1) | |
3617 { | |
3618 if (word[i + k] != ws[1]) | |
3619 continue; | |
3620 if (k0 > 2) | |
3621 { | |
3622 pf = word + i + k + 1; | |
3623 for (j = 2; j < k0; ++j) | |
3624 if (*pf++ != ws[j]) | |
3625 break; | |
3626 if (j < k0) | |
3627 continue; | |
3628 } | |
3629 } | |
3630 k0 += k - 1; | |
3631 | |
375 | 3632 if ((pf = smp[n0].sm_oneof_w) != NULL) |
372 | 3633 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3634 // Check for match with one of the chars in |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3635 // "sm_oneof". |
372 | 3636 while (*pf != NUL && *pf != word[i + k0]) |
3637 ++pf; | |
3638 if (*pf == NUL) | |
3639 continue; | |
3640 ++k0; | |
3641 } | |
3642 | |
3643 p0 = 5; | |
3644 s = smp[n0].sm_rules; | |
3645 while (*s == '-') | |
3646 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3647 // "k0" gets NOT reduced because |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3648 // "if (k0 == k)" |
372 | 3649 s++; |
3650 } | |
3651 if (*s == '<') | |
3652 s++; | |
3653 if (VIM_ISDIGIT(*s)) | |
3654 { | |
3655 p0 = *s - '0'; | |
3656 s++; | |
3657 } | |
3658 | |
3659 if (*s == NUL | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3660 // *s == '^' cuts |
372 | 3661 || (*s == '$' |
376 | 3662 && !spell_iswordp_w(word + i + k0, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3663 curwin))) |
372 | 3664 { |
3665 if (k0 == k) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3666 // this is just a piece of the string |
372 | 3667 continue; |
3668 | |
3669 if (p0 < pri) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3670 // priority too low |
372 | 3671 continue; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3672 // rule fits; stop search |
372 | 3673 break; |
3674 } | |
3675 } | |
3676 | |
3677 if (p0 >= pri && (smp[n0].sm_lead_w[0] & 0xff) | |
3678 == (c0 & 0xff)) | |
3679 continue; | |
3680 } | |
3681 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3682 // replace string |
372 | 3683 ws = smp[n].sm_to_w; |
3684 s = smp[n].sm_rules; | |
3685 p0 = (vim_strchr(s, '<') != NULL) ? 1 : 0; | |
3686 if (p0 == 1 && z == 0) | |
3687 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3688 // rule with '<' is used |
389 | 3689 if (reslen > 0 && ws != NULL && *ws != NUL |
3690 && (wres[reslen - 1] == c | |
372 | 3691 || wres[reslen - 1] == *ws)) |
3692 reslen--; | |
3693 z0 = 1; | |
3694 z = 1; | |
3695 k0 = 0; | |
389 | 3696 if (ws != NULL) |
3697 while (*ws != NUL && word[i + k0] != NUL) | |
3698 { | |
3699 word[i + k0] = *ws; | |
3700 k0++; | |
3701 ws++; | |
3702 } | |
372 | 3703 if (k > k0) |
3704 mch_memmove(word + i + k0, word + i + k, | |
3520 | 3705 sizeof(int) * (wordlen - (i + k) + 1)); |
372 | 3706 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3707 // new "actual letter" |
372 | 3708 c = word[i]; |
3709 } | |
3710 else | |
3711 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3712 // no '<' rule used |
372 | 3713 i += k - 1; |
3714 z = 0; | |
389 | 3715 if (ws != NULL) |
3716 while (*ws != NUL && ws[1] != NUL | |
3717 && reslen < MAXWLEN) | |
3718 { | |
3719 if (reslen == 0 || wres[reslen - 1] != *ws) | |
3720 wres[reslen++] = *ws; | |
3721 ws++; | |
3722 } | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3723 // new "actual letter" |
389 | 3724 if (ws == NULL) |
3725 c = NUL; | |
3726 else | |
3727 c = *ws; | |
372 | 3728 if (strstr((char *)s, "^^") != NULL) |
3729 { | |
3730 if (c != NUL) | |
3731 wres[reslen++] = c; | |
3732 mch_memmove(word, word + i + 1, | |
3520 | 3733 sizeof(int) * (wordlen - (i + 1) + 1)); |
372 | 3734 i = 0; |
3735 z0 = 1; | |
3736 } | |
3737 } | |
3738 break; | |
3739 } | |
3740 } | |
3741 } | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
3742 else if (VIM_ISWHITE(c)) |
372 | 3743 { |
3744 c = ' '; | |
3745 k = 1; | |
3746 } | |
3747 | |
3748 if (z0 == 0) | |
3749 { | |
3750 if (k && !p0 && reslen < MAXWLEN && c != NUL | |
3751 && (!slang->sl_collapse || reslen == 0 | |
3752 || wres[reslen - 1] != c)) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3753 // condense only double letters |
372 | 3754 wres[reslen++] = c; |
3755 | |
3756 i++; | |
3757 z = 0; | |
3758 k = 0; | |
3759 } | |
3760 } | |
3761 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3762 // Convert wide characters in "wres" to a multi-byte string in "res". |
372 | 3763 l = 0; |
3764 for (n = 0; n < reslen; ++n) | |
3765 { | |
3766 l += mb_char2bytes(wres[n], res + l); | |
3767 if (l + MB_MAXBYTES > MAXWLEN) | |
3768 break; | |
3769 } | |
3770 res[l] = NUL; | |
3771 } | |
3772 | |
324 | 3773 /* |
714 | 3774 * ":spellinfo" |
3775 */ | |
3776 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3777 ex_spellinfo(exarg_T *eap UNUSED) |
714 | 3778 { |
3779 int lpi; | |
3780 langp_T *lp; | |
3781 char_u *p; | |
3782 | |
3783 if (no_spell_checking(curwin)) | |
3784 return; | |
3785 | |
3786 msg_start(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3787 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len && !got_int; ++lpi) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3788 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3789 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3790 msg_puts("file: "); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3791 msg_puts((char *)lp->lp_slang->sl_fname); |
714 | 3792 msg_putchar('\n'); |
3793 p = lp->lp_slang->sl_info; | |
3794 if (p != NULL) | |
3795 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3796 msg_puts((char *)p); |
714 | 3797 msg_putchar('\n'); |
3798 } | |
3799 } | |
3800 msg_end(); | |
3801 } | |
3802 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3803 #define DUMPFLAG_KEEPCASE 1 // round 2: keep-case tree |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3804 #define DUMPFLAG_COUNT 2 // include word count |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3805 #define DUMPFLAG_ICASE 4 // ignore case when finding matches |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3806 #define DUMPFLAG_ONECAP 8 // pattern starts with capital |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3807 #define DUMPFLAG_ALLCAP 16 // pattern is all capitals |
625 | 3808 |
351 | 3809 /* |
3810 * ":spelldump" | |
3811 */ | |
3812 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3813 ex_spelldump(exarg_T *eap) |
351 | 3814 { |
5382 | 3815 char_u *spl; |
3816 long dummy; | |
3817 | |
701 | 3818 if (no_spell_checking(curwin)) |
3819 return; | |
5382 | 3820 get_option_value((char_u*)"spl", &dummy, &spl, OPT_LOCAL); |
3821 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3822 // Create a new empty buffer in a new window. |
701 | 3823 do_cmdline_cmd((char_u *)"new"); |
5382 | 3824 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3825 // enable spelling locally in the new window |
5382 | 3826 set_option_value((char_u*)"spell", TRUE, (char_u*)"", OPT_LOCAL); |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
6949
diff
changeset
|
3827 set_option_value((char_u*)"spl", dummy, spl, OPT_LOCAL); |
5382 | 3828 vim_free(spl); |
3829 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10950
diff
changeset
|
3830 if (!BUFEMPTY()) |
701 | 3831 return; |
3832 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3833 spell_dump_compl(NULL, 0, NULL, eap->forceit ? DUMPFLAG_COUNT : 0); |
701 | 3834 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3835 // Delete the empty line that we started with. |
701 | 3836 if (curbuf->b_ml.ml_line_count > 1) |
20599
d571231175b4
patch 8.2.0853: ml_delete() often called with FALSE argument
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
3837 ml_delete(curbuf->b_ml.ml_line_count); |
701 | 3838 |
3839 redraw_later(NOT_VALID); | |
3840 } | |
3841 | |
3842 /* | |
3843 * Go through all possible words and: | |
3844 * 1. When "pat" is NULL: dump a list of all words in the current buffer. | |
3845 * "ic" and "dir" are not used. | |
3846 * 2. When "pat" is not NULL: add matching words to insert mode completion. | |
3847 */ | |
3848 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3849 spell_dump_compl( |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3850 char_u *pat, // leading part of the word |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3851 int ic, // ignore case |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3852 int *dir, // direction for adding matches |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3853 int dumpflags_arg) // DUMPFLAG_* |
701 | 3854 { |
351 | 3855 langp_T *lp; |
3856 slang_T *slang; | |
3857 idx_T arridx[MAXWLEN]; | |
3858 int curi[MAXWLEN]; | |
3859 char_u word[MAXWLEN]; | |
3860 int c; | |
3861 char_u *byts; | |
3862 idx_T *idxs; | |
3863 linenr_T lnum = 0; | |
3864 int round; | |
3865 int depth; | |
3866 int n; | |
3867 int flags; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3868 char_u *region_names = NULL; // region names being used |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3869 int do_region = TRUE; // dump region names and numbers |
381 | 3870 char_u *p; |
500 | 3871 int lpi; |
701 | 3872 int dumpflags = dumpflags_arg; |
3873 int patlen; | |
3874 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3875 // When ignoring case or when the pattern starts with capital pass this on |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3876 // to dump_word(). |
710 | 3877 if (pat != NULL) |
3878 { | |
3879 if (ic) | |
3880 dumpflags |= DUMPFLAG_ICASE; | |
3881 else | |
3882 { | |
3883 n = captype(pat, NULL); | |
3884 if (n == WF_ONECAP) | |
3885 dumpflags |= DUMPFLAG_ONECAP; | |
15605
62b3805506b3
patch 8.1.0810: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
3886 else if (n == WF_ALLCAP && (int)STRLEN(pat) > mb_ptr2len(pat)) |
710 | 3887 dumpflags |= DUMPFLAG_ALLCAP; |
3888 } | |
3889 } | |
351 | 3890 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3891 // Find out if we can support regions: All languages must support the same |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3892 // regions or none at all. |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3893 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3894 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3895 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
381 | 3896 p = lp->lp_slang->sl_regions; |
3897 if (p[0] != 0) | |
3898 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3899 if (region_names == NULL) // first language with regions |
381 | 3900 region_names = p; |
3901 else if (STRCMP(region_names, p) != 0) | |
3902 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3903 do_region = FALSE; // region names are different |
381 | 3904 break; |
3905 } | |
3906 } | |
3907 } | |
3908 | |
3909 if (do_region && region_names != NULL) | |
3910 { | |
701 | 3911 if (pat == NULL) |
3912 { | |
3913 vim_snprintf((char *)IObuff, IOSIZE, "/regions=%s", region_names); | |
3914 ml_append(lnum++, IObuff, (colnr_T)0, FALSE); | |
3915 } | |
381 | 3916 } |
3917 else | |
3918 do_region = FALSE; | |
3919 | |
3920 /* | |
3921 * Loop over all files loaded for the entries in 'spelllang'. | |
3922 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3923 for (lpi = 0; lpi < curwin->w_s->b_langp.ga_len; ++lpi) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3924 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
3925 lp = LANGP_ENTRY(curwin->w_s->b_langp, lpi); |
351 | 3926 slang = lp->lp_slang; |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3927 if (slang->sl_fbyts == NULL) // reloading failed |
500 | 3928 continue; |
351 | 3929 |
701 | 3930 if (pat == NULL) |
3931 { | |
3932 vim_snprintf((char *)IObuff, IOSIZE, "# file: %s", slang->sl_fname); | |
3933 ml_append(lnum++, IObuff, (colnr_T)0, FALSE); | |
3934 } | |
3935 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3936 // When matching with a pattern and there are no prefixes only use |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3937 // parts of the tree that match "pat". |
701 | 3938 if (pat != NULL && slang->sl_pbyts == NULL) |
835 | 3939 patlen = (int)STRLEN(pat); |
701 | 3940 else |
840 | 3941 patlen = -1; |
351 | 3942 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3943 // round 1: case-folded tree |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3944 // round 2: keep-case tree |
351 | 3945 for (round = 1; round <= 2; ++round) |
3946 { | |
3947 if (round == 1) | |
3948 { | |
701 | 3949 dumpflags &= ~DUMPFLAG_KEEPCASE; |
351 | 3950 byts = slang->sl_fbyts; |
3951 idxs = slang->sl_fidxs; | |
3952 } | |
3953 else | |
3954 { | |
701 | 3955 dumpflags |= DUMPFLAG_KEEPCASE; |
351 | 3956 byts = slang->sl_kbyts; |
3957 idxs = slang->sl_kidxs; | |
3958 } | |
3959 if (byts == NULL) | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3960 continue; // array is empty |
351 | 3961 |
3962 depth = 0; | |
3963 arridx[0] = 0; | |
3964 curi[0] = 1; | |
701 | 3965 while (depth >= 0 && !got_int |
16142
570a296aa0b4
patch 8.1.1076: file for Insert mode is much too big
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
3966 && (pat == NULL || !ins_compl_interrupted())) |
351 | 3967 { |
3968 if (curi[depth] > byts[arridx[depth]]) | |
3969 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3970 // Done all bytes at this node, go up one level. |
351 | 3971 --depth; |
3972 line_breakcheck(); | |
10277
154d5a2e7395
commit https://github.com/vim/vim/commit/472e85970ee3a80abd824bef510df12e9cfe9e96
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
3973 ins_compl_check_keys(50, FALSE); |
351 | 3974 } |
3975 else | |
3976 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3977 // Do one more byte at this node. |
351 | 3978 n = arridx[depth] + curi[depth]; |
3979 ++curi[depth]; | |
3980 c = byts[n]; | |
3981 if (c == 0) | |
3982 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3983 // End of word, deal with the word. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3984 // Don't use keep-case words in the fold-case tree, |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3985 // they will appear in the keep-case tree. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3986 // Only use the word when the region matches. |
351 | 3987 flags = (int)idxs[n]; |
3988 if ((round == 2 || (flags & WF_KEEPCAP) == 0) | |
500 | 3989 && (flags & WF_NEEDCOMP) == 0 |
381 | 3990 && (do_region |
3991 || (flags & WF_REGION) == 0 | |
390 | 3992 || (((unsigned)flags >> 16) |
351 | 3993 & lp->lp_region) != 0)) |
3994 { | |
3995 word[depth] = NUL; | |
381 | 3996 if (!do_region) |
3997 flags &= ~WF_REGION; | |
355 | 3998 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
3999 // Dump the basic word if there is no prefix or |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4000 // when it's the first one. |
390 | 4001 c = (unsigned)flags >> 24; |
355 | 4002 if (c == 0 || curi[depth] == 2) |
701 | 4003 { |
4004 dump_word(slang, word, pat, dir, | |
4005 dumpflags, flags, lnum); | |
4006 if (pat == NULL) | |
4007 ++lnum; | |
4008 } | |
351 | 4009 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4010 // Apply the prefix, if there is one. |
355 | 4011 if (c != 0) |
701 | 4012 lnum = dump_prefixes(slang, word, pat, dir, |
4013 dumpflags, flags, lnum); | |
351 | 4014 } |
4015 } | |
4016 else | |
4017 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4018 // Normal char, go one level deeper. |
351 | 4019 word[depth++] = c; |
4020 arridx[depth] = idxs[n]; | |
4021 curi[depth] = 1; | |
701 | 4022 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4023 // Check if this characters matches with the pattern. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4024 // If not skip the whole tree below it. |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4025 // Always ignore case here, dump_word() will check |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4026 // proper case later. This isn't exactly right when |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4027 // length changes for multi-byte characters with |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4028 // ignore case... |
710 | 4029 if (depth <= patlen |
4030 && MB_STRNICMP(word, pat, depth) != 0) | |
701 | 4031 --depth; |
351 | 4032 } |
4033 } | |
4034 } | |
4035 } | |
4036 } | |
4037 } | |
4038 | |
4039 /* | |
4040 * Dump one word: apply case modifications and append a line to the buffer. | |
701 | 4041 * When "lnum" is zero add insert mode completion. |
4042 */ | |
4043 static void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4044 dump_word( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4045 slang_T *slang, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4046 char_u *word, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4047 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4048 int *dir, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4049 int dumpflags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4050 int wordflags, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4051 linenr_T lnum) |
351 | 4052 { |
4053 int keepcap = FALSE; | |
4054 char_u *p; | |
625 | 4055 char_u *tw; |
351 | 4056 char_u cword[MAXWLEN]; |
381 | 4057 char_u badword[MAXWLEN + 10]; |
4058 int i; | |
710 | 4059 int flags = wordflags; |
4060 | |
4061 if (dumpflags & DUMPFLAG_ONECAP) | |
4062 flags |= WF_ONECAP; | |
4063 if (dumpflags & DUMPFLAG_ALLCAP) | |
4064 flags |= WF_ALLCAP; | |
351 | 4065 |
625 | 4066 if ((dumpflags & DUMPFLAG_KEEPCASE) == 0 && (flags & WF_CAPMASK) != 0) |
351 | 4067 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4068 // Need to fix case according to "flags". |
351 | 4069 make_case_word(word, cword, flags); |
4070 p = cword; | |
4071 } | |
4072 else | |
4073 { | |
4074 p = word; | |
625 | 4075 if ((dumpflags & DUMPFLAG_KEEPCASE) |
4076 && ((captype(word, NULL) & WF_KEEPCAP) == 0 | |
389 | 4077 || (flags & WF_FIXCAP) != 0)) |
351 | 4078 keepcap = TRUE; |
4079 } | |
625 | 4080 tw = p; |
351 | 4081 |
701 | 4082 if (pat == NULL) |
4083 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4084 // Add flags and regions after a slash. |
701 | 4085 if ((flags & (WF_BANNED | WF_RARE | WF_REGION)) || keepcap) |
4086 { | |
4087 STRCPY(badword, p); | |
4088 STRCAT(badword, "/"); | |
4089 if (keepcap) | |
4090 STRCAT(badword, "="); | |
4091 if (flags & WF_BANNED) | |
4092 STRCAT(badword, "!"); | |
4093 else if (flags & WF_RARE) | |
4094 STRCAT(badword, "?"); | |
4095 if (flags & WF_REGION) | |
4096 for (i = 0; i < 7; ++i) | |
4097 if (flags & (0x10000 << i)) | |
4098 sprintf((char *)badword + STRLEN(badword), "%d", i + 1); | |
4099 p = badword; | |
4100 } | |
4101 | |
4102 if (dumpflags & DUMPFLAG_COUNT) | |
4103 { | |
4104 hashitem_T *hi; | |
4105 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4106 // Include the word count for ":spelldump!". |
701 | 4107 hi = hash_find(&slang->sl_wordcount, tw); |
4108 if (!HASHITEM_EMPTY(hi)) | |
4109 { | |
4110 vim_snprintf((char *)IObuff, IOSIZE, "%s\t%d", | |
625 | 4111 tw, HI2WC(hi)->wc_count); |
701 | 4112 p = IObuff; |
4113 } | |
4114 } | |
4115 | |
4116 ml_append(lnum, p, (colnr_T)0, FALSE); | |
4117 } | |
710 | 4118 else if (((dumpflags & DUMPFLAG_ICASE) |
4119 ? MB_STRNICMP(p, pat, STRLEN(pat)) == 0 | |
4120 : STRNCMP(p, pat, STRLEN(pat)) == 0) | |
701 | 4121 && ins_compl_add_infercase(p, (int)STRLEN(p), |
16239
5df26b29e809
patch 8.1.1124: insert completion flags are mixed up
Bram Moolenaar <Bram@vim.org>
parents:
16162
diff
changeset
|
4122 p_ic, NULL, *dir, FALSE) == OK) |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4123 // if dir was BACKWARD then honor it just once |
710 | 4124 *dir = FORWARD; |
351 | 4125 } |
4126 | |
4127 /* | |
372 | 4128 * For ":spelldump": Find matching prefixes for "word". Prepend each to |
4129 * "word" and append a line to the buffer. | |
701 | 4130 * When "lnum" is zero add insert mode completion. |
351 | 4131 * Return the updated line number. |
4132 */ | |
4133 static linenr_T | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4134 dump_prefixes( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4135 slang_T *slang, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4136 char_u *word, // case-folded word |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4137 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4138 int *dir, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4139 int dumpflags, |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4140 int flags, // flags with prefix ID |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4141 linenr_T startlnum) |
351 | 4142 { |
4143 idx_T arridx[MAXWLEN]; | |
4144 int curi[MAXWLEN]; | |
4145 char_u prefix[MAXWLEN]; | |
455 | 4146 char_u word_up[MAXWLEN]; |
4147 int has_word_up = FALSE; | |
351 | 4148 int c; |
4149 char_u *byts; | |
4150 idx_T *idxs; | |
4151 linenr_T lnum = startlnum; | |
4152 int depth; | |
4153 int n; | |
4154 int len; | |
4155 int i; | |
4156 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4157 // If the word starts with a lower-case letter make the word with an |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4158 // upper-case letter in word_up[]. |
455 | 4159 c = PTR2CHAR(word); |
4160 if (SPELL_TOUPPER(c) != c) | |
4161 { | |
4162 onecap_copy(word, word_up, TRUE); | |
4163 has_word_up = TRUE; | |
4164 } | |
4165 | |
351 | 4166 byts = slang->sl_pbyts; |
4167 idxs = slang->sl_pidxs; | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4168 if (byts != NULL) // array not is empty |
351 | 4169 { |
4170 /* | |
4171 * Loop over all prefixes, building them byte-by-byte in prefix[]. | |
390 | 4172 * When at the end of a prefix check that it supports "flags". |
351 | 4173 */ |
4174 depth = 0; | |
4175 arridx[0] = 0; | |
4176 curi[0] = 1; | |
4177 while (depth >= 0 && !got_int) | |
4178 { | |
390 | 4179 n = arridx[depth]; |
4180 len = byts[n]; | |
4181 if (curi[depth] > len) | |
351 | 4182 { |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4183 // Done all bytes at this node, go up one level. |
351 | 4184 --depth; |
4185 line_breakcheck(); | |
4186 } | |
4187 else | |
4188 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4189 // Do one more byte at this node. |
390 | 4190 n += curi[depth]; |
351 | 4191 ++curi[depth]; |
4192 c = byts[n]; | |
4193 if (c == 0) | |
4194 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4195 // End of prefix, find out how many IDs there are. |
351 | 4196 for (i = 1; i < len; ++i) |
4197 if (byts[n + i] != 0) | |
4198 break; | |
4199 curi[depth] += i - 1; | |
4200 | |
455 | 4201 c = valid_word_prefix(i, n, flags, word, slang, FALSE); |
4202 if (c != 0) | |
351 | 4203 { |
376 | 4204 vim_strncpy(prefix + depth, word, MAXWLEN - depth - 1); |
701 | 4205 dump_word(slang, prefix, pat, dir, dumpflags, |
455 | 4206 (c & WF_RAREPFX) ? (flags | WF_RARE) |
701 | 4207 : flags, lnum); |
4208 if (lnum != 0) | |
4209 ++lnum; | |
351 | 4210 } |
455 | 4211 |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4212 // Check for prefix that matches the word when the |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4213 // first letter is upper-case, but only if the prefix has |
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4214 // a condition. |
455 | 4215 if (has_word_up) |
4216 { | |
4217 c = valid_word_prefix(i, n, flags, word_up, slang, | |
4218 TRUE); | |
4219 if (c != 0) | |
4220 { | |
4221 vim_strncpy(prefix + depth, word_up, | |
4222 MAXWLEN - depth - 1); | |
701 | 4223 dump_word(slang, prefix, pat, dir, dumpflags, |
455 | 4224 (c & WF_RAREPFX) ? (flags | WF_RARE) |
701 | 4225 : flags, lnum); |
4226 if (lnum != 0) | |
4227 ++lnum; | |
455 | 4228 } |
4229 } | |
351 | 4230 } |
4231 else | |
4232 { | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4233 // Normal char, go one level deeper. |
351 | 4234 prefix[depth++] = c; |
4235 arridx[depth] = idxs[n]; | |
4236 curi[depth] = 1; | |
4237 } | |
4238 } | |
4239 } | |
4240 } | |
4241 | |
4242 return lnum; | |
4243 } | |
4244 | |
498 | 4245 /* |
626 | 4246 * Move "p" to the end of word "start". |
4247 * Uses the spell-checking word characters. | |
498 | 4248 */ |
4249 char_u * | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4250 spell_to_word_end(char_u *start, win_T *win) |
498 | 4251 { |
4252 char_u *p = start; | |
4253 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
4254 while (*p != NUL && spell_iswordp(p, win)) |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4255 MB_PTR_ADV(p); |
498 | 4256 return p; |
4257 } | |
4258 | |
475 | 4259 /* |
626 | 4260 * For Insert mode completion CTRL-X s: |
4261 * Find start of the word in front of column "startcol". | |
4262 * We don't check if it is badly spelled, with completion we can only change | |
4263 * the word in front of the cursor. | |
475 | 4264 * Returns the column number of the word. |
4265 */ | |
4266 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4267 spell_word_start(int startcol) |
475 | 4268 { |
4269 char_u *line; | |
4270 char_u *p; | |
4271 int col = 0; | |
4272 | |
498 | 4273 if (no_spell_checking(curwin)) |
475 | 4274 return startcol; |
4275 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4276 // Find a word character before "startcol". |
475 | 4277 line = ml_get_curline(); |
4278 for (p = line + startcol; p > line; ) | |
4279 { | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4280 MB_PTR_BACK(line, p); |
5477 | 4281 if (spell_iswordp_nmw(p, curwin)) |
475 | 4282 break; |
4283 } | |
4284 | |
18814
7e7ec935e7c8
patch 8.1.2395: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18358
diff
changeset
|
4285 // Go back to start of the word. |
475 | 4286 while (p > line) |
4287 { | |
835 | 4288 col = (int)(p - line); |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4289 MB_PTR_BACK(line, p); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2229
diff
changeset
|
4290 if (!spell_iswordp(p, curwin)) |
475 | 4291 break; |
4292 col = 0; | |
4293 } | |
4294 | |
535 | 4295 return col; |
4296 } | |
4297 | |
4298 /* | |
4299 * Need to check for 'spellcapcheck' now, the word is removed before | |
4300 * expand_spelling() is called. Therefore the ugly global variable. | |
4301 */ | |
4302 static int spell_expand_need_cap; | |
4303 | |
4304 void | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4305 spell_expand_check_cap(colnr_T col) |
535 | 4306 { |
475 | 4307 spell_expand_need_cap = check_need_cap(curwin->w_cursor.lnum, col); |
4308 } | |
4309 | |
4310 /* | |
4311 * Get list of spelling suggestions. | |
4312 * Used for Insert mode completion CTRL-X ?. | |
4313 * Returns the number of matches. The matches are in "matchp[]", array of | |
4314 * allocated strings. | |
4315 */ | |
4316 int | |
7835
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4317 expand_spelling( |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4318 linenr_T lnum UNUSED, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4319 char_u *pat, |
4d7ce6c03fda
commit https://github.com/vim/vim/commit/764b23c8fd3369cb05ae9122abf3ca16fec539d7
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4320 char_u ***matchp) |
475 | 4321 { |
4322 garray_T ga; | |
4323 | |
625 | 4324 spell_suggest_list(&ga, pat, 100, spell_expand_need_cap, TRUE); |
475 | 4325 *matchp = ga.ga_data; |
4326 return ga.ga_len; | |
4327 } | |
4328 | |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4329 /* |
20760
813b9a7064a4
patch 8.2.0932: missspelling spelllang
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4330 * Return TRUE if "val" is a valid 'spelllang' value. |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4331 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4332 int |
20760
813b9a7064a4
patch 8.2.0932: missspelling spelllang
Bram Moolenaar <Bram@vim.org>
parents:
20599
diff
changeset
|
4333 valid_spelllang(char_u *val) |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4334 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4335 return valid_name(val, ".-_,@"); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4336 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4337 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4338 /* |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4339 * Return TRUE if "val" is a valid 'spellfile' value. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4340 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4341 int |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4342 valid_spellfile(char_u *val) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4343 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4344 char_u *s; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4345 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4346 for (s = val; *s != NUL; ++s) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4347 if (!vim_isfilec(*s) && *s != ',') |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4348 return FALSE; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4349 return TRUE; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4350 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4351 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4352 /* |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4353 * Handle side effects of setting 'spell'. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4354 * Return an error message or NULL for success. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4355 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4356 char * |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4357 did_set_spell_option(int is_spellfile) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4358 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4359 char *errmsg = NULL; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4360 win_T *wp; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4361 int l; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4362 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4363 if (is_spellfile) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4364 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4365 l = (int)STRLEN(curwin->w_s->b_p_spf); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4366 if (l > 0 && (l < 4 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4367 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0)) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4368 errmsg = e_invarg; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4369 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4370 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4371 if (errmsg == NULL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4372 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4373 FOR_ALL_WINDOWS(wp) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4374 if (wp->w_buffer == curbuf && wp->w_p_spell) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4375 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4376 errmsg = did_set_spelllang(wp); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4377 break; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4378 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4379 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4380 return errmsg; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4381 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4382 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4383 /* |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4384 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4385 * Return error message when failed, NULL when OK. |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4386 */ |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4387 char * |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4388 compile_cap_prog(synblock_T *synblock) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4389 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4390 regprog_T *rp = synblock->b_cap_prog; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4391 char_u *re; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4392 |
18305
f4db8631d9c5
patch 8.1.2147: crash when allocating memory fails
Bram Moolenaar <Bram@vim.org>
parents:
18251
diff
changeset
|
4393 if (synblock->b_p_spc == NULL || *synblock->b_p_spc == NUL) |
17940
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4394 synblock->b_cap_prog = NULL; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4395 else |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4396 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4397 // Prepend a ^ so that we only match at one column |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4398 re = concat_str((char_u *)"^", synblock->b_p_spc); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4399 if (re != NULL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4400 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4401 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4402 vim_free(re); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4403 if (synblock->b_cap_prog == NULL) |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4404 { |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4405 synblock->b_cap_prog = rp; // restore the previous program |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4406 return e_invarg; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4407 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4408 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4409 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4410 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4411 vim_regfree(rp); |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4412 return NULL; |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4413 } |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4414 |
079e10a49ea1
patch 8.1.1966: some code in options.c fits better elsewhere
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
4415 #endif // FEAT_SPELL |