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